[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 03/04: News: Added DDLs for handling GNUNET_PEERSTORE_StoreHell
From: |
gnunet |
Subject: |
[gnunet] 03/04: News: Added DDLs for handling GNUNET_PEERSTORE_StoreHelloContext |
Date: |
Tue, 24 Oct 2023 17:40:48 +0200 |
This is an automated email from the git hooks/post-receive script.
t3sserakt pushed a commit to branch master
in repository gnunet.
commit 233a6be0f23f0dcd0f1c40e4f816d1380f872a40
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Tue Oct 24 14:56:14 2023 +0200
News: Added DDLs for handling GNUNET_PEERSTORE_StoreHelloContext
---
src/include/gnunet_peerstore_service.h | 57 ++++++++++++++++++++++
.../hostlist/gnunet-daemon-hostlist_client.c | 30 ++++++++++--
src/service/peerstore/peerstore_api.c | 48 +-----------------
src/service/topology/gnunet-daemon-topology.c | 31 ++++++++++--
src/service/transport/gnunet-service-transport.c | 31 +++++++++++-
5 files changed, 142 insertions(+), 55 deletions(-)
diff --git a/src/include/gnunet_peerstore_service.h
b/src/include/gnunet_peerstore_service.h
index 1cb60cb04..99ba98593 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -178,6 +178,63 @@ struct GNUNET_PEERSTORE_Record
typedef void (*GNUNET_PEERSTORE_Continuation) (void *cls, int success);
+/**
+ * Context for a add hello uri request.
+ */
+struct GNUNET_PEERSTORE_StoreHelloContext
+{
+ /**
+ * Kept (also) in a DLL.
+ */
+ struct GNUNET_PEERSTORE_StoreHelloContext *prev;
+
+ /**
+ * Kept (also) in a DLL.
+ */
+ struct GNUNET_PEERSTORE_StoreHelloContext *next;
+
+ /**
+ * Peerstore handle.
+ */
+ struct GNUNET_PEERSTORE_Handle *h;
+
+ /**
+ * Function to call with information.
+ */
+ GNUNET_PEERSTORE_Continuation cont;
+
+ /**
+ * Closure for @e callback.
+ */
+ void *cont_cls;
+
+ /**
+ * Map with all store contexts started during adding hello.
+ */
+ struct GNUNET_CONTAINER_MultiPeerMap *store_context_map;
+
+ /**
+ * Active watch to be notified about conflicting hello uri add requests.
+ */
+ struct GNUNET_PEERSTORE_WatchContext *wc;
+
+ /**
+ * Hello uri which was request for storing.
+ */
+ struct GNUNET_MessageHeader *hello;
+
+ /**
+ * The peer id for the hello.
+ */
+ struct GNUNET_PeerIdentity *pid;
+
+ /**
+ * Was this request successful.
+ */
+ int success;
+};
+
+
/**
* Function called by PEERSTORE for each matching record.
*
diff --git a/src/service/hostlist/gnunet-daemon-hostlist_client.c
b/src/service/hostlist/gnunet-daemon-hostlist_client.c
index aceea0aaf..483233fc6 100644
--- a/src/service/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/service/hostlist/gnunet-daemon-hostlist_client.c
@@ -229,6 +229,16 @@ static struct GNUNET_SCHEDULER_Task
*ti_testing_intervall_task;
*/
static struct GNUNET_TIME_Absolute end_time;
+/**
+ * Head of the linkd list to store the store context for hellos.
+ */
+static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head;
+
+/**
+ * Tail of the linkd list to store the store context for hellos.
+ */
+static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail;
+
/**
* Head of the linked list used to store hostlists
*/
@@ -313,8 +323,14 @@ static struct GNUNET_PEERSTORE_Handle *peerstore;
static void
shc_cont (void *cls, int success)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist entry stored successfully!\n");
+ (void *) cls;
+
+ if (GNUNET_YES == success)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlist entry stored successfully!\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error storing hostlist entry!\n");
}
@@ -398,7 +414,8 @@ callback_download (void *ptr, size_t size, size_t nmemb,
void *ctx)
shc = GNUNET_PEERSTORE_hello_add (peerstore,
msg,
shc_cont,
- shc);
+ NULL);
+ GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc);
memmove (download_buffer, &download_buffer[msize], download_pos - msize);
download_pos -= msize;
}
@@ -1735,7 +1752,14 @@ GNUNET_HOSTLIST_client_start (const struct
GNUNET_CONFIGURATION_Handle *c,
void
GNUNET_HOSTLIST_client_stop ()
{
+ struct GNUNET_PEERSTORE_StoreHelloContext *pos;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
+ while (NULL != (pos = shc_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos);
+ GNUNET_PEERSTORE_hello_add_cancel (pos);
+ }
if (NULL != sget)
{
GNUNET_STATISTICS_get_cancel (sget);
diff --git a/src/service/peerstore/peerstore_api.c
b/src/service/peerstore/peerstore_api.c
index 8770c36e4..a774d3baa 100644
--- a/src/service/peerstore/peerstore_api.c
+++ b/src/service/peerstore/peerstore_api.c
@@ -312,52 +312,6 @@ struct GNUNET_PEERSTORE_NotifyContext
unsigned int canceled;
};
-/**
- * Context for a add hello uri request.
- */
-struct GNUNET_PEERSTORE_StoreHelloContext
-{
- /**
- * Peerstore handle.
- */
- struct GNUNET_PEERSTORE_Handle *h;
-
- /**
- * Function to call with information.
- */
- GNUNET_PEERSTORE_Continuation cont;
-
- /**
- * Closure for @e callback.
- */
- void *cont_cls;
-
- /**
- * Map with all store contexts started during adding hello.
- */
- struct GNUNET_CONTAINER_MultiPeerMap *store_context_map;
-
- /**
- * Active watch to be notified about conflicting hello uri add requests.
- */
- struct GNUNET_PEERSTORE_WatchContext *wc;
-
- /**
- * Hello uri which was request for storing.
- */
- struct GNUNET_MessageHeader *hello;
-
- /**
- * The peer id for the hello.
- */
- struct GNUNET_PeerIdentity *pid;
-
- /**
- * Was this request successful.
- */
- int success;
-};
-
/******************************************************************************/
/******************* DECLARATIONS
*********************/
/******************************************************************************/
@@ -1319,7 +1273,7 @@ GNUNET_PEERSTORE_hello_add (struct
GNUNET_PEERSTORE_Handle *h,
{
struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (msg);
struct GNUNET_PEERSTORE_StoreHelloContext *huc;
- struct GNUNET_PeerIdentity *pid;
+ const struct GNUNET_PeerIdentity *pid;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Absolute hello_exp =
GNUNET_HELLO_builder_get_expiration_time (msg);
diff --git a/src/service/topology/gnunet-daemon-topology.c
b/src/service/topology/gnunet-daemon-topology.c
index 71cc5bd19..ca5435657 100644
--- a/src/service/topology/gnunet-daemon-topology.c
+++ b/src/service/topology/gnunet-daemon-topology.c
@@ -178,6 +178,16 @@ static unsigned int connection_count;
*/
static unsigned int target_connection_count;
+/**
+ * Head of the linkd list to store the store context for hellos.
+ */
+static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head;
+
+/**
+ * Tail of the linkd list to store the store context for hellos.
+ */
+static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail;
+
/**
* Free all resources associated with the given peer.
*
@@ -833,7 +843,14 @@ check_hello (void *cls, const struct GNUNET_MessageHeader
*message)
static void
shc_cont (void *cls, int success)
{
- GNUNET_free (cls);
+ (void *) cls;
+
+ if (GNUNET_YES == success)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hello stored successfully!\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error storing hello!\n");
}
@@ -860,8 +877,8 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader
*message)
1,
GNUNET_NO);
GNUNET_HELLO_builder_from_msg (message);
- // FIXME this is not working shc uninitialized
- shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, shc);
+ shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, NULL);
+ GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc);
GNUNET_HELLO_builder_free (builder);
}
@@ -875,6 +892,14 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader
*message)
static void
cleaning_task (void *cls)
{
+ struct GNUNET_PEERSTORE_StoreHelloContext *pos;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology shutdown\n");
+ while (NULL != (pos = shc_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos);
+ GNUNET_PEERSTORE_hello_add_cancel (pos);
+ }
if (NULL != peerstore_notify)
{
GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify);
diff --git a/src/service/transport/gnunet-service-transport.c
b/src/service/transport/gnunet-service-transport.c
index 5825dff14..cdd7b5179 100644
--- a/src/service/transport/gnunet-service-transport.c
+++ b/src/service/transport/gnunet-service-transport.c
@@ -2888,6 +2888,16 @@ static struct GNUNET_TIME_Absolute hello_mono_time;
*/
static int in_shutdown;
+/**
+ * Head of the linkd list to store the store context for hellos.
+ */
+static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head;
+
+/**
+ * Tail of the linkd list to store the store context for hellos.
+ */
+static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail;
+
/**
* Get an offset into the transmission history buffer for `struct
* PerformanceData`. Note that the caller must perform the required
@@ -5472,7 +5482,14 @@ peerstore_store_own_cb (void *cls, int success)
static void
shc_cont (void *cls, int success)
{
- GNUNET_free (cls);
+ (void *) cls;
+
+ if (GNUNET_YES == success)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hello stored successfully!\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error storing hello!\n");
}
@@ -5517,10 +5534,13 @@ store_pi (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"store_pi 1\n");
if (GNUNET_YES == add_result)
+ {
shc = GNUNET_PEERSTORE_hello_add (peerstore,
msg,
shc_cont,
- shc);
+ NULL);
+ GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc);
+ }
else if (GNUNET_SYSERR == add_result)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Error adding address to peerstore hello!\n");
@@ -11494,9 +11514,16 @@ static void
do_shutdown (void *cls)
{
struct LearnLaunchEntry *lle;
+ struct GNUNET_PEERSTORE_StoreHelloContext *pos;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"shutdown logic\n");
+ while (NULL != (pos = shc_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos);
+ GNUNET_PEERSTORE_hello_add_cancel (pos);
+ }
+
(void) cls;
GNUNET_CONTAINER_multipeermap_iterate (neighbours,
&free_neighbour_cb, NULL);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.