diff options
author | t3sserakt <t3ss@posteo.de> | 2023-10-24 14:56:14 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2023-10-24 14:56:14 +0200 |
commit | 233a6be0f23f0dcd0f1c40e4f816d1380f872a40 (patch) | |
tree | 161383bb4c6d8b7885602c1e24f6eff9ee13550d | |
parent | b5e243908f1539b9f00bfe5c485804d02d682aab (diff) | |
download | gnunet-233a6be0f23f0dcd0f1c40e4f816d1380f872a40.tar.gz gnunet-233a6be0f23f0dcd0f1c40e4f816d1380f872a40.zip |
News: Added DDLs for handling GNUNET_PEERSTORE_StoreHelloContext
-rw-r--r-- | src/include/gnunet_peerstore_service.h | 57 | ||||
-rw-r--r-- | src/service/hostlist/gnunet-daemon-hostlist_client.c | 30 | ||||
-rw-r--r-- | src/service/peerstore/peerstore_api.c | 48 | ||||
-rw-r--r-- | src/service/topology/gnunet-daemon-topology.c | 31 | ||||
-rw-r--r-- | 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 | |||
@@ -179,6 +179,63 @@ typedef void (*GNUNET_PEERSTORE_Continuation) (void *cls, int success); | |||
179 | 179 | ||
180 | 180 | ||
181 | /** | 181 | /** |
182 | * Context for a add hello uri request. | ||
183 | */ | ||
184 | struct GNUNET_PEERSTORE_StoreHelloContext | ||
185 | { | ||
186 | /** | ||
187 | * Kept (also) in a DLL. | ||
188 | */ | ||
189 | struct GNUNET_PEERSTORE_StoreHelloContext *prev; | ||
190 | |||
191 | /** | ||
192 | * Kept (also) in a DLL. | ||
193 | */ | ||
194 | struct GNUNET_PEERSTORE_StoreHelloContext *next; | ||
195 | |||
196 | /** | ||
197 | * Peerstore handle. | ||
198 | */ | ||
199 | struct GNUNET_PEERSTORE_Handle *h; | ||
200 | |||
201 | /** | ||
202 | * Function to call with information. | ||
203 | */ | ||
204 | GNUNET_PEERSTORE_Continuation cont; | ||
205 | |||
206 | /** | ||
207 | * Closure for @e callback. | ||
208 | */ | ||
209 | void *cont_cls; | ||
210 | |||
211 | /** | ||
212 | * Map with all store contexts started during adding hello. | ||
213 | */ | ||
214 | struct GNUNET_CONTAINER_MultiPeerMap *store_context_map; | ||
215 | |||
216 | /** | ||
217 | * Active watch to be notified about conflicting hello uri add requests. | ||
218 | */ | ||
219 | struct GNUNET_PEERSTORE_WatchContext *wc; | ||
220 | |||
221 | /** | ||
222 | * Hello uri which was request for storing. | ||
223 | */ | ||
224 | struct GNUNET_MessageHeader *hello; | ||
225 | |||
226 | /** | ||
227 | * The peer id for the hello. | ||
228 | */ | ||
229 | struct GNUNET_PeerIdentity *pid; | ||
230 | |||
231 | /** | ||
232 | * Was this request successful. | ||
233 | */ | ||
234 | int success; | ||
235 | }; | ||
236 | |||
237 | |||
238 | /** | ||
182 | * Function called by PEERSTORE for each matching record. | 239 | * Function called by PEERSTORE for each matching record. |
183 | * | 240 | * |
184 | * @param cls closure | 241 | * @param cls closure |
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 | |||
@@ -230,6 +230,16 @@ static struct GNUNET_SCHEDULER_Task *ti_testing_intervall_task; | |||
230 | static struct GNUNET_TIME_Absolute end_time; | 230 | static struct GNUNET_TIME_Absolute end_time; |
231 | 231 | ||
232 | /** | 232 | /** |
233 | * Head of the linkd list to store the store context for hellos. | ||
234 | */ | ||
235 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head; | ||
236 | |||
237 | /** | ||
238 | * Tail of the linkd list to store the store context for hellos. | ||
239 | */ | ||
240 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail; | ||
241 | |||
242 | /** | ||
233 | * Head of the linked list used to store hostlists | 243 | * Head of the linked list used to store hostlists |
234 | */ | 244 | */ |
235 | static struct Hostlist *linked_list_head; | 245 | static struct Hostlist *linked_list_head; |
@@ -313,8 +323,14 @@ static struct GNUNET_PEERSTORE_Handle *peerstore; | |||
313 | static void | 323 | static void |
314 | shc_cont (void *cls, int success) | 324 | shc_cont (void *cls, int success) |
315 | { | 325 | { |
316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 326 | (void *) cls; |
317 | "Hostlist entry stored successfully!\n"); | 327 | |
328 | if (GNUNET_YES == success) | ||
329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
330 | "Hostlist entry stored successfully!\n"); | ||
331 | else | ||
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
333 | "Error storing hostlist entry!\n"); | ||
318 | } | 334 | } |
319 | 335 | ||
320 | 336 | ||
@@ -398,7 +414,8 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
398 | shc = GNUNET_PEERSTORE_hello_add (peerstore, | 414 | shc = GNUNET_PEERSTORE_hello_add (peerstore, |
399 | msg, | 415 | msg, |
400 | shc_cont, | 416 | shc_cont, |
401 | shc); | 417 | NULL); |
418 | GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc); | ||
402 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); | 419 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); |
403 | download_pos -= msize; | 420 | download_pos -= msize; |
404 | } | 421 | } |
@@ -1735,7 +1752,14 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1735 | void | 1752 | void |
1736 | GNUNET_HOSTLIST_client_stop () | 1753 | GNUNET_HOSTLIST_client_stop () |
1737 | { | 1754 | { |
1755 | struct GNUNET_PEERSTORE_StoreHelloContext *pos; | ||
1756 | |||
1738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); | 1757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1758 | while (NULL != (pos = shc_head)) | ||
1759 | { | ||
1760 | GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos); | ||
1761 | GNUNET_PEERSTORE_hello_add_cancel (pos); | ||
1762 | } | ||
1739 | if (NULL != sget) | 1763 | if (NULL != sget) |
1740 | { | 1764 | { |
1741 | GNUNET_STATISTICS_get_cancel (sget); | 1765 | 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 | |||
312 | unsigned int canceled; | 312 | unsigned int canceled; |
313 | }; | 313 | }; |
314 | 314 | ||
315 | /** | ||
316 | * Context for a add hello uri request. | ||
317 | */ | ||
318 | struct GNUNET_PEERSTORE_StoreHelloContext | ||
319 | { | ||
320 | /** | ||
321 | * Peerstore handle. | ||
322 | */ | ||
323 | struct GNUNET_PEERSTORE_Handle *h; | ||
324 | |||
325 | /** | ||
326 | * Function to call with information. | ||
327 | */ | ||
328 | GNUNET_PEERSTORE_Continuation cont; | ||
329 | |||
330 | /** | ||
331 | * Closure for @e callback. | ||
332 | */ | ||
333 | void *cont_cls; | ||
334 | |||
335 | /** | ||
336 | * Map with all store contexts started during adding hello. | ||
337 | */ | ||
338 | struct GNUNET_CONTAINER_MultiPeerMap *store_context_map; | ||
339 | |||
340 | /** | ||
341 | * Active watch to be notified about conflicting hello uri add requests. | ||
342 | */ | ||
343 | struct GNUNET_PEERSTORE_WatchContext *wc; | ||
344 | |||
345 | /** | ||
346 | * Hello uri which was request for storing. | ||
347 | */ | ||
348 | struct GNUNET_MessageHeader *hello; | ||
349 | |||
350 | /** | ||
351 | * The peer id for the hello. | ||
352 | */ | ||
353 | struct GNUNET_PeerIdentity *pid; | ||
354 | |||
355 | /** | ||
356 | * Was this request successful. | ||
357 | */ | ||
358 | int success; | ||
359 | }; | ||
360 | |||
361 | /******************************************************************************/ | 315 | /******************************************************************************/ |
362 | /******************* DECLARATIONS *********************/ | 316 | /******************* DECLARATIONS *********************/ |
363 | /******************************************************************************/ | 317 | /******************************************************************************/ |
@@ -1319,7 +1273,7 @@ GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h, | |||
1319 | { | 1273 | { |
1320 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (msg); | 1274 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (msg); |
1321 | struct GNUNET_PEERSTORE_StoreHelloContext *huc; | 1275 | struct GNUNET_PEERSTORE_StoreHelloContext *huc; |
1322 | struct GNUNET_PeerIdentity *pid; | 1276 | const struct GNUNET_PeerIdentity *pid; |
1323 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 1277 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
1324 | struct GNUNET_TIME_Absolute hello_exp = | 1278 | struct GNUNET_TIME_Absolute hello_exp = |
1325 | GNUNET_HELLO_builder_get_expiration_time (msg); | 1279 | 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 | |||
@@ -179,6 +179,16 @@ static unsigned int connection_count; | |||
179 | static unsigned int target_connection_count; | 179 | static unsigned int target_connection_count; |
180 | 180 | ||
181 | /** | 181 | /** |
182 | * Head of the linkd list to store the store context for hellos. | ||
183 | */ | ||
184 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head; | ||
185 | |||
186 | /** | ||
187 | * Tail of the linkd list to store the store context for hellos. | ||
188 | */ | ||
189 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail; | ||
190 | |||
191 | /** | ||
182 | * Free all resources associated with the given peer. | 192 | * Free all resources associated with the given peer. |
183 | * | 193 | * |
184 | * @param cls closure (not used) | 194 | * @param cls closure (not used) |
@@ -833,7 +843,14 @@ check_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
833 | static void | 843 | static void |
834 | shc_cont (void *cls, int success) | 844 | shc_cont (void *cls, int success) |
835 | { | 845 | { |
836 | GNUNET_free (cls); | 846 | (void *) cls; |
847 | |||
848 | if (GNUNET_YES == success) | ||
849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
850 | "Hello stored successfully!\n"); | ||
851 | else | ||
852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
853 | "Error storing hello!\n"); | ||
837 | } | 854 | } |
838 | 855 | ||
839 | 856 | ||
@@ -860,8 +877,8 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
860 | 1, | 877 | 1, |
861 | GNUNET_NO); | 878 | GNUNET_NO); |
862 | GNUNET_HELLO_builder_from_msg (message); | 879 | GNUNET_HELLO_builder_from_msg (message); |
863 | // FIXME this is not working shc uninitialized | 880 | shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, NULL); |
864 | shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, shc); | 881 | GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc); |
865 | GNUNET_HELLO_builder_free (builder); | 882 | GNUNET_HELLO_builder_free (builder); |
866 | } | 883 | } |
867 | 884 | ||
@@ -875,6 +892,14 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
875 | static void | 892 | static void |
876 | cleaning_task (void *cls) | 893 | cleaning_task (void *cls) |
877 | { | 894 | { |
895 | struct GNUNET_PEERSTORE_StoreHelloContext *pos; | ||
896 | |||
897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology shutdown\n"); | ||
898 | while (NULL != (pos = shc_head)) | ||
899 | { | ||
900 | GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos); | ||
901 | GNUNET_PEERSTORE_hello_add_cancel (pos); | ||
902 | } | ||
878 | if (NULL != peerstore_notify) | 903 | if (NULL != peerstore_notify) |
879 | { | 904 | { |
880 | GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify); | 905 | 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 | |||
@@ -2889,6 +2889,16 @@ static struct GNUNET_TIME_Absolute hello_mono_time; | |||
2889 | static int in_shutdown; | 2889 | static int in_shutdown; |
2890 | 2890 | ||
2891 | /** | 2891 | /** |
2892 | * Head of the linkd list to store the store context for hellos. | ||
2893 | */ | ||
2894 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head; | ||
2895 | |||
2896 | /** | ||
2897 | * Tail of the linkd list to store the store context for hellos. | ||
2898 | */ | ||
2899 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail; | ||
2900 | |||
2901 | /** | ||
2892 | * Get an offset into the transmission history buffer for `struct | 2902 | * Get an offset into the transmission history buffer for `struct |
2893 | * PerformanceData`. Note that the caller must perform the required | 2903 | * PerformanceData`. Note that the caller must perform the required |
2894 | * modulo #GOODPUT_AGING_SLOTS operation before indexing into the | 2904 | * modulo #GOODPUT_AGING_SLOTS operation before indexing into the |
@@ -5472,7 +5482,14 @@ peerstore_store_own_cb (void *cls, int success) | |||
5472 | static void | 5482 | static void |
5473 | shc_cont (void *cls, int success) | 5483 | shc_cont (void *cls, int success) |
5474 | { | 5484 | { |
5475 | GNUNET_free (cls); | 5485 | (void *) cls; |
5486 | |||
5487 | if (GNUNET_YES == success) | ||
5488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5489 | "Hello stored successfully!\n"); | ||
5490 | else | ||
5491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5492 | "Error storing hello!\n"); | ||
5476 | } | 5493 | } |
5477 | 5494 | ||
5478 | 5495 | ||
@@ -5517,10 +5534,13 @@ store_pi (void *cls) | |||
5517 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5518 | "store_pi 1\n"); | 5535 | "store_pi 1\n"); |
5519 | if (GNUNET_YES == add_result) | 5536 | if (GNUNET_YES == add_result) |
5537 | { | ||
5520 | shc = GNUNET_PEERSTORE_hello_add (peerstore, | 5538 | shc = GNUNET_PEERSTORE_hello_add (peerstore, |
5521 | msg, | 5539 | msg, |
5522 | shc_cont, | 5540 | shc_cont, |
5523 | shc); | 5541 | NULL); |
5542 | GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc); | ||
5543 | } | ||
5524 | else if (GNUNET_SYSERR == add_result) | 5544 | else if (GNUNET_SYSERR == add_result) |
5525 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 5545 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
5526 | "Error adding address to peerstore hello!\n"); | 5546 | "Error adding address to peerstore hello!\n"); |
@@ -11494,9 +11514,16 @@ static void | |||
11494 | do_shutdown (void *cls) | 11514 | do_shutdown (void *cls) |
11495 | { | 11515 | { |
11496 | struct LearnLaunchEntry *lle; | 11516 | struct LearnLaunchEntry *lle; |
11517 | struct GNUNET_PEERSTORE_StoreHelloContext *pos; | ||
11497 | 11518 | ||
11498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 11519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
11499 | "shutdown logic\n"); | 11520 | "shutdown logic\n"); |
11521 | while (NULL != (pos = shc_head)) | ||
11522 | { | ||
11523 | GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos); | ||
11524 | GNUNET_PEERSTORE_hello_add_cancel (pos); | ||
11525 | } | ||
11526 | |||
11500 | (void) cls; | 11527 | (void) cls; |
11501 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | 11528 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, |
11502 | &free_neighbour_cb, NULL); | 11529 | &free_neighbour_cb, NULL); |