gnunet-svn
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]