gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 285/324: examples: Distribute the example.


From: gnunet
Subject: [gnunet-scheme] 285/324: examples: Distribute the example.
Date: Tue, 21 Sep 2021 13:25:25 +0200

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 7dfbb2919fcf908944187e99282d7221d7f1c36f
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Mon Sep 13 17:34:16 2021 +0200

    examples: Distribute the example.
    
    TODO: document the examples somewhere.
---
 Makefile.am          |  1 +
 examples/nse-web.scm | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 15673e2..5f921b3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -190,6 +190,7 @@ doc/scheme-gnunet.html: doc/scheme-gnunet.tm
        $(TEXMACS_CONVERT) -x $(TEXMACS_HTML_SETTINGS) -c "$<" "$@" -q
 
 dist_doc_DATA = doc/scheme-gnunet.tm doc/fdl.tm
+nobase_dist_doc_DATA = examples/nse-web.scm
 nodist_html_DATA = doc/scheme-gnunet.html
 nodist_pdf_DATA = doc/scheme-gnunet.pdf
 
diff --git a/examples/nse-web.scm b/examples/nse-web.scm
new file mode 100644
index 0000000..8d9d810
--- /dev/null
+++ b/examples/nse-web.scm
@@ -0,0 +1,45 @@
+;; Copyright (C) 2021 Maxime Devos
+;; SPDX-License-Identifier: FSFAP
+;; Copying and distribution of this file, with or without modification,
+;; are permitted in any medium without royalty provided the copyright
+;; notice and this notice are preserved.  This file is offered as-is,
+;; without any warranty.
+
+(use-modules (fibers)
+            (gnu gnunet config db)
+            (gnu gnunet config fs)
+            (rnrs hashtables)
+            (gnu gnunet nse client)
+            (web server)
+            (srfi srfi-11))
+
+(define config (load-configuration))
+
+(define (url-handler server request body)
+  (define current-estimate (estimate server))
+  (define body
+    (if current-estimate
+       (format #f "timestamp: ~a~%number peers: ~a~%stddev logarithm: ~a"
+               (estimate:timestamp current-estimate)
+               (estimate:number-peers current-estimate)
+               (estimate:standard-deviation current-estimate))
+       "no estimate available yet ..."))
+  (values '((content-type text/plain)) body #f))
+
+(define (start config)
+  (define nse-server (connect config))
+  (define impl (lookup-server-impl 'fiberized))
+  (define server (open-server impl `(#:port 8089)))
+  (define (url-handler* request body)
+    (url-handler nse-server request body))
+  (let loop ()
+    (let-values (((client request body)
+                 (read-client impl server)))
+      (spawn-fiber
+       (lambda ()
+        (let-values (((response body state)
+                      (handle-request url-handler* request body '())))
+          (write-client impl server client response body)))))
+    (loop)))
+
+(run-fibers (lambda () (start config)))

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