[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 03/42: dht/client: Extract message handlers.
From: |
gnunet |
Subject: |
[gnunet-scheme] 03/42: dht/client: Extract message handlers. |
Date: |
Sat, 10 Sep 2022 19:07:56 +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 e1304f749fdc4a48b2941a10c4d21aa2f460aeee
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Thu Sep 8 00:28:43 2022 +0200
dht/client: Extract message handlers.
This will fit better in the (gnu gnunet server) structures.
* gnu/gnunet/dht/client.scm (make-message-handlers): Extract from ...
(reconnect)[handlers,request-search-result-iterator]: ... here.
---
gnu/gnunet/dht/client.scm | 133 ++++++++++++++++++++++++----------------------
1 file changed, 69 insertions(+), 64 deletions(-)
diff --git a/gnu/gnunet/dht/client.scm b/gnu/gnunet/dht/client.scm
index ad8a086..d5e95a7 100644
--- a/gnu/gnunet/dht/client.scm
+++ b/gnu/gnunet/dht/client.scm
@@ -768,6 +768,72 @@ code automatically tries to reconnect, so @var{connected}
can be called after
(weak-vector-ref reference 0)
reference))
+ (define* (make-message-handlers #:key terminal-condition control-channel
+ #:allow-other-keys)
+ (define (request-search-result-iterator unique-id)
+ "Ask @code{control} what is the iterator for the get operation with
+unique id @var{unique-id}. If there is no such get operation, or the get
+operation is cancelled, return @code{#false} instead."
+ ;; It is possible to look at id->operation-map directly instead,
+ ;; but hash tables are thread-unsafe.
+ ;; TODO: is the 'terminal-condition' case needed?
+ (maybe-ask* terminal-condition control-channel
+ 'request-search-result-iterator
+ unique-id))
+ (message-handlers
+ (message-handler
+ (type (symbol-value message-type msg:dht:monitor:get))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; The C implementation verifies that 'get-path-length' at most
+ ;; (- (expt 2 16) 1), but this seems only to prevent integer overflow,
+ ;; which cannot happen in Scheme due to the use of bignums.
+ ;;
+ ;; This message does _not_ have a payload, so use = instead of >=.
+ (well-formed?/path-length slice /:msg:dht:monitor:get-response
+ (get-path-length) =))
+ ((handle! slice) ???))
+ (message-handler
+ (type (symbol-value message-type msg:dht:monitor:get-response))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; Payload follows, hence >= instead of =.
+ (well-formed?/path-length slice /:msg:dht:monitor:get-response
+ (get-path-length put-path-length) >=))
+ ((handle! slice) ???))
+ (message-handler
+ (type (symbol-value message-type msg:dht:monitor:put))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; Payload follows, hence >= instead of =.
+ (well-formed?/path-length slice /:msg:dht:monitor:put
+ (put-path-length) >=))
+ ((handle! slice) ???))
+ (message-handler
+ (type (symbol-value message-type msg:dht:client:result))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; Actual data follows, hence >= instead of =.
+ (well-formed?/path-length slice /:msg:dht:client:result
+ (get-path-length put-path-length) >=))
+ ((handle! slice)
+ ;; The DHT service found some data we were looking for.
+ (let^ ((<-- (search-result unique-id)
+ ;; TODO: maybe verify the type and key?
+ (analyse-client-result slice))
+ (! handle (request-search-result-iterator unique-id))
+ (? (not handle)
+ ;; Perhaps the search object became unreachable;
+ ;; 'process-stop-search' (see next commit) will be
+ ;; called soon to inform the DHT service.
+ (values))
+ (? (get? handle)
+ ;; TODO might not be true once monitoring operations
+ ;; are supported.
+ ((get:iterator handle) search-result)))
+ ;; TODO: wrong type (maybe a put handle?).
+ TODO-error-reporting/2)))))
+
(define* (reconnect terminal-condition config
old-id->operation-map control-channel lost-and-found
#:key (spawn spawn-fiber)
@@ -792,70 +858,9 @@ code automatically tries to reconnect, so @var{connected}
can be called after
;; This code is written to support both the correct and incorrect
behaviour
;; of guardians+weak vectors.
(define id->operation-map (make-hash-table))
- (define (request-search-result-iterator unique-id)
- "Ask @code{control} what is the iterator for the get operation with
-unique id @var{unique-id}. If there is no such get operation, or the get
-operation is cancelled, return @code{#false} instead."
- ;; It is possible to look at id->operation-map directly instead,
- ;; but hash tables are thread-unsafe.
- ;; TODO: is the 'terminal-condition' case needed?
- (maybe-ask* terminal-condition control-channel
- 'request-search-result-iterator
- unique-id))
- (define handlers
- (message-handlers
- (message-handler
- (type (symbol-value message-type msg:dht:monitor:get))
- ((interpose exp) exp)
- ((well-formed? slice)
- ;; The C implementation verifies that 'get-path-length' at most
- ;; (- (expt 2 16) 1), but this seems only to prevent integer
overflow,
- ;; which cannot happen in Scheme due to the use of bignums.
- ;;
- ;; This message does _not_ have a payload, so use = instead of >=.
- (well-formed?/path-length slice /:msg:dht:monitor:get-response
- (get-path-length) =))
- ((handle! slice) ???))
- (message-handler
- (type (symbol-value message-type msg:dht:monitor:get-response))
- ((interpose exp) exp)
- ((well-formed? slice)
- ;; Payload follows, hence >= instead of =.
- (well-formed?/path-length slice /:msg:dht:monitor:get-response
- (get-path-length put-path-length) >=))
- ((handle! slice) ???))
- (message-handler
- (type (symbol-value message-type msg:dht:monitor:put))
- ((interpose exp) exp)
- ((well-formed? slice)
- ;; Payload follows, hence >= instead of =.
- (well-formed?/path-length slice /:msg:dht:monitor:put
- (put-path-length) >=))
- ((handle! slice) ???))
- (message-handler
- (type (symbol-value message-type msg:dht:client:result))
- ((interpose exp) exp)
- ((well-formed? slice)
- ;; Actual data follows, hence >= instead of =.
- (well-formed?/path-length slice /:msg:dht:client:result
- (get-path-length put-path-length) >=))
- ((handle! slice)
- ;; The DHT service found some data we were looking for.
- (let^ ((<-- (search-result unique-id)
- ;; TODO: maybe verify the type and key?
- (analyse-client-result slice))
- (! handle (request-search-result-iterator unique-id))
- (? (not handle)
- ;; Perhaps the search object became unreachable;
- ;; 'process-stop-search' (see next commit) will be
- ;; called soon to inform the DHT service.
- (values))
- (? (get? handle)
- ;; TODO might not be true once monitoring operations
- ;; are supported.
- ((get:iterator handle) search-result)))
- ;; TODO: wrong type (maybe a put handle?).
- TODO-error-reporting/2)))))
+ (define handlers (apply make-message-handlers
+ #:terminal-condition terminal-condition
+ #:control-channel control-channel rest))
(define error-handler
(make-error-handler connected disconnected terminal-condition
control-channel))
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] branch master updated (f5dc44e -> 58b0a65), gnunet, 2022/09/10
- [gnunet-scheme] 02/42: nse/client: Extract the reconnection loop., gnunet, 2022/09/10
- [gnunet-scheme] 06/42: server: Bring the reconnect loop state into a single structure., gnunet, 2022/09/10
- [gnunet-scheme] 09/42: server: Make #:message-queue a regular argument., gnunet, 2022/09/10
- [gnunet-scheme] 01/42: dht/server: Pass 'spawn' to connect/fibers., gnunet, 2022/09/10
- [gnunet-scheme] 10/42: server: Only accept a single 'state' argument., gnunet, 2022/09/10
- [gnunet-scheme] 08/42: nse/client: Simplify state passing with a new subtype of <loop>., gnunet, 2022/09/10
- [gnunet-scheme] 03/42: dht/client: Extract message handlers.,
gnunet <=
- [gnunet-scheme] 04/42: dht/client: Eliminate mutation from the control loop., gnunet, 2022/09/10
- [gnunet-scheme] 07/42: server: Rename 'primitive-reconnect' to 'run-loop'., gnunet, 2022/09/10
- [gnunet-scheme] 14/42: server: Deduplicate make-error-handler*., gnunet, 2022/09/10
- [gnunet-scheme] 19/42: cadet/client: Minimise imports., gnunet, 2022/09/10
- [gnunet-scheme] 21/42: server: Unify loop spawning., gnunet, 2022/09/10
- [gnunet-scheme] 29/42: doc/service-communication: Document <server>., gnunet, 2022/09/10
- [gnunet-scheme] 20/42: server: Add default arguments to 'make-loop'., gnunet, 2022/09/10
- [gnunet-scheme] 25/42: server: Re-indent., gnunet, 2022/09/10
- [gnunet-scheme] 31/42: doc/service-communication: Document spawn-server-loop., gnunet, 2022/09/10
- [gnunet-scheme] 11/42: dht: Use <loop> for state where possible., gnunet, 2022/09/10