gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 27/49: examples/web: Process DHT insertion forms.


From: gnunet
Subject: [gnunet-scheme] 27/49: examples/web: Process DHT insertion forms.
Date: Sat, 25 Dec 2021 23:00:04 +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 a3dd8cec064d16a5910cfc4cfdde1e0edc89b8c2
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sun Sep 26 22:55:18 2021 +0200

    examples/web: Process DHT insertion forms.
    
    * examples/web.scm
      (decode, process-put-dht): New procedures.
      (url-handler)[put-handler]: Use them.
      (start): Adjust call to url-handler.
---
 examples/web.scm | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/examples/web.scm b/examples/web.scm
index 08693e0..1df5444 100644
--- a/examples/web.scm
+++ b/examples/web.scm
@@ -85,7 +85,24 @@
        (dt "Standard deviation")
        (dd ,(number->string (nse:estimate:standard-deviation estimate)))))
 
-(define (url-handler server request body)
+(define (decode encoding data)
+  (match encoding
+    ("utf-8-text"
+     (slice/read-only (bv-slice/read-write (string->utf8 data))))
+    ;; TODO other encodings
+    ))
+
+(define (process-put-dht dht-server parameters)
+  ;; TODO replication level, expiration ...
+  (dht:put! dht-server
+           (string->number (assoc-ref parameters "type"))
+           (decode (assoc-ref parameters "key-encoding")
+                   ;; TODO the key is 00000.... according to gnunet-dht-monitor
+                   (assoc-ref parameters "key"))
+           (decode (assoc-ref parameters "data-encoding")
+                   (assoc-ref parameters "data"))))
+
+(define (url-handler dht-server server request body)
   (match (uri-path (request-uri request))
     ("/" (respond/html
          `(div (p "A few links")
@@ -99,9 +116,12 @@
            (estimate->html current-estimate)
            '(p "No etimate yet")))))
     ("/search-dht" (respond/html search-form))
-    ("/put-dht" ; TODO check method and Content-Type
-     (pk 'parameters (urlencoded->alist body))
-     (respond/html put-form))
+    ("/put-dht" ; TODO check method and Content-Type, validation ...
+     (if body
+        (begin
+          (process-put-dht dht-server (urlencoded->alist body))
+          (respond/html '(p "Success!")))
+        (respond/html put-form)))
     (_ (respond/html '(p "not found"))))) ; TODO 404
 
 (define (start config)
@@ -110,7 +130,7 @@
   (define impl (lookup-server-impl 'fiberized))
   (define server (open-server impl `(#:port 8089)))
   (define (url-handler* request body)
-    (url-handler nse-server request body))
+    (url-handler dht-server nse-server request body))
   ;; TODO: Form to start GET and PUT requests?
   ;; For now, hard code the data to insert.
   (dht:put! dht-server

-- 
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]