[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 17/40: PEERSTORE: change watch to return actual values, before
From: |
gnunet |
Subject: |
[gnunet] 17/40: PEERSTORE: change watch to return actual values, before watching. |
Date: |
Thu, 05 Oct 2023 08:57:20 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
commit 86ae84f761725e12b6570d12785b970c88fe16d9
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Thu Aug 24 11:30:16 2023 +0200
PEERSTORE: change watch to return actual values, before watching.
---
src/peerstore/peerstore_api.c | 107 ++++++++++++++++++++++++++++++++++--------
1 file changed, 88 insertions(+), 19 deletions(-)
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index 72742c919..1bac046f2 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -259,6 +259,26 @@ struct GNUNET_PEERSTORE_WatchContext
* Hash of the combined key
*/
struct GNUNET_HashCode keyhash;
+
+ /**
+ * The iteration context to deliver the actual values for the key.
+ */
+ struct GNUNET_PEERSTORE_IterateContext *ic;
+
+ /**
+ * The peer we are watching for values.
+ */
+ const struct GNUNET_PeerIdentity *peer;
+
+ /**
+ * The key we like to watch for values.
+ */
+ const char *key;
+
+ /**
+ * The sub system requested the watch.
+ */
+ const char *sub_system;
};
/**
@@ -982,6 +1002,13 @@ GNUNET_PEERSTORE_watch_cancel (struct
GNUNET_PEERSTORE_WatchContext *wc)
struct StoreKeyHashMessage *hm;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n");
+ if (NULL != wc->ic)
+ {
+ GNUNET_PEERSTORE_iterate_cancel (wc->ic);
+ GNUNET_free (wc);
+ return;
+ }
+
ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL);
hm->keyhash = wc->keyhash;
GNUNET_MQ_send (h->mq, ev);
@@ -992,9 +1019,56 @@ GNUNET_PEERSTORE_watch_cancel (struct
GNUNET_PEERSTORE_WatchContext *wc)
}
+static void
+watch_iterate (void *cls,
+ const struct GNUNET_PEERSTORE_Record *record,
+ const char *emsg)
+{
+ struct GNUNET_PEERSTORE_WatchContext *wc = cls;
+ struct GNUNET_PEERSTORE_Handle *h = wc->h;
+ struct StoreKeyHashMessage *hm;
+
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Got failure from PEERSTORE: %s\n",
+ emsg);
+ wc->callback (wc->callback_cls, NULL, emsg);
+ return;
+ }
+ if (NULL == record)
+ {
+ struct GNUNET_MQ_Envelope *ev;
+
+ ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH);
+ PEERSTORE_hash_key (wc->sub_system, wc->peer, wc->key, &hm->keyhash);
+ wc->keyhash = hm->keyhash;
+ if (NULL == h->watches)
+ h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
+ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
+ h->watches,
+
&wc->keyhash,
+ wc,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n",
+ wc->sub_system,
+ GNUNET_i2s (wc->peer),
+ wc->key);
+ GNUNET_MQ_send (h->mq, ev);
+ wc->ic = NULL;
+ return;
+ }
+
+ if (NULL != wc->callback)
+ wc->callback (wc->callback_cls, record, NULL);
+}
+
+
/**
* Request watching a given key
- * User will be notified with any new values added to key
+ * User will be notified with any new values added to key,
+ * all existing entries are supplied beforehand.
*
* @param h handle to the PEERSTORE service
* @param sub_system name of sub system
@@ -1012,30 +1086,25 @@ GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle
*h,
GNUNET_PEERSTORE_Processor callback,
void *callback_cls)
{
- struct GNUNET_MQ_Envelope *ev;
- struct StoreKeyHashMessage *hm;
+ struct GNUNET_PEERSTORE_IterateContext *ic;
struct GNUNET_PEERSTORE_WatchContext *wc;
- ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH);
- PEERSTORE_hash_key (sub_system, peer, key, &hm->keyhash);
+ ic = GNUNET_PEERSTORE_iterate (h,
+ sub_system,
+ peer,
+ key,
+ &watch_iterate,
+ NULL);
+
wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext);
wc->callback = callback;
wc->callback_cls = callback_cls;
wc->h = h;
- wc->keyhash = hm->keyhash;
- if (NULL == h->watches)
- h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
- h->watches,
- &wc->keyhash,
- wc,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n",
- sub_system,
- GNUNET_i2s (peer),
- key);
- GNUNET_MQ_send (h->mq, ev);
+ wc->ic = ic;
+ wc->key = key;
+ wc->peer = peer;
+ wc->sub_system = sub_system;
+
return wc;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] 06/40: TNG: Accidentally removed code., (continued)
- [gnunet] 06/40: TNG: Accidentally removed code., gnunet, 2023/10/05
- [gnunet] 02/40: NEWS: Added __attribute__((deprecated)) to the old transport API, gnunet, 2023/10/05
- [gnunet] 09/40: NEWS: Moved start peer command to testing subsystem., gnunet, 2023/10/05
- [gnunet] 05/40: TNG: Deactivated all tests which rely on the old transport api., gnunet, 2023/10/05
- [gnunet] 12/40: TNG: Fixed bug that QueueEntry of another queue still holds reference to PendingMessage., gnunet, 2023/10/05
- [gnunet] 13/40: NEWS: Changed new hello uri api to allow to change the expiration time, gnunet, 2023/10/05
- [gnunet] 22/40: NEWS: Code moved to the core package to get rid of circular dependencies., gnunet, 2023/10/05
- [gnunet] 16/40: TOPOLOGY: Exchanged peerinfo api to store hellos with new peerstore api., gnunet, 2023/10/05
- [gnunet] 19/40: HELLO: Cli tool for changing hello files in contrib can change file from old to new hello design., gnunet, 2023/10/05
- [gnunet] 07/40: NEWS: Added command to execute a script., gnunet, 2023/10/05
- [gnunet] 17/40: PEERSTORE: change watch to return actual values, before watching.,
gnunet <=
- [gnunet] 32/40: Merge branch 'master' into l20integration, gnunet, 2023/10/05
- [gnunet] 29/40: TNG: Fixed syntax., gnunet, 2023/10/05
- [gnunet] 03/40: News: Merge branch 'l20integration' of ssh://git.gnunet.org/gnunet into l20integration, gnunet, 2023/10/05
- [gnunet] 36/40: Fix warnings; CADET not FTBFS because old hello removed, gnunet, 2023/10/05
- [gnunet] 33/40: Merge branch 'master' into l20integration, gnunet, 2023/10/05
- [gnunet] 18/40: NEWS: The old hello design replaced by the new hello design., gnunet, 2023/10/05
- [gnunet] 39/40: Make fs and cadet build again; cadet hello handling suspicious, gnunet, 2023/10/05
- [gnunet] 25/40: Hello: Changed address and hello format to new TNG format., gnunet, 2023/10/05
- [gnunet] 38/40: Remove more traces of old transport, gnunet, 2023/10/05
- [gnunet] 31/40: BUILD: Make meson build without ats, tesbed, peerinfo, gnunet, 2023/10/05