aboutsummaryrefslogtreecommitdiff
path: root/gnu/gnunet/nse
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-09-08 14:51:03 +0200
committerMaxime Devos <maximedevos@telenet.be>2021-09-21 12:20:58 +0200
commit33c550405e606548617e4dc758ea0ad45a2a7a6b (patch)
tree7f01548688b9b71bc9ccc4920b924a35b515bf7a /gnu/gnunet/nse
parent125e7947f4db6b2386e3528148e8d7d0a63051f2 (diff)
downloadgnunet-scheme-33c550405e606548617e4dc758ea0ad45a2a7a6b.tar.gz
gnunet-scheme-33c550405e606548617e4dc758ea0ad45a2a7a6b.zip
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.
Diffstat (limited to 'gnu/gnunet/nse')
-rw-r--r--gnu/gnunet/nse/client.scm19
1 files changed, 12 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 @@
78 (immutable mq nse-mq) ; message queue 78 (immutable mq nse-mq) ; message queue
79 (immutable config server-config) 79 (immutable config server-config)
80 (immutable connected-callback server-connected-callback) 80 (immutable connected-callback server-connected-callback)
81 ; TODO 81 (immutable disconnected-callback server-disconnected-callback)
82 ; (immutable disconnected-callback nse-disconnected-callback)
83 (immutable estimate-update-callback server-update-callback))) 82 (immutable estimate-update-callback server-update-callback)))
84 83
85 (define (estimate server) 84 (define (estimate server)
@@ -118,14 +117,19 @@ Maybe +inf.0 as well?"
118timestamp." 117timestamp."
119 (%estimate:timestamp estimate)) 118 (%estimate:timestamp estimate))
120 119
121 (define* (connect config #:key updated connected (spawn spawn-fiber)) 120 (define* (connect config #:key updated connected disconnected
121 (spawn spawn-fiber))
122 "Connect to the NSE service in the background. 122 "Connect to the NSE service in the background.
123 123
124When connected, the thunk @var{connected} is called and estimates 124When connected, the thunk @var{connected} is called and estimates
125will become available (but possibly not immediately). When a new 125will become available (but possibly not immediately). When a new
126estimate is available, the procedure @var{updated} is called. This 126estimate is available, the procedure @var{updated} is called. This
127procedure should accept the new estimate. The procedures @var{updated} 127procedure should accept the new estimate. When disconnected, the
128and @var{connected} are optional." 128thunk @code{disconnected} and updates will be (temporarily) unavailable,
129until connected again. It is possible for @var{updated} to be called
130shortly after calling @var{disconnected}.
131
132The procedures @var{updated}, @var{connected} and @var{disconnected} are optional."
129 (define estimate/box (make-atomic-box #f)) 133 (define estimate/box (make-atomic-box #f))
130 (define (handle-estimate! estimate-slice) 134 (define (handle-estimate! estimate-slice)
131 (define estimate 135 (define estimate
@@ -161,8 +165,9 @@ and @var{connected} are optional."
161 (when connected (connected))) 165 (when connected (connected)))
162 ;; TODO this means the server has closed the connection ... 166 ;; TODO this means the server has closed the connection ...
163 ;; ---> reconnect? 167 ;; ---> reconnect?
164 ((input:regular-end-of-file) 168 ((input:regular-end-of-file input:premature-end-of-file)
169 (when disconnected (disconnected))
165 (values)))) 170 (values))))
166 (define mq (connect/fibers config "nse" handlers error-handler 171 (define mq (connect/fibers config "nse" handlers error-handler
167 #:spawn spawn)) 172 #:spawn spawn))
168 (%make-server estimate/box mq config connected updated)))) 173 (%make-server estimate/box mq config connected disconnected updated))))