aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2023-10-27 11:33:37 +0200
committert3sserakt <t3ss@posteo.de>2023-10-27 11:45:26 +0200
commit21be8873788b1b5a725ec78116d3c0cde5e0b6cb (patch)
treef04f59f454fae2bb67c88d4a21e0c19e79c0bab7
parentaa9bebd0ea357b84551c51ad3579bea3f7a3a662 (diff)
downloadgnunet-21be8873788b1b5a725ec78116d3c0cde5e0b6cb.tar.gz
gnunet-21be8873788b1b5a725ec78116d3c0cde5e0b6cb.zip
News: Introduced closure to hold store context when caling function to add hello in peerstore.
-rw-r--r--src/include/gnunet_peerstore_service.h10
-rw-r--r--src/service/hostlist/gnunet-daemon-hostlist_client.c13
-rw-r--r--src/service/topology/gnunet-daemon-topology.c13
3 files changed, 30 insertions, 6 deletions
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h
index 99ba98593..c57a66b1f 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -234,6 +234,16 @@ struct GNUNET_PEERSTORE_StoreHelloContext
234 int success; 234 int success;
235}; 235};
236 236
237/**
238 * Closure to hold a GNUNET_PEERSTORE_StoreHelloContext.
239 */
240struct GNUNET_PEERSTORE_StoreHelloContextClosure
241{
242 /**
243 * The GNUNET_PEERSTORE_StoreHelloContext to hold.
244 */
245 struct GNUNET_PEERSTORE_StoreHelloContext *shc;
246};
237 247
238/** 248/**
239 * Function called by PEERSTORE for each matching record. 249 * 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 483233fc6..75b497d14 100644
--- a/src/service/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/service/hostlist/gnunet-daemon-hostlist_client.c
@@ -323,7 +323,7 @@ static struct GNUNET_PEERSTORE_Handle *peerstore;
323static void 323static void
324shc_cont (void *cls, int success) 324shc_cont (void *cls, int success)
325{ 325{
326 (void *) cls; 326 struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls = cls;
327 327
328 if (GNUNET_YES == success) 328 if (GNUNET_YES == success)
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -331,6 +331,7 @@ shc_cont (void *cls, int success)
331 else 331 else
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Error storing hostlist entry!\n"); 333 "Error storing hostlist entry!\n");
334 GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, shc_cls->shc);
334} 335}
335 336
336 337
@@ -348,6 +349,7 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
348{ 349{
349 static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; 350 static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1];
350 struct GNUNET_PEERSTORE_StoreHelloContext *shc; 351 struct GNUNET_PEERSTORE_StoreHelloContext *shc;
352 struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls;
351 const char *cbuf = ptr; 353 const char *cbuf = ptr;
352 const struct GNUNET_MessageHeader *msg; 354 const struct GNUNET_MessageHeader *msg;
353 size_t total; 355 size_t total;
@@ -411,11 +413,16 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
411 1, 413 1,
412 GNUNET_NO); 414 GNUNET_NO);
413 stat_hellos_obtained++; 415 stat_hellos_obtained++;
416 shc_cls = GNUNET_new (struct GNUNET_PEERSTORE_StoreHelloContextClosure);
414 shc = GNUNET_PEERSTORE_hello_add (peerstore, 417 shc = GNUNET_PEERSTORE_hello_add (peerstore,
415 msg, 418 msg,
416 shc_cont, 419 shc_cont,
417 NULL); 420 shc_cls);
418 GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc); 421 if (NULL != shc)
422 {
423 shc_cls->shc = shc;
424 GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc);
425 }
419 memmove (download_buffer, &download_buffer[msize], download_pos - msize); 426 memmove (download_buffer, &download_buffer[msize], download_pos - msize);
420 download_pos -= msize; 427 download_pos -= msize;
421 } 428 }
diff --git a/src/service/topology/gnunet-daemon-topology.c b/src/service/topology/gnunet-daemon-topology.c
index 0f4b046f8..19bd29563 100644
--- a/src/service/topology/gnunet-daemon-topology.c
+++ b/src/service/topology/gnunet-daemon-topology.c
@@ -843,7 +843,7 @@ check_hello (void *cls, const struct GNUNET_MessageHeader *message)
843static void 843static void
844shc_cont (void *cls, int success) 844shc_cont (void *cls, int success)
845{ 845{
846 (void *) cls; 846 struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls = cls;
847 847
848 if (GNUNET_YES == success) 848 if (GNUNET_YES == success)
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -851,6 +851,7 @@ shc_cont (void *cls, int success)
851 else 851 else
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Error storing hello!\n"); 853 "Error storing hello!\n");
854 GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, shc_cls->shc);
854} 855}
855 856
856 857
@@ -865,6 +866,7 @@ static void
865handle_hello (void *cls, const struct GNUNET_MessageHeader *message) 866handle_hello (void *cls, const struct GNUNET_MessageHeader *message)
866{ 867{
867 struct GNUNET_PEERSTORE_StoreHelloContext *shc; 868 struct GNUNET_PEERSTORE_StoreHelloContext *shc;
869 struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls;
868 const struct GNUNET_PeerIdentity *other = cls; 870 const struct GNUNET_PeerIdentity *other = cls;
869 struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg ( 871 struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (
870 message); 872 message);
@@ -877,8 +879,13 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *message)
877 1, 879 1,
878 GNUNET_NO); 880 GNUNET_NO);
879 GNUNET_HELLO_builder_from_msg (message); 881 GNUNET_HELLO_builder_from_msg (message);
880 shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, NULL); 882 shc_cls = GNUNET_new (struct GNUNET_PEERSTORE_StoreHelloContextClosure);
881 GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc); 883 shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, shc_cls);
884 if (NULL != shc)
885 {
886 shc_cls->shc = shc;
887 GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc);
888 }
882 GNUNET_HELLO_builder_free (builder); 889 GNUNET_HELLO_builder_free (builder);
883} 890}
884 891