gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] branch master updated (a5e9d35 -> fd4321e)


From: gnunet
Subject: [gnunet-scheme] branch master updated (a5e9d35 -> fd4321e)
Date: Mon, 14 Feb 2022 22:01:04 +0100

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a change to branch master
in repository gnunet-scheme.

    from a5e9d35  dht/client: Verify that 'start-get!' can be called from 
callbacks.
     new 113fc69  dht: Allow cancelling get operations.
     new fd4321e  examples/web: Cancel the search when done.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/distributed-hash-table.tm |  7 +++++++
 examples/web.scm              | 12 ++++++++----
 gnu/gnunet/dht/client.scm     | 25 ++++++++++++++++++++++++-
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/doc/distributed-hash-table.tm b/doc/distributed-hash-table.tm
index 46eb5db..784c804 100644
--- a/doc/distributed-hash-table.tm
+++ b/doc/distributed-hash-table.tm
@@ -156,6 +156,13 @@
     to make a copy of the search result, using <scm|copy-search-result>.
   </explain>
 
+  <\explain>
+    <scm|(stop-get! <var|search>)><index|stop-get!>
+  </explain|Cancel the get operation described by the search object
+  <var|search>. This is an asynchronuous operation; it does not have an
+  immediate effect. This is an idempotent operation: cancelling a search does
+  not have any additional effect.>
+
   <\explain>
     <scm|(put! <var|server> <var|insertion> <var|#:confirmed>)><index|put!>
   <|explain>
diff --git a/examples/web.scm b/examples/web.scm
index 8f105b6..c73094b 100644
--- a/examples/web.scm
+++ b/examples/web.scm
@@ -1,5 +1,5 @@
 ;; This file is part of scheme-GNUnet.
-;; Copyright (C) 2021 GNUnet e.V.
+;; Copyright © 2021, 2022 GNUnet e.V.
 ;;
 ;; scheme-GNUnet is free software: you can redistribute it and/or modify it
 ;; under the terms of the GNU Affero General Public License as published
@@ -163,12 +163,16 @@ If incorrect, return @code{#false}. TODO more validation."
   (define (found %search-result)
     ;; TODO: document necessity of copies and this procedure
     (set! search-result (dht:copy-search-result %search-result))
-    (signal-condition! found?))
+    (unless (signal-condition! found?)
+      (pk "already signalled, is cancelling working correctly, or was this \
+merely a race?")))
   (define query (parameters->query parameters))
   (if query
-      (begin
-       (dht:start-get! dht-server query found)
+      (let ((search-handle (dht:start-get! dht-server query found)))
        (wait found?)
+       ;; For this example application, a single response is sufficient.
+       ;; TODO: cancel from within 'found' (probably buggy)
+       (dht:stop-get! search-handle)
        ;; TODO: properly format the result, streaming, stop searching
        ;; after something has been found or if the client closes the 
connection ...
        (respond/html `(div (p "Found! ")
diff --git a/gnu/gnunet/dht/client.scm b/gnu/gnunet/dht/client.scm
index 2520bf6..8b74f43 100644
--- a/gnu/gnunet/dht/client.scm
+++ b/gnu/gnunet/dht/client.scm
@@ -581,7 +581,7 @@ currently unsupported."
              ;; Atomic box holding an unsigned 64-bit integer.
              (immutable next-unique-id/box server-next-unique-id/box)
              ;; Hash table from operation ids to their corresponding
-             ;; <get> object.
+             ;; <get> object.  TODO: hash maps are thread-unsafe
              (immutable id->operation-map server-id->operation-map)))
 
     (define (maybe-send-control-message!* terminal-condition control-channel
@@ -619,6 +619,13 @@ do anything if @var{server} has been permanently 
disconnected."
                                              (get:unique-id get)
                                              (get:options get))))
 
+    (define (send-stop-get! mq get)
+      "Send a message for stopping the get operation @var{get}."
+      (send-message!
+       mq
+       (construct-client-get-stop (query-key (get:query get))
+                                 (get:unique-id get))))
+
     (define (fresh-id server)
       "Generate a fresh numeric ID to use for communication with @var{server}."
       ;; Atomically increment the ‘next unique id’, but avoid
@@ -673,6 +680,13 @@ search result, using @lisp{copy-search-result}."
       (maybe-send-control-message! server 'start-get! handle)
       handle)
 
+    (define (stop-get! search)
+      "Cancel the get operation @var{search}.  This is an asynchronuous 
operation;
+it does not have an immediate effect.  This is an idempotent operation; 
cancelling
+a search twice does not have any additional effect."
+      (maybe-send-control-message! (get:server search) 'stop-get! get)
+      (values))
+
     (define* (put! server insertion #:key (confirmed values))
       "Perform the insertion @var{insertion}. When the datum has been inserted,
 the thunk @var{confirmed} is called. A @emph{put object} is returned which can
@@ -862,6 +876,15 @@ code automatically tries to reconnect, so @var{connected} 
can be called after
           (send-get! mq get)
           ;; Continue!
           (control))
+         (('stop-get! get)
+          ;; TODO: tests!
+          ;; TODO: racy!
+          ;; TODO: cancel outstanding messages to the DHT services for this
+          ;; get operation (including the request to start searching), if
+          ;; any.
+          (when (hashv-ref id->operation-map (get:unique-id get))
+            (hashv-set! id->operation-map (get:unique-id get) #false)
+            (send-stop-get! mq get)))
          (('put! put)
           ;; Send the put operation to the DHT service.
           (send-message! mq (put:message put))

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