[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.
- [gnunet-scheme] 216/324: mq: Inject errors if no appropriate message handler exists., (continued)
- [gnunet-scheme] 216/324: mq: Inject errors if no appropriate message handler exists., gnunet, 2021/09/21
- [gnunet-scheme] 190/324: Correct XXX and TODO on input:regular-end-of-file., gnunet, 2021/09/21
- [gnunet-scheme] 196/324: mq-impl/stream: Stop all fibers when EOF is reached (part 1)., gnunet, 2021/09/21
- [gnunet-scheme] 201/324: tests/mq-stream: Make test more strict., gnunet, 2021/09/21
- [gnunet-scheme] 204/324: mq-impl/stream: Document implementation pitfall., gnunet, 2021/09/21
- [gnunet-scheme] 214/324: tests/mq: Use 'message-handler' macro., gnunet, 2021/09/21
- [gnunet-scheme] 217/324: tests/mq: Spam the log less., gnunet, 2021/09/21
- [gnunet-scheme] 233/324: doc: Document the message type database a little., gnunet, 2021/09/21
- [gnunet-scheme] 232/324: doc: Partially document handler procedures and interposers., gnunet, 2021/09/21
- [gnunet-scheme] 239/324: tests/network-size: Don't let the GC close port., gnunet, 2021/09/21
- [gnunet-scheme] 241/324: nse/client: Add a 'disconnected' callback.,
gnunet <=
- [gnunet-scheme] 195/324: mq-impl/stream: Reduce nesting., gnunet, 2021/09/21
- [gnunet-scheme] 200/324: mq-impl/stream: Make error injection less unobviously correct., gnunet, 2021/09/21
- [gnunet-scheme] 210/324: mq-stream: Reuse 'type' variable instead of reading the type again., gnunet, 2021/09/21
- [gnunet-scheme] 219/324: mq-impl/stream: Create the message queue as late as possible., gnunet, 2021/09/21
- [gnunet-scheme] 230/324: doc: Correct errors in ‘network structure’ section., gnunet, 2021/09/21
- [gnunet-scheme] 235/324: doc: Document how errors and received/sent messages are ordered., gnunet, 2021/09/21
- [gnunet-scheme] 199/324: guix: Use patched version of guile-fibers., gnunet, 2021/09/21
- [gnunet-scheme] 209/324: doc: Resolve the TODO about broken pipes., gnunet, 2021/09/21
- [gnunet-scheme] 213/324: nse/client: Use 'message-handler' macro., gnunet, 2021/09/21
- [gnunet-scheme] 222/324: mq-impl/stream: Handle closed ports more gracefully., gnunet, 2021/09/21