[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 06/11: Hostlist: Changed hostlist server to use a hello cache.
From: |
gnunet |
Subject: |
[gnunet] 06/11: Hostlist: Changed hostlist server to use a hello cache. |
Date: |
Wed, 18 Oct 2023 15:49:35 +0200 |
This is an automated email from the git hooks/post-receive script.
t3sserakt pushed a commit to branch master
in repository gnunet.
commit e4b146efc4620a435fdd6f0afbcdea5278b84b6e
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Wed Oct 18 13:52:10 2023 +0200
Hostlist: Changed hostlist server to use a hello cache.
---
src/hostlist/gnunet-daemon-hostlist_server.c | 121 ++++++++++++---------------
1 file changed, 52 insertions(+), 69 deletions(-)
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c
b/src/hostlist/gnunet-daemon-hostlist_server.c
index 1da654f8f..c4a7aab03 100644
--- a/src/hostlist/gnunet-daemon-hostlist_server.c
+++ b/src/hostlist/gnunet-daemon-hostlist_server.c
@@ -42,6 +42,10 @@
#define GNUNET_ADV_TIMEOUT \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
+/**
+ * Map with hellos we build the hostlist with.
+ */
+struct GNUNET_CONTAINER_MultiPeerMap *hellos;
/**
* Handle to the HTTP server as provided by libmicrohttpd for IPv6.
@@ -116,11 +120,6 @@ static char *hostlist_uri;
*/
struct HostSet
{
- /**
- * Iterator used to build @e data (NULL when done).
- */
- struct GNUNET_PEERSTORE_IterateContext *pitr;
-
/**
* Place where we accumulate all of the HELLO messages.
*/
@@ -194,64 +193,27 @@ finish_response ()
* @param hello hello message for the peer (can be NULL)
* @param err_msg message
*/
-static void
+static enum GNUNET_GenericReturnValue
host_processor (void *cls,
- const struct GNUNET_PEERSTORE_Record *record,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *peer,
+ void *value)
{
+ (void *) cls;
size_t old;
size_t s;
- struct GNUNET_MessageHeader *hello;
+ struct GNUNET_MessageHeader *hello = value;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Absolute hello_exp;
- if (NULL != emsg)
- {
- GNUNET_assert (NULL == &record->peer);
- builder->pitr = NULL;
- GNUNET_free (builder->data);
- GNUNET_free (builder);
- builder = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _ ("Error in communication with PEERSTORE service: %s\n"),
- emsg);
- return;
- }
- if (NULL == record)
- {
- builder->pitr = NULL;
- finish_response ();
- return;
- }
- else
- {
- hello = record->value;
- if ((0 == record->value_size))
- {
- GNUNET_break (0);
- return;
- }
- hello_exp = GNUNET_HELLO_builder_get_expiration_time (hello);
- if (GNUNET_TIME_absolute_cmp (hello_exp, <, now))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "HELLO for peer `%4s' has expired address, not suitable for
hostlist!\n",
- GNUNET_i2s (&record->peer));
- GNUNET_STATISTICS_update (stats,
- gettext_noop (
- "Expired HELLO encountered (ignored)"),
- 1,
- GNUNET_NO);
- return;
- }
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "host_processor\n");
old = builder->size;
s = ntohs (hello->size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received %u bytes of `%s' from peer `%s' for hostlist.\n",
(unsigned int) s,
"HELLO",
- GNUNET_i2s (&record->peer));
+ GNUNET_i2s (peer));
if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
(old + s >= MAX_BYTES_PER_HOSTLISTS))
{
@@ -261,14 +223,16 @@ host_processor (void *cls,
"bytes not included in hostlist (size limit)"),
s,
GNUNET_NO);
- return;
+ return GNUNET_YES;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Adding peer `%s' to hostlist (%u bytes)\n",
- GNUNET_i2s (&record->peer),
+ GNUNET_i2s (peer),
(unsigned int) s);
GNUNET_array_grow (builder->data, builder->size, old + s);
GNUNET_memcpy (&builder->data[old], hello, s);
+
+ return GNUNET_YES;
}
@@ -506,20 +470,23 @@ process_notify (void *cls,
const struct GNUNET_MessageHeader *hello,
const char *err_msg)
{
+ unsigned int map_size;
+ struct GNUNET_MessageHeader *hello_cpy;
+ struct GNUNET_PeerIdentity *peer_cpy;
+
+ map_size = GNUNET_CONTAINER_multipeermap_size (hellos);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peerstore is notifying us to rebuild our hostlist\n");
+ "Peerstore is notifying us to rebuild our hostlist map size
%u\n",
+ map_size);
if (NULL != err_msg)
+ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_ ("Error in communication with PEERSTORE service: %s\n"),
err_msg);
+ return;
+ }
if (NULL != builder)
{
- /* restart re-build already in progress ... */
- if (NULL != builder->pitr)
- {
- GNUNET_PEERSTORE_iterate_cancel (builder->pitr);
- builder->pitr = NULL;
- }
GNUNET_free (builder->data);
builder->size = 0;
builder->data = NULL;
@@ -528,9 +495,27 @@ process_notify (void *cls,
{
builder = GNUNET_new (struct HostSet);
}
- GNUNET_assert (NULL != peerstore);
- builder->pitr =
- GNUNET_PEERSTORE_iterate (peerstore, "hostlist", NULL,
GNUNET_PEERSTORE_HELLO_KEY, &host_processor, NULL);
+
+ peer_cpy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_memcpy (peer_cpy, peer, sizeof (struct GNUNET_PeerIdentity));
+ hello_cpy = GNUNET_malloc (ntohs (hello->size));
+ GNUNET_memcpy (hello_cpy, hello, ntohs (hello->size));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_put (hellos,
+ peer_cpy,
+ (struct
+ GNUNET_MessageHeader *)
+ hello_cpy,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ if (0 != GNUNET_CONTAINER_multipeermap_iterate (hellos,
+ &host_processor,
+ NULL))
+ finish_response ();
+ map_size = GNUNET_CONTAINER_multipeermap_size (hellos);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "1 Peerstore is notifying us to rebuild our hostlist map size %u
peer %s\n",
+ map_size,
+ GNUNET_i2s (peer));
}
@@ -616,9 +601,11 @@ start_notify (void *cls)
{
(void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to process new hellos to add
to hostlist.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting to process new hellos to add to hostlist.\n");
peerstore_notify =
- GNUNET_PEERSTORE_hello_changed_notify (peerstore, GNUNET_NO,
&process_notify, NULL);
+ GNUNET_PEERSTORE_hello_changed_notify (peerstore, GNUNET_NO,
+ &process_notify, NULL);
}
@@ -651,6 +638,7 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
const struct sockaddr *sa4;
const struct sockaddr *sa6;
+ hellos = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
advertising = advertise;
if (! advertising)
{
@@ -884,11 +872,6 @@ GNUNET_HOSTLIST_server_stop ()
}
if (NULL != builder)
{
- if (NULL != builder->pitr)
- {
- GNUNET_PEERSTORE_iterate_cancel (builder->pitr);
- builder->pitr = NULL;
- }
GNUNET_free (builder->data);
GNUNET_free (builder);
builder = NULL;
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] branch master updated (65dbd214b -> 67362c231), gnunet, 2023/10/18
- [gnunet] 03/11: Hello: Fix bug in cli tool to generate contrib hello file., gnunet, 2023/10/18
- [gnunet] 02/11: Hostlist: Added test config to have a peer running the hostlist server., gnunet, 2023/10/18
- [gnunet] 01/11: Hostlist: Task added to start reading the hostlist entries only after a certain period of time has elapsed., gnunet, 2023/10/18
- [gnunet] 04/11: Hello: Changed signature of method GNUNET_HELLO_builder_get_id, gnunet, 2023/10/18
- [gnunet] 06/11: Hostlist: Changed hostlist server to use a hello cache.,
gnunet <=
- [gnunet] 10/11: Merge branch 'master' of ssh://git.gnunet.org/gnunet. Undeleted src/hello/gnunet-hello.c, because it is still needed., gnunet, 2023/10/18
- [gnunet] 08/11: TNG: Fixed bug in shared secret handling of udo communicator., gnunet, 2023/10/18
- [gnunet] 07/11: Bootstrap: Fixed bug to not replace hellos for a peer., gnunet, 2023/10/18
- [gnunet] 05/11: Hostlist: Fixed bug in hostlist client., gnunet, 2023/10/18
- [gnunet] 09/11: Hello: Fix another bug in cli tool to generate contrib hello file., gnunet, 2023/10/18
- [gnunet] 11/11: Merge branch 'master' of ssh://git.gnunet.org/gnunet, gnunet, 2023/10/18