gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 250/324: doc: Document that (gnu gnunet nse client) reco


From: gnunet
Subject: [gnunet-scheme] 250/324: doc: Document that (gnu gnunet nse client) reconnects.
Date: Tue, 21 Sep 2021 13:24:50 +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 1a0ff0a7d1a8aa0f16e9f3b75b38b73e6b037ff5
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Sep 8 20:58:44 2021 +0200

    doc: Document that (gnu gnunet nse client) reconnects.
    
    * doc/scheme-gnunet.tm (Estimation of the size of the network):
      Document that the module will retry after a disconnect.
---
 doc/scheme-gnunet.tm      |  6 +++--
 gnu/gnunet/nse/client.scm |  8 +++++--
 tests/network-size.scm    | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index e454d2d..cc6d835 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -566,8 +566,10 @@
   the latest available estimate.<space|1em>If the
   <with|font-shape|italic|server object> doesn't have an estimate yet, that
   procedure will return <scm|#false> instead of an estimate.<space|1em>When
-  the connection is lost, the (optional) thunk <var|disconnected> is
-  called.<space|1em><todo|reconnecting, disconnecting>
+  the connection is lost, the (optional) thunk <var|disconnected> is called
+  and <scm|(gnu gnunet nse client)> will retry connecting.
+
+  <todo|disconnecting>
 
   The estimate object has a number of accessors:
 
diff --git a/gnu/gnunet/nse/client.scm b/gnu/gnunet/nse/client.scm
index a9072ef..f19f06c 100644
--- a/gnu/gnunet/nse/client.scm
+++ b/gnu/gnunet/nse/client.scm
@@ -116,7 +116,7 @@ timestamp."
 
     ;; See 'connect'.
     (define* (reconnect estimate/box config #:key updated connected 
disconnected
-                       (spawn spawn-fiber))
+                       (spawn spawn-fiber) #:rest rest)
       (define (handle-estimate! estimate-slice)
        (define estimate
          (%make-estimate
@@ -157,8 +157,12 @@ timestamp."
          ;; TODO this means the server has closed the connection ...
          ;; ---> reconnect?
          ((input:regular-end-of-file input:premature-end-of-file)
+          ;; Call 'reconnect' after 'disconnected'.  Otherwise,
+          ;; it is possible that 'connected' is called twice without
+          ;; a call to 'disconnected' in-between, which would presumably
+          ;; be confusing.
           (when disconnected (disconnected))
-          (values))))
+          (apply reconnect estimate/box config rest))))
       (define mq (connect/fibers config "nse" handlers error-handler
                                 #:spawn spawn))
       (signal-condition! mq-defined))
diff --git a/tests/network-size.scm b/tests/network-size.scm
index 69865cd..8ba03bb 100644
--- a/tests/network-size.scm
+++ b/tests/network-size.scm
@@ -31,6 +31,7 @@
        (only (tests utils) call-with-services/fibers)
        (only (fibers) sleep)
        (gnu gnunet netstruct syntactic)
+       (ice-9 match)
        (srfi srfi-1)
        (srfi srfi-26)
        (srfi srfi-43)
@@ -203,4 +204,59 @@
      (sleep 0.001)
      #t)))
 
+(define forever (make-condition))
+
+(test-assert "reconnects"
+  (let ((n 9)
+       (too-many? #f)
+       (done (make-condition)))
+    (call-with-services/fibers
+     `(("nse" . ,(lambda (port spawn-fiber)
+                  (if (> n 0)
+                      (begin
+                        (set! n (- n 1))
+                        (close-port port))
+                      (wait forever)))))
+     (lambda (config spawn-fiber)
+       (define disconnected? #f)
+       (define connected? #f)
+       (define disconnect-count 0)
+       (define (connected)
+        (match (cons disconnected? connected?)
+          ((#t . #f)
+           (set! disconnected? #f)
+           (set! connected? #t)
+           (values))
+          ((#t . #t) (error "impossible"))
+          ((#f . #f)
+           (set! connected? #t)
+           (values)) ; first connect
+          ((#f . #t) (error "doubly connected"))))
+       (define (disconnected)
+        (match (cons connected? disconnected?)
+          ((#t . #f)
+           (set! connected? #f)
+           (set! disconnected? #t)
+           (set! disconnect-count (+ 1 disconnect-count))
+           (cond
+            ((= disconnect-count 9)
+             (signal-condition! done))
+            ((> disconnect-count 9)
+             (set! too-many? #t)
+             (error "too many disconnects")))
+           (values))
+          ((#t . #t) (error "impossible"))
+          ((#f . #f)
+           (error "disconnected before connecting"))
+          ((#f . #t)
+           (error "doubly disconnected"))))
+       (define server
+        (nse:connect config #:spawn spawn-fiber #:connected connected
+                     #:disconnected disconnected))
+       (wait done)
+       (sleep 0.01)
+       (assert (not too-many?))
+       (assert connected?)
+       #t))))
+
 (test-end "network-size")

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