gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 20/49: dht/client: Call the callback on the client resul


From: gnunet
Subject: [gnunet-scheme] 20/49: dht/client: Call the callback on the client result.
Date: Sat, 25 Dec 2021 22:59:57 +0100

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 891e3ea4c0fe704542e202b3f8520fd1b2366410
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sat Sep 25 13:45:07 2021 +0200

    dht/client: Call the callback on the client result.
    
    * gnu/gnunet/dht/client.scm
      (start-get!): Document arguments of callback.
      (reconnect)[process-client-result]: New procedure.
---
 gnu/gnunet/dht/client.scm | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/gnu/gnunet/dht/client.scm b/gnu/gnunet/dht/client.scm
index 0bf6045..4ee6655 100644
--- a/gnu/gnunet/dht/client.scm
+++ b/gnu/gnunet/dht/client.scm
@@ -168,7 +168,15 @@
       "Perform an asynchronous GET operation on the DHT, and return a handle
 to control the GET operation.  Search for a block of type @var{type} (a
 @code{block-type} or its numeric value) and key @var{key}, a readable 
bytevector
-slice.  Call @var{found} on every search result."
+slice.  Call the procedure @var{found} on every search result.
+
+This procedure is called as @code((found type key data expiration get-path 
put-path)w},
+where @var{key}, @var{data}, @var{get-path} and @var{put-path} are readable
+bytevector slices and @var{type} is the numeric value of the block type.
+(TODO: why does the DHT service include the key and type?).
+
+These slices must not be used after @var{found} returns, as the underlying 
buffer
+might be reused."
       ;; TODO: options, xquery ...
       (unless (= (slice-length key) (sizeof /hashcode:512 '()))
        (error "length of key incorrect"))
@@ -271,6 +279,32 @@ even if not connected.  This is an idempotent operation."
                        id->operation-map
                        #:key (spawn spawn-fiber)
                        #:rest rest)
+      (define (process-client-result handle slice)
+       "Process a reply @var{slice} (a @code{/:msg:dht:client:result}
+structure) to the get request @var{handle}."
+       (define header (slice/read-only slice 0
+                                       (sizeof /:msg:dht:client:result '())))
+       (define rest (slice/read-only slice
+                                     (sizeof /:msg:dht:client:result '())))
+       (define put-path-length
+         (read% /:msg:dht:client:result '(put-path-length) header))
+       (define get-path-length
+         (read% /:msg:dht:client:result '(get-path-length) header))
+       (define put-path
+         (slice-slice rest 0 (* (sizeof /peer-identity '()) put-path-length)))
+       (define get-path
+         (slice-slice rest (* (sizeof /peer-identity '()) put-path-length)
+                      (* (sizeof /peer-identity '()) get-path-length)))
+       (define data
+         (slice-slice rest (* (sizeof /peer-identity '())
+                              (+ put-path-length get-path-length))))
+       ;; TODO: maybe validate 'key' and 'type'
+       ((get:iterator handle)
+        (read% /:msg:dht:client:result '(type) header)
+        (select /:msg:dht:client:result '(key) header)
+        data
+        (read% /:msg:dht:client:result '(expiration) header)
+        get-path put-path))
       (define handlers
        (message-handlers
         (message-handler

-- 
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]