diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2024-02-25 10:53:16 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2024-02-25 10:53:16 +0100 |
commit | 2de3ca3a659f731aa9e533991db5fd46e7e90860 (patch) | |
tree | c223ac0f564bf7207937d930205dd1e55dc64cd1 | |
parent | 3761097c25ff5c4a8dd660d77f83b98d62d0bda3 (diff) | |
download | gnunet-2de3ca3a659f731aa9e533991db5fd46e7e90860.tar.gz gnunet-2de3ca3a659f731aa9e533991db5fd46e7e90860.zip |
PEERSTORE: Fix hello_add API
The new UPSERT API does not work as indended.
Instead, we now iterate over all entries and check if we have a newer
hello to add/replace.
This also fixes some handle/closure oddities exposed in the peerstore
API.
-rw-r--r-- | src/include/gnunet_peerstore_service.h | 54 | ||||
-rw-r--r-- | src/service/hostlist/gnunet-daemon-hostlist_client.c | 88 | ||||
-rw-r--r-- | src/service/peerstore/peerstore_api.c | 119 | ||||
-rw-r--r-- | src/service/topology/gnunet-daemon-topology.c | 60 |
4 files changed, 197 insertions, 124 deletions
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h index 0284d46dd..319946e1d 100644 --- a/src/include/gnunet_peerstore_service.h +++ b/src/include/gnunet_peerstore_service.h | |||
@@ -181,60 +181,8 @@ typedef void (*GNUNET_PEERSTORE_Continuation) (void *cls, int success); | |||
181 | /** | 181 | /** |
182 | * Context for a add hello uri request. | 182 | * Context for a add hello uri request. |
183 | */ | 183 | */ |
184 | struct GNUNET_PEERSTORE_StoreHelloContext | 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 | * Hello uri which was request for storing. | ||
213 | */ | ||
214 | struct GNUNET_MessageHeader *hello; | ||
215 | |||
216 | /** | ||
217 | * The peer id for the hello. | ||
218 | */ | ||
219 | struct GNUNET_PeerIdentity *pid; | ||
220 | |||
221 | /** | ||
222 | * The iteration for the merge | ||
223 | */ | ||
224 | struct GNUNET_PEERSTORE_StoreContext *sc; | ||
225 | 185 | ||
226 | }; | ||
227 | |||
228 | /** | ||
229 | * Closure to hold a GNUNET_PEERSTORE_StoreHelloContext. | ||
230 | */ | ||
231 | struct GNUNET_PEERSTORE_StoreHelloContextClosure | ||
232 | { | ||
233 | /** | ||
234 | * The GNUNET_PEERSTORE_StoreHelloContext to hold. | ||
235 | */ | ||
236 | struct GNUNET_PEERSTORE_StoreHelloContext *shc; | ||
237 | }; | ||
238 | 186 | ||
239 | /** | 187 | /** |
240 | * Function called by PEERSTORE for each matching record. | 188 | * 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 9388c8940..95891a1ad 100644 --- a/src/service/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/service/hostlist/gnunet-daemon-hostlist_client.c | |||
@@ -138,6 +138,26 @@ struct Hostlist | |||
138 | uint32_t times_used; | 138 | uint32_t times_used; |
139 | }; | 139 | }; |
140 | 140 | ||
141 | /** | ||
142 | * Context for a add hello uri request. | ||
143 | */ | ||
144 | struct StoreHelloEntry | ||
145 | { | ||
146 | /** | ||
147 | * Kept (also) in a DLL. | ||
148 | */ | ||
149 | struct StoreHelloEntry *prev; | ||
150 | |||
151 | /** | ||
152 | * Kept (also) in a DLL. | ||
153 | */ | ||
154 | struct StoreHelloEntry *next; | ||
155 | |||
156 | /** | ||
157 | * Store hello ctx | ||
158 | */ | ||
159 | struct GNUNET_PEERSTORE_StoreHelloContext *sc; | ||
160 | }; | ||
141 | 161 | ||
142 | /** | 162 | /** |
143 | * Our configuration. | 163 | * Our configuration. |
@@ -232,12 +252,12 @@ static struct GNUNET_TIME_Absolute end_time; | |||
232 | /** | 252 | /** |
233 | * Head of the linkd list to store the store context for hellos. | 253 | * Head of the linkd list to store the store context for hellos. |
234 | */ | 254 | */ |
235 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head; | 255 | static struct StoreHelloEntry *she_head; |
236 | 256 | ||
237 | /** | 257 | /** |
238 | * Tail of the linkd list to store the store context for hellos. | 258 | * Tail of the linkd list to store the store context for hellos. |
239 | */ | 259 | */ |
240 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail; | 260 | static struct StoreHelloEntry *she_tail; |
241 | 261 | ||
242 | /** | 262 | /** |
243 | * Head of the linked list used to store hostlists | 263 | * Head of the linked list used to store hostlists |
@@ -323,16 +343,17 @@ static struct GNUNET_PEERSTORE_Handle *peerstore; | |||
323 | static void | 343 | static void |
324 | shc_cont (void *cls, int success) | 344 | shc_cont (void *cls, int success) |
325 | { | 345 | { |
326 | struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls = cls; | 346 | struct StoreHelloEntry *she = cls; |
327 | 347 | ||
348 | she->sc = NULL; | ||
328 | if (GNUNET_YES == success) | 349 | if (GNUNET_YES == success) |
329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
330 | "Hostlist entry stored successfully!\n"); | 351 | "Hostlist entry stored successfully!\n"); |
331 | else | 352 | else |
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
333 | "Error storing hostlist entry!\n"); | 354 | "Error storing hostlist entry!\n"); |
334 | GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, shc_cls->shc); | 355 | GNUNET_CONTAINER_DLL_remove (she_head, she_tail, she); |
335 | GNUNET_free (shc_cls); | 356 | GNUNET_free (she); |
336 | } | 357 | } |
337 | 358 | ||
338 | 359 | ||
@@ -349,8 +370,7 @@ static size_t | |||
349 | callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | 370 | callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) |
350 | { | 371 | { |
351 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; | 372 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; |
352 | struct GNUNET_PEERSTORE_StoreHelloContext *shc; | 373 | struct StoreHelloEntry *she; |
353 | struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls; | ||
354 | const char *cbuf = ptr; | 374 | const char *cbuf = ptr; |
355 | const struct GNUNET_MessageHeader *msg; | 375 | const struct GNUNET_MessageHeader *msg; |
356 | size_t total; | 376 | size_t total; |
@@ -414,18 +434,17 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
414 | 1, | 434 | 1, |
415 | GNUNET_NO); | 435 | GNUNET_NO); |
416 | stat_hellos_obtained++; | 436 | stat_hellos_obtained++; |
417 | shc_cls = GNUNET_new (struct GNUNET_PEERSTORE_StoreHelloContextClosure); | 437 | she = GNUNET_new (struct StoreHelloEntry); |
418 | shc = GNUNET_PEERSTORE_hello_add (peerstore, | 438 | she->sc = GNUNET_PEERSTORE_hello_add (peerstore, |
419 | msg, | 439 | msg, |
420 | shc_cont, | 440 | shc_cont, |
421 | shc_cls); | 441 | she); |
422 | if (NULL != shc) | 442 | if (NULL != she->sc) |
423 | { | 443 | { |
424 | shc_cls->shc = shc; | 444 | GNUNET_CONTAINER_DLL_insert (she_head, she_tail, she); |
425 | GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc); | ||
426 | } | 445 | } |
427 | else | 446 | else |
428 | GNUNET_free (shc_cls); | 447 | GNUNET_free (she); |
429 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); | 448 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); |
430 | download_pos -= msize; | 449 | download_pos -= msize; |
431 | } | 450 | } |
@@ -1042,28 +1061,40 @@ download_hostlist () | |||
1042 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); | 1061 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); |
1043 | #ifdef CURLOPT_REDIR_PROTOCOLS_STR | 1062 | #ifdef CURLOPT_REDIR_PROTOCOLS_STR |
1044 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) | 1063 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) |
1045 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "https")); | 1064 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, |
1065 | CURLOPT_REDIR_PROTOCOLS_STR, | ||
1066 | "https")); | ||
1046 | else | 1067 | else |
1047 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https")); | 1068 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, |
1069 | CURLOPT_REDIR_PROTOCOLS_STR, | ||
1070 | "http,https")); | ||
1048 | #else | 1071 | #else |
1049 | #ifdef CURLOPT_REDIR_PROTOCOLS | 1072 | #ifdef CURLOPT_REDIR_PROTOCOLS |
1050 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) | 1073 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) |
1051 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS)); | 1074 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, |
1075 | CURLPROTO_HTTPS)); | ||
1052 | else | 1076 | else |
1053 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS)); | 1077 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, |
1078 | CURLPROTO_HTTP | ||
1079 | | CURLPROTO_HTTPS)); | ||
1054 | #endif | 1080 | #endif |
1055 | #endif | 1081 | #endif |
1056 | #ifdef CURLOPT_PROTOCOLS_STR | 1082 | #ifdef CURLOPT_PROTOCOLS_STR |
1057 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) | 1083 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) |
1058 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR, "https")); | 1084 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR, |
1085 | "https")); | ||
1059 | else | 1086 | else |
1060 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR, "http,https")); | 1087 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR, |
1088 | "http,https")); | ||
1061 | #else | 1089 | #else |
1062 | #ifdef CURLOPT_PROTOCOLS | 1090 | #ifdef CURLOPT_PROTOCOLS |
1063 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) | 1091 | if (0 == strncasecmp (current_url, "https://", strlen ("https://"))) |
1064 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS)); | 1092 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS, |
1093 | CURLPROTO_HTTPS)); | ||
1065 | else | 1094 | else |
1066 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS)); | 1095 | GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS, |
1096 | CURLPROTO_HTTP | ||
1097 | | CURLPROTO_HTTPS)); | ||
1067 | #endif | 1098 | #endif |
1068 | #endif | 1099 | #endif |
1069 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); | 1100 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); |
@@ -1784,13 +1815,14 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1784 | void | 1815 | void |
1785 | GNUNET_HOSTLIST_client_stop () | 1816 | GNUNET_HOSTLIST_client_stop () |
1786 | { | 1817 | { |
1787 | struct GNUNET_PEERSTORE_StoreHelloContext *pos; | 1818 | struct StoreHelloEntry *pos; |
1788 | 1819 | ||
1789 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); | 1820 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1790 | while (NULL != (pos = shc_head)) | 1821 | while (NULL != (pos = she_head)) |
1791 | { | 1822 | { |
1792 | GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos); | 1823 | GNUNET_CONTAINER_DLL_remove (she_head, she_tail, pos); |
1793 | GNUNET_PEERSTORE_hello_add_cancel (pos); | 1824 | GNUNET_PEERSTORE_hello_add_cancel (pos->sc); |
1825 | GNUNET_free (pos); | ||
1794 | } | 1826 | } |
1795 | if (NULL != sget) | 1827 | if (NULL != sget) |
1796 | { | 1828 | { |
diff --git a/src/service/peerstore/peerstore_api.c b/src/service/peerstore/peerstore_api.c index 6272ebdff..bf8b990e5 100644 --- a/src/service/peerstore/peerstore_api.c +++ b/src/service/peerstore/peerstore_api.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @author Omar Tarabai | 23 | * @author Omar Tarabai |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "gnunet_time_lib.h" | ||
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
28 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
@@ -96,6 +97,47 @@ struct GNUNET_PEERSTORE_Handle | |||
96 | }; | 97 | }; |
97 | 98 | ||
98 | /** | 99 | /** |
100 | * Context for a add hello uri request. | ||
101 | */ | ||
102 | struct GNUNET_PEERSTORE_StoreHelloContext | ||
103 | { | ||
104 | /** | ||
105 | * Peerstore handle. | ||
106 | */ | ||
107 | struct GNUNET_PEERSTORE_Handle *h; | ||
108 | |||
109 | /** | ||
110 | * Function to call with information. | ||
111 | */ | ||
112 | GNUNET_PEERSTORE_Continuation cont; | ||
113 | |||
114 | /** | ||
115 | * Closure for @e callback. | ||
116 | */ | ||
117 | void *cont_cls; | ||
118 | |||
119 | /** | ||
120 | * Hello uri which was request for storing. | ||
121 | */ | ||
122 | struct GNUNET_MessageHeader *hello; | ||
123 | |||
124 | /** | ||
125 | * The peer id for the hello. | ||
126 | */ | ||
127 | struct GNUNET_PeerIdentity pid; | ||
128 | |||
129 | /** | ||
130 | * Store operation for the merge | ||
131 | */ | ||
132 | struct GNUNET_PEERSTORE_StoreContext *sc; | ||
133 | |||
134 | /** | ||
135 | * The iteration for the merge | ||
136 | */ | ||
137 | struct GNUNET_PEERSTORE_IterateContext *ic; | ||
138 | }; | ||
139 | |||
140 | /** | ||
99 | * Context for a store request | 141 | * Context for a store request |
100 | */ | 142 | */ |
101 | struct GNUNET_PEERSTORE_StoreContext | 143 | struct GNUNET_PEERSTORE_StoreContext |
@@ -635,7 +677,7 @@ handle_iterate_result (void *cls, const struct PeerstoreRecordMessage *msg) | |||
635 | */ | 677 | */ |
636 | void | 678 | void |
637 | GNUNET_PEERSTORE_iteration_next (struct GNUNET_PEERSTORE_IterateContext *ic, | 679 | GNUNET_PEERSTORE_iteration_next (struct GNUNET_PEERSTORE_IterateContext *ic, |
638 | uint64_t limit) | 680 | uint64_t limit) |
639 | { | 681 | { |
640 | struct GNUNET_MQ_Envelope *ev; | 682 | struct GNUNET_MQ_Envelope *ev; |
641 | struct PeerstoreIterationNextMessage *inm; | 683 | struct PeerstoreIterationNextMessage *inm; |
@@ -686,11 +728,11 @@ GNUNET_PEERSTORE_iteration_stop (struct GNUNET_PEERSTORE_IterateContext *ic) | |||
686 | 728 | ||
687 | struct GNUNET_PEERSTORE_IterateContext * | 729 | struct GNUNET_PEERSTORE_IterateContext * |
688 | GNUNET_PEERSTORE_iteration_start (struct GNUNET_PEERSTORE_Handle *h, | 730 | GNUNET_PEERSTORE_iteration_start (struct GNUNET_PEERSTORE_Handle *h, |
689 | const char *sub_system, | 731 | const char *sub_system, |
690 | const struct GNUNET_PeerIdentity *peer, | 732 | const struct GNUNET_PeerIdentity *peer, |
691 | const char *key, | 733 | const char *key, |
692 | GNUNET_PEERSTORE_Processor callback, | 734 | GNUNET_PEERSTORE_Processor callback, |
693 | void *callback_cls) | 735 | void *callback_cls) |
694 | { | 736 | { |
695 | struct GNUNET_MQ_Envelope *ev; | 737 | struct GNUNET_MQ_Envelope *ev; |
696 | struct PeerstoreIterationStartMessage *srm; | 738 | struct PeerstoreIterationStartMessage *srm; |
@@ -806,17 +848,50 @@ hello_store_success (void *cls, int success) | |||
806 | "Storing hello uri failed\n"); | 848 | "Storing hello uri failed\n"); |
807 | huc->cont (huc->cont_cls, success); | 849 | huc->cont (huc->cont_cls, success); |
808 | GNUNET_free (huc->hello); | 850 | GNUNET_free (huc->hello); |
809 | GNUNET_free (huc->pid); | ||
810 | GNUNET_free (huc); | 851 | GNUNET_free (huc); |
811 | return; | 852 | return; |
812 | } | 853 | } |
813 | huc->cont (huc->cont_cls, GNUNET_OK); | 854 | huc->cont (huc->cont_cls, GNUNET_OK); |
814 | GNUNET_free (huc->hello); | 855 | GNUNET_free (huc->hello); |
815 | GNUNET_free (huc->pid); | ||
816 | GNUNET_free (huc); | 856 | GNUNET_free (huc); |
817 | } | 857 | } |
818 | 858 | ||
819 | 859 | ||
860 | static void | ||
861 | hello_add_iter (void *cls, const struct GNUNET_PEERSTORE_Record *record, | ||
862 | const char *emsg) | ||
863 | { | ||
864 | struct GNUNET_PEERSTORE_StoreHelloContext *huc = cls; | ||
865 | struct GNUNET_TIME_Absolute hello_exp = | ||
866 | GNUNET_HELLO_builder_get_expiration_time (huc->hello); | ||
867 | if (NULL == record) | ||
868 | { | ||
869 | /** If we ever get here, we are newer than the existing record | ||
870 | * or the only/first record. | ||
871 | */ | ||
872 | huc->sc = GNUNET_PEERSTORE_store (huc->h, | ||
873 | "peerstore", | ||
874 | &huc->pid, | ||
875 | GNUNET_PEERSTORE_HELLO_KEY, | ||
876 | huc->hello, | ||
877 | ntohs (huc->hello->size), | ||
878 | hello_exp, | ||
879 | GNUNET_PEERSTORE_STOREOPTION_UPSERT_LATER_EXPIRY, | ||
880 | &hello_store_success, | ||
881 | huc); | ||
882 | return; | ||
883 | } | ||
884 | if (GNUNET_TIME_absolute_cmp (record->expiry, >, hello_exp)) | ||
885 | { | ||
886 | huc->cont (huc->cont_cls, GNUNET_OK); | ||
887 | GNUNET_PEERSTORE_iteration_stop (huc->ic); | ||
888 | GNUNET_free (huc->hello); | ||
889 | GNUNET_free (huc); | ||
890 | return; | ||
891 | } | ||
892 | } | ||
893 | |||
894 | |||
820 | struct GNUNET_PEERSTORE_StoreHelloContext * | 895 | struct GNUNET_PEERSTORE_StoreHelloContext * |
821 | GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h, | 896 | GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h, |
822 | const struct GNUNET_MessageHeader *msg, | 897 | const struct GNUNET_MessageHeader *msg, |
@@ -830,7 +905,6 @@ GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h, | |||
830 | struct GNUNET_TIME_Absolute hello_exp = | 905 | struct GNUNET_TIME_Absolute hello_exp = |
831 | GNUNET_HELLO_builder_get_expiration_time (msg); | 906 | GNUNET_HELLO_builder_get_expiration_time (msg); |
832 | struct GNUNET_TIME_Absolute huc_exp; | 907 | struct GNUNET_TIME_Absolute huc_exp; |
833 | uint16_t pid_size; | ||
834 | uint16_t size_msg = ntohs (msg->size); | 908 | uint16_t size_msg = ntohs (msg->size); |
835 | 909 | ||
836 | if (NULL == builder) | 910 | if (NULL == builder) |
@@ -847,24 +921,17 @@ GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h, | |||
847 | huc_exp = | 921 | huc_exp = |
848 | GNUNET_HELLO_builder_get_expiration_time (huc->hello); | 922 | GNUNET_HELLO_builder_get_expiration_time (huc->hello); |
849 | pid = GNUNET_HELLO_builder_get_id (builder); | 923 | pid = GNUNET_HELLO_builder_get_id (builder); |
850 | pid_size = sizeof (struct GNUNET_PeerIdentity); | 924 | huc->pid = *pid; |
851 | huc->pid = GNUNET_malloc (pid_size); | ||
852 | GNUNET_memcpy (huc->pid, pid, pid_size); | ||
853 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 925 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
854 | "Adding hello for peer %s with expiration %s msg size %u\n", | 926 | "Adding hello for peer %s with expiration %s msg size %u\n", |
855 | GNUNET_i2s (huc->pid), | 927 | GNUNET_i2s (&huc->pid), |
856 | GNUNET_STRINGS_absolute_time_to_string (huc_exp), | 928 | GNUNET_STRINGS_absolute_time_to_string (huc_exp), |
857 | size_msg); | 929 | size_msg); |
858 | huc->sc = GNUNET_PEERSTORE_store (h, | 930 | |
859 | "peerstore", | 931 | huc->ic = GNUNET_PEERSTORE_iteration_start (h, "peerstore", &huc->pid, |
860 | huc->pid, | 932 | GNUNET_PEERSTORE_HELLO_KEY, |
861 | GNUNET_PEERSTORE_HELLO_KEY, | 933 | &hello_add_iter, |
862 | huc->hello, | 934 | huc); |
863 | ntohs (huc->hello->size), | ||
864 | hello_exp, | ||
865 | GNUNET_PEERSTORE_STOREOPTION_UPSERT_LATER_EXPIRY, | ||
866 | &hello_store_success, | ||
867 | huc); | ||
868 | GNUNET_HELLO_builder_free (builder); | 935 | GNUNET_HELLO_builder_free (builder); |
869 | return huc; | 936 | return huc; |
870 | } | 937 | } |
@@ -874,9 +941,11 @@ void | |||
874 | GNUNET_PEERSTORE_hello_add_cancel (struct | 941 | GNUNET_PEERSTORE_hello_add_cancel (struct |
875 | GNUNET_PEERSTORE_StoreHelloContext *huc) | 942 | GNUNET_PEERSTORE_StoreHelloContext *huc) |
876 | { | 943 | { |
877 | GNUNET_PEERSTORE_store_cancel (huc->sc); | 944 | if (NULL != huc->sc) |
945 | GNUNET_PEERSTORE_store_cancel (huc->sc); | ||
946 | if (NULL != huc->ic) | ||
947 | GNUNET_PEERSTORE_iteration_stop (huc->ic); | ||
878 | GNUNET_free (huc->hello); | 948 | GNUNET_free (huc->hello); |
879 | GNUNET_free (huc->pid); | ||
880 | GNUNET_free (huc); | 949 | GNUNET_free (huc); |
881 | } | 950 | } |
882 | 951 | ||
diff --git a/src/service/topology/gnunet-daemon-topology.c b/src/service/topology/gnunet-daemon-topology.c index 588000358..c59610014 100644 --- a/src/service/topology/gnunet-daemon-topology.c +++ b/src/service/topology/gnunet-daemon-topology.c | |||
@@ -107,6 +107,26 @@ struct Peer | |||
107 | 107 | ||
108 | }; | 108 | }; |
109 | 109 | ||
110 | /** | ||
111 | * Context for a add hello uri request. | ||
112 | */ | ||
113 | struct StoreHelloEntry | ||
114 | { | ||
115 | /** | ||
116 | * Kept (also) in a DLL. | ||
117 | */ | ||
118 | struct StoreHelloEntry *prev; | ||
119 | |||
120 | /** | ||
121 | * Kept (also) in a DLL. | ||
122 | */ | ||
123 | struct StoreHelloEntry *next; | ||
124 | |||
125 | /** | ||
126 | * Store hello ctx | ||
127 | */ | ||
128 | struct GNUNET_PEERSTORE_StoreHelloContext *sc; | ||
129 | }; | ||
110 | 130 | ||
111 | /** | 131 | /** |
112 | * The task to delayed start the notification process intially. | 132 | * The task to delayed start the notification process intially. |
@@ -182,12 +202,12 @@ static unsigned int target_connection_count; | |||
182 | /** | 202 | /** |
183 | * Head of the linkd list to store the store context for hellos. | 203 | * Head of the linkd list to store the store context for hellos. |
184 | */ | 204 | */ |
185 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_head; | 205 | static struct StoreHelloEntry *she_head; |
186 | 206 | ||
187 | /** | 207 | /** |
188 | * Tail of the linkd list to store the store context for hellos. | 208 | * Tail of the linkd list to store the store context for hellos. |
189 | */ | 209 | */ |
190 | static struct GNUNET_PEERSTORE_StoreHelloContext *shc_tail; | 210 | static struct StoreHelloEntry *she_tail; |
191 | 211 | ||
192 | /** | 212 | /** |
193 | * Free all resources associated with the given peer. | 213 | * Free all resources associated with the given peer. |
@@ -730,10 +750,12 @@ static void | |||
730 | error_cb (void *cls) | 750 | error_cb (void *cls) |
731 | { | 751 | { |
732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
733 | _ ("Error in communication with PEERSTORE service to monitor.\n")); | 753 | _ ( |
754 | "Error in communication with PEERSTORE service to monitor.\n")); | ||
734 | return; | 755 | return; |
735 | } | 756 | } |
736 | 757 | ||
758 | |||
737 | static void | 759 | static void |
738 | sync_cb (void *cls) | 760 | sync_cb (void *cls) |
739 | { | 761 | { |
@@ -742,6 +764,7 @@ sync_cb (void *cls) | |||
742 | return; | 764 | return; |
743 | } | 765 | } |
744 | 766 | ||
767 | |||
745 | /** | 768 | /** |
746 | * PEERSTORE calls this function to let us know about a possible peer | 769 | * PEERSTORE calls this function to let us know about a possible peer |
747 | * that we might want to connect to. | 770 | * that we might want to connect to. |
@@ -886,16 +909,17 @@ check_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
886 | static void | 909 | static void |
887 | shc_cont (void *cls, int success) | 910 | shc_cont (void *cls, int success) |
888 | { | 911 | { |
889 | struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls = cls; | 912 | struct StoreHelloEntry *she = cls; |
890 | 913 | ||
914 | she->sc = NULL; | ||
891 | if (GNUNET_YES == success) | 915 | if (GNUNET_YES == success) |
892 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
893 | "Hello stored successfully!\n"); | 917 | "Hello stored successfully!\n"); |
894 | else | 918 | else |
895 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
896 | "Error storing hello!\n"); | 920 | "Error storing hello!\n"); |
897 | GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, shc_cls->shc); | 921 | GNUNET_CONTAINER_DLL_remove (she_head, she_tail, she); |
898 | GNUNET_free (shc_cls); | 922 | GNUNET_free (she); |
899 | } | 923 | } |
900 | 924 | ||
901 | 925 | ||
@@ -909,8 +933,7 @@ shc_cont (void *cls, int success) | |||
909 | static void | 933 | static void |
910 | handle_hello (void *cls, const struct GNUNET_MessageHeader *message) | 934 | handle_hello (void *cls, const struct GNUNET_MessageHeader *message) |
911 | { | 935 | { |
912 | struct GNUNET_PEERSTORE_StoreHelloContext *shc; | 936 | struct StoreHelloEntry *she; |
913 | struct GNUNET_PEERSTORE_StoreHelloContextClosure *shc_cls; | ||
914 | const struct GNUNET_PeerIdentity *other = cls; | 937 | const struct GNUNET_PeerIdentity *other = cls; |
915 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg ( | 938 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg ( |
916 | message); | 939 | message); |
@@ -923,15 +946,14 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
923 | 1, | 946 | 1, |
924 | GNUNET_NO); | 947 | GNUNET_NO); |
925 | GNUNET_HELLO_builder_from_msg (message); | 948 | GNUNET_HELLO_builder_from_msg (message); |
926 | shc_cls = GNUNET_new (struct GNUNET_PEERSTORE_StoreHelloContextClosure); | 949 | she = GNUNET_new (struct StoreHelloEntry); |
927 | shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, shc_cls); | 950 | she->sc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, she); |
928 | if (NULL != shc) | 951 | if (NULL != she->sc) |
929 | { | 952 | { |
930 | shc_cls->shc = shc; | 953 | GNUNET_CONTAINER_DLL_insert (she_head, she_tail, she); |
931 | GNUNET_CONTAINER_DLL_insert (shc_head, shc_tail, shc); | ||
932 | } | 954 | } |
933 | else | 955 | else |
934 | GNUNET_free (shc_cls); | 956 | GNUNET_free (she); |
935 | GNUNET_HELLO_builder_free (builder); | 957 | GNUNET_HELLO_builder_free (builder); |
936 | } | 958 | } |
937 | 959 | ||
@@ -945,13 +967,15 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
945 | static void | 967 | static void |
946 | cleaning_task (void *cls) | 968 | cleaning_task (void *cls) |
947 | { | 969 | { |
948 | struct GNUNET_PEERSTORE_StoreHelloContext *pos; | 970 | struct StoreHelloEntry *pos; |
949 | 971 | ||
950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology shutdown\n"); | 972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology shutdown\n"); |
951 | while (NULL != (pos = shc_head)) | 973 | while (NULL != (pos = she_head)) |
952 | { | 974 | { |
953 | GNUNET_CONTAINER_DLL_remove (shc_head, shc_tail, pos); | 975 | GNUNET_CONTAINER_DLL_remove (she_head, she_tail, pos); |
954 | GNUNET_PEERSTORE_hello_add_cancel (pos); | 976 | if (NULL != pos->sc) |
977 | GNUNET_PEERSTORE_hello_add_cancel (pos->sc); | ||
978 | GNUNET_free (pos); | ||
955 | } | 979 | } |
956 | if (NULL != peerstore_notify) | 980 | if (NULL != peerstore_notify) |
957 | { | 981 | { |