gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 38/49: examples/web: Implement searching form.


From: gnunet
Subject: [gnunet-scheme] 38/49: examples/web: Implement searching form.
Date: Sat, 25 Dec 2021 23:00:15 +0100

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit 128a9765217561dcc2a75bebd1f5d452dde54d6c
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Tue Oct 5 09:40:28 2021 +0000

    examples/web: Implement searching form.
    
    * examples/web.scm
      (search-form)[method]: Change to "post" for now.
      (process-search-dht): New procedure.
      (url-handler)[/search-dht]: Call 'process-search-dht' if there is a body.
---
 examples/web.scm | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/examples/web.scm b/examples/web.scm
index 01b47f0..68b7083 100644
--- a/examples/web.scm
+++ b/examples/web.scm
@@ -21,6 +21,7 @@
   #:declarative? #f)
 
 (use-modules (fibers)
+            (fibers conditions)
             (rnrs bytevectors)
             (gnu extractor enum)
             (gnu gnunet block)
@@ -78,7 +79,7 @@
 
 (define search-form
   `(form
-    (@ (action "/search-dht") (method "get"))
+    (@ (action "/search-dht") (method "post")) ; TODO should be "get"
     (ul ,@(common-get/put-form-parts "get-"))
     (input (@ (type "submit") (value "Search the DHT")))))
 
@@ -118,6 +119,24 @@
            (decode (assoc-ref parameters "data-encoding")
                    (assoc-ref parameters "data"))))
 
+(define (process-search-dht dht-server parameters)
+  (define what)
+  (define found? (make-condition))
+  (define (found . stuff)
+    (set! what stuff)
+    (signal-condition! found?))
+  (dht:start-get! dht-server
+                 (string->number (assoc-ref parameters "type"))
+                 (decode (assoc-ref parameters "key-encoding")
+                         (assoc-ref parameters "key"))
+                 found
+                 #:desired-replication-level
+                 (string->number (assoc-ref parameters "replication-level")))
+  (wait found?)
+  ;; TODO: properly format the result, streaming, stop searching
+  ;; after something has been found or if the client closes the connection ...
+  (respond/html `(p "Found! " ,(object->string what))))
+
 (define-once started? #f)
 
 (define (url-handler dht-server server request body)
@@ -136,7 +155,10 @@
        (if current-estimate
            (estimate->html current-estimate)
            '(p "No etimate yet")))))
-    ("/search-dht" (respond/html search-form))
+    ("/search-dht" ; TODO check method and Content-Type, validation ...
+     (if (pk 'b body)
+        (process-search-dht dht-server (urlencoded->alist body))
+        (respond/html search-form)))
     ("/put-dht" ; TODO check method and Content-Type, validation ...
      (if body
         (begin

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]