aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2023-10-18 13:52:10 +0200
committert3sserakt <t3ss@posteo.de>2023-10-18 13:52:10 +0200
commite4b146efc4620a435fdd6f0afbcdea5278b84b6e (patch)
tree7e91234e9641ecddb1eb4c02fccd4047bc1ace80 /src
parent3b62cab22b126bec58d760a46d05136bfd45941e (diff)
downloadgnunet-e4b146efc4620a435fdd6f0afbcdea5278b84b6e.tar.gz
gnunet-e4b146efc4620a435fdd6f0afbcdea5278b84b6e.zip
Hostlist: Changed hostlist server to use a hello cache.
Diffstat (limited to 'src')
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_server.c121
1 files 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 @@
42#define GNUNET_ADV_TIMEOUT \ 42#define GNUNET_ADV_TIMEOUT \
43 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 43 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
44 44
45/**
46 * Map with hellos we build the hostlist with.
47 */
48struct GNUNET_CONTAINER_MultiPeerMap *hellos;
45 49
46/** 50/**
47 * Handle to the HTTP server as provided by libmicrohttpd for IPv6. 51 * Handle to the HTTP server as provided by libmicrohttpd for IPv6.
@@ -117,11 +121,6 @@ static char *hostlist_uri;
117struct HostSet 121struct HostSet
118{ 122{
119 /** 123 /**
120 * Iterator used to build @e data (NULL when done).
121 */
122 struct GNUNET_PEERSTORE_IterateContext *pitr;
123
124 /**
125 * Place where we accumulate all of the HELLO messages. 124 * Place where we accumulate all of the HELLO messages.
126 */ 125 */
127 char *data; 126 char *data;
@@ -194,64 +193,27 @@ finish_response ()
194 * @param hello hello message for the peer (can be NULL) 193 * @param hello hello message for the peer (can be NULL)
195 * @param err_msg message 194 * @param err_msg message
196 */ 195 */
197static void 196static enum GNUNET_GenericReturnValue
198host_processor (void *cls, 197host_processor (void *cls,
199 const struct GNUNET_PEERSTORE_Record *record, 198 const struct GNUNET_PeerIdentity *peer,
200 const char *emsg) 199 void *value)
201{ 200{
201 (void *) cls;
202 size_t old; 202 size_t old;
203 size_t s; 203 size_t s;
204 struct GNUNET_MessageHeader *hello; 204 struct GNUNET_MessageHeader *hello = value;
205 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 205 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
206 struct GNUNET_TIME_Absolute hello_exp; 206 struct GNUNET_TIME_Absolute hello_exp;
207 207
208 if (NULL != emsg) 208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 { 209 "host_processor\n");
210 GNUNET_assert (NULL == &record->peer);
211 builder->pitr = NULL;
212 GNUNET_free (builder->data);
213 GNUNET_free (builder);
214 builder = NULL;
215 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
216 _ ("Error in communication with PEERSTORE service: %s\n"),
217 emsg);
218 return;
219 }
220 if (NULL == record)
221 {
222 builder->pitr = NULL;
223 finish_response ();
224 return;
225 }
226 else
227 {
228 hello = record->value;
229 if ((0 == record->value_size))
230 {
231 GNUNET_break (0);
232 return;
233 }
234 hello_exp = GNUNET_HELLO_builder_get_expiration_time (hello);
235 if (GNUNET_TIME_absolute_cmp (hello_exp, <, now))
236 {
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
238 "HELLO for peer `%4s' has expired address, not suitable for hostlist!\n",
239 GNUNET_i2s (&record->peer));
240 GNUNET_STATISTICS_update (stats,
241 gettext_noop (
242 "Expired HELLO encountered (ignored)"),
243 1,
244 GNUNET_NO);
245 return;
246 }
247 }
248 old = builder->size; 210 old = builder->size;
249 s = ntohs (hello->size); 211 s = ntohs (hello->size);
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
251 "Received %u bytes of `%s' from peer `%s' for hostlist.\n", 213 "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
252 (unsigned int) s, 214 (unsigned int) s,
253 "HELLO", 215 "HELLO",
254 GNUNET_i2s (&record->peer)); 216 GNUNET_i2s (peer));
255 if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || 217 if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
256 (old + s >= MAX_BYTES_PER_HOSTLISTS)) 218 (old + s >= MAX_BYTES_PER_HOSTLISTS))
257 { 219 {
@@ -261,14 +223,16 @@ host_processor (void *cls,
261 "bytes not included in hostlist (size limit)"), 223 "bytes not included in hostlist (size limit)"),
262 s, 224 s,
263 GNUNET_NO); 225 GNUNET_NO);
264 return; 226 return GNUNET_YES;
265 } 227 }
266 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 228 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
267 "Adding peer `%s' to hostlist (%u bytes)\n", 229 "Adding peer `%s' to hostlist (%u bytes)\n",
268 GNUNET_i2s (&record->peer), 230 GNUNET_i2s (peer),
269 (unsigned int) s); 231 (unsigned int) s);
270 GNUNET_array_grow (builder->data, builder->size, old + s); 232 GNUNET_array_grow (builder->data, builder->size, old + s);
271 GNUNET_memcpy (&builder->data[old], hello, s); 233 GNUNET_memcpy (&builder->data[old], hello, s);
234
235 return GNUNET_YES;
272} 236}
273 237
274 238
@@ -506,20 +470,23 @@ process_notify (void *cls,
506 const struct GNUNET_MessageHeader *hello, 470 const struct GNUNET_MessageHeader *hello,
507 const char *err_msg) 471 const char *err_msg)
508{ 472{
473 unsigned int map_size;
474 struct GNUNET_MessageHeader *hello_cpy;
475 struct GNUNET_PeerIdentity *peer_cpy;
476
477 map_size = GNUNET_CONTAINER_multipeermap_size (hellos);
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Peerstore is notifying us to rebuild our hostlist\n"); 479 "Peerstore is notifying us to rebuild our hostlist map size %u\n",
480 map_size);
511 if (NULL != err_msg) 481 if (NULL != err_msg)
482 {
512 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 483 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
513 _ ("Error in communication with PEERSTORE service: %s\n"), 484 _ ("Error in communication with PEERSTORE service: %s\n"),
514 err_msg); 485 err_msg);
486 return;
487 }
515 if (NULL != builder) 488 if (NULL != builder)
516 { 489 {
517 /* restart re-build already in progress ... */
518 if (NULL != builder->pitr)
519 {
520 GNUNET_PEERSTORE_iterate_cancel (builder->pitr);
521 builder->pitr = NULL;
522 }
523 GNUNET_free (builder->data); 490 GNUNET_free (builder->data);
524 builder->size = 0; 491 builder->size = 0;
525 builder->data = NULL; 492 builder->data = NULL;
@@ -528,9 +495,27 @@ process_notify (void *cls,
528 { 495 {
529 builder = GNUNET_new (struct HostSet); 496 builder = GNUNET_new (struct HostSet);
530 } 497 }
531 GNUNET_assert (NULL != peerstore); 498
532 builder->pitr = 499 peer_cpy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
533 GNUNET_PEERSTORE_iterate (peerstore, "hostlist", NULL, GNUNET_PEERSTORE_HELLO_KEY, &host_processor, NULL); 500 GNUNET_memcpy (peer_cpy, peer, sizeof (struct GNUNET_PeerIdentity));
501 hello_cpy = GNUNET_malloc (ntohs (hello->size));
502 GNUNET_memcpy (hello_cpy, hello, ntohs (hello->size));
503 GNUNET_assert (GNUNET_YES ==
504 GNUNET_CONTAINER_multipeermap_put (hellos,
505 peer_cpy,
506 (struct
507 GNUNET_MessageHeader *)
508 hello_cpy,
509 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
510 if (0 != GNUNET_CONTAINER_multipeermap_iterate (hellos,
511 &host_processor,
512 NULL))
513 finish_response ();
514 map_size = GNUNET_CONTAINER_multipeermap_size (hellos);
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 "1 Peerstore is notifying us to rebuild our hostlist map size %u peer %s\n",
517 map_size,
518 GNUNET_i2s (peer));
534} 519}
535 520
536 521
@@ -616,9 +601,11 @@ start_notify (void *cls)
616{ 601{
617 (void) cls; 602 (void) cls;
618 603
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to process new hellos to add to hostlist.\n"); 604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
605 "Starting to process new hellos to add to hostlist.\n");
620 peerstore_notify = 606 peerstore_notify =
621 GNUNET_PEERSTORE_hello_changed_notify (peerstore, GNUNET_NO, &process_notify, NULL); 607 GNUNET_PEERSTORE_hello_changed_notify (peerstore, GNUNET_NO,
608 &process_notify, NULL);
622} 609}
623 610
624 611
@@ -651,6 +638,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
651 const struct sockaddr *sa4; 638 const struct sockaddr *sa4;
652 const struct sockaddr *sa6; 639 const struct sockaddr *sa6;
653 640
641 hellos = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
654 advertising = advertise; 642 advertising = advertise;
655 if (! advertising) 643 if (! advertising)
656 { 644 {
@@ -884,11 +872,6 @@ GNUNET_HOSTLIST_server_stop ()
884 } 872 }
885 if (NULL != builder) 873 if (NULL != builder)
886 { 874 {
887 if (NULL != builder->pitr)
888 {
889 GNUNET_PEERSTORE_iterate_cancel (builder->pitr);
890 builder->pitr = NULL;
891 }
892 GNUNET_free (builder->data); 875 GNUNET_free (builder->data);
893 GNUNET_free (builder); 876 GNUNET_free (builder);
894 builder = NULL; 877 builder = NULL;