gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 241/324: nse/client: Add a 'disconnected' callback.


From: gnunet
Subject: [gnunet-scheme] 241/324: nse/client: Add a 'disconnected' callback.
Date: Tue, 21 Sep 2021 13:24:41 +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 33c550405e606548617e4dc758ea0ad45a2a7a6b
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Sep 8 14:51:03 2021 +0200

    nse/client: Add a 'disconnected' callback.
    
    * gnu/gnunet/nse/client.scm
      (connect): Add 'disconnected' optional keyword argument.  Document
      it.
      (connect)[error-handler]: In case of input:regular-end-of-file and
      input:premature-end-of-file, call 'disconnected'.
      (<server>)[disconnected]: New field.
    * tests/network-size.scm
      ("notify disconnected after end-of-file, after 'connected'"):
      New test.
---
 gnu/gnunet/nse/client.scm | 19 ++++++++++++-------
 tests/network-size.scm    | 27 +++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/gnu/gnunet/nse/client.scm b/gnu/gnunet/nse/client.scm
index 5442c7c..17c16a3 100644
--- a/gnu/gnunet/nse/client.scm
+++ b/gnu/gnunet/nse/client.scm
@@ -78,8 +78,7 @@
              (immutable mq nse-mq) ; message queue
              (immutable config server-config)
              (immutable connected-callback server-connected-callback)
-                                       ; TODO
-                                       ; (immutable disconnected-callback 
nse-disconnected-callback)
+             (immutable disconnected-callback server-disconnected-callback)
              (immutable estimate-update-callback server-update-callback)))
 
     (define (estimate server)
@@ -118,14 +117,19 @@ Maybe +inf.0 as well?"
 timestamp."
       (%estimate:timestamp estimate))
 
-    (define* (connect config #:key updated connected (spawn spawn-fiber))
+    (define* (connect config #:key updated connected disconnected
+                     (spawn spawn-fiber))
       "Connect to the NSE service in the background.
 
 When connected, the thunk @var{connected} is called and estimates
 will become available (but possibly not immediately).  When a new
 estimate is available, the procedure @var{updated} is called.  This
-procedure should accept the new estimate.  The procedures @var{updated}
-and @var{connected} are optional."
+procedure should accept the new estimate.   When disconnected, the
+thunk @code{disconnected} and updates will be (temporarily) unavailable,
+until connected again.  It is possible for @var{updated} to be called
+shortly after calling @var{disconnected}.
+
+The procedures @var{updated}, @var{connected} and @var{disconnected} are 
optional."
       (define estimate/box (make-atomic-box #f))
       (define (handle-estimate! estimate-slice)
        (define estimate
@@ -161,8 +165,9 @@ and @var{connected} are optional."
           (when connected (connected)))
          ;; TODO this means the server has closed the connection ...
          ;; ---> reconnect?
-         ((input:regular-end-of-file)
+         ((input:regular-end-of-file input:premature-end-of-file)
+          (when disconnected (disconnected))
           (values))))
       (define mq (connect/fibers config "nse" handlers error-handler
                                 #:spawn spawn))
-      (%make-server estimate/box mq config connected updated))))
+      (%make-server estimate/box mq config connected disconnected updated))))
diff --git a/tests/network-size.scm b/tests/network-size.scm
index 44e6be9..69865cd 100644
--- a/tests/network-size.scm
+++ b/tests/network-size.scm
@@ -176,4 +176,31 @@
         (loop (standard-back-off time-delta))))
      #t)))
 
+(test-assert "notify disconnected after end-of-file, after 'connected'"
+  (call-with-services/fibers
+   `(("nse" . ,(lambda (port spawn-fiber)
+                (close-port port))))
+   (lambda (config spawn-fiber)
+     (define disconnected? #f)
+     (define connected? #f)
+     (define c (make-condition))
+     (define (connected)
+       (set! connected? #t))
+     (define (disconnected)
+       (assert connected?)
+       ;; XXX not yet implemented
+       ;; Because (gnu gnunet nse client) automatically reconnects,
+       ;; the following commented-out assertion can be false.
+       #;(assert (not disconnected?))
+       (set! disconnected? #t)
+       (signal-condition! c))
+     (define server
+       (nse:connect config #:spawn spawn-fiber #:connected connected
+                   #:disconnected disconnected))
+     (wait c)
+     ;; Give (gnu gnunet nse client) a chance to (incorrectly) call
+     ;; disconnected again.
+     (sleep 0.001)
+     #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]