diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/hostlist | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 282 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.h | 4 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 1771 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.h | 18 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.c | 887 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.h | 16 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 236 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 659 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | 260 |
9 files changed, 2067 insertions, 2066 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 760d5f543..7c1863dc0 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file hostlist/gnunet-daemon-hostlist.c | 22 | * @file hostlist/gnunet-daemon-hostlist.c |
@@ -102,8 +102,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
102 | * unaligned!) | 102 | * unaligned!) |
103 | * 4) address (address-length bytes; possibly unaligned!) | 103 | * 4) address (address-length bytes; possibly unaligned!) |
104 | */ | 104 | */ |
105 | struct GNUNET_HOSTLIST_ADV_Message | 105 | struct GNUNET_HOSTLIST_ADV_Message { |
106 | { | ||
107 | /** | 106 | /** |
108 | * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT. | 107 | * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT. |
109 | */ | 108 | */ |
@@ -130,8 +129,8 @@ static struct GNUNET_PeerIdentity me; | |||
130 | * @param my_identity our peer's identity | 129 | * @param my_identity our peer's identity |
131 | */ | 130 | */ |
132 | static void | 131 | static void |
133 | core_init (void *cls, | 132 | core_init(void *cls, |
134 | const struct GNUNET_PeerIdentity *my_identity) | 133 | const struct GNUNET_PeerIdentity *my_identity) |
135 | { | 134 | { |
136 | me = *my_identity; | 135 | me = *my_identity; |
137 | } | 136 | } |
@@ -145,26 +144,26 @@ core_init (void *cls, | |||
145 | * @return #GNUNET_OK if message is well-formed | 144 | * @return #GNUNET_OK if message is well-formed |
146 | */ | 145 | */ |
147 | static int | 146 | static int |
148 | check_advertisement (void *cls, | 147 | check_advertisement(void *cls, |
149 | const struct GNUNET_MessageHeader *message) | 148 | const struct GNUNET_MessageHeader *message) |
150 | { | 149 | { |
151 | size_t size; | 150 | size_t size; |
152 | size_t uri_size; | 151 | size_t uri_size; |
153 | const char *uri; | 152 | const char *uri; |
154 | 153 | ||
155 | size = ntohs (message->size); | 154 | size = ntohs(message->size); |
156 | if (size <= sizeof (struct GNUNET_MessageHeader)) | 155 | if (size <= sizeof(struct GNUNET_MessageHeader)) |
157 | { | 156 | { |
158 | GNUNET_break_op (0); | 157 | GNUNET_break_op(0); |
159 | return GNUNET_SYSERR; | 158 | return GNUNET_SYSERR; |
160 | } | 159 | } |
161 | uri = (const char *) &message[1]; | 160 | uri = (const char *)&message[1]; |
162 | uri_size = size - sizeof (struct GNUNET_MessageHeader); | 161 | uri_size = size - sizeof(struct GNUNET_MessageHeader); |
163 | if (uri[uri_size - 1] != '\0') | 162 | if (uri[uri_size - 1] != '\0') |
164 | { | 163 | { |
165 | GNUNET_break_op (0); | 164 | GNUNET_break_op(0); |
166 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
167 | } | 166 | } |
168 | return GNUNET_OK; | 167 | return GNUNET_OK; |
169 | } | 168 | } |
170 | 169 | ||
@@ -177,13 +176,13 @@ check_advertisement (void *cls, | |||
177 | * @return #GNUNET_OK on success | 176 | * @return #GNUNET_OK on success |
178 | */ | 177 | */ |
179 | static void | 178 | static void |
180 | handle_advertisement (void *cls, | 179 | handle_advertisement(void *cls, |
181 | const struct GNUNET_MessageHeader *message) | 180 | const struct GNUNET_MessageHeader *message) |
182 | { | 181 | { |
183 | const char *uri = (const char *) &message[1]; | 182 | const char *uri = (const char *)&message[1]; |
184 | 183 | ||
185 | GNUNET_assert (NULL != client_adv_handler); | 184 | GNUNET_assert(NULL != client_adv_handler); |
186 | (void) (*client_adv_handler) (uri); | 185 | (void)(*client_adv_handler)(uri); |
187 | } | 186 | } |
188 | 187 | ||
189 | 188 | ||
@@ -197,28 +196,28 @@ handle_advertisement (void *cls, | |||
197 | * @return peer | 196 | * @return peer |
198 | */ | 197 | */ |
199 | static void * | 198 | static void * |
200 | connect_handler (void *cls, | 199 | connect_handler(void *cls, |
201 | const struct GNUNET_PeerIdentity *peer, | 200 | const struct GNUNET_PeerIdentity *peer, |
202 | struct GNUNET_MQ_Handle *mq) | 201 | struct GNUNET_MQ_Handle *mq) |
203 | { | 202 | { |
204 | if (0 == GNUNET_memcmp (&me, | 203 | if (0 == GNUNET_memcmp(&me, |
205 | peer)) | 204 | peer)) |
206 | return NULL; | 205 | return NULL; |
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
208 | "A new peer connected, notifying client and server\n"); | 207 | "A new peer connected, notifying client and server\n"); |
209 | if (NULL != client_ch) | 208 | if (NULL != client_ch) |
210 | GNUNET_assert (NULL == | 209 | GNUNET_assert(NULL == |
211 | (*client_ch) (cls, | 210 | (*client_ch)(cls, |
212 | peer, | 211 | peer, |
213 | mq)); | 212 | mq)); |
214 | #if HAVE_MHD | 213 | #if HAVE_MHD |
215 | if (NULL != server_ch) | 214 | if (NULL != server_ch) |
216 | GNUNET_assert (NULL == | 215 | GNUNET_assert(NULL == |
217 | (*server_ch) (cls, | 216 | (*server_ch)(cls, |
218 | peer, | 217 | peer, |
219 | mq)); | 218 | mq)); |
220 | #endif | 219 | #endif |
221 | return (void *) peer; | 220 | return (void *)peer; |
222 | } | 221 | } |
223 | 222 | ||
224 | 223 | ||
@@ -230,18 +229,18 @@ connect_handler (void *cls, | |||
230 | * @param peer peer identity this notification is about | 229 | * @param peer peer identity this notification is about |
231 | */ | 230 | */ |
232 | static void | 231 | static void |
233 | disconnect_handler (void *cls, | 232 | disconnect_handler(void *cls, |
234 | const struct GNUNET_PeerIdentity *peer, | 233 | const struct GNUNET_PeerIdentity *peer, |
235 | void *internal_cls) | 234 | void *internal_cls) |
236 | { | 235 | { |
237 | if (0 == GNUNET_memcmp (&me, | 236 | if (0 == GNUNET_memcmp(&me, |
238 | peer)) | 237 | peer)) |
239 | return; | 238 | return; |
240 | /* call hostlist client disconnect handler */ | 239 | /* call hostlist client disconnect handler */ |
241 | if (NULL != client_dh) | 240 | if (NULL != client_dh) |
242 | (*client_dh) (cls, | 241 | (*client_dh)(cls, |
243 | peer, | 242 | peer, |
244 | NULL); | 243 | NULL); |
245 | } | 244 | } |
246 | 245 | ||
247 | 246 | ||
@@ -252,31 +251,31 @@ disconnect_handler (void *cls, | |||
252 | * @param cls NULL | 251 | * @param cls NULL |
253 | */ | 252 | */ |
254 | static void | 253 | static void |
255 | cleaning_task (void *cls) | 254 | cleaning_task(void *cls) |
256 | { | 255 | { |
257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 256 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
258 | "Hostlist daemon is shutting down\n"); | 257 | "Hostlist daemon is shutting down\n"); |
259 | if (NULL != core) | 258 | if (NULL != core) |
260 | { | 259 | { |
261 | GNUNET_CORE_disconnect (core); | 260 | GNUNET_CORE_disconnect(core); |
262 | core = NULL; | 261 | core = NULL; |
263 | } | 262 | } |
264 | if (bootstrapping) | 263 | if (bootstrapping) |
265 | { | 264 | { |
266 | GNUNET_HOSTLIST_client_stop (); | 265 | GNUNET_HOSTLIST_client_stop(); |
267 | } | 266 | } |
268 | #if HAVE_MHD | 267 | #if HAVE_MHD |
269 | if (provide_hostlist) | 268 | if (provide_hostlist) |
270 | { | 269 | { |
271 | GNUNET_HOSTLIST_server_stop (); | 270 | GNUNET_HOSTLIST_server_stop(); |
272 | } | 271 | } |
273 | #endif | 272 | #endif |
274 | if (NULL != stats) | 273 | if (NULL != stats) |
275 | { | 274 | { |
276 | GNUNET_STATISTICS_destroy (stats, | 275 | GNUNET_STATISTICS_destroy(stats, |
277 | GNUNET_NO); | 276 | GNUNET_NO); |
278 | stats = NULL; | 277 | stats = NULL; |
279 | } | 278 | } |
280 | } | 279 | } |
281 | 280 | ||
282 | 281 | ||
@@ -289,71 +288,72 @@ cleaning_task (void *cls) | |||
289 | * @param cfg configuration | 288 | * @param cfg configuration |
290 | */ | 289 | */ |
291 | static void | 290 | static void |
292 | run (void *cls, | 291 | run(void *cls, |
293 | char *const *args, | 292 | char *const *args, |
294 | const char *cfgfile, | 293 | const char *cfgfile, |
295 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 294 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
296 | { | 295 | { |
297 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { | 296 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { |
298 | GNUNET_MQ_hd_var_size (advertisement, | 297 | GNUNET_MQ_hd_var_size(advertisement, |
299 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, | 298 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, |
300 | struct GNUNET_MessageHeader, | 299 | struct GNUNET_MessageHeader, |
301 | NULL), | 300 | NULL), |
302 | GNUNET_MQ_handler_end () | 301 | GNUNET_MQ_handler_end() |
303 | }; | 302 | }; |
304 | struct GNUNET_MQ_MessageHandler no_learn_handlers[] = { | 303 | struct GNUNET_MQ_MessageHandler no_learn_handlers[] = { |
305 | GNUNET_MQ_handler_end () | 304 | GNUNET_MQ_handler_end() |
306 | }; | 305 | }; |
307 | if ((! bootstrapping) && (! learning) | 306 | |
307 | if ((!bootstrapping) && (!learning) | ||
308 | #if HAVE_MHD | 308 | #if HAVE_MHD |
309 | && (! provide_hostlist) | 309 | && (!provide_hostlist) |
310 | #endif | 310 | #endif |
311 | ) | 311 | ) |
312 | { | 312 | { |
313 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 313 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
314 | _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); | 314 | _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); |
315 | return; | 315 | return; |
316 | } | 316 | } |
317 | stats = GNUNET_STATISTICS_create ("hostlist", cfg); | 317 | stats = GNUNET_STATISTICS_create("hostlist", cfg); |
318 | if (NULL == stats) | 318 | if (NULL == stats) |
319 | { | 319 | { |
320 | GNUNET_break (0); | 320 | GNUNET_break(0); |
321 | return; | 321 | return; |
322 | } | 322 | } |
323 | if (bootstrapping) | 323 | if (bootstrapping) |
324 | GNUNET_HOSTLIST_client_start (cfg, | 324 | GNUNET_HOSTLIST_client_start(cfg, |
325 | stats, | 325 | stats, |
326 | &client_ch, | 326 | &client_ch, |
327 | &client_dh, | 327 | &client_dh, |
328 | &client_adv_handler, | 328 | &client_adv_handler, |
329 | learning); | 329 | learning); |
330 | core = | 330 | core = |
331 | GNUNET_CORE_connect (cfg, | 331 | GNUNET_CORE_connect(cfg, |
332 | NULL, | 332 | NULL, |
333 | &core_init, | 333 | &core_init, |
334 | &connect_handler, | 334 | &connect_handler, |
335 | &disconnect_handler, | 335 | &disconnect_handler, |
336 | learning ? learn_handlers : no_learn_handlers); | 336 | learning ? learn_handlers : no_learn_handlers); |
337 | 337 | ||
338 | 338 | ||
339 | #if HAVE_MHD | 339 | #if HAVE_MHD |
340 | if (provide_hostlist) | 340 | if (provide_hostlist) |
341 | GNUNET_HOSTLIST_server_start (cfg, | 341 | GNUNET_HOSTLIST_server_start(cfg, |
342 | stats, | 342 | stats, |
343 | core, | 343 | core, |
344 | &server_ch, | 344 | &server_ch, |
345 | advertising); | 345 | advertising); |
346 | #endif | 346 | #endif |
347 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, | 347 | GNUNET_SCHEDULER_add_shutdown(&cleaning_task, |
348 | NULL); | 348 | NULL); |
349 | 349 | ||
350 | if (NULL == core) | 350 | if (NULL == core) |
351 | { | 351 | { |
352 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 352 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
353 | _("Failed to connect to `%s' service.\n"), "core"); | 353 | _("Failed to connect to `%s' service.\n"), "core"); |
354 | GNUNET_SCHEDULER_shutdown (); | 354 | GNUNET_SCHEDULER_shutdown(); |
355 | return; | 355 | return; |
356 | } | 356 | } |
357 | } | 357 | } |
358 | 358 | ||
359 | 359 | ||
@@ -365,46 +365,46 @@ run (void *cls, | |||
365 | * @return 0 ok, 1 on error | 365 | * @return 0 ok, 1 on error |
366 | */ | 366 | */ |
367 | int | 367 | int |
368 | main (int argc, char *const *argv) | 368 | main(int argc, char *const *argv) |
369 | { | 369 | { |
370 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 370 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
371 | #if HAVE_MHD | 371 | #if HAVE_MHD |
372 | GNUNET_GETOPT_option_flag ('a', | 372 | GNUNET_GETOPT_option_flag('a', |
373 | "advertise", | 373 | "advertise", |
374 | gettext_noop ("advertise our hostlist to other peers"), | 374 | gettext_noop("advertise our hostlist to other peers"), |
375 | &advertising), | 375 | &advertising), |
376 | #endif | 376 | #endif |
377 | GNUNET_GETOPT_option_flag ('b', | 377 | GNUNET_GETOPT_option_flag('b', |
378 | "bootstrap", | 378 | "bootstrap", |
379 | gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), | 379 | gettext_noop("bootstrap using hostlists (it is highly recommended that you always use this option)"), |
380 | &bootstrapping), | 380 | &bootstrapping), |
381 | GNUNET_GETOPT_option_flag ('e', | 381 | GNUNET_GETOPT_option_flag('e', |
382 | "enable-learning", | 382 | "enable-learning", |
383 | gettext_noop ("enable learning about hostlist servers from other peers"), | 383 | gettext_noop("enable learning about hostlist servers from other peers"), |
384 | &learning), | 384 | &learning), |
385 | #if HAVE_MHD | 385 | #if HAVE_MHD |
386 | GNUNET_GETOPT_option_flag ('p', | 386 | GNUNET_GETOPT_option_flag('p', |
387 | "provide-hostlist", | 387 | "provide-hostlist", |
388 | gettext_noop ("provide a hostlist server"), | 388 | gettext_noop("provide a hostlist server"), |
389 | &provide_hostlist), | 389 | &provide_hostlist), |
390 | #endif | 390 | #endif |
391 | GNUNET_GETOPT_OPTION_END | 391 | GNUNET_GETOPT_OPTION_END |
392 | }; | 392 | }; |
393 | 393 | ||
394 | int ret; | 394 | int ret; |
395 | 395 | ||
396 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 396 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
397 | return 2; | 397 | return 2; |
398 | 398 | ||
399 | GNUNET_log_setup ("hostlist", "WARNING", NULL); | 399 | GNUNET_log_setup("hostlist", "WARNING", NULL); |
400 | ret = | 400 | ret = |
401 | (GNUNET_OK == | 401 | (GNUNET_OK == |
402 | GNUNET_PROGRAM_run (argc, argv, | 402 | GNUNET_PROGRAM_run(argc, argv, |
403 | "hostlist", | 403 | "hostlist", |
404 | _("GNUnet hostlist server and client"), | 404 | _("GNUnet hostlist server and client"), |
405 | options, | 405 | options, |
406 | &run, NULL)) ? 0 : 1; | 406 | &run, NULL)) ? 0 : 1; |
407 | GNUNET_free ((void*) argv); | 407 | GNUNET_free((void*)argv); |
408 | return ret; | 408 | return ret; |
409 | } | 409 | } |
410 | 410 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist.h b/src/hostlist/gnunet-daemon-hostlist.h index df4c54db0..aec413fe6 100644 --- a/src/hostlist/gnunet-daemon-hostlist.h +++ b/src/hostlist/gnunet-daemon-hostlist.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file hostlist/gnunet-daemon-hostlist.h | 22 | * @file hostlist/gnunet-daemon-hostlist.h |
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index 0428e64b8..af3fd6fce 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file hostlist/gnunet-daemon-hostlist_client.c | 21 | * @file hostlist/gnunet-daemon-hostlist_client.c |
22 | * @brief hostlist support. Downloads HELLOs via HTTP. | 22 | * @brief hostlist support. Downloads HELLOs via HTTP. |
@@ -49,19 +49,19 @@ | |||
49 | * Time interval hostlists are saved to disk | 49 | * Time interval hostlists are saved to disk |
50 | */ | 50 | */ |
51 | #define SAVING_INTERVAL \ | 51 | #define SAVING_INTERVAL \ |
52 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | 52 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Time interval between two hostlist tests | 55 | * Time interval between two hostlist tests |
56 | */ | 56 | */ |
57 | #define TESTING_INTERVAL \ | 57 | #define TESTING_INTERVAL \ |
58 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | 58 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Time interval for download dispatcher before a download is re-scheduled | 61 | * Time interval for download dispatcher before a download is re-scheduled |
62 | */ | 62 | */ |
63 | #define WAITING_INTERVAL \ | 63 | #define WAITING_INTERVAL \ |
64 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 64 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Defines concerning the hostlist quality metric | 67 | * Defines concerning the hostlist quality metric |
@@ -91,8 +91,7 @@ | |||
91 | /** | 91 | /** |
92 | * A single hostlist obtained by hostlist advertisements | 92 | * A single hostlist obtained by hostlist advertisements |
93 | */ | 93 | */ |
94 | struct Hostlist | 94 | struct Hostlist { |
95 | { | ||
96 | /** | 95 | /** |
97 | * previous entry, used to manage entries in a double linked list | 96 | * previous entry, used to manage entries in a double linked list |
98 | */ | 97 | */ |
@@ -321,7 +320,7 @@ static struct GNUNET_PEERINFO_Handle *pi; | |||
321 | * @return number of bytes that were processed (always size*nmemb) | 320 | * @return number of bytes that were processed (always size*nmemb) |
322 | */ | 321 | */ |
323 | static size_t | 322 | static size_t |
324 | callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | 323 | callback_download(void *ptr, size_t size, size_t nmemb, void *ctx) |
325 | { | 324 | { |
326 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; | 325 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; |
327 | const char *cbuf = ptr; | 326 | const char *cbuf = ptr; |
@@ -334,85 +333,85 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
334 | total = size * nmemb; | 333 | total = size * nmemb; |
335 | stat_bytes_downloaded += total; | 334 | stat_bytes_downloaded += total; |
336 | if ((total == 0) || (stat_bogus_url)) | 335 | if ((total == 0) || (stat_bogus_url)) |
337 | { | ||
338 | return total; /* ok, no data or bogus data */ | ||
339 | } | ||
340 | |||
341 | GNUNET_STATISTICS_update (stats, | ||
342 | gettext_noop ( | ||
343 | "# bytes downloaded from hostlist servers"), | ||
344 | (int64_t) total, | ||
345 | GNUNET_NO); | ||
346 | left = total; | ||
347 | while ((left > 0) || (download_pos > 0)) | ||
348 | { | ||
349 | cpy = GNUNET_MIN (left, GNUNET_MAX_MESSAGE_SIZE - 1 - download_pos); | ||
350 | GNUNET_memcpy (&download_buffer[download_pos], cbuf, cpy); | ||
351 | cbuf += cpy; | ||
352 | download_pos += cpy; | ||
353 | left -= cpy; | ||
354 | if (download_pos < sizeof (struct GNUNET_MessageHeader)) | ||
355 | { | ||
356 | GNUNET_assert (0 == left); | ||
357 | break; | ||
358 | } | ||
359 | msg = (const struct GNUNET_MessageHeader *) download_buffer; | ||
360 | msize = ntohs (msg->size); | ||
361 | if (msize < sizeof (struct GNUNET_MessageHeader)) | ||
362 | { | 336 | { |
363 | GNUNET_STATISTICS_update ( | 337 | return total; /* ok, no data or bogus data */ |
364 | stats, | ||
365 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | ||
366 | 1, | ||
367 | GNUNET_NO); | ||
368 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
369 | _ ("Invalid `%s' message received from hostlist at `%s'\n"), | ||
370 | "HELLO", | ||
371 | current_url); | ||
372 | stat_hellos_obtained++; | ||
373 | stat_bogus_url = 1; | ||
374 | return total; | ||
375 | } | 338 | } |
376 | if (download_pos < msize) | 339 | |
377 | { | 340 | GNUNET_STATISTICS_update(stats, |
378 | GNUNET_assert (left == 0); | 341 | gettext_noop( |
379 | break; | 342 | "# bytes downloaded from hostlist servers"), |
380 | } | 343 | (int64_t)total, |
381 | if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize) | 344 | GNUNET_NO); |
382 | { | 345 | left = total; |
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 346 | while ((left > 0) || (download_pos > 0)) |
384 | "Received valid `%s' message from hostlist server.\n", | ||
385 | "HELLO"); | ||
386 | GNUNET_STATISTICS_update ( | ||
387 | stats, | ||
388 | gettext_noop ("# valid HELLOs downloaded from hostlist servers"), | ||
389 | 1, | ||
390 | GNUNET_NO); | ||
391 | stat_hellos_obtained++; | ||
392 | (void) | ||
393 | GNUNET_PEERINFO_add_peer (pi, | ||
394 | (const struct GNUNET_HELLO_Message *) msg, | ||
395 | NULL, | ||
396 | NULL); | ||
397 | } | ||
398 | else | ||
399 | { | 347 | { |
400 | GNUNET_STATISTICS_update ( | 348 | cpy = GNUNET_MIN(left, GNUNET_MAX_MESSAGE_SIZE - 1 - download_pos); |
401 | stats, | 349 | GNUNET_memcpy(&download_buffer[download_pos], cbuf, cpy); |
402 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | 350 | cbuf += cpy; |
403 | 1, | 351 | download_pos += cpy; |
404 | GNUNET_NO); | 352 | left -= cpy; |
405 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 353 | if (download_pos < sizeof(struct GNUNET_MessageHeader)) |
406 | _ ("Invalid `%s' message received from hostlist at `%s'\n"), | 354 | { |
407 | "HELLO", | 355 | GNUNET_assert(0 == left); |
408 | current_url); | 356 | break; |
409 | stat_bogus_url = GNUNET_YES; | 357 | } |
410 | stat_hellos_obtained++; | 358 | msg = (const struct GNUNET_MessageHeader *)download_buffer; |
411 | return total; | 359 | msize = ntohs(msg->size); |
360 | if (msize < sizeof(struct GNUNET_MessageHeader)) | ||
361 | { | ||
362 | GNUNET_STATISTICS_update( | ||
363 | stats, | ||
364 | gettext_noop("# invalid HELLOs downloaded from hostlist servers"), | ||
365 | 1, | ||
366 | GNUNET_NO); | ||
367 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
368 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
369 | "HELLO", | ||
370 | current_url); | ||
371 | stat_hellos_obtained++; | ||
372 | stat_bogus_url = 1; | ||
373 | return total; | ||
374 | } | ||
375 | if (download_pos < msize) | ||
376 | { | ||
377 | GNUNET_assert(left == 0); | ||
378 | break; | ||
379 | } | ||
380 | if (GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)msg) == msize) | ||
381 | { | ||
382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
383 | "Received valid `%s' message from hostlist server.\n", | ||
384 | "HELLO"); | ||
385 | GNUNET_STATISTICS_update( | ||
386 | stats, | ||
387 | gettext_noop("# valid HELLOs downloaded from hostlist servers"), | ||
388 | 1, | ||
389 | GNUNET_NO); | ||
390 | stat_hellos_obtained++; | ||
391 | (void) | ||
392 | GNUNET_PEERINFO_add_peer(pi, | ||
393 | (const struct GNUNET_HELLO_Message *)msg, | ||
394 | NULL, | ||
395 | NULL); | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | GNUNET_STATISTICS_update( | ||
400 | stats, | ||
401 | gettext_noop("# invalid HELLOs downloaded from hostlist servers"), | ||
402 | 1, | ||
403 | GNUNET_NO); | ||
404 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
405 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
406 | "HELLO", | ||
407 | current_url); | ||
408 | stat_bogus_url = GNUNET_YES; | ||
409 | stat_hellos_obtained++; | ||
410 | return total; | ||
411 | } | ||
412 | memmove(download_buffer, &download_buffer[msize], download_pos - msize); | ||
413 | download_pos -= msize; | ||
412 | } | 414 | } |
413 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); | ||
414 | download_pos -= msize; | ||
415 | } | ||
416 | return total; | 415 | return total; |
417 | } | 416 | } |
418 | 417 | ||
@@ -423,63 +422,63 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
423 | * @return NULL if there is no URL available | 422 | * @return NULL if there is no URL available |
424 | */ | 423 | */ |
425 | static char * | 424 | static char * |
426 | get_bootstrap_server () | 425 | get_bootstrap_server() |
427 | { | 426 | { |
428 | char *servers; | 427 | char *servers; |
429 | char *ret; | 428 | char *ret; |
430 | size_t urls; | 429 | size_t urls; |
431 | size_t pos; | 430 | size_t pos; |
432 | 431 | ||
433 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 432 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
434 | "HOSTLIST", | 433 | "HOSTLIST", |
435 | "SERVERS", | 434 | "SERVERS", |
436 | &servers)) | 435 | &servers)) |
437 | { | 436 | { |
438 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | 437 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, |
439 | "hostlist", | 438 | "hostlist", |
440 | "SERVERS"); | 439 | "SERVERS"); |
441 | return NULL; | 440 | return NULL; |
442 | } | 441 | } |
443 | 442 | ||
444 | urls = 0; | 443 | urls = 0; |
445 | if (strlen (servers) > 0) | 444 | if (strlen(servers) > 0) |
446 | { | ||
447 | urls++; | ||
448 | pos = strlen (servers) - 1; | ||
449 | while (pos > 0) | ||
450 | { | 445 | { |
451 | if (servers[pos] == ' ') | 446 | urls++; |
452 | urls++; | 447 | pos = strlen(servers) - 1; |
453 | pos--; | 448 | while (pos > 0) |
449 | { | ||
450 | if (servers[pos] == ' ') | ||
451 | urls++; | ||
452 | pos--; | ||
453 | } | ||
454 | } | 454 | } |
455 | } | ||
456 | if (urls == 0) | 455 | if (urls == 0) |
457 | { | ||
458 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | ||
459 | "hostlist", | ||
460 | "SERVERS"); | ||
461 | GNUNET_free (servers); | ||
462 | return NULL; | ||
463 | } | ||
464 | |||
465 | urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; | ||
466 | pos = strlen (servers) - 1; | ||
467 | while (pos > 0) | ||
468 | { | ||
469 | if (servers[pos] == ' ') | ||
470 | { | 456 | { |
471 | urls--; | 457 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, |
472 | servers[pos] = '\0'; | 458 | "hostlist", |
459 | "SERVERS"); | ||
460 | GNUNET_free(servers); | ||
461 | return NULL; | ||
473 | } | 462 | } |
474 | if (urls == 0) | 463 | |
464 | urls = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; | ||
465 | pos = strlen(servers) - 1; | ||
466 | while (pos > 0) | ||
475 | { | 467 | { |
476 | pos++; | 468 | if (servers[pos] == ' ') |
477 | break; | 469 | { |
470 | urls--; | ||
471 | servers[pos] = '\0'; | ||
472 | } | ||
473 | if (urls == 0) | ||
474 | { | ||
475 | pos++; | ||
476 | break; | ||
477 | } | ||
478 | pos--; | ||
478 | } | 479 | } |
479 | pos--; | 480 | ret = GNUNET_strdup(&servers[pos]); |
480 | } | 481 | GNUNET_free(servers); |
481 | ret = GNUNET_strdup (&servers[pos]); | ||
482 | GNUNET_free (servers); | ||
483 | return ret; | 482 | return ret; |
484 | } | 483 | } |
485 | 484 | ||
@@ -489,64 +488,64 @@ get_bootstrap_server () | |||
489 | * @return uri to use, NULL if there is no URL available | 488 | * @return uri to use, NULL if there is no URL available |
490 | */ | 489 | */ |
491 | static char * | 490 | static char * |
492 | download_get_url () | 491 | download_get_url() |
493 | { | 492 | { |
494 | uint32_t index; | 493 | uint32_t index; |
495 | unsigned int counter; | 494 | unsigned int counter; |
496 | struct Hostlist *pos; | 495 | struct Hostlist *pos; |
497 | 496 | ||
498 | if (GNUNET_NO == stat_learning) | 497 | if (GNUNET_NO == stat_learning) |
499 | { | 498 | { |
500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
501 | "Using preconfigured bootstrap server\n"); | 500 | "Using preconfigured bootstrap server\n"); |
502 | current_hostlist = NULL; | 501 | current_hostlist = NULL; |
503 | return get_bootstrap_server (); | 502 | return get_bootstrap_server(); |
504 | } | 503 | } |
505 | 504 | ||
506 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) | 505 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) |
507 | { | 506 | { |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 507 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
509 | "Testing new advertised hostlist if it is obtainable\n"); | 508 | "Testing new advertised hostlist if it is obtainable\n"); |
510 | current_hostlist = hostlist_to_test; | 509 | current_hostlist = hostlist_to_test; |
511 | return GNUNET_strdup (hostlist_to_test->hostlist_uri); | 510 | return GNUNET_strdup(hostlist_to_test->hostlist_uri); |
512 | } | 511 | } |
513 | 512 | ||
514 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) | 513 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) |
515 | { | 514 | { |
516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 515 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
517 | "Using preconfigured bootstrap server\n"); | 516 | "Using preconfigured bootstrap server\n"); |
518 | current_hostlist = NULL; | 517 | current_hostlist = NULL; |
519 | return get_bootstrap_server (); | 518 | return get_bootstrap_server(); |
520 | } | 519 | } |
521 | index = | 520 | index = |
522 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); | 521 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); |
523 | counter = 0; | 522 | counter = 0; |
524 | pos = linked_list_head; | 523 | pos = linked_list_head; |
525 | while (counter < index) | 524 | while (counter < index) |
526 | { | 525 | { |
527 | pos = pos->next; | 526 | pos = pos->next; |
528 | counter++; | 527 | counter++; |
529 | } | 528 | } |
530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 529 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
531 | "Using learned hostlist `%s'\n", | 530 | "Using learned hostlist `%s'\n", |
532 | pos->hostlist_uri); | 531 | pos->hostlist_uri); |
533 | current_hostlist = pos; | 532 | current_hostlist = pos; |
534 | return GNUNET_strdup (pos->hostlist_uri); | 533 | return GNUNET_strdup(pos->hostlist_uri); |
535 | } | 534 | } |
536 | 535 | ||
537 | 536 | ||
538 | #define CURL_EASY_SETOPT(c, a, b) \ | 537 | #define CURL_EASY_SETOPT(c, a, b) \ |
539 | do \ | 538 | do \ |
540 | { \ | 539 | { \ |
541 | ret = curl_easy_setopt (c, a, b); \ | 540 | ret = curl_easy_setopt(c, a, b); \ |
542 | if (CURLE_OK != ret) \ | 541 | if (CURLE_OK != ret) \ |
543 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ | 542 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ |
544 | _ ("%s failed at %s:%d: `%s'\n"), \ | 543 | _("%s failed at %s:%d: `%s'\n"), \ |
545 | "curl_easy_setopt", \ | 544 | "curl_easy_setopt", \ |
546 | __FILE__, \ | 545 | __FILE__, \ |
547 | __LINE__, \ | 546 | __LINE__, \ |
548 | curl_easy_strerror (ret)); \ | 547 | curl_easy_strerror(ret)); \ |
549 | } while (0) | 548 | } while (0) |
550 | 549 | ||
551 | 550 | ||
552 | /** | 551 | /** |
@@ -555,7 +554,7 @@ download_get_url () | |||
555 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 554 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
556 | */ | 555 | */ |
557 | static void | 556 | static void |
558 | save_hostlist_file (int shutdown); | 557 | save_hostlist_file(int shutdown); |
559 | 558 | ||
560 | 559 | ||
561 | /** | 560 | /** |
@@ -566,7 +565,7 @@ save_hostlist_file (int shutdown); | |||
566 | * @return result | 565 | * @return result |
567 | */ | 566 | */ |
568 | static uint64_t | 567 | static uint64_t |
569 | checked_add (uint64_t val1, uint64_t val2) | 568 | checked_add(uint64_t val1, uint64_t val2) |
570 | { | 569 | { |
571 | static uint64_t temp; | 570 | static uint64_t temp; |
572 | static uint64_t maxv; | 571 | static uint64_t maxv; |
@@ -589,11 +588,11 @@ checked_add (uint64_t val1, uint64_t val2) | |||
589 | * @return result | 588 | * @return result |
590 | */ | 589 | */ |
591 | static uint64_t | 590 | static uint64_t |
592 | checked_sub (uint64_t val1, uint64_t val2) | 591 | checked_sub(uint64_t val1, uint64_t val2) |
593 | { | 592 | { |
594 | if (val1 <= val2) | 593 | if (val1 <= val2) |
595 | return 0; | 594 | return 0; |
596 | return (val1 - val2); | 595 | return(val1 - val2); |
597 | } | 596 | } |
598 | 597 | ||
599 | 598 | ||
@@ -604,17 +603,17 @@ checked_sub (uint64_t val1, uint64_t val2) | |||
604 | * @return #GNUNET_YES if existing in linked list, #GNUNET_NO if not | 603 | * @return #GNUNET_YES if existing in linked list, #GNUNET_NO if not |
605 | */ | 604 | */ |
606 | static int | 605 | static int |
607 | linked_list_contains (const char *uri) | 606 | linked_list_contains(const char *uri) |
608 | { | 607 | { |
609 | struct Hostlist *pos; | 608 | struct Hostlist *pos; |
610 | 609 | ||
611 | pos = linked_list_head; | 610 | pos = linked_list_head; |
612 | while (pos != NULL) | 611 | while (pos != NULL) |
613 | { | 612 | { |
614 | if (0 == strcmp (pos->hostlist_uri, uri)) | 613 | if (0 == strcmp(pos->hostlist_uri, uri)) |
615 | return GNUNET_YES; | 614 | return GNUNET_YES; |
616 | pos = pos->next; | 615 | pos = pos->next; |
617 | } | 616 | } |
618 | return GNUNET_NO; | 617 | return GNUNET_NO; |
619 | } | 618 | } |
620 | 619 | ||
@@ -624,7 +623,7 @@ linked_list_contains (const char *uri) | |||
624 | * @return hostlist with lowest quality | 623 | * @return hostlist with lowest quality |
625 | */ | 624 | */ |
626 | static struct Hostlist * | 625 | static struct Hostlist * |
627 | linked_list_get_lowest_quality () | 626 | linked_list_get_lowest_quality() |
628 | { | 627 | { |
629 | struct Hostlist *pos; | 628 | struct Hostlist *pos; |
630 | struct Hostlist *lowest; | 629 | struct Hostlist *lowest; |
@@ -634,11 +633,11 @@ linked_list_get_lowest_quality () | |||
634 | lowest = linked_list_head; | 633 | lowest = linked_list_head; |
635 | pos = linked_list_head->next; | 634 | pos = linked_list_head->next; |
636 | while (pos != NULL) | 635 | while (pos != NULL) |
637 | { | 636 | { |
638 | if (pos->quality < lowest->quality) | 637 | if (pos->quality < lowest->quality) |
639 | lowest = pos; | 638 | lowest = pos; |
640 | pos = pos->next; | 639 | pos = pos->next; |
641 | } | 640 | } |
642 | return lowest; | 641 | return lowest; |
643 | } | 642 | } |
644 | 643 | ||
@@ -649,34 +648,34 @@ linked_list_get_lowest_quality () | |||
649 | * quality is dismissed | 648 | * quality is dismissed |
650 | */ | 649 | */ |
651 | static void | 650 | static void |
652 | insert_hostlist () | 651 | insert_hostlist() |
653 | { | 652 | { |
654 | struct Hostlist *lowest_quality; | 653 | struct Hostlist *lowest_quality; |
655 | 654 | ||
656 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) | 655 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) |
657 | { | 656 | { |
658 | /* No free entries available, replace existing entry */ | 657 | /* No free entries available, replace existing entry */ |
659 | lowest_quality = linked_list_get_lowest_quality (); | 658 | lowest_quality = linked_list_get_lowest_quality(); |
660 | GNUNET_assert (lowest_quality != NULL); | 659 | GNUNET_assert(lowest_quality != NULL); |
661 | GNUNET_log ( | 660 | GNUNET_log( |
662 | GNUNET_ERROR_TYPE_DEBUG, | 661 | GNUNET_ERROR_TYPE_DEBUG, |
663 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", | 662 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", |
664 | lowest_quality->hostlist_uri, | 663 | lowest_quality->hostlist_uri, |
665 | (unsigned long long) lowest_quality->quality); | 664 | (unsigned long long)lowest_quality->quality); |
666 | GNUNET_CONTAINER_DLL_remove (linked_list_head, | 665 | GNUNET_CONTAINER_DLL_remove(linked_list_head, |
667 | linked_list_tail, | 666 | linked_list_tail, |
668 | lowest_quality); | 667 | lowest_quality); |
669 | linked_list_size--; | 668 | linked_list_size--; |
670 | GNUNET_free (lowest_quality); | 669 | GNUNET_free(lowest_quality); |
671 | } | 670 | } |
672 | GNUNET_CONTAINER_DLL_insert (linked_list_head, | 671 | GNUNET_CONTAINER_DLL_insert(linked_list_head, |
673 | linked_list_tail, | 672 | linked_list_tail, |
674 | hostlist_to_test); | 673 | hostlist_to_test); |
675 | linked_list_size++; | 674 | linked_list_size++; |
676 | GNUNET_STATISTICS_set (stats, | 675 | GNUNET_STATISTICS_set(stats, |
677 | gettext_noop ("# advertised hostlist URIs"), | 676 | gettext_noop("# advertised hostlist URIs"), |
678 | linked_list_size, | 677 | linked_list_size, |
679 | GNUNET_NO); | 678 | GNUNET_NO); |
680 | stat_testing_hostlist = GNUNET_NO; | 679 | stat_testing_hostlist = GNUNET_NO; |
681 | } | 680 | } |
682 | 681 | ||
@@ -685,37 +684,37 @@ insert_hostlist () | |||
685 | * Method updating hostlist statistics | 684 | * Method updating hostlist statistics |
686 | */ | 685 | */ |
687 | static void | 686 | static void |
688 | update_hostlist () | 687 | update_hostlist() |
689 | { | 688 | { |
690 | char *stat; | 689 | char *stat; |
691 | 690 | ||
692 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || | 691 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || |
693 | ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist))) | 692 | ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist))) |
694 | { | ||
695 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
696 | "Updating hostlist statics for URI `%s'\n", | ||
697 | current_hostlist->hostlist_uri); | ||
698 | current_hostlist->hello_count = stat_hellos_obtained; | ||
699 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get (); | ||
700 | current_hostlist->quality = | ||
701 | checked_add (current_hostlist->quality, | ||
702 | (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); | ||
703 | if (GNUNET_YES == stat_download_successful) | ||
704 | { | 693 | { |
705 | current_hostlist->times_used++; | 694 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
695 | "Updating hostlist statics for URI `%s'\n", | ||
696 | current_hostlist->hostlist_uri); | ||
697 | current_hostlist->hello_count = stat_hellos_obtained; | ||
698 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get(); | ||
706 | current_hostlist->quality = | 699 | current_hostlist->quality = |
707 | checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); | 700 | checked_add(current_hostlist->quality, |
708 | GNUNET_asprintf (&stat, | 701 | (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); |
709 | gettext_noop ("# advertised URI `%s' downloaded"), | 702 | if (GNUNET_YES == stat_download_successful) |
710 | current_hostlist->hostlist_uri); | 703 | { |
711 | 704 | current_hostlist->times_used++; | |
712 | GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES); | 705 | current_hostlist->quality = |
713 | GNUNET_free (stat); | 706 | checked_add(current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); |
707 | GNUNET_asprintf(&stat, | ||
708 | gettext_noop("# advertised URI `%s' downloaded"), | ||
709 | current_hostlist->hostlist_uri); | ||
710 | |||
711 | GNUNET_STATISTICS_update(stats, stat, 1, GNUNET_YES); | ||
712 | GNUNET_free(stat); | ||
713 | } | ||
714 | else | ||
715 | current_hostlist->quality = | ||
716 | checked_sub(current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); | ||
714 | } | 717 | } |
715 | else | ||
716 | current_hostlist->quality = | ||
717 | checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); | ||
718 | } | ||
719 | current_hostlist = NULL; | 718 | current_hostlist = NULL; |
720 | /* Alternating the usage of preconfigured and learned hostlists */ | 719 | /* Alternating the usage of preconfigured and learned hostlists */ |
721 | 720 | ||
@@ -723,12 +722,12 @@ update_hostlist () | |||
723 | return; | 722 | return; |
724 | 723 | ||
725 | if (GNUNET_YES == stat_learning) | 724 | if (GNUNET_YES == stat_learning) |
726 | { | 725 | { |
727 | if (stat_use_bootstrap == GNUNET_YES) | 726 | if (stat_use_bootstrap == GNUNET_YES) |
728 | stat_use_bootstrap = GNUNET_NO; | 727 | stat_use_bootstrap = GNUNET_NO; |
729 | else | 728 | else |
730 | stat_use_bootstrap = GNUNET_YES; | 729 | stat_use_bootstrap = GNUNET_YES; |
731 | } | 730 | } |
732 | else | 731 | else |
733 | stat_use_bootstrap = GNUNET_YES; | 732 | stat_use_bootstrap = GNUNET_YES; |
734 | } | 733 | } |
@@ -739,58 +738,58 @@ update_hostlist () | |||
739 | * hostlist and schedule the next task. | 738 | * hostlist and schedule the next task. |
740 | */ | 739 | */ |
741 | static void | 740 | static void |
742 | clean_up () | 741 | clean_up() |
743 | { | 742 | { |
744 | CURLMcode mret; | 743 | CURLMcode mret; |
745 | 744 | ||
746 | if ((stat_testing_hostlist == GNUNET_YES) && | 745 | if ((stat_testing_hostlist == GNUNET_YES) && |
747 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) | 746 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) |
748 | { | 747 | { |
749 | GNUNET_log ( | 748 | GNUNET_log( |
750 | GNUNET_ERROR_TYPE_INFO, | 749 | GNUNET_ERROR_TYPE_INFO, |
751 | _ ( | 750 | _( |
752 | "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), | 751 | "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), |
753 | hostlist_to_test->hostlist_uri); | 752 | hostlist_to_test->hostlist_uri); |
754 | } | 753 | } |
755 | 754 | ||
756 | if (stat_testing_hostlist == GNUNET_YES) | 755 | if (stat_testing_hostlist == GNUNET_YES) |
757 | { | 756 | { |
758 | stat_testing_hostlist = GNUNET_NO; | 757 | stat_testing_hostlist = GNUNET_NO; |
759 | } | 758 | } |
760 | if (NULL != hostlist_to_test) | 759 | if (NULL != hostlist_to_test) |
761 | { | 760 | { |
762 | GNUNET_free (hostlist_to_test); | 761 | GNUNET_free(hostlist_to_test); |
763 | hostlist_to_test = NULL; | 762 | hostlist_to_test = NULL; |
764 | } | 763 | } |
765 | 764 | ||
766 | if (NULL != multi) | 765 | if (NULL != multi) |
767 | { | ||
768 | mret = curl_multi_remove_handle (multi, curl); | ||
769 | if (mret != CURLM_OK) | ||
770 | { | 766 | { |
771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 767 | mret = curl_multi_remove_handle(multi, curl); |
772 | _ ("%s failed at %s:%d: `%s'\n"), | 768 | if (mret != CURLM_OK) |
773 | "curl_multi_remove_handle", | 769 | { |
774 | __FILE__, | 770 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
775 | __LINE__, | 771 | _("%s failed at %s:%d: `%s'\n"), |
776 | curl_multi_strerror (mret)); | 772 | "curl_multi_remove_handle", |
773 | __FILE__, | ||
774 | __LINE__, | ||
775 | curl_multi_strerror(mret)); | ||
776 | } | ||
777 | mret = curl_multi_cleanup(multi); | ||
778 | if (mret != CURLM_OK) | ||
779 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
780 | _("%s failed at %s:%d: `%s'\n"), | ||
781 | "curl_multi_cleanup", | ||
782 | __FILE__, | ||
783 | __LINE__, | ||
784 | curl_multi_strerror(mret)); | ||
785 | multi = NULL; | ||
777 | } | 786 | } |
778 | mret = curl_multi_cleanup (multi); | ||
779 | if (mret != CURLM_OK) | ||
780 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
781 | _ ("%s failed at %s:%d: `%s'\n"), | ||
782 | "curl_multi_cleanup", | ||
783 | __FILE__, | ||
784 | __LINE__, | ||
785 | curl_multi_strerror (mret)); | ||
786 | multi = NULL; | ||
787 | } | ||
788 | if (NULL != curl) | 787 | if (NULL != curl) |
789 | { | 788 | { |
790 | curl_easy_cleanup (curl); | 789 | curl_easy_cleanup(curl); |
791 | curl = NULL; | 790 | curl = NULL; |
792 | } | 791 | } |
793 | GNUNET_free_non_null (current_url); | 792 | GNUNET_free_non_null(current_url); |
794 | current_url = NULL; | 793 | current_url = NULL; |
795 | stat_bytes_downloaded = 0; | 794 | stat_bytes_downloaded = 0; |
796 | stat_download_in_progress = GNUNET_NO; | 795 | stat_download_in_progress = GNUNET_NO; |
@@ -805,7 +804,7 @@ clean_up () | |||
805 | * @param tc task context, unused | 804 | * @param tc task context, unused |
806 | */ | 805 | */ |
807 | static void | 806 | static void |
808 | task_download (void *cls); | 807 | task_download(void *cls); |
809 | 808 | ||
810 | 809 | ||
811 | /** | 810 | /** |
@@ -813,7 +812,7 @@ task_download (void *cls); | |||
813 | * receiving task with the scheduler. | 812 | * receiving task with the scheduler. |
814 | */ | 813 | */ |
815 | static void | 814 | static void |
816 | download_prepare () | 815 | download_prepare() |
817 | { | 816 | { |
818 | CURLMcode mret; | 817 | CURLMcode mret; |
819 | fd_set rs; | 818 | fd_set rs; |
@@ -826,50 +825,50 @@ download_prepare () | |||
826 | struct GNUNET_TIME_Relative rtime; | 825 | struct GNUNET_TIME_Relative rtime; |
827 | 826 | ||
828 | max = -1; | 827 | max = -1; |
829 | FD_ZERO (&rs); | 828 | FD_ZERO(&rs); |
830 | FD_ZERO (&ws); | 829 | FD_ZERO(&ws); |
831 | FD_ZERO (&es); | 830 | FD_ZERO(&es); |
832 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 831 | mret = curl_multi_fdset(multi, &rs, &ws, &es, &max); |
833 | if (mret != CURLM_OK) | 832 | if (mret != CURLM_OK) |
834 | { | 833 | { |
835 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 834 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
836 | _ ("%s failed at %s:%d: `%s'\n"), | 835 | _("%s failed at %s:%d: `%s'\n"), |
837 | "curl_multi_fdset", | 836 | "curl_multi_fdset", |
838 | __FILE__, | 837 | __FILE__, |
839 | __LINE__, | 838 | __LINE__, |
840 | curl_multi_strerror (mret)); | 839 | curl_multi_strerror(mret)); |
841 | clean_up (); | 840 | clean_up(); |
842 | return; | 841 | return; |
843 | } | 842 | } |
844 | mret = curl_multi_timeout (multi, &timeout); | 843 | mret = curl_multi_timeout(multi, &timeout); |
845 | if (mret != CURLM_OK) | 844 | if (mret != CURLM_OK) |
846 | { | 845 | { |
847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 846 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
848 | _ ("%s failed at %s:%d: `%s'\n"), | 847 | _("%s failed at %s:%d: `%s'\n"), |
849 | "curl_multi_timeout", | 848 | "curl_multi_timeout", |
850 | __FILE__, | 849 | __FILE__, |
851 | __LINE__, | 850 | __LINE__, |
852 | curl_multi_strerror (mret)); | 851 | curl_multi_strerror(mret)); |
853 | clean_up (); | 852 | clean_up(); |
854 | return; | 853 | return; |
855 | } | 854 | } |
856 | rtime = GNUNET_TIME_relative_min ( | 855 | rtime = GNUNET_TIME_relative_min( |
857 | GNUNET_TIME_absolute_get_remaining (end_time), | 856 | GNUNET_TIME_absolute_get_remaining(end_time), |
858 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout)); | 857 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, timeout)); |
859 | grs = GNUNET_NETWORK_fdset_create (); | 858 | grs = GNUNET_NETWORK_fdset_create(); |
860 | gws = GNUNET_NETWORK_fdset_create (); | 859 | gws = GNUNET_NETWORK_fdset_create(); |
861 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); | 860 | GNUNET_NETWORK_fdset_copy_native(grs, &rs, max + 1); |
862 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); | 861 | GNUNET_NETWORK_fdset_copy_native(gws, &ws, max + 1); |
863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 862 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
864 | "Scheduling task for hostlist download using cURL\n"); | 863 | "Scheduling task for hostlist download using cURL\n"); |
865 | ti_download = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 864 | ti_download = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
866 | rtime, | 865 | rtime, |
867 | grs, | 866 | grs, |
868 | gws, | 867 | gws, |
869 | &task_download, | 868 | &task_download, |
870 | multi); | 869 | multi); |
871 | GNUNET_NETWORK_fdset_destroy (gws); | 870 | GNUNET_NETWORK_fdset_destroy(gws); |
872 | GNUNET_NETWORK_fdset_destroy (grs); | 871 | GNUNET_NETWORK_fdset_destroy(grs); |
873 | } | 872 | } |
874 | 873 | ||
875 | 874 | ||
@@ -880,93 +879,95 @@ download_prepare () | |||
880 | * @param cls closure, unused | 879 | * @param cls closure, unused |
881 | */ | 880 | */ |
882 | static void | 881 | static void |
883 | task_download (void *cls) | 882 | task_download(void *cls) |
884 | { | 883 | { |
885 | int running; | 884 | int running; |
886 | struct CURLMsg *msg; | 885 | struct CURLMsg *msg; |
887 | CURLMcode mret; | 886 | CURLMcode mret; |
888 | 887 | ||
889 | ti_download = NULL; | 888 | ti_download = NULL; |
890 | if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us) | 889 | if (0 == GNUNET_TIME_absolute_get_remaining(end_time).rel_value_us) |
891 | { | ||
892 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
893 | _ ("Timeout trying to download hostlist from `%s'\n"), | ||
894 | current_url); | ||
895 | update_hostlist (); | ||
896 | clean_up (); | ||
897 | return; | ||
898 | } | ||
899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
900 | "Ready for processing hostlist client request\n"); | ||
901 | do | ||
902 | { | ||
903 | running = 0; | ||
904 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | ||
905 | { | 890 | { |
906 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 891 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
907 | _ ( | 892 | _("Timeout trying to download hostlist from `%s'\n"), |
908 | "Download limit of %u bytes exceeded, stopping download\n"), | 893 | current_url); |
909 | MAX_BYTES_PER_HOSTLISTS); | 894 | update_hostlist(); |
910 | clean_up (); | 895 | clean_up(); |
911 | return; | 896 | return; |
912 | } | 897 | } |
913 | mret = curl_multi_perform (multi, &running); | 898 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
914 | if (running == 0) | 899 | "Ready for processing hostlist client request\n"); |
900 | do | ||
915 | { | 901 | { |
916 | do | 902 | running = 0; |
917 | { | 903 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) |
918 | msg = curl_multi_info_read (multi, &running); | ||
919 | GNUNET_break (msg != NULL); | ||
920 | if (msg == NULL) | ||
921 | break; | ||
922 | switch (msg->msg) | ||
923 | { | 904 | { |
924 | case CURLMSG_DONE: | 905 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
925 | if ((msg->data.result != CURLE_OK) && | 906 | _( |
926 | (msg->data.result != CURLE_GOT_NOTHING)) | 907 | "Download limit of %u bytes exceeded, stopping download\n"), |
927 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 908 | MAX_BYTES_PER_HOSTLISTS); |
928 | _ ("Download of hostlist from `%s' failed: `%s'\n"), | 909 | clean_up(); |
929 | current_url, | 910 | return; |
930 | curl_easy_strerror (msg->data.result)); | 911 | } |
931 | else | 912 | mret = curl_multi_perform(multi, &running); |
932 | { | 913 | if (running == 0) |
933 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 914 | { |
934 | _ ("Download of hostlist `%s' completed.\n"), | 915 | do |
935 | current_url); | ||
936 | stat_download_successful = GNUNET_YES; | ||
937 | update_hostlist (); | ||
938 | if (GNUNET_YES == stat_testing_hostlist) | ||
939 | { | 916 | { |
940 | GNUNET_log ( | 917 | msg = curl_multi_info_read(multi, &running); |
941 | GNUNET_ERROR_TYPE_INFO, | 918 | GNUNET_break(msg != NULL); |
942 | _ ("Adding successfully tested hostlist `%s' datastore.\n"), | 919 | if (msg == NULL) |
943 | current_url); | 920 | break; |
944 | insert_hostlist (); | 921 | switch (msg->msg) |
945 | hostlist_to_test = NULL; | 922 | { |
946 | stat_testing_hostlist = GNUNET_NO; | 923 | case CURLMSG_DONE: |
924 | if ((msg->data.result != CURLE_OK) && | ||
925 | (msg->data.result != CURLE_GOT_NOTHING)) | ||
926 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
927 | _("Download of hostlist from `%s' failed: `%s'\n"), | ||
928 | current_url, | ||
929 | curl_easy_strerror(msg->data.result)); | ||
930 | else | ||
931 | { | ||
932 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
933 | _("Download of hostlist `%s' completed.\n"), | ||
934 | current_url); | ||
935 | stat_download_successful = GNUNET_YES; | ||
936 | update_hostlist(); | ||
937 | if (GNUNET_YES == stat_testing_hostlist) | ||
938 | { | ||
939 | GNUNET_log( | ||
940 | GNUNET_ERROR_TYPE_INFO, | ||
941 | _("Adding successfully tested hostlist `%s' datastore.\n"), | ||
942 | current_url); | ||
943 | insert_hostlist(); | ||
944 | hostlist_to_test = NULL; | ||
945 | stat_testing_hostlist = GNUNET_NO; | ||
946 | } | ||
947 | } | ||
948 | clean_up(); | ||
949 | return; | ||
950 | |||
951 | default: | ||
952 | break; | ||
953 | } | ||
947 | } | 954 | } |
948 | } | 955 | while ((running > 0)); |
949 | clean_up (); | ||
950 | return; | ||
951 | default: | ||
952 | break; | ||
953 | } | 956 | } |
954 | |||
955 | } while ((running > 0)); | ||
956 | } | 957 | } |
957 | } while (mret == CURLM_CALL_MULTI_PERFORM); | 958 | while (mret == CURLM_CALL_MULTI_PERFORM); |
958 | 959 | ||
959 | if (mret != CURLM_OK) | 960 | if (mret != CURLM_OK) |
960 | { | 961 | { |
961 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 962 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
962 | _ ("%s failed at %s:%d: `%s'\n"), | 963 | _("%s failed at %s:%d: `%s'\n"), |
963 | "curl_multi_perform", | 964 | "curl_multi_perform", |
964 | __FILE__, | 965 | __FILE__, |
965 | __LINE__, | 966 | __LINE__, |
966 | curl_multi_strerror (mret)); | 967 | curl_multi_strerror(mret)); |
967 | clean_up (); | 968 | clean_up(); |
968 | } | 969 | } |
969 | download_prepare (); | 970 | download_prepare(); |
970 | } | 971 | } |
971 | 972 | ||
972 | 973 | ||
@@ -975,133 +976,133 @@ task_download (void *cls) | |||
975 | * data. | 976 | * data. |
976 | */ | 977 | */ |
977 | static void | 978 | static void |
978 | download_hostlist () | 979 | download_hostlist() |
979 | { | 980 | { |
980 | CURLcode ret; | 981 | CURLcode ret; |
981 | CURLMcode mret; | 982 | CURLMcode mret; |
982 | 983 | ||
983 | 984 | ||
984 | current_url = download_get_url (); | 985 | current_url = download_get_url(); |
985 | if (current_url == NULL) | 986 | if (current_url == NULL) |
986 | return; | 987 | return; |
987 | curl = curl_easy_init (); | 988 | curl = curl_easy_init(); |
988 | multi = NULL; | 989 | multi = NULL; |
989 | if (curl == NULL) | 990 | if (curl == NULL) |
990 | { | 991 | { |
991 | GNUNET_break (0); | 992 | GNUNET_break(0); |
992 | clean_up (); | 993 | clean_up(); |
993 | return; | 994 | return; |
994 | } | 995 | } |
995 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 996 | GNUNET_log(GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
996 | _ ("Bootstrapping using hostlist at `%s'.\n"), | 997 | _("Bootstrapping using hostlist at `%s'.\n"), |
997 | current_url); | 998 | current_url); |
998 | 999 | ||
999 | stat_download_in_progress = GNUNET_YES; | 1000 | stat_download_in_progress = GNUNET_YES; |
1000 | stat_download_successful = GNUNET_NO; | 1001 | stat_download_successful = GNUNET_NO; |
1001 | stat_hellos_obtained = 0; | 1002 | stat_hellos_obtained = 0; |
1002 | stat_bytes_downloaded = 0; | 1003 | stat_bytes_downloaded = 0; |
1003 | 1004 | ||
1004 | GNUNET_STATISTICS_update (stats, | 1005 | GNUNET_STATISTICS_update(stats, |
1005 | gettext_noop ("# hostlist downloads initiated"), | 1006 | gettext_noop("# hostlist downloads initiated"), |
1006 | 1, | 1007 | 1, |
1007 | GNUNET_NO); | 1008 | GNUNET_NO); |
1008 | if (NULL != proxy) | 1009 | if (NULL != proxy) |
1009 | { | 1010 | { |
1010 | CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); | 1011 | CURL_EASY_SETOPT(curl, CURLOPT_PROXY, proxy); |
1011 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYTYPE, proxy_type); | 1012 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYTYPE, proxy_type); |
1012 | if (NULL != proxy_username) | 1013 | if (NULL != proxy_username) |
1013 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYUSERNAME, proxy_username); | 1014 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYUSERNAME, proxy_username); |
1014 | if (NULL != proxy_password) | 1015 | if (NULL != proxy_password) |
1015 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYPASSWORD, proxy_password); | 1016 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYPASSWORD, proxy_password); |
1016 | } | 1017 | } |
1017 | download_pos = 0; | 1018 | download_pos = 0; |
1018 | stat_bogus_url = 0; | 1019 | stat_bogus_url = 0; |
1019 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download); | 1020 | CURL_EASY_SETOPT(curl, CURLOPT_WRITEFUNCTION, &callback_download); |
1020 | if (ret != CURLE_OK) | 1021 | if (ret != CURLE_OK) |
1021 | { | 1022 | { |
1022 | clean_up (); | 1023 | clean_up(); |
1023 | return; | 1024 | return; |
1024 | } | 1025 | } |
1025 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL); | 1026 | CURL_EASY_SETOPT(curl, CURLOPT_WRITEDATA, NULL); |
1026 | if (ret != CURLE_OK) | 1027 | if (ret != CURLE_OK) |
1027 | { | 1028 | { |
1028 | clean_up (); | 1029 | clean_up(); |
1029 | return; | 1030 | return; |
1030 | } | 1031 | } |
1031 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); | 1032 | CURL_EASY_SETOPT(curl, CURLOPT_FOLLOWLOCATION, 1); |
1032 | CURL_EASY_SETOPT (curl, | 1033 | CURL_EASY_SETOPT(curl, |
1033 | CURLOPT_REDIR_PROTOCOLS, | 1034 | CURLOPT_REDIR_PROTOCOLS, |
1034 | CURLPROTO_HTTP | CURLPROTO_HTTPS); | 1035 | CURLPROTO_HTTP | CURLPROTO_HTTPS); |
1035 | CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); | 1036 | CURL_EASY_SETOPT(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
1036 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); | 1037 | CURL_EASY_SETOPT(curl, CURLOPT_MAXREDIRS, 4); |
1037 | /* no need to abort if the above failed */ | 1038 | /* no need to abort if the above failed */ |
1038 | CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url); | 1039 | CURL_EASY_SETOPT(curl, CURLOPT_URL, current_url); |
1039 | if (ret != CURLE_OK) | 1040 | if (ret != CURLE_OK) |
1040 | { | 1041 | { |
1041 | clean_up (); | 1042 | clean_up(); |
1042 | return; | 1043 | return; |
1043 | } | 1044 | } |
1044 | CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1); | 1045 | CURL_EASY_SETOPT(curl, CURLOPT_FAILONERROR, 1); |
1045 | #if 0 | 1046 | #if 0 |
1046 | CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1); | 1047 | CURL_EASY_SETOPT(curl, CURLOPT_VERBOSE, 1); |
1047 | #endif | 1048 | #endif |
1048 | CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE); | 1049 | CURL_EASY_SETOPT(curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE); |
1049 | if (0 == strncmp (current_url, "http", 4)) | 1050 | if (0 == strncmp(current_url, "http", 4)) |
1050 | CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet"); | 1051 | CURL_EASY_SETOPT(curl, CURLOPT_USERAGENT, "GNUnet"); |
1051 | CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L); | 1052 | CURL_EASY_SETOPT(curl, CURLOPT_CONNECTTIMEOUT, 60L); |
1052 | CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L); | 1053 | CURL_EASY_SETOPT(curl, CURLOPT_TIMEOUT, 60L); |
1053 | multi = curl_multi_init (); | 1054 | multi = curl_multi_init(); |
1054 | if (multi == NULL) | 1055 | if (multi == NULL) |
1055 | { | 1056 | { |
1056 | GNUNET_break (0); | 1057 | GNUNET_break(0); |
1057 | /* clean_up (); */ | 1058 | /* clean_up (); */ |
1058 | return; | 1059 | return; |
1059 | } | 1060 | } |
1060 | mret = curl_multi_add_handle (multi, curl); | 1061 | mret = curl_multi_add_handle(multi, curl); |
1061 | if (mret != CURLM_OK) | 1062 | if (mret != CURLM_OK) |
1062 | { | 1063 | { |
1063 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1064 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1064 | _ ("%s failed at %s:%d: `%s'\n"), | 1065 | _("%s failed at %s:%d: `%s'\n"), |
1065 | "curl_multi_add_handle", | 1066 | "curl_multi_add_handle", |
1066 | __FILE__, | 1067 | __FILE__, |
1067 | __LINE__, | 1068 | __LINE__, |
1068 | curl_multi_strerror (mret)); | 1069 | curl_multi_strerror(mret)); |
1069 | mret = curl_multi_cleanup (multi); | 1070 | mret = curl_multi_cleanup(multi); |
1070 | if (mret != CURLM_OK) | 1071 | if (mret != CURLM_OK) |
1071 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1072 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1072 | _ ("%s failed at %s:%d: `%s'\n"), | 1073 | _("%s failed at %s:%d: `%s'\n"), |
1073 | "curl_multi_cleanup", | 1074 | "curl_multi_cleanup", |
1074 | __FILE__, | 1075 | __FILE__, |
1075 | __LINE__, | 1076 | __LINE__, |
1076 | curl_multi_strerror (mret)); | 1077 | curl_multi_strerror(mret)); |
1077 | multi = NULL; | 1078 | multi = NULL; |
1078 | clean_up (); | 1079 | clean_up(); |
1079 | return; | 1080 | return; |
1080 | } | 1081 | } |
1081 | end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 1082 | end_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); |
1082 | download_prepare (); | 1083 | download_prepare(); |
1083 | } | 1084 | } |
1084 | 1085 | ||
1085 | 1086 | ||
1086 | static void | 1087 | static void |
1087 | task_download_dispatcher (void *cls) | 1088 | task_download_dispatcher(void *cls) |
1088 | { | 1089 | { |
1089 | ti_download_dispatcher_task = NULL; | 1090 | ti_download_dispatcher_task = NULL; |
1090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); | 1091 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); |
1091 | if (GNUNET_NO == stat_download_in_progress) | 1092 | if (GNUNET_NO == stat_download_in_progress) |
1092 | { | 1093 | { |
1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); | 1094 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); |
1094 | download_hostlist (); | 1095 | download_hostlist(); |
1095 | } | 1096 | } |
1096 | else | 1097 | else |
1097 | { | 1098 | { |
1098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1099 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1099 | "Download in progess, have to wait...\n"); | 1100 | "Download in progess, have to wait...\n"); |
1100 | ti_download_dispatcher_task = | 1101 | ti_download_dispatcher_task = |
1101 | GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL, | 1102 | GNUNET_SCHEDULER_add_delayed(WAITING_INTERVAL, |
1102 | &task_download_dispatcher, | 1103 | &task_download_dispatcher, |
1103 | NULL); | 1104 | NULL); |
1104 | } | 1105 | } |
1105 | } | 1106 | } |
1106 | 1107 | ||
1107 | 1108 | ||
@@ -1111,49 +1112,49 @@ task_download_dispatcher (void *cls) | |||
1111 | * this task again for a later time. | 1112 | * this task again for a later time. |
1112 | */ | 1113 | */ |
1113 | static void | 1114 | static void |
1114 | task_check (void *cls) | 1115 | task_check(void *cls) |
1115 | { | 1116 | { |
1116 | static int once; | 1117 | static int once; |
1117 | struct GNUNET_TIME_Relative delay; | 1118 | struct GNUNET_TIME_Relative delay; |
1118 | 1119 | ||
1119 | ti_check_download = NULL; | 1120 | ti_check_download = NULL; |
1120 | if (stats == NULL) | 1121 | if (stats == NULL) |
1121 | { | 1122 | { |
1122 | curl_global_cleanup (); | 1123 | curl_global_cleanup(); |
1123 | return; /* in shutdown */ | 1124 | return; /* in shutdown */ |
1124 | } | 1125 | } |
1125 | if ((stat_connection_count < MIN_CONNECTIONS) && | 1126 | if ((stat_connection_count < MIN_CONNECTIONS) && |
1126 | (NULL == ti_download_dispatcher_task)) | 1127 | (NULL == ti_download_dispatcher_task)) |
1127 | ti_download_dispatcher_task = | 1128 | ti_download_dispatcher_task = |
1128 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); | 1129 | GNUNET_SCHEDULER_add_now(&task_download_dispatcher, NULL); |
1129 | 1130 | ||
1130 | delay = hostlist_delay; | 1131 | delay = hostlist_delay; |
1131 | if (0 == hostlist_delay.rel_value_us) | 1132 | if (0 == hostlist_delay.rel_value_us) |
1132 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; | 1133 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; |
1133 | else | 1134 | else |
1134 | hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2); | 1135 | hostlist_delay = GNUNET_TIME_relative_multiply(hostlist_delay, 2); |
1135 | if (hostlist_delay.rel_value_us > | 1136 | if (hostlist_delay.rel_value_us > |
1136 | GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) | 1137 | GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) |
1137 | hostlist_delay = | 1138 | hostlist_delay = |
1138 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, | 1139 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, |
1139 | (1 + stat_connection_count)); | 1140 | (1 + stat_connection_count)); |
1140 | GNUNET_STATISTICS_set (stats, | 1141 | GNUNET_STATISTICS_set(stats, |
1141 | gettext_noop ( | 1142 | gettext_noop( |
1142 | "# milliseconds between hostlist downloads"), | 1143 | "# milliseconds between hostlist downloads"), |
1143 | hostlist_delay.rel_value_us / 1000LL, | 1144 | hostlist_delay.rel_value_us / 1000LL, |
1144 | GNUNET_YES); | 1145 | GNUNET_YES); |
1145 | if (0 == once) | 1146 | if (0 == once) |
1146 | { | 1147 | { |
1147 | delay = GNUNET_TIME_UNIT_ZERO; | 1148 | delay = GNUNET_TIME_UNIT_ZERO; |
1148 | once = 1; | 1149 | once = 1; |
1149 | } | 1150 | } |
1150 | GNUNET_log ( | 1151 | GNUNET_log( |
1151 | GNUNET_ERROR_TYPE_INFO, | 1152 | GNUNET_ERROR_TYPE_INFO, |
1152 | _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"), | 1153 | _("Have %u/%u connections. Will consider downloading hostlist in %s\n"), |
1153 | stat_connection_count, | 1154 | stat_connection_count, |
1154 | MIN_CONNECTIONS, | 1155 | MIN_CONNECTIONS, |
1155 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); | 1156 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); |
1156 | ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); | 1157 | ti_check_download = GNUNET_SCHEDULER_add_delayed(delay, &task_check, NULL); |
1157 | } | 1158 | } |
1158 | 1159 | ||
1159 | 1160 | ||
@@ -1163,12 +1164,12 @@ task_check (void *cls) | |||
1163 | * @param cls closure | 1164 | * @param cls closure |
1164 | */ | 1165 | */ |
1165 | static void | 1166 | static void |
1166 | task_testing_intervall_reset (void *cls) | 1167 | task_testing_intervall_reset(void *cls) |
1167 | { | 1168 | { |
1168 | ti_testing_intervall_task = NULL; | 1169 | ti_testing_intervall_task = NULL; |
1169 | stat_testing_allowed = GNUNET_OK; | 1170 | stat_testing_allowed = GNUNET_OK; |
1170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1171 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1171 | "Testing new hostlist advertisements is allowed again\n"); | 1172 | "Testing new hostlist advertisements is allowed again\n"); |
1172 | } | 1173 | } |
1173 | 1174 | ||
1174 | 1175 | ||
@@ -1178,17 +1179,17 @@ task_testing_intervall_reset (void *cls) | |||
1178 | * @param cls closure | 1179 | * @param cls closure |
1179 | */ | 1180 | */ |
1180 | static void | 1181 | static void |
1181 | task_hostlist_saving (void *cls) | 1182 | task_hostlist_saving(void *cls) |
1182 | { | 1183 | { |
1183 | ti_saving_task = NULL; | 1184 | ti_saving_task = NULL; |
1184 | save_hostlist_file (GNUNET_NO); | 1185 | save_hostlist_file(GNUNET_NO); |
1185 | 1186 | ||
1186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1187 | "Hostlists will be saved to file again in %s\n", | 1188 | "Hostlists will be saved to file again in %s\n", |
1188 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, | 1189 | GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, |
1189 | GNUNET_YES)); | 1190 | GNUNET_YES)); |
1190 | ti_saving_task = | 1191 | ti_saving_task = |
1191 | GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, NULL); | 1192 | GNUNET_SCHEDULER_add_delayed(SAVING_INTERVAL, &task_hostlist_saving, NULL); |
1192 | } | 1193 | } |
1193 | 1194 | ||
1194 | 1195 | ||
@@ -1200,16 +1201,16 @@ task_hostlist_saving (void *cls) | |||
1200 | * @param mq message queue for transmissions to @a peer | 1201 | * @param mq message queue for transmissions to @a peer |
1201 | */ | 1202 | */ |
1202 | static void * | 1203 | static void * |
1203 | handler_connect (void *cls, | 1204 | handler_connect(void *cls, |
1204 | const struct GNUNET_PeerIdentity *peer, | 1205 | const struct GNUNET_PeerIdentity *peer, |
1205 | struct GNUNET_MQ_Handle *mq) | 1206 | struct GNUNET_MQ_Handle *mq) |
1206 | { | 1207 | { |
1207 | GNUNET_assert (stat_connection_count < UINT_MAX); | 1208 | GNUNET_assert(stat_connection_count < UINT_MAX); |
1208 | stat_connection_count++; | 1209 | stat_connection_count++; |
1209 | GNUNET_STATISTICS_update (stats, | 1210 | GNUNET_STATISTICS_update(stats, |
1210 | gettext_noop ("# active connections"), | 1211 | gettext_noop("# active connections"), |
1211 | 1, | 1212 | 1, |
1212 | GNUNET_NO); | 1213 | GNUNET_NO); |
1213 | return NULL; | 1214 | return NULL; |
1214 | } | 1215 | } |
1215 | 1216 | ||
@@ -1221,16 +1222,16 @@ handler_connect (void *cls, | |||
1221 | * @param peer peer identity this notification is about | 1222 | * @param peer peer identity this notification is about |
1222 | */ | 1223 | */ |
1223 | static void | 1224 | static void |
1224 | handler_disconnect (void *cls, | 1225 | handler_disconnect(void *cls, |
1225 | const struct GNUNET_PeerIdentity *peer, | 1226 | const struct GNUNET_PeerIdentity *peer, |
1226 | void *internal_cls) | 1227 | void *internal_cls) |
1227 | { | 1228 | { |
1228 | GNUNET_assert (stat_connection_count > 0); | 1229 | GNUNET_assert(stat_connection_count > 0); |
1229 | stat_connection_count--; | 1230 | stat_connection_count--; |
1230 | GNUNET_STATISTICS_update (stats, | 1231 | GNUNET_STATISTICS_update(stats, |
1231 | gettext_noop ("# active connections"), | 1232 | gettext_noop("# active connections"), |
1232 | -1, | 1233 | -1, |
1233 | GNUNET_NO); | 1234 | GNUNET_NO); |
1234 | } | 1235 | } |
1235 | 1236 | ||
1236 | 1237 | ||
@@ -1240,57 +1241,57 @@ handler_disconnect (void *cls, | |||
1240 | * @param uri the advertised URI | 1241 | * @param uri the advertised URI |
1241 | */ | 1242 | */ |
1242 | static void | 1243 | static void |
1243 | handler_advertisement (const char *uri) | 1244 | handler_advertisement(const char *uri) |
1244 | { | 1245 | { |
1245 | size_t uri_size; | 1246 | size_t uri_size; |
1246 | struct Hostlist *hostlist; | 1247 | struct Hostlist *hostlist; |
1247 | 1248 | ||
1248 | uri_size = strlen (uri) + 1; | 1249 | uri_size = strlen(uri) + 1; |
1249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1250 | "Hostlist client recieved advertisement containing URI `%s'\n", | 1251 | "Hostlist client recieved advertisement containing URI `%s'\n", |
1251 | uri); | 1252 | uri); |
1252 | if (GNUNET_NO != linked_list_contains (uri)) | 1253 | if (GNUNET_NO != linked_list_contains(uri)) |
1253 | { | 1254 | { |
1254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); | 1255 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); |
1255 | return; | 1256 | return; |
1256 | } | 1257 | } |
1257 | 1258 | ||
1258 | if (GNUNET_NO == stat_testing_allowed) | 1259 | if (GNUNET_NO == stat_testing_allowed) |
1259 | { | 1260 | { |
1260 | GNUNET_log ( | 1261 | GNUNET_log( |
1261 | GNUNET_ERROR_TYPE_DEBUG, | 1262 | GNUNET_ERROR_TYPE_DEBUG, |
1262 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); | 1263 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); |
1263 | return; | 1264 | return; |
1264 | } | 1265 | } |
1265 | if (GNUNET_YES == stat_testing_hostlist) | 1266 | if (GNUNET_YES == stat_testing_hostlist) |
1266 | { | 1267 | { |
1267 | GNUNET_log ( | 1268 | GNUNET_log( |
1268 | GNUNET_ERROR_TYPE_DEBUG, | 1269 | GNUNET_ERROR_TYPE_DEBUG, |
1269 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); | 1270 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); |
1270 | return; | 1271 | return; |
1271 | } | 1272 | } |
1272 | 1273 | ||
1273 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); | 1274 | hostlist = GNUNET_malloc(sizeof(struct Hostlist) + uri_size); |
1274 | hostlist->hostlist_uri = (const char *) &hostlist[1]; | 1275 | hostlist->hostlist_uri = (const char *)&hostlist[1]; |
1275 | GNUNET_memcpy (&hostlist[1], uri, uri_size); | 1276 | GNUNET_memcpy(&hostlist[1], uri, uri_size); |
1276 | hostlist->time_creation = GNUNET_TIME_absolute_get (); | 1277 | hostlist->time_creation = GNUNET_TIME_absolute_get(); |
1277 | hostlist->quality = HOSTLIST_INITIAL; | 1278 | hostlist->quality = HOSTLIST_INITIAL; |
1278 | hostlist_to_test = hostlist; | 1279 | hostlist_to_test = hostlist; |
1279 | 1280 | ||
1280 | stat_testing_hostlist = GNUNET_YES; | 1281 | stat_testing_hostlist = GNUNET_YES; |
1281 | stat_testing_allowed = GNUNET_NO; | 1282 | stat_testing_allowed = GNUNET_NO; |
1282 | ti_testing_intervall_task = | 1283 | ti_testing_intervall_task = |
1283 | GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, | 1284 | GNUNET_SCHEDULER_add_delayed(TESTING_INTERVAL, |
1284 | &task_testing_intervall_reset, | 1285 | &task_testing_intervall_reset, |
1285 | NULL); | 1286 | NULL); |
1286 | 1287 | ||
1287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1288 | "Testing new hostlist advertisements is locked for the next %s\n", | 1289 | "Testing new hostlist advertisements is locked for the next %s\n", |
1289 | GNUNET_STRINGS_relative_time_to_string (TESTING_INTERVAL, | 1290 | GNUNET_STRINGS_relative_time_to_string(TESTING_INTERVAL, |
1290 | GNUNET_YES)); | 1291 | GNUNET_YES)); |
1291 | 1292 | ||
1292 | ti_download_dispatcher_task = | 1293 | ti_download_dispatcher_task = |
1293 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); | 1294 | GNUNET_SCHEDULER_add_now(&task_download_dispatcher, NULL); |
1294 | } | 1295 | } |
1295 | 1296 | ||
1296 | 1297 | ||
@@ -1303,18 +1304,18 @@ handler_advertisement (const char *uri) | |||
1303 | * successfully obtained, #GNUNET_SYSERR if not. | 1304 | * successfully obtained, #GNUNET_SYSERR if not. |
1304 | */ | 1305 | */ |
1305 | static void | 1306 | static void |
1306 | primary_task (void *cls, int success) | 1307 | primary_task(void *cls, int success) |
1307 | { | 1308 | { |
1308 | if (NULL != ti_check_download) | 1309 | if (NULL != ti_check_download) |
1309 | { | 1310 | { |
1310 | GNUNET_SCHEDULER_cancel (ti_check_download); | 1311 | GNUNET_SCHEDULER_cancel(ti_check_download); |
1311 | ti_check_download = NULL; | 1312 | ti_check_download = NULL; |
1312 | } | 1313 | } |
1313 | sget = NULL; | 1314 | sget = NULL; |
1314 | GNUNET_assert (NULL != stats); | 1315 | GNUNET_assert(NULL != stats); |
1315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1316 | "Statistics request done, scheduling hostlist download\n"); | 1317 | "Statistics request done, scheduling hostlist download\n"); |
1317 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); | 1318 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); |
1318 | } | 1319 | } |
1319 | 1320 | ||
1320 | 1321 | ||
@@ -1327,11 +1328,11 @@ primary_task (void *cls, int success) | |||
1327 | * successfully obtained, #GNUNET_SYSERR if not. | 1328 | * successfully obtained, #GNUNET_SYSERR if not. |
1328 | */ | 1329 | */ |
1329 | static void | 1330 | static void |
1330 | stat_timeout_task (void *cls) | 1331 | stat_timeout_task(void *cls) |
1331 | { | 1332 | { |
1332 | GNUNET_STATISTICS_get_cancel (sget); | 1333 | GNUNET_STATISTICS_get_cancel(sget); |
1333 | sget = NULL; | 1334 | sget = NULL; |
1334 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); | 1335 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); |
1335 | } | 1336 | } |
1336 | 1337 | ||
1337 | 1338 | ||
@@ -1345,17 +1346,17 @@ stat_timeout_task (void *cls) | |||
1345 | * @param is_persistent unused, will be #GNUNET_YES | 1346 | * @param is_persistent unused, will be #GNUNET_YES |
1346 | */ | 1347 | */ |
1347 | static int | 1348 | static int |
1348 | process_stat (void *cls, | 1349 | process_stat(void *cls, |
1349 | const char *subsystem, | 1350 | const char *subsystem, |
1350 | const char *name, | 1351 | const char *name, |
1351 | uint64_t value, | 1352 | uint64_t value, |
1352 | int is_persistent) | 1353 | int is_persistent) |
1353 | { | 1354 | { |
1354 | hostlist_delay.rel_value_us = value * 1000LL; | 1355 | hostlist_delay.rel_value_us = value * 1000LL; |
1355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1356 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1356 | "Initial time between hostlist downloads is %s\n", | 1357 | "Initial time between hostlist downloads is %s\n", |
1357 | GNUNET_STRINGS_relative_time_to_string (hostlist_delay, | 1358 | GNUNET_STRINGS_relative_time_to_string(hostlist_delay, |
1358 | GNUNET_YES)); | 1359 | GNUNET_YES)); |
1359 | return GNUNET_OK; | 1360 | return GNUNET_OK; |
1360 | } | 1361 | } |
1361 | 1362 | ||
@@ -1364,7 +1365,7 @@ process_stat (void *cls, | |||
1364 | * Method to load persistent hostlist file during hostlist client startup | 1365 | * Method to load persistent hostlist file during hostlist client startup |
1365 | */ | 1366 | */ |
1366 | static void | 1367 | static void |
1367 | load_hostlist_file () | 1368 | load_hostlist_file() |
1368 | { | 1369 | { |
1369 | char *filename; | 1370 | char *filename; |
1370 | char *uri; | 1371 | char *uri; |
@@ -1379,87 +1380,87 @@ load_hostlist_file () | |||
1379 | struct GNUNET_BIO_ReadHandle *rh; | 1380 | struct GNUNET_BIO_ReadHandle *rh; |
1380 | 1381 | ||
1381 | uri = NULL; | 1382 | uri = NULL; |
1382 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 1383 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
1383 | "HOSTLIST", | 1384 | "HOSTLIST", |
1384 | "HOSTLISTFILE", | 1385 | "HOSTLISTFILE", |
1385 | &filename)) | 1386 | &filename)) |
1386 | { | 1387 | { |
1387 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | 1388 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, |
1388 | "hostlist", | 1389 | "hostlist", |
1389 | "HOSTLISTFILE"); | 1390 | "HOSTLISTFILE"); |
1390 | return; | 1391 | return; |
1391 | } | 1392 | } |
1392 | 1393 | ||
1393 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1394 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1394 | _ ("Loading saved hostlist entries from file `%s' \n"), | 1395 | _("Loading saved hostlist entries from file `%s' \n"), |
1395 | filename); | 1396 | filename); |
1396 | if (GNUNET_NO == GNUNET_DISK_file_test (filename)) | 1397 | if (GNUNET_NO == GNUNET_DISK_file_test(filename)) |
1397 | { | 1398 | { |
1398 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1399 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1399 | _ ("Hostlist file `%s' does not exist\n"), | 1400 | _("Hostlist file `%s' does not exist\n"), |
1400 | filename); | 1401 | filename); |
1401 | GNUNET_free (filename); | 1402 | GNUNET_free(filename); |
1402 | return; | 1403 | return; |
1403 | } | 1404 | } |
1404 | 1405 | ||
1405 | rh = GNUNET_BIO_read_open (filename); | 1406 | rh = GNUNET_BIO_read_open(filename); |
1406 | if (NULL == rh) | 1407 | if (NULL == rh) |
1407 | { | 1408 | { |
1408 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1409 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1409 | _ ( | 1410 | _( |
1410 | "Could not open file `%s' for reading to load hostlists: %s\n"), | 1411 | "Could not open file `%s' for reading to load hostlists: %s\n"), |
1411 | filename, | 1412 | filename, |
1412 | strerror (errno)); | 1413 | strerror(errno)); |
1413 | GNUNET_free (filename); | 1414 | GNUNET_free(filename); |
1414 | return; | 1415 | return; |
1415 | } | 1416 | } |
1416 | 1417 | ||
1417 | counter = 0; | 1418 | counter = 0; |
1418 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && | 1419 | while ((GNUNET_OK == GNUNET_BIO_read_string(rh, "url", &uri, MAX_URL_LEN)) && |
1419 | (NULL != uri) && | 1420 | (NULL != uri) && |
1420 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && | 1421 | (GNUNET_OK == GNUNET_BIO_read_int32(rh, ×_used)) && |
1421 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && | 1422 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &quality)) && |
1422 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && | 1423 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &last_used)) && |
1423 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && | 1424 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &created)) && |
1424 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) | 1425 | (GNUNET_OK == GNUNET_BIO_read_int32(rh, &hellos_returned))) |
1425 | { | 1426 | { |
1426 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1); | 1427 | hostlist = GNUNET_malloc(sizeof(struct Hostlist) + strlen(uri) + 1); |
1427 | hostlist->hello_count = hellos_returned; | 1428 | hostlist->hello_count = hellos_returned; |
1428 | hostlist->hostlist_uri = (const char *) &hostlist[1]; | 1429 | hostlist->hostlist_uri = (const char *)&hostlist[1]; |
1429 | GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1); | 1430 | GNUNET_memcpy(&hostlist[1], uri, strlen(uri) + 1); |
1430 | hostlist->quality = quality; | 1431 | hostlist->quality = quality; |
1431 | hostlist->time_creation.abs_value_us = created; | 1432 | hostlist->time_creation.abs_value_us = created; |
1432 | hostlist->time_last_usage.abs_value_us = last_used; | 1433 | hostlist->time_last_usage.abs_value_us = last_used; |
1433 | GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, hostlist); | 1434 | GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist); |
1434 | linked_list_size++; | 1435 | linked_list_size++; |
1435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1436 | "Added hostlist entry eith URI `%s' \n", | 1437 | "Added hostlist entry eith URI `%s' \n", |
1437 | hostlist->hostlist_uri); | 1438 | hostlist->hostlist_uri); |
1438 | GNUNET_free (uri); | 1439 | GNUNET_free(uri); |
1439 | uri = NULL; | 1440 | uri = NULL; |
1440 | counter++; | 1441 | counter++; |
1441 | if (counter >= MAX_NUMBER_HOSTLISTS) | 1442 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1442 | break; | 1443 | break; |
1443 | } | 1444 | } |
1444 | 1445 | ||
1445 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1446 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1446 | _ ("%u hostlist URIs loaded from file\n"), | 1447 | _("%u hostlist URIs loaded from file\n"), |
1447 | counter); | 1448 | counter); |
1448 | GNUNET_STATISTICS_set (stats, | 1449 | GNUNET_STATISTICS_set(stats, |
1449 | gettext_noop ("# hostlist URIs read from file"), | 1450 | gettext_noop("# hostlist URIs read from file"), |
1450 | counter, | 1451 | counter, |
1451 | GNUNET_YES); | 1452 | GNUNET_YES); |
1452 | GNUNET_STATISTICS_set (stats, | 1453 | GNUNET_STATISTICS_set(stats, |
1453 | gettext_noop ("# advertised hostlist URIs"), | 1454 | gettext_noop("# advertised hostlist URIs"), |
1454 | linked_list_size, | 1455 | linked_list_size, |
1455 | GNUNET_NO); | 1456 | GNUNET_NO); |
1456 | 1457 | ||
1457 | GNUNET_free_non_null (uri); | 1458 | GNUNET_free_non_null(uri); |
1458 | emsg = NULL; | 1459 | emsg = NULL; |
1459 | (void) GNUNET_BIO_read_close (rh, &emsg); | 1460 | (void)GNUNET_BIO_read_close(rh, &emsg); |
1460 | if (emsg != NULL) | 1461 | if (emsg != NULL) |
1461 | GNUNET_free (emsg); | 1462 | GNUNET_free(emsg); |
1462 | GNUNET_free (filename); | 1463 | GNUNET_free(filename); |
1463 | } | 1464 | } |
1464 | 1465 | ||
1465 | 1466 | ||
@@ -1469,7 +1470,7 @@ load_hostlist_file () | |||
1469 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 1470 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
1470 | */ | 1471 | */ |
1471 | static void | 1472 | static void |
1472 | save_hostlist_file (int shutdown) | 1473 | save_hostlist_file(int shutdown) |
1473 | { | 1474 | { |
1474 | char *filename; | 1475 | char *filename; |
1475 | struct Hostlist *pos; | 1476 | struct Hostlist *pos; |
@@ -1477,80 +1478,80 @@ save_hostlist_file (int shutdown) | |||
1477 | int ok; | 1478 | int ok; |
1478 | uint32_t counter; | 1479 | uint32_t counter; |
1479 | 1480 | ||
1480 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 1481 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
1481 | "HOSTLIST", | 1482 | "HOSTLIST", |
1482 | "HOSTLISTFILE", | 1483 | "HOSTLISTFILE", |
1483 | &filename)) | 1484 | &filename)) |
1484 | { | 1485 | { |
1485 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | 1486 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, |
1486 | "hostlist", | 1487 | "hostlist", |
1487 | "HOSTLISTFILE"); | 1488 | "HOSTLISTFILE"); |
1488 | return; | 1489 | return; |
1489 | } | 1490 | } |
1490 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) | 1491 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file(filename)) |
1491 | { | 1492 | { |
1492 | GNUNET_free (filename); | 1493 | GNUNET_free(filename); |
1493 | return; | 1494 | return; |
1494 | } | 1495 | } |
1495 | wh = GNUNET_BIO_write_open (filename); | 1496 | wh = GNUNET_BIO_write_open(filename); |
1496 | if (NULL == wh) | 1497 | if (NULL == wh) |
1497 | { | 1498 | { |
1498 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1499 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1499 | _ ( | 1500 | _( |
1500 | "Could not open file `%s' for writing to save hostlists: %s\n"), | 1501 | "Could not open file `%s' for writing to save hostlists: %s\n"), |
1501 | filename, | 1502 | filename, |
1502 | strerror (errno)); | 1503 | strerror(errno)); |
1503 | GNUNET_free (filename); | 1504 | GNUNET_free(filename); |
1504 | return; | 1505 | return; |
1505 | } | 1506 | } |
1506 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1507 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1507 | _ ("Writing %u hostlist URIs to `%s'\n"), | 1508 | _("Writing %u hostlist URIs to `%s'\n"), |
1508 | linked_list_size, | 1509 | linked_list_size, |
1509 | filename); | 1510 | filename); |
1510 | /* add code to write hostlists to file using bio */ | 1511 | /* add code to write hostlists to file using bio */ |
1511 | ok = GNUNET_YES; | 1512 | ok = GNUNET_YES; |
1512 | counter = 0; | 1513 | counter = 0; |
1513 | while (NULL != (pos = linked_list_head)) | 1514 | while (NULL != (pos = linked_list_head)) |
1514 | { | ||
1515 | if (GNUNET_YES == shutdown) | ||
1516 | { | 1515 | { |
1517 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); | 1516 | if (GNUNET_YES == shutdown) |
1518 | linked_list_size--; | 1517 | { |
1519 | } | 1518 | GNUNET_CONTAINER_DLL_remove(linked_list_head, linked_list_tail, pos); |
1520 | if (GNUNET_YES == ok) | 1519 | linked_list_size--; |
1521 | { | 1520 | } |
1522 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | 1521 | if (GNUNET_YES == ok) |
1523 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) || | 1522 | { |
1524 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) || | 1523 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, pos->hostlist_uri)) || |
1525 | (GNUNET_OK != | 1524 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pos->times_used)) || |
1526 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value_us)) || | 1525 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, pos->quality)) || |
1527 | (GNUNET_OK != | 1526 | (GNUNET_OK != |
1528 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value_us)) || | 1527 | GNUNET_BIO_write_int64(wh, pos->time_last_usage.abs_value_us)) || |
1529 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) | 1528 | (GNUNET_OK != |
1530 | { | 1529 | GNUNET_BIO_write_int64(wh, pos->time_creation.abs_value_us)) || |
1531 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1530 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pos->hello_count))) |
1532 | _ ("Error writing hostlist URIs to file `%s'\n"), | 1531 | { |
1533 | filename); | 1532 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1534 | ok = GNUNET_NO; | 1533 | _("Error writing hostlist URIs to file `%s'\n"), |
1535 | } | 1534 | filename); |
1536 | } | 1535 | ok = GNUNET_NO; |
1536 | } | ||
1537 | } | ||
1537 | 1538 | ||
1538 | if (GNUNET_YES == shutdown) | 1539 | if (GNUNET_YES == shutdown) |
1539 | GNUNET_free (pos); | 1540 | GNUNET_free(pos); |
1540 | counter++; | 1541 | counter++; |
1541 | if (counter >= MAX_NUMBER_HOSTLISTS) | 1542 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1542 | break; | 1543 | break; |
1543 | } | 1544 | } |
1544 | GNUNET_STATISTICS_set (stats, | 1545 | GNUNET_STATISTICS_set(stats, |
1545 | gettext_noop ("# hostlist URIs written to file"), | 1546 | gettext_noop("# hostlist URIs written to file"), |
1546 | counter, | 1547 | counter, |
1547 | GNUNET_YES); | 1548 | GNUNET_YES); |
1548 | 1549 | ||
1549 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1550 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
1550 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1551 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1551 | _ ("Error writing hostlist URIs to file `%s'\n"), | 1552 | _("Error writing hostlist URIs to file `%s'\n"), |
1552 | filename); | 1553 | filename); |
1553 | GNUNET_free (filename); | 1554 | GNUNET_free(filename); |
1554 | } | 1555 | } |
1555 | 1556 | ||
1556 | 1557 | ||
@@ -1566,94 +1567,94 @@ save_hostlist_file (int shutdown) | |||
1566 | * @return #GNUNET_OK on success | 1567 | * @return #GNUNET_OK on success |
1567 | */ | 1568 | */ |
1568 | int | 1569 | int |
1569 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | 1570 | GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, |
1570 | struct GNUNET_STATISTICS_Handle *st, | 1571 | struct GNUNET_STATISTICS_Handle *st, |
1571 | GNUNET_CORE_ConnectEventHandler *ch, | 1572 | GNUNET_CORE_ConnectEventHandler *ch, |
1572 | GNUNET_CORE_DisconnectEventHandler *dh, | 1573 | GNUNET_CORE_DisconnectEventHandler *dh, |
1573 | GNUNET_HOSTLIST_UriHandler *msgh, | 1574 | GNUNET_HOSTLIST_UriHandler *msgh, |
1574 | int learn) | 1575 | int learn) |
1575 | { | 1576 | { |
1576 | char *filename; | 1577 | char *filename; |
1577 | char *proxytype_str; | 1578 | char *proxytype_str; |
1578 | int result; | 1579 | int result; |
1579 | 1580 | ||
1580 | GNUNET_assert (NULL != st); | 1581 | GNUNET_assert(NULL != st); |
1581 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 1582 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
1582 | { | 1583 | { |
1583 | GNUNET_break (0); | 1584 | GNUNET_break(0); |
1584 | return GNUNET_SYSERR; | 1585 | return GNUNET_SYSERR; |
1585 | } | 1586 | } |
1586 | cfg = c; | 1587 | cfg = c; |
1587 | stats = st; | 1588 | stats = st; |
1588 | 1589 | ||
1589 | /* Read proxy configuration */ | 1590 | /* Read proxy configuration */ |
1590 | pi = GNUNET_PEERINFO_connect (c); | 1591 | pi = GNUNET_PEERINFO_connect(c); |
1591 | if (GNUNET_OK == | 1592 | if (GNUNET_OK == |
1592 | GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy)) | 1593 | GNUNET_CONFIGURATION_get_value_string(cfg, "HOSTLIST", "PROXY", &proxy)) |
1593 | { | ||
1594 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy); | ||
1595 | /* proxy username */ | ||
1596 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1597 | "HOSTLIST", | ||
1598 | "PROXY_USERNAME", | ||
1599 | &proxy_username)) | ||
1600 | { | 1594 | { |
1601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1595 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy); |
1602 | "Found proxy username name: `%s'\n", | 1596 | /* proxy username */ |
1603 | proxy_username); | 1597 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, |
1604 | } | 1598 | "HOSTLIST", |
1599 | "PROXY_USERNAME", | ||
1600 | &proxy_username)) | ||
1601 | { | ||
1602 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1603 | "Found proxy username name: `%s'\n", | ||
1604 | proxy_username); | ||
1605 | } | ||
1605 | 1606 | ||
1606 | /* proxy password */ | 1607 | /* proxy password */ |
1607 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | 1608 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, |
1608 | "HOSTLIST", | 1609 | "HOSTLIST", |
1609 | "PROXY_PASSWORD", | 1610 | "PROXY_PASSWORD", |
1610 | &proxy_password)) | 1611 | &proxy_password)) |
1611 | { | 1612 | { |
1612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1613 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1613 | "Found proxy password name: `%s'\n", | 1614 | "Found proxy password name: `%s'\n", |
1614 | proxy_password); | 1615 | proxy_password); |
1615 | } | 1616 | } |
1616 | 1617 | ||
1617 | /* proxy type */ | 1618 | /* proxy type */ |
1618 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | 1619 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, |
1619 | "HOSTLIST", | 1620 | "HOSTLIST", |
1620 | "PROXY_TYPE", | 1621 | "PROXY_TYPE", |
1621 | &proxytype_str)) | 1622 | &proxytype_str)) |
1622 | { | 1623 | { |
1623 | GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str); | 1624 | GNUNET_STRINGS_utf8_toupper(proxytype_str, proxytype_str); |
1624 | proxy_type = CURLPROXY_HTTP; | 1625 | proxy_type = CURLPROXY_HTTP; |
1625 | if (0 == strcmp (proxytype_str, "HTTP")) | 1626 | if (0 == strcmp(proxytype_str, "HTTP")) |
1626 | proxy_type = CURLPROXY_HTTP; | 1627 | proxy_type = CURLPROXY_HTTP; |
1627 | else if (0 == strcmp (proxytype_str, "HTTP_1_0")) | 1628 | else if (0 == strcmp(proxytype_str, "HTTP_1_0")) |
1628 | proxy_type = CURLPROXY_HTTP_1_0; | 1629 | proxy_type = CURLPROXY_HTTP_1_0; |
1629 | else if (0 == strcmp (proxytype_str, "SOCKS4")) | 1630 | else if (0 == strcmp(proxytype_str, "SOCKS4")) |
1630 | proxy_type = CURLPROXY_SOCKS4; | 1631 | proxy_type = CURLPROXY_SOCKS4; |
1631 | else if (0 == strcmp (proxytype_str, "SOCKS5")) | 1632 | else if (0 == strcmp(proxytype_str, "SOCKS5")) |
1632 | proxy_type = CURLPROXY_SOCKS5; | 1633 | proxy_type = CURLPROXY_SOCKS5; |
1633 | else if (0 == strcmp (proxytype_str, "SOCKS4A")) | 1634 | else if (0 == strcmp(proxytype_str, "SOCKS4A")) |
1634 | proxy_type = CURLPROXY_SOCKS4A; | 1635 | proxy_type = CURLPROXY_SOCKS4A; |
1635 | else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME")) | 1636 | else if (0 == strcmp(proxytype_str, "SOCKS5_HOSTNAME")) |
1636 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; | 1637 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; |
1637 | else | 1638 | else |
1638 | { | 1639 | { |
1639 | GNUNET_log ( | 1640 | GNUNET_log( |
1640 | GNUNET_ERROR_TYPE_ERROR, | 1641 | GNUNET_ERROR_TYPE_ERROR, |
1641 | _ ( | 1642 | _( |
1642 | "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), | 1643 | "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), |
1643 | proxytype_str); | 1644 | proxytype_str); |
1644 | GNUNET_free (proxytype_str); | 1645 | GNUNET_free(proxytype_str); |
1645 | GNUNET_free (proxy); | 1646 | GNUNET_free(proxy); |
1646 | proxy = NULL; | 1647 | proxy = NULL; |
1647 | GNUNET_free_non_null (proxy_username); | 1648 | GNUNET_free_non_null(proxy_username); |
1648 | proxy_username = NULL; | 1649 | proxy_username = NULL; |
1649 | GNUNET_free_non_null (proxy_password); | 1650 | GNUNET_free_non_null(proxy_password); |
1650 | proxy_password = NULL; | 1651 | proxy_password = NULL; |
1651 | 1652 | ||
1652 | return GNUNET_SYSERR; | 1653 | return GNUNET_SYSERR; |
1653 | } | 1654 | } |
1655 | } | ||
1656 | GNUNET_free_non_null(proxytype_str); | ||
1654 | } | 1657 | } |
1655 | GNUNET_free_non_null (proxytype_str); | ||
1656 | } | ||
1657 | 1658 | ||
1658 | stat_learning = learn; | 1659 | stat_learning = learn; |
1659 | *ch = &handler_connect; | 1660 | *ch = &handler_connect; |
@@ -1665,67 +1666,67 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1665 | stat_testing_allowed = GNUNET_YES; | 1666 | stat_testing_allowed = GNUNET_YES; |
1666 | 1667 | ||
1667 | if (GNUNET_YES == stat_learning) | 1668 | if (GNUNET_YES == stat_learning) |
1668 | { | 1669 | { |
1669 | *msgh = &handler_advertisement; | 1670 | *msgh = &handler_advertisement; |
1670 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1671 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1671 | _ ("Learning is enabled on this peer\n")); | 1672 | _("Learning is enabled on this peer\n")); |
1672 | load_hostlist_file (); | 1673 | load_hostlist_file(); |
1673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1674 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1674 | "Hostlists will be saved to file again in %s\n", | 1675 | "Hostlists will be saved to file again in %s\n", |
1675 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, | 1676 | GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, |
1676 | GNUNET_YES)); | 1677 | GNUNET_YES)); |
1677 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, | 1678 | ti_saving_task = GNUNET_SCHEDULER_add_delayed(SAVING_INTERVAL, |
1678 | &task_hostlist_saving, | 1679 | &task_hostlist_saving, |
1679 | NULL); | 1680 | NULL); |
1680 | } | 1681 | } |
1681 | else | 1682 | else |
1682 | { | ||
1683 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1684 | _ ("Learning is not enabled on this peer\n")); | ||
1685 | *msgh = NULL; | ||
1686 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
1687 | "HOSTLIST", | ||
1688 | "HOSTLISTFILE", | ||
1689 | &filename)) | ||
1690 | { | 1683 | { |
1691 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 1684 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1692 | { | 1685 | _("Learning is not enabled on this peer\n")); |
1693 | result = remove (filename); | 1686 | *msgh = NULL; |
1694 | if (0 == result) | 1687 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, |
1695 | GNUNET_log ( | 1688 | "HOSTLIST", |
1696 | GNUNET_ERROR_TYPE_INFO, | 1689 | "HOSTLISTFILE", |
1697 | _ ( | 1690 | &filename)) |
1698 | "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), | 1691 | { |
1699 | filename); | 1692 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) |
1700 | else | 1693 | { |
1701 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 1694 | result = remove(filename); |
1702 | "remove", | 1695 | if (0 == result) |
1703 | filename); | 1696 | GNUNET_log( |
1704 | } | 1697 | GNUNET_ERROR_TYPE_INFO, |
1698 | _( | ||
1699 | "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), | ||
1700 | filename); | ||
1701 | else | ||
1702 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | ||
1703 | "remove", | ||
1704 | filename); | ||
1705 | } | ||
1706 | } | ||
1707 | GNUNET_free(filename); | ||
1705 | } | 1708 | } |
1706 | GNUNET_free (filename); | 1709 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1707 | } | 1710 | "Loading stats value on hostlist download frequency\n"); |
1708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1711 | sget = GNUNET_STATISTICS_get(stats, |
1709 | "Loading stats value on hostlist download frequency\n"); | 1712 | "hostlist", |
1710 | sget = GNUNET_STATISTICS_get (stats, | 1713 | gettext_noop( |
1711 | "hostlist", | 1714 | "# milliseconds between hostlist downloads"), |
1712 | gettext_noop ( | 1715 | &primary_task, |
1713 | "# milliseconds between hostlist downloads"), | 1716 | &process_stat, |
1714 | &primary_task, | 1717 | NULL); |
1715 | &process_stat, | ||
1716 | NULL); | ||
1717 | if (NULL == sget) | 1718 | if (NULL == sget) |
1718 | { | 1719 | { |
1719 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1720 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1720 | "Statistics request failed, scheduling hostlist download\n"); | 1721 | "Statistics request failed, scheduling hostlist download\n"); |
1721 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); | 1722 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); |
1722 | } | 1723 | } |
1723 | else | 1724 | else |
1724 | { | 1725 | { |
1725 | ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 1726 | ti_check_download = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, |
1726 | &stat_timeout_task, | 1727 | &stat_timeout_task, |
1727 | NULL); | 1728 | NULL); |
1728 | } | 1729 | } |
1729 | return GNUNET_OK; | 1730 | return GNUNET_OK; |
1730 | } | 1731 | } |
1731 | 1732 | ||
@@ -1734,56 +1735,56 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1734 | * Stop downloading hostlists from hostlist servers as necessary. | 1735 | * Stop downloading hostlists from hostlist servers as necessary. |
1735 | */ | 1736 | */ |
1736 | void | 1737 | void |
1737 | GNUNET_HOSTLIST_client_stop () | 1738 | GNUNET_HOSTLIST_client_stop() |
1738 | { | 1739 | { |
1739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); | 1740 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1740 | if (NULL != sget) | 1741 | if (NULL != sget) |
1741 | { | 1742 | { |
1742 | GNUNET_STATISTICS_get_cancel (sget); | 1743 | GNUNET_STATISTICS_get_cancel(sget); |
1743 | sget = NULL; | 1744 | sget = NULL; |
1744 | } | 1745 | } |
1745 | stats = NULL; | 1746 | stats = NULL; |
1746 | if (GNUNET_YES == stat_learning) | 1747 | if (GNUNET_YES == stat_learning) |
1747 | save_hostlist_file (GNUNET_YES); | 1748 | save_hostlist_file(GNUNET_YES); |
1748 | if (NULL != ti_saving_task) | 1749 | if (NULL != ti_saving_task) |
1749 | { | 1750 | { |
1750 | GNUNET_SCHEDULER_cancel (ti_saving_task); | 1751 | GNUNET_SCHEDULER_cancel(ti_saving_task); |
1751 | ti_saving_task = NULL; | 1752 | ti_saving_task = NULL; |
1752 | } | 1753 | } |
1753 | if (NULL != ti_download_dispatcher_task) | 1754 | if (NULL != ti_download_dispatcher_task) |
1754 | { | 1755 | { |
1755 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); | 1756 | GNUNET_SCHEDULER_cancel(ti_download_dispatcher_task); |
1756 | ti_download_dispatcher_task = NULL; | 1757 | ti_download_dispatcher_task = NULL; |
1757 | } | 1758 | } |
1758 | if (NULL != ti_testing_intervall_task) | 1759 | if (NULL != ti_testing_intervall_task) |
1759 | { | 1760 | { |
1760 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); | 1761 | GNUNET_SCHEDULER_cancel(ti_testing_intervall_task); |
1761 | ti_testing_intervall_task = NULL; | 1762 | ti_testing_intervall_task = NULL; |
1762 | } | 1763 | } |
1763 | if (NULL != ti_download) | 1764 | if (NULL != ti_download) |
1764 | { | 1765 | { |
1765 | GNUNET_SCHEDULER_cancel (ti_download); | 1766 | GNUNET_SCHEDULER_cancel(ti_download); |
1766 | ti_download = NULL; | 1767 | ti_download = NULL; |
1767 | update_hostlist (); | 1768 | update_hostlist(); |
1768 | clean_up (); | 1769 | clean_up(); |
1769 | } | 1770 | } |
1770 | if (NULL != ti_check_download) | 1771 | if (NULL != ti_check_download) |
1771 | { | 1772 | { |
1772 | GNUNET_SCHEDULER_cancel (ti_check_download); | 1773 | GNUNET_SCHEDULER_cancel(ti_check_download); |
1773 | ti_check_download = NULL; | 1774 | ti_check_download = NULL; |
1774 | curl_global_cleanup (); | 1775 | curl_global_cleanup(); |
1775 | } | 1776 | } |
1776 | GNUNET_free_non_null (proxy); | 1777 | GNUNET_free_non_null(proxy); |
1777 | proxy = NULL; | 1778 | proxy = NULL; |
1778 | GNUNET_free_non_null (proxy_username); | 1779 | GNUNET_free_non_null(proxy_username); |
1779 | proxy_username = NULL; | 1780 | proxy_username = NULL; |
1780 | GNUNET_free_non_null (proxy_password); | 1781 | GNUNET_free_non_null(proxy_password); |
1781 | proxy_password = NULL; | 1782 | proxy_password = NULL; |
1782 | if (NULL != pi) | 1783 | if (NULL != pi) |
1783 | { | 1784 | { |
1784 | GNUNET_PEERINFO_disconnect (pi); | 1785 | GNUNET_PEERINFO_disconnect(pi); |
1785 | pi = NULL; | 1786 | pi = NULL; |
1786 | } | 1787 | } |
1787 | cfg = NULL; | 1788 | cfg = NULL; |
1788 | } | 1789 | } |
1789 | 1790 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.h b/src/hostlist/gnunet-daemon-hostlist_client.h index 8ac5bdb58..4268b26dd 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.h +++ b/src/hostlist/gnunet-daemon-hostlist_client.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file hostlist/gnunet-daemon-hostlist_client.h | 21 | * @file hostlist/gnunet-daemon-hostlist_client.h |
22 | * @brief hostlist support. Downloads HELLOs via HTTP. | 22 | * @brief hostlist support. Downloads HELLOs via HTTP. |
@@ -51,19 +51,19 @@ typedef void | |||
51 | * @return #GNUNET_OK on success | 51 | * @return #GNUNET_OK on success |
52 | */ | 52 | */ |
53 | int | 53 | int |
54 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | 54 | GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, |
55 | struct GNUNET_STATISTICS_Handle *st, | 55 | struct GNUNET_STATISTICS_Handle *st, |
56 | GNUNET_CORE_ConnectEventHandler *ch, | 56 | GNUNET_CORE_ConnectEventHandler *ch, |
57 | GNUNET_CORE_DisconnectEventHandler *dh, | 57 | GNUNET_CORE_DisconnectEventHandler *dh, |
58 | GNUNET_HOSTLIST_UriHandler *msgh, | 58 | GNUNET_HOSTLIST_UriHandler *msgh, |
59 | int learn); | 59 | int learn); |
60 | 60 | ||
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Stop downloading hostlists from hostlist servers as necessary. | 63 | * Stop downloading hostlists from hostlist servers as necessary. |
64 | */ | 64 | */ |
65 | void | 65 | void |
66 | GNUNET_HOSTLIST_client_stop (void); | 66 | GNUNET_HOSTLIST_client_stop(void); |
67 | 67 | ||
68 | 68 | ||
69 | #endif | 69 | #endif |
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c index 8764586d6..b4e0df34e 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.c +++ b/src/hostlist/gnunet-daemon-hostlist_server.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file hostlist/gnunet-daemon-hostlist_server.c | 22 | * @file hostlist/gnunet-daemon-hostlist_server.c |
@@ -39,7 +39,7 @@ | |||
39 | * time out? | 39 | * time out? |
40 | */ | 40 | */ |
41 | #define GNUNET_ADV_TIMEOUT \ | 41 | #define GNUNET_ADV_TIMEOUT \ |
42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 42 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -106,8 +106,7 @@ static char *hostlist_uri; | |||
106 | /** | 106 | /** |
107 | * Context for #host_processor(). | 107 | * Context for #host_processor(). |
108 | */ | 108 | */ |
109 | struct HostSet | 109 | struct HostSet { |
110 | { | ||
111 | /** | 110 | /** |
112 | * Iterator used to build @e data (NULL when done). | 111 | * Iterator used to build @e data (NULL when done). |
113 | */ | 112 | */ |
@@ -138,13 +137,13 @@ static struct HostSet *builder; | |||
138 | * @param response response to add headers to | 137 | * @param response response to add headers to |
139 | */ | 138 | */ |
140 | static void | 139 | static void |
141 | add_cors_headers (struct MHD_Response *response) | 140 | add_cors_headers(struct MHD_Response *response) |
142 | { | 141 | { |
143 | MHD_add_response_header (response, "Access-Control-Allow-Origin", "*"); | 142 | MHD_add_response_header(response, "Access-Control-Allow-Origin", "*"); |
144 | MHD_add_response_header (response, | 143 | MHD_add_response_header(response, |
145 | "Access-Control-Allow-Methods", | 144 | "Access-Control-Allow-Methods", |
146 | "GET, OPTIONS"); | 145 | "GET, OPTIONS"); |
147 | MHD_add_response_header (response, "Access-Control-Max-Age", "86400"); | 146 | MHD_add_response_header(response, "Access-Control-Max-Age", "86400"); |
148 | } | 147 | } |
149 | 148 | ||
150 | 149 | ||
@@ -152,27 +151,27 @@ add_cors_headers (struct MHD_Response *response) | |||
152 | * Function that assembles our response. | 151 | * Function that assembles our response. |
153 | */ | 152 | */ |
154 | static void | 153 | static void |
155 | finish_response () | 154 | finish_response() |
156 | { | 155 | { |
157 | if (NULL != response) | 156 | if (NULL != response) |
158 | MHD_destroy_response (response); | 157 | MHD_destroy_response(response); |
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 158 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
160 | "Creating hostlist response with %u bytes\n", | 159 | "Creating hostlist response with %u bytes\n", |
161 | (unsigned int) builder->size); | 160 | (unsigned int)builder->size); |
162 | response = MHD_create_response_from_buffer (builder->size, | 161 | response = MHD_create_response_from_buffer(builder->size, |
163 | builder->data, | 162 | builder->data, |
164 | MHD_RESPMEM_MUST_FREE); | 163 | MHD_RESPMEM_MUST_FREE); |
165 | add_cors_headers (response); | 164 | add_cors_headers(response); |
166 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) | 165 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) |
167 | { | 166 | { |
168 | MHD_destroy_response (response); | 167 | MHD_destroy_response(response); |
169 | response = NULL; | 168 | response = NULL; |
170 | } | 169 | } |
171 | GNUNET_STATISTICS_set (stats, | 170 | GNUNET_STATISTICS_set(stats, |
172 | gettext_noop ("bytes in hostlist"), | 171 | gettext_noop("bytes in hostlist"), |
173 | builder->size, | 172 | builder->size, |
174 | GNUNET_YES); | 173 | GNUNET_YES); |
175 | GNUNET_free (builder); | 174 | GNUNET_free(builder); |
176 | builder = NULL; | 175 | builder = NULL; |
177 | } | 176 | } |
178 | 177 | ||
@@ -186,20 +185,20 @@ finish_response () | |||
186 | * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured) | 185 | * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured) |
187 | */ | 186 | */ |
188 | static int | 187 | static int |
189 | check_has_addr (void *cls, | 188 | check_has_addr(void *cls, |
190 | const struct GNUNET_HELLO_Address *address, | 189 | const struct GNUNET_HELLO_Address *address, |
191 | struct GNUNET_TIME_Absolute expiration) | 190 | struct GNUNET_TIME_Absolute expiration) |
192 | { | 191 | { |
193 | int *arg = cls; | 192 | int *arg = cls; |
194 | 193 | ||
195 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 194 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) |
196 | { | 195 | { |
197 | GNUNET_STATISTICS_update (stats, | 196 | GNUNET_STATISTICS_update(stats, |
198 | gettext_noop ("expired addresses encountered"), | 197 | gettext_noop("expired addresses encountered"), |
199 | 1, | 198 | 1, |
200 | GNUNET_YES); | 199 | GNUNET_YES); |
201 | return GNUNET_YES; /* ignore this address */ | 200 | return GNUNET_YES; /* ignore this address */ |
202 | } | 201 | } |
203 | *arg = GNUNET_YES; | 202 | *arg = GNUNET_YES; |
204 | return GNUNET_SYSERR; | 203 | return GNUNET_SYSERR; |
205 | } | 204 | } |
@@ -215,73 +214,73 @@ check_has_addr (void *cls, | |||
215 | * @param err_msg message | 214 | * @param err_msg message |
216 | */ | 215 | */ |
217 | static void | 216 | static void |
218 | host_processor (void *cls, | 217 | host_processor(void *cls, |
219 | const struct GNUNET_PeerIdentity *peer, | 218 | const struct GNUNET_PeerIdentity *peer, |
220 | const struct GNUNET_HELLO_Message *hello, | 219 | const struct GNUNET_HELLO_Message *hello, |
221 | const char *err_msg) | 220 | const char *err_msg) |
222 | { | 221 | { |
223 | size_t old; | 222 | size_t old; |
224 | size_t s; | 223 | size_t s; |
225 | int has_addr; | 224 | int has_addr; |
226 | 225 | ||
227 | if (NULL != err_msg) | 226 | if (NULL != err_msg) |
228 | { | 227 | { |
229 | GNUNET_assert (NULL == peer); | 228 | GNUNET_assert(NULL == peer); |
230 | builder->pitr = NULL; | 229 | builder->pitr = NULL; |
231 | GNUNET_free_non_null (builder->data); | 230 | GNUNET_free_non_null(builder->data); |
232 | GNUNET_free (builder); | 231 | GNUNET_free(builder); |
233 | builder = NULL; | 232 | builder = NULL; |
234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 233 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
235 | _ ("Error in communication with PEERINFO service: %s\n"), | 234 | _("Error in communication with PEERINFO service: %s\n"), |
236 | err_msg); | 235 | err_msg); |
237 | return; | 236 | return; |
238 | } | 237 | } |
239 | if (NULL == peer) | 238 | if (NULL == peer) |
240 | { | 239 | { |
241 | builder->pitr = NULL; | 240 | builder->pitr = NULL; |
242 | finish_response (); | 241 | finish_response(); |
243 | return; | 242 | return; |
244 | } | 243 | } |
245 | if (NULL == hello) | 244 | if (NULL == hello) |
246 | return; | 245 | return; |
247 | has_addr = GNUNET_NO; | 246 | has_addr = GNUNET_NO; |
248 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr, &has_addr); | 247 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, &check_has_addr, &has_addr); |
249 | if (GNUNET_NO == has_addr) | 248 | if (GNUNET_NO == has_addr) |
250 | { | 249 | { |
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
252 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", | 251 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", |
253 | GNUNET_i2s (peer)); | 252 | GNUNET_i2s(peer)); |
254 | GNUNET_STATISTICS_update (stats, | 253 | GNUNET_STATISTICS_update(stats, |
255 | gettext_noop ( | 254 | gettext_noop( |
256 | "HELLOs without addresses encountered (ignored)"), | 255 | "HELLOs without addresses encountered (ignored)"), |
257 | 1, | 256 | 1, |
258 | GNUNET_NO); | 257 | GNUNET_NO); |
259 | return; | 258 | return; |
260 | } | 259 | } |
261 | old = builder->size; | 260 | old = builder->size; |
262 | s = GNUNET_HELLO_size (hello); | 261 | s = GNUNET_HELLO_size(hello); |
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 262 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
264 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", | 263 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", |
265 | (unsigned int) s, | 264 | (unsigned int)s, |
266 | "HELLO", | 265 | "HELLO", |
267 | GNUNET_i2s (peer)); | 266 | GNUNET_i2s(peer)); |
268 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || | 267 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || |
269 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) | 268 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) |
270 | { | 269 | { |
271 | /* too large, skip! */ | 270 | /* too large, skip! */ |
272 | GNUNET_STATISTICS_update (stats, | 271 | GNUNET_STATISTICS_update(stats, |
273 | gettext_noop ( | 272 | gettext_noop( |
274 | "bytes not included in hostlist (size limit)"), | 273 | "bytes not included in hostlist (size limit)"), |
275 | s, | 274 | s, |
276 | GNUNET_NO); | 275 | GNUNET_NO); |
277 | return; | 276 | return; |
278 | } | 277 | } |
279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 278 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
280 | "Adding peer `%s' to hostlist (%u bytes)\n", | 279 | "Adding peer `%s' to hostlist (%u bytes)\n", |
281 | GNUNET_i2s (peer), | 280 | GNUNET_i2s(peer), |
282 | (unsigned int) s); | 281 | (unsigned int)s); |
283 | GNUNET_array_grow (builder->data, builder->size, old + s); | 282 | GNUNET_array_grow(builder->data, builder->size, old + s); |
284 | GNUNET_memcpy (&builder->data[old], hello, s); | 283 | GNUNET_memcpy(&builder->data[old], hello, s); |
285 | } | 284 | } |
286 | 285 | ||
287 | 286 | ||
@@ -295,17 +294,17 @@ host_processor (void *cls, | |||
295 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) | 294 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) |
296 | */ | 295 | */ |
297 | static int | 296 | static int |
298 | accept_policy_callback (void *cls, | 297 | accept_policy_callback(void *cls, |
299 | const struct sockaddr *addr, | 298 | const struct sockaddr *addr, |
300 | socklen_t addrlen) | 299 | socklen_t addrlen) |
301 | { | 300 | { |
302 | if (NULL == response) | 301 | if (NULL == response) |
303 | { | 302 | { |
304 | GNUNET_log ( | 303 | GNUNET_log( |
305 | GNUNET_ERROR_TYPE_DEBUG, | 304 | GNUNET_ERROR_TYPE_DEBUG, |
306 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); | 305 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); |
307 | return MHD_NO; | 306 | return MHD_NO; |
308 | } | 307 | } |
309 | return MHD_YES; /* accept all */ | 308 | return MHD_YES; /* accept all */ |
310 | } | 309 | } |
311 | 310 | ||
@@ -346,80 +345,80 @@ accept_policy_callback (void *cls, | |||
346 | * error while handling the request | 345 | * error while handling the request |
347 | */ | 346 | */ |
348 | static int | 347 | static int |
349 | access_handler_callback (void *cls, | 348 | access_handler_callback(void *cls, |
350 | struct MHD_Connection *connection, | 349 | struct MHD_Connection *connection, |
351 | const char *url, | 350 | const char *url, |
352 | const char *method, | 351 | const char *method, |
353 | const char *version, | 352 | const char *version, |
354 | const char *upload_data, | 353 | const char *upload_data, |
355 | size_t *upload_data_size, | 354 | size_t *upload_data_size, |
356 | void **con_cls) | 355 | void **con_cls) |
357 | { | 356 | { |
358 | static int dummy; | 357 | static int dummy; |
359 | 358 | ||
360 | /* CORS pre-flight request */ | 359 | /* CORS pre-flight request */ |
361 | if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method)) | 360 | if (0 == strcmp(MHD_HTTP_METHOD_OPTIONS, method)) |
362 | { | 361 | { |
363 | struct MHD_Response *options_response; | 362 | struct MHD_Response *options_response; |
364 | int rc; | 363 | int rc; |
365 | 364 | ||
366 | options_response = | 365 | options_response = |
367 | MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT); | 366 | MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT); |
368 | add_cors_headers (options_response); | 367 | add_cors_headers(options_response); |
369 | rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response); | 368 | rc = MHD_queue_response(connection, MHD_HTTP_OK, options_response); |
370 | MHD_destroy_response (options_response); | 369 | MHD_destroy_response(options_response); |
371 | return rc; | 370 | return rc; |
372 | } | 371 | } |
373 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) | 372 | if (0 != strcmp(method, MHD_HTTP_METHOD_GET)) |
374 | { | 373 | { |
375 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 374 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
376 | _ ("Refusing `%s' request to hostlist server\n"), | 375 | _("Refusing `%s' request to hostlist server\n"), |
377 | method); | 376 | method); |
378 | GNUNET_STATISTICS_update (stats, | 377 | GNUNET_STATISTICS_update(stats, |
379 | gettext_noop ( | 378 | gettext_noop( |
380 | "hostlist requests refused (not HTTP GET)"), | 379 | "hostlist requests refused (not HTTP GET)"), |
381 | 1, | 380 | 1, |
382 | GNUNET_YES); | 381 | GNUNET_YES); |
383 | return MHD_NO; | 382 | return MHD_NO; |
384 | } | 383 | } |
385 | if (NULL == *con_cls) | 384 | if (NULL == *con_cls) |
386 | { | 385 | { |
387 | (*con_cls) = &dummy; | 386 | (*con_cls) = &dummy; |
388 | return MHD_YES; | 387 | return MHD_YES; |
389 | } | 388 | } |
390 | if (0 != *upload_data_size) | 389 | if (0 != *upload_data_size) |
391 | { | 390 | { |
392 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 391 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
393 | _ ("Refusing `%s' request with %llu bytes of upload data\n"), | 392 | _("Refusing `%s' request with %llu bytes of upload data\n"), |
394 | method, | 393 | method, |
395 | (unsigned long long) *upload_data_size); | 394 | (unsigned long long)*upload_data_size); |
396 | GNUNET_STATISTICS_update (stats, | 395 | GNUNET_STATISTICS_update(stats, |
397 | gettext_noop ( | 396 | gettext_noop( |
398 | "hostlist requests refused (upload data)"), | 397 | "hostlist requests refused (upload data)"), |
399 | 1, | 398 | 1, |
400 | GNUNET_YES); | 399 | GNUNET_YES); |
401 | return MHD_NO; /* do not support upload data */ | 400 | return MHD_NO; /* do not support upload data */ |
402 | } | 401 | } |
403 | if (NULL == response) | 402 | if (NULL == response) |
404 | { | 403 | { |
405 | GNUNET_log ( | 404 | GNUNET_log( |
406 | GNUNET_ERROR_TYPE_WARNING, | 405 | GNUNET_ERROR_TYPE_WARNING, |
407 | _ ( | 406 | _( |
408 | "Could not handle hostlist request since I do not have a response yet\n")); | 407 | "Could not handle hostlist request since I do not have a response yet\n")); |
409 | GNUNET_STATISTICS_update (stats, | 408 | GNUNET_STATISTICS_update(stats, |
410 | gettext_noop ( | 409 | gettext_noop( |
411 | "hostlist requests refused (not ready)"), | 410 | "hostlist requests refused (not ready)"), |
412 | 1, | 411 | 1, |
413 | GNUNET_YES); | 412 | GNUNET_YES); |
414 | return MHD_NO; /* internal error, no response yet */ | 413 | return MHD_NO; /* internal error, no response yet */ |
415 | } | 414 | } |
416 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 415 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
417 | _ ("Received request for our hostlist\n")); | 416 | _("Received request for our hostlist\n")); |
418 | GNUNET_STATISTICS_update (stats, | 417 | GNUNET_STATISTICS_update(stats, |
419 | gettext_noop ("hostlist requests processed"), | 418 | gettext_noop("hostlist requests processed"), |
420 | 1, | 419 | 1, |
421 | GNUNET_YES); | 420 | GNUNET_YES); |
422 | return MHD_queue_response (connection, MHD_HTTP_OK, response); | 421 | return MHD_queue_response(connection, MHD_HTTP_OK, response); |
423 | } | 422 | } |
424 | 423 | ||
425 | 424 | ||
@@ -433,33 +432,33 @@ access_handler_callback (void *cls, | |||
433 | * @return number of bytes copied to @a buf | 432 | * @return number of bytes copied to @a buf |
434 | */ | 433 | */ |
435 | static void | 434 | static void |
436 | adv_transmit (struct GNUNET_MQ_Handle *mq) | 435 | adv_transmit(struct GNUNET_MQ_Handle *mq) |
437 | { | 436 | { |
438 | static uint64_t hostlist_adv_count; | 437 | static uint64_t hostlist_adv_count; |
439 | size_t uri_size; /* Including \0 termination! */ | 438 | size_t uri_size; /* Including \0 termination! */ |
440 | struct GNUNET_MessageHeader *header; | 439 | struct GNUNET_MessageHeader *header; |
441 | struct GNUNET_MQ_Envelope *env; | 440 | struct GNUNET_MQ_Envelope *env; |
442 | 441 | ||
443 | uri_size = strlen (hostlist_uri) + 1; | 442 | uri_size = strlen(hostlist_uri) + 1; |
444 | env = GNUNET_MQ_msg_extra (header, | 443 | env = GNUNET_MQ_msg_extra(header, |
445 | uri_size, | 444 | uri_size, |
446 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 445 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); |
447 | GNUNET_memcpy (&header[1], hostlist_uri, uri_size); | 446 | GNUNET_memcpy(&header[1], hostlist_uri, uri_size); |
448 | GNUNET_MQ_env_set_options (env, | 447 | GNUNET_MQ_env_set_options(env, |
449 | GNUNET_MQ_PREF_CORK_ALLOWED | | 448 | GNUNET_MQ_PREF_CORK_ALLOWED | |
450 | GNUNET_MQ_PREF_UNRELIABLE); | 449 | GNUNET_MQ_PREF_UNRELIABLE); |
451 | GNUNET_MQ_send (mq, env); | 450 | GNUNET_MQ_send(mq, env); |
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
453 | "Sent advertisement message: Copied %u bytes into buffer!\n", | 452 | "Sent advertisement message: Copied %u bytes into buffer!\n", |
454 | (unsigned int) uri_size); | 453 | (unsigned int)uri_size); |
455 | hostlist_adv_count++; | 454 | hostlist_adv_count++; |
456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 455 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
457 | " # Sent advertisement message: %llu\n", | 456 | " # Sent advertisement message: %llu\n", |
458 | (unsigned long long) hostlist_adv_count); | 457 | (unsigned long long)hostlist_adv_count); |
459 | GNUNET_STATISTICS_update (stats, | 458 | GNUNET_STATISTICS_update(stats, |
460 | gettext_noop ("# hostlist advertisements send"), | 459 | gettext_noop("# hostlist advertisements send"), |
461 | 1, | 460 | 1, |
462 | GNUNET_NO); | 461 | GNUNET_NO); |
463 | } | 462 | } |
464 | 463 | ||
465 | 464 | ||
@@ -472,34 +471,34 @@ adv_transmit (struct GNUNET_MQ_Handle *mq) | |||
472 | * @return NULL (must!) | 471 | * @return NULL (must!) |
473 | */ | 472 | */ |
474 | static void * | 473 | static void * |
475 | connect_handler (void *cls, | 474 | connect_handler(void *cls, |
476 | const struct GNUNET_PeerIdentity *peer, | 475 | const struct GNUNET_PeerIdentity *peer, |
477 | struct GNUNET_MQ_Handle *mq) | 476 | struct GNUNET_MQ_Handle *mq) |
478 | { | 477 | { |
479 | size_t size; | 478 | size_t size; |
480 | 479 | ||
481 | if (! advertising) | 480 | if (!advertising) |
482 | return NULL; | 481 | return NULL; |
483 | if (NULL == hostlist_uri) | 482 | if (NULL == hostlist_uri) |
484 | return NULL; | 483 | return NULL; |
485 | size = strlen (hostlist_uri) + 1; | 484 | size = strlen(hostlist_uri) + 1; |
486 | if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE) | 485 | if (size + sizeof(struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE) |
487 | { | 486 | { |
488 | GNUNET_break (0); | 487 | GNUNET_break(0); |
489 | return NULL; | 488 | return NULL; |
490 | } | 489 | } |
491 | size += sizeof (struct GNUNET_MessageHeader); | 490 | size += sizeof(struct GNUNET_MessageHeader); |
492 | if (NULL == core) | 491 | if (NULL == core) |
493 | { | 492 | { |
494 | GNUNET_break (0); | 493 | GNUNET_break(0); |
495 | return NULL; | 494 | return NULL; |
496 | } | 495 | } |
497 | GNUNET_log ( | 496 | GNUNET_log( |
498 | GNUNET_ERROR_TYPE_DEBUG, | 497 | GNUNET_ERROR_TYPE_DEBUG, |
499 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", | 498 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", |
500 | (unsigned int) size, | 499 | (unsigned int)size, |
501 | GNUNET_i2s (peer)); | 500 | GNUNET_i2s(peer)); |
502 | adv_transmit (mq); | 501 | adv_transmit(mq); |
503 | return NULL; | 502 | return NULL; |
504 | } | 503 | } |
505 | 504 | ||
@@ -514,36 +513,36 @@ connect_handler (void *cls, | |||
514 | * @param err_msg NULL if successful, otherwise contains error message | 513 | * @param err_msg NULL if successful, otherwise contains error message |
515 | */ | 514 | */ |
516 | static void | 515 | static void |
517 | process_notify (void *cls, | 516 | process_notify(void *cls, |
518 | const struct GNUNET_PeerIdentity *peer, | 517 | const struct GNUNET_PeerIdentity *peer, |
519 | const struct GNUNET_HELLO_Message *hello, | 518 | const struct GNUNET_HELLO_Message *hello, |
520 | const char *err_msg) | 519 | const char *err_msg) |
521 | { | 520 | { |
522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 521 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
523 | "Peerinfo is notifying us to rebuild our hostlist\n"); | 522 | "Peerinfo is notifying us to rebuild our hostlist\n"); |
524 | if (NULL != err_msg) | 523 | if (NULL != err_msg) |
525 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 524 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
526 | _ ("Error in communication with PEERINFO service: %s\n"), | 525 | _("Error in communication with PEERINFO service: %s\n"), |
527 | err_msg); | 526 | err_msg); |
528 | if (NULL != builder) | 527 | if (NULL != builder) |
529 | { | ||
530 | /* restart re-build already in progress ... */ | ||
531 | if (NULL != builder->pitr) | ||
532 | { | 528 | { |
533 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); | 529 | /* restart re-build already in progress ... */ |
534 | builder->pitr = NULL; | 530 | if (NULL != builder->pitr) |
531 | { | ||
532 | GNUNET_PEERINFO_iterate_cancel(builder->pitr); | ||
533 | builder->pitr = NULL; | ||
534 | } | ||
535 | GNUNET_free_non_null(builder->data); | ||
536 | builder->size = 0; | ||
537 | builder->data = NULL; | ||
535 | } | 538 | } |
536 | GNUNET_free_non_null (builder->data); | ||
537 | builder->size = 0; | ||
538 | builder->data = NULL; | ||
539 | } | ||
540 | else | 539 | else |
541 | { | 540 | { |
542 | builder = GNUNET_new (struct HostSet); | 541 | builder = GNUNET_new(struct HostSet); |
543 | } | 542 | } |
544 | GNUNET_assert (NULL != peerinfo); | 543 | GNUNET_assert(NULL != peerinfo); |
545 | builder->pitr = | 544 | builder->pitr = |
546 | GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, &host_processor, NULL); | 545 | GNUNET_PEERINFO_iterate(peerinfo, GNUNET_NO, NULL, &host_processor, NULL); |
547 | } | 546 | } |
548 | 547 | ||
549 | 548 | ||
@@ -552,7 +551,7 @@ process_notify (void *cls, | |||
552 | * starts the task waiting for them. | 551 | * starts the task waiting for them. |
553 | */ | 552 | */ |
554 | static struct GNUNET_SCHEDULER_Task * | 553 | static struct GNUNET_SCHEDULER_Task * |
555 | prepare_daemon (struct MHD_Daemon *daemon_handle); | 554 | prepare_daemon(struct MHD_Daemon *daemon_handle); |
556 | 555 | ||
557 | 556 | ||
558 | /** | 557 | /** |
@@ -562,7 +561,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle); | |||
562 | * @param cls the `struct MHD_Daemon` of the HTTP server to run | 561 | * @param cls the `struct MHD_Daemon` of the HTTP server to run |
563 | */ | 562 | */ |
564 | static void | 563 | static void |
565 | run_daemon (void *cls) | 564 | run_daemon(void *cls) |
566 | { | 565 | { |
567 | struct MHD_Daemon *daemon_handle = cls; | 566 | struct MHD_Daemon *daemon_handle = cls; |
568 | 567 | ||
@@ -570,11 +569,11 @@ run_daemon (void *cls) | |||
570 | hostlist_task_v4 = NULL; | 569 | hostlist_task_v4 = NULL; |
571 | else | 570 | else |
572 | hostlist_task_v6 = NULL; | 571 | hostlist_task_v6 = NULL; |
573 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); | 572 | GNUNET_assert(MHD_YES == MHD_run(daemon_handle)); |
574 | if (daemon_handle == daemon_handle_v4) | 573 | if (daemon_handle == daemon_handle_v4) |
575 | hostlist_task_v4 = prepare_daemon (daemon_handle); | 574 | hostlist_task_v4 = prepare_daemon(daemon_handle); |
576 | else | 575 | else |
577 | hostlist_task_v6 = prepare_daemon (daemon_handle); | 576 | hostlist_task_v6 = prepare_daemon(daemon_handle); |
578 | } | 577 | } |
579 | 578 | ||
580 | 579 | ||
@@ -585,7 +584,7 @@ run_daemon (void *cls) | |||
585 | * @param daemon_handle HTTP server to prepare to run | 584 | * @param daemon_handle HTTP server to prepare to run |
586 | */ | 585 | */ |
587 | static struct GNUNET_SCHEDULER_Task * | 586 | static struct GNUNET_SCHEDULER_Task * |
588 | prepare_daemon (struct MHD_Daemon *daemon_handle) | 587 | prepare_daemon(struct MHD_Daemon *daemon_handle) |
589 | { | 588 | { |
590 | struct GNUNET_SCHEDULER_Task *ret; | 589 | struct GNUNET_SCHEDULER_Task *ret; |
591 | fd_set rs; | 590 | fd_set rs; |
@@ -598,28 +597,28 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
598 | int haveto; | 597 | int haveto; |
599 | struct GNUNET_TIME_Relative tv; | 598 | struct GNUNET_TIME_Relative tv; |
600 | 599 | ||
601 | FD_ZERO (&rs); | 600 | FD_ZERO(&rs); |
602 | FD_ZERO (&ws); | 601 | FD_ZERO(&ws); |
603 | FD_ZERO (&es); | 602 | FD_ZERO(&es); |
604 | wrs = GNUNET_NETWORK_fdset_create (); | 603 | wrs = GNUNET_NETWORK_fdset_create(); |
605 | wws = GNUNET_NETWORK_fdset_create (); | 604 | wws = GNUNET_NETWORK_fdset_create(); |
606 | max = -1; | 605 | max = -1; |
607 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); | 606 | GNUNET_assert(MHD_YES == MHD_get_fdset(daemon_handle, &rs, &ws, &es, &max)); |
608 | haveto = MHD_get_timeout (daemon_handle, &timeout); | 607 | haveto = MHD_get_timeout(daemon_handle, &timeout); |
609 | if (haveto == MHD_YES) | 608 | if (haveto == MHD_YES) |
610 | tv.rel_value_us = (uint64_t) timeout * 1000LL; | 609 | tv.rel_value_us = (uint64_t)timeout * 1000LL; |
611 | else | 610 | else |
612 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | 611 | tv = GNUNET_TIME_UNIT_FOREVER_REL; |
613 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | 612 | GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); |
614 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 613 | GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); |
615 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 614 | ret = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, |
616 | tv, | 615 | tv, |
617 | wrs, | 616 | wrs, |
618 | wws, | 617 | wws, |
619 | &run_daemon, | 618 | &run_daemon, |
620 | daemon_handle); | 619 | daemon_handle); |
621 | GNUNET_NETWORK_fdset_destroy (wrs); | 620 | GNUNET_NETWORK_fdset_destroy(wrs); |
622 | GNUNET_NETWORK_fdset_destroy (wws); | 621 | GNUNET_NETWORK_fdset_destroy(wws); |
623 | return ret; | 622 | return ret; |
624 | } | 623 | } |
625 | 624 | ||
@@ -635,11 +634,11 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
635 | * @return #GNUNET_OK on success | 634 | * @return #GNUNET_OK on success |
636 | */ | 635 | */ |
637 | int | 636 | int |
638 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | 637 | GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, |
639 | struct GNUNET_STATISTICS_Handle *st, | 638 | struct GNUNET_STATISTICS_Handle *st, |
640 | struct GNUNET_CORE_Handle *co, | 639 | struct GNUNET_CORE_Handle *co, |
641 | GNUNET_CORE_ConnectEventHandler *server_ch, | 640 | GNUNET_CORE_ConnectEventHandler *server_ch, |
642 | int advertise) | 641 | int advertise) |
643 | { | 642 | { |
644 | unsigned long long port; | 643 | unsigned long long port; |
645 | char *hostname; | 644 | char *hostname; |
@@ -654,189 +653,189 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
654 | const struct sockaddr *sa6; | 653 | const struct sockaddr *sa6; |
655 | 654 | ||
656 | advertising = advertise; | 655 | advertising = advertise; |
657 | if (! advertising) | 656 | if (!advertising) |
658 | { | 657 | { |
659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 658 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
660 | "Advertising not enabled on this hostlist server\n"); | 659 | "Advertising not enabled on this hostlist server\n"); |
661 | } | 660 | } |
662 | else | 661 | else |
663 | { | 662 | { |
664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 663 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
665 | "Advertising enabled on this hostlist server\n"); | 664 | "Advertising enabled on this hostlist server\n"); |
666 | } | 665 | } |
667 | cfg = c; | 666 | cfg = c; |
668 | stats = st; | 667 | stats = st; |
669 | peerinfo = GNUNET_PEERINFO_connect (cfg); | 668 | peerinfo = GNUNET_PEERINFO_connect(cfg); |
670 | if (NULL == peerinfo) | 669 | if (NULL == peerinfo) |
671 | { | 670 | { |
672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 671 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
673 | _ ("Could not access PEERINFO service. Exiting.\n")); | 672 | _("Could not access PEERINFO service. Exiting.\n")); |
674 | return GNUNET_SYSERR; | 673 | return GNUNET_SYSERR; |
675 | } | 674 | } |
676 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | 675 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, |
677 | "HOSTLIST", | 676 | "HOSTLIST", |
678 | "HTTPPORT", | 677 | "HTTPPORT", |
679 | &port)) | 678 | &port)) |
680 | return GNUNET_SYSERR; | 679 | return GNUNET_SYSERR; |
681 | if ((0 == port) || (port > UINT16_MAX)) | 680 | if ((0 == port) || (port > UINT16_MAX)) |
682 | { | 681 | { |
683 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 682 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
684 | _ ("Invalid port number %llu. Exiting.\n"), | 683 | _("Invalid port number %llu. Exiting.\n"), |
685 | port); | 684 | port); |
686 | return GNUNET_SYSERR; | 685 | return GNUNET_SYSERR; |
687 | } | 686 | } |
688 | 687 | ||
689 | if (GNUNET_SYSERR == | 688 | if (GNUNET_SYSERR == |
690 | GNUNET_CONFIGURATION_get_value_string (cfg, | 689 | GNUNET_CONFIGURATION_get_value_string(cfg, |
691 | "HOSTLIST", | 690 | "HOSTLIST", |
692 | "EXTERNAL_DNS_NAME", | 691 | "EXTERNAL_DNS_NAME", |
693 | &hostname)) | 692 | &hostname)) |
694 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 693 | hostname = GNUNET_RESOLVER_local_fqdn_get(); |
695 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 694 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
696 | _ ("Hostlist service starts on %s:%llu\n"), | 695 | _("Hostlist service starts on %s:%llu\n"), |
697 | hostname, | 696 | hostname, |
698 | port); | 697 | port); |
699 | if (NULL != hostname) | 698 | if (NULL != hostname) |
700 | { | ||
701 | size = strlen (hostname); | ||
702 | if (size + 15 > MAX_URL_LEN) | ||
703 | { | 699 | { |
704 | GNUNET_break (0); | 700 | size = strlen(hostname); |
701 | if (size + 15 > MAX_URL_LEN) | ||
702 | { | ||
703 | GNUNET_break(0); | ||
704 | } | ||
705 | else | ||
706 | { | ||
707 | GNUNET_asprintf(&hostlist_uri, | ||
708 | "http://%s:%u/", | ||
709 | hostname, | ||
710 | (unsigned int)port); | ||
711 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
712 | _("Address to obtain hostlist: `%s'\n"), | ||
713 | hostlist_uri); | ||
714 | } | ||
715 | GNUNET_free(hostname); | ||
705 | } | 716 | } |
706 | else | ||
707 | { | ||
708 | GNUNET_asprintf (&hostlist_uri, | ||
709 | "http://%s:%u/", | ||
710 | hostname, | ||
711 | (unsigned int) port); | ||
712 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
713 | _ ("Address to obtain hostlist: `%s'\n"), | ||
714 | hostlist_uri); | ||
715 | } | ||
716 | GNUNET_free (hostname); | ||
717 | } | ||
718 | 717 | ||
719 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4")) | 718 | if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV4")) |
720 | { | ||
721 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | ||
722 | "HOSTLIST", | ||
723 | "BINDTOIP", | ||
724 | &ipv4)) | ||
725 | { | 719 | { |
726 | GNUNET_log ( | 720 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
727 | GNUNET_ERROR_TYPE_WARNING, | 721 | "HOSTLIST", |
728 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); | 722 | "BINDTOIP", |
723 | &ipv4)) | ||
724 | { | ||
725 | GNUNET_log( | ||
726 | GNUNET_ERROR_TYPE_WARNING, | ||
727 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); | ||
728 | } | ||
729 | } | 729 | } |
730 | } | ||
731 | else | 730 | else |
732 | ipv4 = NULL; | 731 | ipv4 = NULL; |
733 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6")) | 732 | if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV6")) |
734 | { | 733 | { |
735 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 734 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
736 | "HOSTLIST", | 735 | "HOSTLIST", |
737 | "BINDTOIP", | 736 | "BINDTOIP", |
738 | &ipv6)) | 737 | &ipv6)) |
739 | { | 738 | { |
740 | GNUNET_log ( | 739 | GNUNET_log( |
741 | GNUNET_ERROR_TYPE_WARNING, | 740 | GNUNET_ERROR_TYPE_WARNING, |
742 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); | 741 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); |
742 | } | ||
743 | } | 743 | } |
744 | } | ||
745 | else | 744 | else |
746 | ipv6 = NULL; | 745 | ipv6 = NULL; |
747 | sa4 = NULL; | 746 | sa4 = NULL; |
748 | if (NULL != ipv4) | 747 | if (NULL != ipv4) |
749 | { | ||
750 | if (1 == inet_pton (AF_INET, ipv4, &i4)) | ||
751 | { | 748 | { |
752 | memset (&v4, 0, sizeof (v4)); | 749 | if (1 == inet_pton(AF_INET, ipv4, &i4)) |
753 | v4.sin_family = AF_INET; | 750 | { |
754 | v4.sin_addr = i4; | 751 | memset(&v4, 0, sizeof(v4)); |
755 | v4.sin_port = htons (port); | 752 | v4.sin_family = AF_INET; |
753 | v4.sin_addr = i4; | ||
754 | v4.sin_port = htons(port); | ||
756 | #if HAVE_SOCKADDR_IN_SIN_LEN | 755 | #if HAVE_SOCKADDR_IN_SIN_LEN |
757 | v4.sin_len = sizeof (v4); | 756 | v4.sin_len = sizeof(v4); |
758 | #endif | 757 | #endif |
759 | sa4 = (const struct sockaddr *) &v4; | 758 | sa4 = (const struct sockaddr *)&v4; |
760 | } | 759 | } |
761 | else | 760 | else |
762 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 761 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
763 | _ ( | 762 | _( |
764 | "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), | 763 | "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), |
765 | ipv4); | 764 | ipv4); |
766 | GNUNET_free (ipv4); | 765 | GNUNET_free(ipv4); |
767 | } | 766 | } |
768 | sa6 = NULL; | 767 | sa6 = NULL; |
769 | if (NULL != ipv6) | 768 | if (NULL != ipv6) |
770 | { | ||
771 | if (1 == inet_pton (AF_INET6, ipv6, &i6)) | ||
772 | { | 769 | { |
773 | memset (&v6, 0, sizeof (v6)); | 770 | if (1 == inet_pton(AF_INET6, ipv6, &i6)) |
774 | v6.sin6_family = AF_INET6; | 771 | { |
775 | v6.sin6_addr = i6; | 772 | memset(&v6, 0, sizeof(v6)); |
776 | v6.sin6_port = htons (port); | 773 | v6.sin6_family = AF_INET6; |
774 | v6.sin6_addr = i6; | ||
775 | v6.sin6_port = htons(port); | ||
777 | #if HAVE_SOCKADDR_IN_SIN_LEN | 776 | #if HAVE_SOCKADDR_IN_SIN_LEN |
778 | v6.sin6_len = sizeof (v6); | 777 | v6.sin6_len = sizeof(v6); |
779 | #endif | 778 | #endif |
780 | sa6 = (const struct sockaddr *) &v6; | 779 | sa6 = (const struct sockaddr *)&v6; |
781 | } | 780 | } |
782 | else | 781 | else |
783 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 782 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
784 | _ ( | 783 | _( |
785 | "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), | 784 | "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), |
786 | ipv6); | 785 | ipv6); |
787 | GNUNET_free (ipv6); | 786 | GNUNET_free(ipv6); |
788 | } | 787 | } |
789 | 788 | ||
790 | daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG, | 789 | daemon_handle_v6 = MHD_start_daemon(MHD_USE_IPv6 | MHD_USE_DEBUG, |
791 | (uint16_t) port, | 790 | (uint16_t)port, |
792 | &accept_policy_callback, | 791 | &accept_policy_callback, |
793 | NULL, | 792 | NULL, |
794 | &access_handler_callback, | 793 | &access_handler_callback, |
795 | NULL, | 794 | NULL, |
796 | MHD_OPTION_CONNECTION_LIMIT, | 795 | MHD_OPTION_CONNECTION_LIMIT, |
797 | (unsigned int) 128, | 796 | (unsigned int)128, |
798 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 797 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
799 | (unsigned int) 32, | 798 | (unsigned int)32, |
800 | MHD_OPTION_CONNECTION_TIMEOUT, | 799 | MHD_OPTION_CONNECTION_TIMEOUT, |
801 | (unsigned int) 16, | 800 | (unsigned int)16, |
802 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 801 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
803 | (size_t) (16 * 1024), | 802 | (size_t)(16 * 1024), |
804 | MHD_OPTION_SOCK_ADDR, | 803 | MHD_OPTION_SOCK_ADDR, |
805 | sa6, | 804 | sa6, |
806 | MHD_OPTION_END); | 805 | MHD_OPTION_END); |
807 | daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG, | 806 | daemon_handle_v4 = MHD_start_daemon(MHD_NO_FLAG | MHD_USE_DEBUG, |
808 | (uint16_t) port, | 807 | (uint16_t)port, |
809 | &accept_policy_callback, | 808 | &accept_policy_callback, |
810 | NULL, | 809 | NULL, |
811 | &access_handler_callback, | 810 | &access_handler_callback, |
812 | NULL, | 811 | NULL, |
813 | MHD_OPTION_CONNECTION_LIMIT, | 812 | MHD_OPTION_CONNECTION_LIMIT, |
814 | (unsigned int) 128, | 813 | (unsigned int)128, |
815 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 814 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
816 | (unsigned int) 32, | 815 | (unsigned int)32, |
817 | MHD_OPTION_CONNECTION_TIMEOUT, | 816 | MHD_OPTION_CONNECTION_TIMEOUT, |
818 | (unsigned int) 16, | 817 | (unsigned int)16, |
819 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 818 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
820 | (size_t) (16 * 1024), | 819 | (size_t)(16 * 1024), |
821 | MHD_OPTION_SOCK_ADDR, | 820 | MHD_OPTION_SOCK_ADDR, |
822 | sa4, | 821 | sa4, |
823 | MHD_OPTION_END); | 822 | MHD_OPTION_END); |
824 | 823 | ||
825 | if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) | 824 | if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) |
826 | { | 825 | { |
827 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 826 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
828 | _ ("Could not start hostlist HTTP server on port %u\n"), | 827 | _("Could not start hostlist HTTP server on port %u\n"), |
829 | (unsigned short) port); | 828 | (unsigned short)port); |
830 | return GNUNET_SYSERR; | 829 | return GNUNET_SYSERR; |
831 | } | 830 | } |
832 | 831 | ||
833 | core = co; | 832 | core = co; |
834 | *server_ch = &connect_handler; | 833 | *server_ch = &connect_handler; |
835 | if (NULL != daemon_handle_v4) | 834 | if (NULL != daemon_handle_v4) |
836 | hostlist_task_v4 = prepare_daemon (daemon_handle_v4); | 835 | hostlist_task_v4 = prepare_daemon(daemon_handle_v4); |
837 | if (NULL != daemon_handle_v6) | 836 | if (NULL != daemon_handle_v6) |
838 | hostlist_task_v6 = prepare_daemon (daemon_handle_v6); | 837 | hostlist_task_v6 = prepare_daemon(daemon_handle_v6); |
839 | notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL); | 838 | notify = GNUNET_PEERINFO_notify(cfg, GNUNET_NO, &process_notify, NULL); |
840 | return GNUNET_OK; | 839 | return GNUNET_OK; |
841 | } | 840 | } |
842 | 841 | ||
@@ -845,55 +844,55 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
845 | * Stop server offering our hostlist. | 844 | * Stop server offering our hostlist. |
846 | */ | 845 | */ |
847 | void | 846 | void |
848 | GNUNET_HOSTLIST_server_stop () | 847 | GNUNET_HOSTLIST_server_stop() |
849 | { | 848 | { |
850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); | 849 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); |
851 | if (NULL != hostlist_task_v6) | 850 | if (NULL != hostlist_task_v6) |
852 | { | 851 | { |
853 | GNUNET_SCHEDULER_cancel (hostlist_task_v6); | 852 | GNUNET_SCHEDULER_cancel(hostlist_task_v6); |
854 | hostlist_task_v6 = NULL; | 853 | hostlist_task_v6 = NULL; |
855 | } | 854 | } |
856 | if (NULL != hostlist_task_v4) | 855 | if (NULL != hostlist_task_v4) |
857 | { | 856 | { |
858 | GNUNET_SCHEDULER_cancel (hostlist_task_v4); | 857 | GNUNET_SCHEDULER_cancel(hostlist_task_v4); |
859 | hostlist_task_v4 = NULL; | 858 | hostlist_task_v4 = NULL; |
860 | } | 859 | } |
861 | if (NULL != daemon_handle_v4) | 860 | if (NULL != daemon_handle_v4) |
862 | { | 861 | { |
863 | MHD_stop_daemon (daemon_handle_v4); | 862 | MHD_stop_daemon(daemon_handle_v4); |
864 | daemon_handle_v4 = NULL; | 863 | daemon_handle_v4 = NULL; |
865 | } | 864 | } |
866 | if (NULL != daemon_handle_v6) | 865 | if (NULL != daemon_handle_v6) |
867 | { | 866 | { |
868 | MHD_stop_daemon (daemon_handle_v6); | 867 | MHD_stop_daemon(daemon_handle_v6); |
869 | daemon_handle_v6 = NULL; | 868 | daemon_handle_v6 = NULL; |
870 | } | 869 | } |
871 | if (NULL != response) | 870 | if (NULL != response) |
872 | { | 871 | { |
873 | MHD_destroy_response (response); | 872 | MHD_destroy_response(response); |
874 | response = NULL; | 873 | response = NULL; |
875 | } | 874 | } |
876 | if (NULL != notify) | 875 | if (NULL != notify) |
877 | { | 876 | { |
878 | GNUNET_PEERINFO_notify_cancel (notify); | 877 | GNUNET_PEERINFO_notify_cancel(notify); |
879 | notify = NULL; | 878 | notify = NULL; |
880 | } | 879 | } |
881 | if (NULL != builder) | 880 | if (NULL != builder) |
882 | { | ||
883 | if (NULL != builder->pitr) | ||
884 | { | 881 | { |
885 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); | 882 | if (NULL != builder->pitr) |
886 | builder->pitr = NULL; | 883 | { |
884 | GNUNET_PEERINFO_iterate_cancel(builder->pitr); | ||
885 | builder->pitr = NULL; | ||
886 | } | ||
887 | GNUNET_free_non_null(builder->data); | ||
888 | GNUNET_free(builder); | ||
889 | builder = NULL; | ||
887 | } | 890 | } |
888 | GNUNET_free_non_null (builder->data); | ||
889 | GNUNET_free (builder); | ||
890 | builder = NULL; | ||
891 | } | ||
892 | if (NULL != peerinfo) | 891 | if (NULL != peerinfo) |
893 | { | 892 | { |
894 | GNUNET_PEERINFO_disconnect (peerinfo); | 893 | GNUNET_PEERINFO_disconnect(peerinfo); |
895 | peerinfo = NULL; | 894 | peerinfo = NULL; |
896 | } | 895 | } |
897 | cfg = NULL; | 896 | cfg = NULL; |
898 | stats = NULL; | 897 | stats = NULL; |
899 | core = NULL; | 898 | core = NULL; |
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.h b/src/hostlist/gnunet-daemon-hostlist_server.h index bb0efef41..407675b41 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.h +++ b/src/hostlist/gnunet-daemon-hostlist_server.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file hostlist/gnunet-daemon-hostlist_server.h | 22 | * @file hostlist/gnunet-daemon-hostlist_server.h |
@@ -43,18 +43,18 @@ | |||
43 | * @return #GNUNET_OK on success | 43 | * @return #GNUNET_OK on success |
44 | */ | 44 | */ |
45 | int | 45 | int |
46 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | 46 | GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, |
47 | struct GNUNET_STATISTICS_Handle *st, | 47 | struct GNUNET_STATISTICS_Handle *st, |
48 | struct GNUNET_CORE_Handle *core, | 48 | struct GNUNET_CORE_Handle *core, |
49 | GNUNET_CORE_ConnectEventHandler *server_ch, | 49 | GNUNET_CORE_ConnectEventHandler *server_ch, |
50 | int advertise); | 50 | int advertise); |
51 | 51 | ||
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Stop server offering our hostlist. | 54 | * Stop server offering our hostlist. |
55 | */ | 55 | */ |
56 | void | 56 | void |
57 | GNUNET_HOSTLIST_server_stop (void); | 57 | GNUNET_HOSTLIST_server_stop(void); |
58 | 58 | ||
59 | 59 | ||
60 | #endif | 60 | #endif |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 557b91d1c..d6853c184 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file hostlist/test_gnunet_daemon_hostlist.c | 21 | * @file hostlist/test_gnunet_daemon_hostlist.c |
22 | * @brief test for gnunet_daemon_hostslist.c | 22 | * @brief test for gnunet_daemon_hostslist.c |
@@ -32,14 +32,13 @@ | |||
32 | /** | 32 | /** |
33 | * How long until we give up on transmitting the message? | 33 | * How long until we give up on transmitting the message? |
34 | */ | 34 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 150) |
36 | 36 | ||
37 | static int ok; | 37 | static int ok; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *timeout_task; | 39 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
40 | 40 | ||
41 | struct PeerContext | 41 | struct PeerContext { |
42 | { | ||
43 | struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | struct GNUNET_CONFIGURATION_Handle *cfg; |
44 | struct GNUNET_TRANSPORT_CoreHandle *th; | 43 | struct GNUNET_TRANSPORT_CoreHandle *th; |
45 | struct GNUNET_MessageHeader *hello; | 44 | struct GNUNET_MessageHeader *hello; |
@@ -53,29 +52,29 @@ static struct PeerContext p2; | |||
53 | 52 | ||
54 | 53 | ||
55 | static void | 54 | static void |
56 | clean_up (void *cls) | 55 | clean_up(void *cls) |
57 | { | 56 | { |
58 | if (NULL != p1.th) | 57 | if (NULL != p1.th) |
59 | { | ||
60 | if (NULL != p1.ghh) | ||
61 | { | 58 | { |
62 | GNUNET_TRANSPORT_hello_get_cancel (p1.ghh); | 59 | if (NULL != p1.ghh) |
63 | p1.ghh = NULL; | 60 | { |
61 | GNUNET_TRANSPORT_hello_get_cancel(p1.ghh); | ||
62 | p1.ghh = NULL; | ||
63 | } | ||
64 | GNUNET_TRANSPORT_core_disconnect(p1.th); | ||
65 | p1.th = NULL; | ||
64 | } | 66 | } |
65 | GNUNET_TRANSPORT_core_disconnect (p1.th); | ||
66 | p1.th = NULL; | ||
67 | } | ||
68 | if (NULL != p2.th) | 67 | if (NULL != p2.th) |
69 | { | ||
70 | if (NULL != p2.ghh) | ||
71 | { | 68 | { |
72 | GNUNET_TRANSPORT_hello_get_cancel (p2.ghh); | 69 | if (NULL != p2.ghh) |
73 | p2.ghh = NULL; | 70 | { |
71 | GNUNET_TRANSPORT_hello_get_cancel(p2.ghh); | ||
72 | p2.ghh = NULL; | ||
73 | } | ||
74 | GNUNET_TRANSPORT_core_disconnect(p2.th); | ||
75 | p2.th = NULL; | ||
74 | } | 76 | } |
75 | GNUNET_TRANSPORT_core_disconnect (p2.th); | 77 | GNUNET_SCHEDULER_shutdown(); |
76 | p2.th = NULL; | ||
77 | } | ||
78 | GNUNET_SCHEDULER_shutdown (); | ||
79 | } | 78 | } |
80 | 79 | ||
81 | 80 | ||
@@ -83,12 +82,12 @@ clean_up (void *cls) | |||
83 | * Timeout, give up. | 82 | * Timeout, give up. |
84 | */ | 83 | */ |
85 | static void | 84 | static void |
86 | timeout_error (void *cls) | 85 | timeout_error(void *cls) |
87 | { | 86 | { |
88 | timeout_task = NULL; | 87 | timeout_task = NULL; |
89 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 88 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
90 | "Timeout trying to connect peers, test failed.\n"); | 89 | "Timeout trying to connect peers, test failed.\n"); |
91 | clean_up (NULL); | 90 | clean_up(NULL); |
92 | } | 91 | } |
93 | 92 | ||
94 | 93 | ||
@@ -101,92 +100,92 @@ timeout_error (void *cls) | |||
101 | * @param mq message queue to send messages to the peer | 100 | * @param mq message queue to send messages to the peer |
102 | */ | 101 | */ |
103 | static void * | 102 | static void * |
104 | notify_connect (void *cls, | 103 | notify_connect(void *cls, |
105 | const struct GNUNET_PeerIdentity *peer, | 104 | const struct GNUNET_PeerIdentity *peer, |
106 | struct GNUNET_MQ_Handle *mq) | 105 | struct GNUNET_MQ_Handle *mq) |
107 | { | 106 | { |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); | 107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
109 | ok = 0; | 108 | ok = 0; |
110 | if (NULL != timeout_task) | 109 | if (NULL != timeout_task) |
111 | { | 110 | { |
112 | GNUNET_SCHEDULER_cancel (timeout_task); | 111 | GNUNET_SCHEDULER_cancel(timeout_task); |
113 | timeout_task = NULL; | 112 | timeout_task = NULL; |
114 | } | 113 | } |
115 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | 114 | GNUNET_SCHEDULER_add_now(&clean_up, NULL); |
116 | return NULL; | 115 | return NULL; |
117 | } | 116 | } |
118 | 117 | ||
119 | 118 | ||
120 | static void | 119 | static void |
121 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) | 120 | process_hello(void *cls, const struct GNUNET_MessageHeader *message) |
122 | { | 121 | { |
123 | struct PeerContext *p = cls; | 122 | struct PeerContext *p = cls; |
124 | 123 | ||
125 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); | 124 | GNUNET_TRANSPORT_hello_get_cancel(p->ghh); |
126 | p->ghh = NULL; | 125 | p->ghh = NULL; |
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
128 | "Received HELLO, starting hostlist service.\n"); | 127 | "Received HELLO, starting hostlist service.\n"); |
129 | } | 128 | } |
130 | 129 | ||
131 | 130 | ||
132 | static void | 131 | static void |
133 | setup_peer (struct PeerContext *p, const char *cfgname) | 132 | setup_peer(struct PeerContext *p, const char *cfgname) |
134 | { | 133 | { |
135 | char *binary; | 134 | char *binary; |
136 | 135 | ||
137 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 136 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
138 | p->cfg = GNUNET_CONFIGURATION_create (); | 137 | p->cfg = GNUNET_CONFIGURATION_create(); |
139 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, | 138 | p->arm_proc = GNUNET_OS_start_process(GNUNET_YES, |
140 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 139 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
141 | NULL, | 140 | NULL, |
142 | NULL, | 141 | NULL, |
143 | NULL, | 142 | NULL, |
144 | binary, | 143 | binary, |
145 | "gnunet-service-arm", | 144 | "gnunet-service-arm", |
146 | "-c", | 145 | "-c", |
147 | cfgname, | 146 | cfgname, |
148 | NULL); | 147 | NULL); |
149 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 148 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname)); |
150 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, | 149 | p->th = GNUNET_TRANSPORT_core_connect(p->cfg, |
151 | NULL, | 150 | NULL, |
152 | NULL, | 151 | NULL, |
153 | p, | 152 | p, |
154 | ¬ify_connect, | 153 | ¬ify_connect, |
155 | NULL, | 154 | NULL, |
156 | NULL); | 155 | NULL); |
157 | GNUNET_assert (NULL != p->th); | 156 | GNUNET_assert(NULL != p->th); |
158 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, | 157 | p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, |
159 | GNUNET_TRANSPORT_AC_ANY, | 158 | GNUNET_TRANSPORT_AC_ANY, |
160 | &process_hello, | 159 | &process_hello, |
161 | p); | 160 | p); |
162 | GNUNET_free (binary); | 161 | GNUNET_free(binary); |
163 | } | 162 | } |
164 | 163 | ||
165 | 164 | ||
166 | static void | 165 | static void |
167 | waitpid_task (void *cls) | 166 | waitpid_task(void *cls) |
168 | { | 167 | { |
169 | struct PeerContext *p = cls; | 168 | struct PeerContext *p = cls; |
170 | 169 | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | 170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
172 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | 171 | if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG)) |
173 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 172 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
174 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) | 173 | if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) |
175 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 174 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 175 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
177 | "ARM process %u stopped\n", | 176 | "ARM process %u stopped\n", |
178 | GNUNET_OS_process_get_pid (p->arm_proc)); | 177 | GNUNET_OS_process_get_pid(p->arm_proc)); |
179 | GNUNET_OS_process_destroy (p->arm_proc); | 178 | GNUNET_OS_process_destroy(p->arm_proc); |
180 | p->arm_proc = NULL; | 179 | p->arm_proc = NULL; |
181 | GNUNET_CONFIGURATION_destroy (p->cfg); | 180 | GNUNET_CONFIGURATION_destroy(p->cfg); |
182 | } | 181 | } |
183 | 182 | ||
184 | 183 | ||
185 | static void | 184 | static void |
186 | stop_arm (struct PeerContext *p) | 185 | stop_arm(struct PeerContext *p) |
187 | { | 186 | { |
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); | 187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
189 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); | 188 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
190 | } | 189 | } |
191 | 190 | ||
192 | 191 | ||
@@ -194,67 +193,68 @@ stop_arm (struct PeerContext *p) | |||
194 | * Try again to connect to transport service. | 193 | * Try again to connect to transport service. |
195 | */ | 194 | */ |
196 | static void | 195 | static void |
197 | shutdown_task (void *cls) | 196 | shutdown_task(void *cls) |
198 | { | 197 | { |
199 | stop_arm (&p1); | 198 | stop_arm(&p1); |
200 | stop_arm (&p2); | 199 | stop_arm(&p2); |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
204 | static void | 203 | static void |
205 | run (void *cls, | 204 | run(void *cls, |
206 | char *const *args, | 205 | char *const *args, |
207 | const char *cfgfile, | 206 | const char *cfgfile, |
208 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 207 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
209 | { | 208 | { |
210 | GNUNET_assert (ok == 1); | 209 | GNUNET_assert(ok == 1); |
211 | ok++; | 210 | ok++; |
212 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); | 211 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL); |
213 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 212 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
214 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 213 | setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
215 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 214 | setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
216 | } | 215 | } |
217 | 216 | ||
218 | 217 | ||
219 | static int | 218 | static int |
220 | check () | 219 | check() |
221 | { | 220 | { |
222 | char *const argv[] = {"test-gnunet-daemon-hostlist", | 221 | char *const argv[] = { "test-gnunet-daemon-hostlist", |
223 | "-c", | 222 | "-c", |
224 | "test_gnunet_daemon_hostlist_data.conf", | 223 | "test_gnunet_daemon_hostlist_data.conf", |
225 | NULL}; | 224 | NULL }; |
226 | struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; | 225 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; |
226 | |||
227 | ok = 1; | 227 | ok = 1; |
228 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 228 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
229 | argv, | 229 | argv, |
230 | "test-gnunet-daemon-hostlist", | 230 | "test-gnunet-daemon-hostlist", |
231 | "nohelp", | 231 | "nohelp", |
232 | options, | 232 | options, |
233 | &run, | 233 | &run, |
234 | &ok); | 234 | &ok); |
235 | return ok; | 235 | return ok; |
236 | } | 236 | } |
237 | 237 | ||
238 | 238 | ||
239 | int | 239 | int |
240 | main (int argc, char *argv[]) | 240 | main(int argc, char *argv[]) |
241 | { | 241 | { |
242 | int ret; | 242 | int ret; |
243 | 243 | ||
244 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 244 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", |
245 | "GNUNET_TEST_HOME"); | 245 | "GNUNET_TEST_HOME"); |
246 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", | 246 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", |
247 | "GNUNET_TEST_HOME"); | 247 | "GNUNET_TEST_HOME"); |
248 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 248 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", |
249 | "GNUNET_TEST_HOME"); | 249 | "GNUNET_TEST_HOME"); |
250 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); | 250 | GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL); |
251 | ret = check (); | 251 | ret = check(); |
252 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 252 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", |
253 | "GNUNET_TEST_HOME"); | 253 | "GNUNET_TEST_HOME"); |
254 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", | 254 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", |
255 | "GNUNET_TEST_HOME"); | 255 | "GNUNET_TEST_HOME"); |
256 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 256 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", |
257 | "GNUNET_TEST_HOME"); | 257 | "GNUNET_TEST_HOME"); |
258 | return ret; | 258 | return ret; |
259 | } | 259 | } |
260 | 260 | ||
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index a18255e6d..fa72ac828 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file hostlist/test_gnunet_daemon_hostlist_learning.c | 21 | * @file hostlist/test_gnunet_daemon_hostlist_learning.c |
22 | * @brief test for gnunet_daemon_hostslist.c | 22 | * @brief test for gnunet_daemon_hostslist.c |
@@ -35,13 +35,12 @@ | |||
35 | /** | 35 | /** |
36 | * How long until wait until testcases fails | 36 | * How long until wait until testcases fails |
37 | */ | 37 | */ |
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 180) |
39 | 39 | ||
40 | #define CHECK_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 40 | #define CHECK_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) |
41 | 41 | ||
42 | 42 | ||
43 | struct PeerContext | 43 | struct PeerContext { |
44 | { | ||
45 | struct GNUNET_CONFIGURATION_Handle *cfg; | 44 | struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | struct GNUNET_MessageHeader *hello; | 45 | struct GNUNET_MessageHeader *hello; |
47 | struct GNUNET_CORE_Handle *core; | 46 | struct GNUNET_CORE_Handle *core; |
@@ -79,86 +78,86 @@ static struct GNUNET_STATISTICS_GetHandle *advsent_stat; | |||
79 | 78 | ||
80 | 79 | ||
81 | static void | 80 | static void |
82 | shutdown_testcase () | 81 | shutdown_testcase() |
83 | { | 82 | { |
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 83 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
85 | "Shutdown testcase....\n"); | 84 | "Shutdown testcase....\n"); |
86 | if (NULL != timeout_task) | 85 | if (NULL != timeout_task) |
87 | { | 86 | { |
88 | GNUNET_SCHEDULER_cancel (timeout_task); | 87 | GNUNET_SCHEDULER_cancel(timeout_task); |
89 | timeout_task = NULL; | 88 | timeout_task = NULL; |
90 | } | 89 | } |
91 | if (NULL != download_stats) | 90 | if (NULL != download_stats) |
92 | { | 91 | { |
93 | GNUNET_STATISTICS_get_cancel (download_stats); | 92 | GNUNET_STATISTICS_get_cancel(download_stats); |
94 | download_stats = NULL; | 93 | download_stats = NULL; |
95 | } | 94 | } |
96 | if (NULL != urisrecv_stat) | 95 | if (NULL != urisrecv_stat) |
97 | { | 96 | { |
98 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 97 | GNUNET_STATISTICS_get_cancel(urisrecv_stat); |
99 | urisrecv_stat = NULL; | 98 | urisrecv_stat = NULL; |
100 | } | 99 | } |
101 | if (NULL != advsent_stat) | 100 | if (NULL != advsent_stat) |
102 | { | 101 | { |
103 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 102 | GNUNET_STATISTICS_get_cancel(advsent_stat); |
104 | advsent_stat = NULL; | 103 | advsent_stat = NULL; |
105 | } | 104 | } |
106 | if (NULL != adv_peer.stats) | 105 | if (NULL != adv_peer.stats) |
107 | { | 106 | { |
108 | GNUNET_STATISTICS_destroy (adv_peer.stats, GNUNET_NO); | 107 | GNUNET_STATISTICS_destroy(adv_peer.stats, GNUNET_NO); |
109 | adv_peer.stats = NULL; | 108 | adv_peer.stats = NULL; |
110 | } | 109 | } |
111 | if (NULL != learn_peer.stats) | 110 | if (NULL != learn_peer.stats) |
112 | { | 111 | { |
113 | GNUNET_STATISTICS_destroy (learn_peer.stats, GNUNET_NO); | 112 | GNUNET_STATISTICS_destroy(learn_peer.stats, GNUNET_NO); |
114 | learn_peer.stats = NULL; | 113 | learn_peer.stats = NULL; |
115 | } | 114 | } |
116 | if (NULL != check_task) | 115 | if (NULL != check_task) |
117 | { | 116 | { |
118 | GNUNET_SCHEDULER_cancel (check_task); | 117 | GNUNET_SCHEDULER_cancel(check_task); |
119 | check_task = NULL; | 118 | check_task = NULL; |
120 | } | 119 | } |
121 | if (NULL != current_adv_uri) | 120 | if (NULL != current_adv_uri) |
122 | { | 121 | { |
123 | GNUNET_free (current_adv_uri); | 122 | GNUNET_free(current_adv_uri); |
124 | current_adv_uri = NULL; | 123 | current_adv_uri = NULL; |
125 | } | 124 | } |
126 | if (NULL != adv_peer.core) | 125 | if (NULL != adv_peer.core) |
127 | { | 126 | { |
128 | GNUNET_CORE_disconnect (adv_peer.core); | 127 | GNUNET_CORE_disconnect(adv_peer.core); |
129 | adv_peer.core = NULL; | 128 | adv_peer.core = NULL; |
130 | } | 129 | } |
131 | if (NULL != learn_peer.core) | 130 | if (NULL != learn_peer.core) |
132 | { | 131 | { |
133 | GNUNET_CORE_disconnect (learn_peer.core); | 132 | GNUNET_CORE_disconnect(learn_peer.core); |
134 | learn_peer.core = NULL; | 133 | learn_peer.core = NULL; |
135 | } | 134 | } |
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
137 | "Killing hostlist server ARM process.\n"); | 136 | "Killing hostlist server ARM process.\n"); |
138 | if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, | 137 | if (0 != GNUNET_OS_process_kill(adv_peer.arm_proc, |
139 | GNUNET_TERM_SIG)) | 138 | GNUNET_TERM_SIG)) |
140 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 139 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
141 | "kill"); | 140 | "kill"); |
142 | if (GNUNET_OK != | 141 | if (GNUNET_OK != |
143 | GNUNET_OS_process_wait (adv_peer.arm_proc)) | 142 | GNUNET_OS_process_wait(adv_peer.arm_proc)) |
144 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 143 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
145 | "waitpid"); | 144 | "waitpid"); |
146 | GNUNET_OS_process_destroy (adv_peer.arm_proc); | 145 | GNUNET_OS_process_destroy(adv_peer.arm_proc); |
147 | adv_peer.arm_proc = NULL; | 146 | adv_peer.arm_proc = NULL; |
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
149 | "Killing hostlist client ARM process.\n"); | 148 | "Killing hostlist client ARM process.\n"); |
150 | if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, | 149 | if (0 != GNUNET_OS_process_kill(learn_peer.arm_proc, |
151 | GNUNET_TERM_SIG)) | 150 | GNUNET_TERM_SIG)) |
152 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 151 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
153 | "kill"); | 152 | "kill"); |
154 | if (GNUNET_OK != | 153 | if (GNUNET_OK != |
155 | GNUNET_OS_process_wait (learn_peer.arm_proc)) | 154 | GNUNET_OS_process_wait(learn_peer.arm_proc)) |
156 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 155 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
157 | "waitpid"); | 156 | "waitpid"); |
158 | GNUNET_OS_process_destroy (learn_peer.arm_proc); | 157 | GNUNET_OS_process_destroy(learn_peer.arm_proc); |
159 | learn_peer.arm_proc = NULL; | 158 | learn_peer.arm_proc = NULL; |
160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 159 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
161 | "Shutdown complete....\n"); | 160 | "Shutdown complete....\n"); |
162 | } | 161 | } |
163 | 162 | ||
164 | 163 | ||
@@ -166,111 +165,112 @@ shutdown_testcase () | |||
166 | * Timeout, give up. | 165 | * Timeout, give up. |
167 | */ | 166 | */ |
168 | static void | 167 | static void |
169 | timeout_error (void *cls) | 168 | timeout_error(void *cls) |
170 | { | 169 | { |
171 | timeout_task = NULL; | 170 | timeout_task = NULL; |
172 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 171 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
173 | "Timeout while executing testcase, test failed.\n"); | 172 | "Timeout while executing testcase, test failed.\n"); |
174 | timeout = GNUNET_YES; | 173 | timeout = GNUNET_YES; |
175 | shutdown_testcase (); | 174 | shutdown_testcase(); |
176 | } | 175 | } |
177 | 176 | ||
178 | 177 | ||
179 | static void | 178 | static void |
180 | process_downloads_done (void *cls, int success) | 179 | process_downloads_done(void *cls, int success) |
181 | { | 180 | { |
182 | download_stats = NULL; | 181 | download_stats = NULL; |
183 | } | 182 | } |
184 | 183 | ||
185 | 184 | ||
186 | static void | 185 | static void |
187 | do_shutdown (void *cls) | 186 | do_shutdown(void *cls) |
188 | { | 187 | { |
189 | shutdown_testcase (); | 188 | shutdown_testcase(); |
190 | } | 189 | } |
191 | 190 | ||
192 | 191 | ||
193 | static int | 192 | static int |
194 | process_downloads (void *cls, | 193 | process_downloads(void *cls, |
195 | const char *subsystem, | 194 | const char *subsystem, |
196 | const char *name, | 195 | const char *name, |
197 | uint64_t value, | 196 | uint64_t value, |
198 | int is_persistent) | 197 | int is_persistent) |
199 | { | 198 | { |
200 | if ( (value >= 2) && | 199 | if ((value >= 2) && |
201 | (GNUNET_NO == learned_hostlist_downloaded) ) | 200 | (GNUNET_NO == learned_hostlist_downloaded)) |
202 | { | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
204 | "Peer has successfully downloaded advertised URI\n"); | ||
205 | learned_hostlist_downloaded = GNUNET_YES; | ||
206 | if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES)) | ||
207 | { | 201 | { |
208 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 202 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
203 | "Peer has successfully downloaded advertised URI\n"); | ||
204 | learned_hostlist_downloaded = GNUNET_YES; | ||
205 | if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES)) | ||
206 | { | ||
207 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
208 | } | ||
209 | } | 209 | } |
210 | } | ||
211 | return GNUNET_OK; | 210 | return GNUNET_OK; |
212 | } | 211 | } |
213 | 212 | ||
214 | 213 | ||
215 | static void | 214 | static void |
216 | process_uris_recv_done (void *cls, int success) | 215 | process_uris_recv_done(void *cls, int success) |
217 | { | 216 | { |
218 | urisrecv_stat = NULL; | 217 | urisrecv_stat = NULL; |
219 | } | 218 | } |
220 | 219 | ||
221 | 220 | ||
222 | static int | 221 | static int |
223 | process_uris_recv (void *cls, | 222 | process_uris_recv(void *cls, |
224 | const char *subsystem, | 223 | const char *subsystem, |
225 | const char *name, | 224 | const char *name, |
226 | uint64_t value, | 225 | uint64_t value, |
227 | int is_persistent) | 226 | int is_persistent) |
228 | { | 227 | { |
229 | struct PeerContext *pc = cls; | 228 | struct PeerContext *pc = cls; |
230 | if ( (pc == &learn_peer) && | 229 | |
231 | (value == 1) && | 230 | if ((pc == &learn_peer) && |
232 | (learned_hostlist_saved == GNUNET_NO) ) | 231 | (value == 1) && |
233 | { | 232 | (learned_hostlist_saved == GNUNET_NO)) |
234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
235 | "Peer has successfully saved advertised URI\n"); | ||
236 | learned_hostlist_saved = GNUNET_YES; | ||
237 | if ( (learned_hostlist_downloaded == GNUNET_YES) && | ||
238 | (adv_sent == GNUNET_YES) ) | ||
239 | { | 233 | { |
240 | GNUNET_SCHEDULER_add_now (&do_shutdown, | 234 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
241 | NULL); | 235 | "Peer has successfully saved advertised URI\n"); |
236 | learned_hostlist_saved = GNUNET_YES; | ||
237 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
238 | (adv_sent == GNUNET_YES)) | ||
239 | { | ||
240 | GNUNET_SCHEDULER_add_now(&do_shutdown, | ||
241 | NULL); | ||
242 | } | ||
242 | } | 243 | } |
243 | } | ||
244 | return GNUNET_OK; | 244 | return GNUNET_OK; |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
248 | static void | 248 | static void |
249 | process_adv_sent_done (void *cls, int success) | 249 | process_adv_sent_done(void *cls, int success) |
250 | { | 250 | { |
251 | advsent_stat = NULL; | 251 | advsent_stat = NULL; |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | static int | 255 | static int |
256 | process_adv_sent (void *cls, | 256 | process_adv_sent(void *cls, |
257 | const char *subsystem, | 257 | const char *subsystem, |
258 | const char *name, | 258 | const char *name, |
259 | uint64_t value, | 259 | uint64_t value, |
260 | int is_persistent) | 260 | int is_persistent) |
261 | { | 261 | { |
262 | if ((value >= 1) && (adv_sent == GNUNET_NO)) | 262 | if ((value >= 1) && (adv_sent == GNUNET_NO)) |
263 | { | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
265 | "Server has successfully sent advertisement\n"); | ||
266 | adv_sent = GNUNET_YES; | ||
267 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
268 | (learned_hostlist_saved == GNUNET_YES)) | ||
269 | { | 263 | { |
270 | GNUNET_SCHEDULER_add_now (&do_shutdown, | 264 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
271 | NULL); | 265 | "Server has successfully sent advertisement\n"); |
266 | adv_sent = GNUNET_YES; | ||
267 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
268 | (learned_hostlist_saved == GNUNET_YES)) | ||
269 | { | ||
270 | GNUNET_SCHEDULER_add_now(&do_shutdown, | ||
271 | NULL); | ||
272 | } | ||
272 | } | 273 | } |
273 | } | ||
274 | return GNUNET_OK; | 274 | return GNUNET_OK; |
275 | } | 275 | } |
276 | 276 | ||
@@ -279,69 +279,70 @@ process_adv_sent (void *cls, | |||
279 | * Check the server statistics regularly | 279 | * Check the server statistics regularly |
280 | */ | 280 | */ |
281 | static void | 281 | static void |
282 | check_statistics (void *cls) | 282 | check_statistics(void *cls) |
283 | { | 283 | { |
284 | char *stat; | 284 | char *stat; |
285 | 285 | ||
286 | check_task = NULL; | 286 | check_task = NULL; |
287 | GNUNET_asprintf (&stat, | 287 | GNUNET_asprintf(&stat, |
288 | gettext_noop ("# advertised URI `%s' downloaded"), | 288 | gettext_noop("# advertised URI `%s' downloaded"), |
289 | current_adv_uri); | 289 | current_adv_uri); |
290 | if (NULL != learn_peer.stats) | 290 | if (NULL != learn_peer.stats) |
291 | { | 291 | { |
292 | if (NULL != download_stats) | 292 | if (NULL != download_stats) |
293 | GNUNET_STATISTICS_get_cancel (download_stats); | 293 | GNUNET_STATISTICS_get_cancel(download_stats); |
294 | download_stats = | 294 | download_stats = |
295 | GNUNET_STATISTICS_get (learn_peer.stats, | 295 | GNUNET_STATISTICS_get(learn_peer.stats, |
296 | "hostlist", | 296 | "hostlist", |
297 | stat, | 297 | stat, |
298 | &process_downloads_done, | 298 | &process_downloads_done, |
299 | &process_downloads, | 299 | &process_downloads, |
300 | &learn_peer); | 300 | &learn_peer); |
301 | if (NULL != urisrecv_stat) | 301 | if (NULL != urisrecv_stat) |
302 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 302 | GNUNET_STATISTICS_get_cancel(urisrecv_stat); |
303 | urisrecv_stat = | 303 | urisrecv_stat = |
304 | GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", | 304 | GNUNET_STATISTICS_get(learn_peer.stats, "hostlist", |
305 | gettext_noop ("# advertised hostlist URIs"), | 305 | gettext_noop("# advertised hostlist URIs"), |
306 | &process_uris_recv_done, &process_uris_recv, | 306 | &process_uris_recv_done, &process_uris_recv, |
307 | &learn_peer); | 307 | &learn_peer); |
308 | } | 308 | } |
309 | GNUNET_free (stat); | 309 | GNUNET_free(stat); |
310 | if (NULL != adv_peer.stats) | 310 | if (NULL != adv_peer.stats) |
311 | { | 311 | { |
312 | if (NULL != advsent_stat) | 312 | if (NULL != advsent_stat) |
313 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 313 | GNUNET_STATISTICS_get_cancel(advsent_stat); |
314 | advsent_stat = | 314 | advsent_stat = |
315 | GNUNET_STATISTICS_get (adv_peer.stats, "hostlist", | 315 | GNUNET_STATISTICS_get(adv_peer.stats, "hostlist", |
316 | gettext_noop ("# hostlist advertisements send"), | 316 | gettext_noop("# hostlist advertisements send"), |
317 | &process_adv_sent_done, | 317 | &process_adv_sent_done, |
318 | &process_adv_sent, | 318 | &process_adv_sent, |
319 | NULL); | 319 | NULL); |
320 | } | 320 | } |
321 | check_task = | 321 | check_task = |
322 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVAL, | 322 | GNUNET_SCHEDULER_add_delayed(CHECK_INTERVAL, |
323 | &check_statistics, | 323 | &check_statistics, |
324 | NULL); | 324 | NULL); |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | static int | 328 | static int |
329 | check_ad_arrive (void *cls, | 329 | check_ad_arrive(void *cls, |
330 | const struct GNUNET_MessageHeader *message) | 330 | const struct GNUNET_MessageHeader *message) |
331 | { | 331 | { |
332 | const char *end = (const char *) &message[1]; | 332 | const char *end = (const char *)&message[1]; |
333 | if ('\0' != end[ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1]) | 333 | |
334 | { | 334 | if ('\0' != end[ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - 1]) |
335 | GNUNET_break (0); | 335 | { |
336 | return GNUNET_SYSERR; | 336 | GNUNET_break(0); |
337 | } | 337 | return GNUNET_SYSERR; |
338 | } | ||
338 | return GNUNET_OK; | 339 | return GNUNET_OK; |
339 | } | 340 | } |
340 | 341 | ||
341 | 342 | ||
342 | static void | 343 | static void |
343 | handle_ad_arrive (void *cls, | 344 | handle_ad_arrive(void *cls, |
344 | const struct GNUNET_MessageHeader *message) | 345 | const struct GNUNET_MessageHeader *message) |
345 | { | 346 | { |
346 | char *hostname; | 347 | char *hostname; |
347 | char *expected_uri; | 348 | char *expected_uri; |
@@ -349,132 +350,132 @@ handle_ad_arrive (void *cls, | |||
349 | const char *end; | 350 | const char *end; |
350 | 351 | ||
351 | if (GNUNET_SYSERR == | 352 | if (GNUNET_SYSERR == |
352 | GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, | 353 | GNUNET_CONFIGURATION_get_value_number(adv_peer.cfg, |
353 | "HOSTLIST", | 354 | "HOSTLIST", |
354 | "HTTPPORT", | 355 | "HTTPPORT", |
355 | &port)) | 356 | &port)) |
356 | { | 357 | { |
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 358 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
358 | "Could not read advertising server's configuration\n"); | 359 | "Could not read advertising server's configuration\n"); |
359 | return; | 360 | return; |
360 | } | 361 | } |
361 | 362 | ||
362 | if (GNUNET_SYSERR == | 363 | if (GNUNET_SYSERR == |
363 | GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, | 364 | GNUNET_CONFIGURATION_get_value_string(adv_peer.cfg, |
364 | "HOSTLIST", | 365 | "HOSTLIST", |
365 | "EXTERNAL_DNS_NAME", | 366 | "EXTERNAL_DNS_NAME", |
366 | &hostname)) | 367 | &hostname)) |
367 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 368 | hostname = GNUNET_RESOLVER_local_fqdn_get(); |
368 | GNUNET_asprintf (&expected_uri, | 369 | GNUNET_asprintf(&expected_uri, |
369 | "http://%s:%u/", | 370 | "http://%s:%u/", |
370 | hostname != NULL ? hostname : "localhost", | 371 | hostname != NULL ? hostname : "localhost", |
371 | (unsigned int) port); | 372 | (unsigned int)port); |
372 | end = (const char *) &message[1]; | 373 | end = (const char *)&message[1]; |
373 | current_adv_uri = GNUNET_strdup (end); | 374 | current_adv_uri = GNUNET_strdup(end); |
374 | if (0 == strcmp (expected_uri, | 375 | if (0 == strcmp(expected_uri, |
375 | current_adv_uri)) | 376 | current_adv_uri)) |
376 | { | 377 | { |
377 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 378 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
378 | "Received hostlist advertisement with URI `%s' as expected\n", | 379 | "Received hostlist advertisement with URI `%s' as expected\n", |
379 | current_adv_uri); | 380 | current_adv_uri); |
380 | adv_arrived = GNUNET_YES; | 381 | adv_arrived = GNUNET_YES; |
381 | adv_sent = GNUNET_YES; | 382 | adv_sent = GNUNET_YES; |
382 | } | 383 | } |
383 | else | 384 | else |
384 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 385 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
385 | "Expected URI `%s' and received URI `%s' differ\n", | 386 | "Expected URI `%s' and received URI `%s' differ\n", |
386 | expected_uri, | 387 | expected_uri, |
387 | current_adv_uri); | 388 | current_adv_uri); |
388 | GNUNET_free (expected_uri); | 389 | GNUNET_free(expected_uri); |
389 | GNUNET_free_non_null (hostname); | 390 | GNUNET_free_non_null(hostname); |
390 | } | 391 | } |
391 | 392 | ||
392 | 393 | ||
393 | static void | 394 | static void |
394 | setup_learn_peer (struct PeerContext *p, | 395 | setup_learn_peer(struct PeerContext *p, |
395 | const char *cfgname) | 396 | const char *cfgname) |
396 | { | 397 | { |
397 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { | 398 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { |
398 | GNUNET_MQ_hd_var_size (ad_arrive, | 399 | GNUNET_MQ_hd_var_size(ad_arrive, |
399 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, | 400 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, |
400 | struct GNUNET_MessageHeader, | 401 | struct GNUNET_MessageHeader, |
401 | NULL), | 402 | NULL), |
402 | GNUNET_MQ_handler_end () | 403 | GNUNET_MQ_handler_end() |
403 | }; | 404 | }; |
404 | char *filename; | 405 | char *filename; |
405 | unsigned int result; | 406 | unsigned int result; |
406 | char *binary; | 407 | char *binary; |
407 | 408 | ||
408 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 409 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
409 | p->cfg = GNUNET_CONFIGURATION_create (); | 410 | p->cfg = GNUNET_CONFIGURATION_create(); |
410 | p->arm_proc = | 411 | p->arm_proc = |
411 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 412 | GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
412 | NULL, NULL, NULL, | 413 | NULL, NULL, NULL, |
413 | binary, | 414 | binary, |
414 | "gnunet-service-arm", | 415 | "gnunet-service-arm", |
415 | "-c", cfgname, NULL); | 416 | "-c", cfgname, NULL); |
416 | GNUNET_assert (GNUNET_OK == | 417 | GNUNET_assert(GNUNET_OK == |
417 | GNUNET_CONFIGURATION_load (p->cfg, | 418 | GNUNET_CONFIGURATION_load(p->cfg, |
418 | cfgname)); | 419 | cfgname)); |
419 | if (GNUNET_OK == | 420 | if (GNUNET_OK == |
420 | GNUNET_CONFIGURATION_get_value_string (p->cfg, | 421 | GNUNET_CONFIGURATION_get_value_string(p->cfg, |
421 | "HOSTLIST", | 422 | "HOSTLIST", |
422 | "HOSTLISTFILE", | 423 | "HOSTLISTFILE", |
423 | &filename)) | 424 | &filename)) |
424 | { | ||
425 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | ||
426 | { | 425 | { |
427 | result = unlink (filename); | 426 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) |
428 | if (result == 0) | 427 | { |
429 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 428 | result = unlink(filename); |
430 | _("Hostlist file `%s' was removed\n"), | 429 | if (result == 0) |
431 | filename); | 430 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
431 | _("Hostlist file `%s' was removed\n"), | ||
432 | filename); | ||
433 | } | ||
434 | GNUNET_free(filename); | ||
432 | } | 435 | } |
433 | GNUNET_free (filename); | 436 | p->core = GNUNET_CORE_connect(p->cfg, |
434 | } | 437 | NULL, |
435 | p->core = GNUNET_CORE_connect (p->cfg, | 438 | NULL, |
436 | NULL, | 439 | NULL, |
437 | NULL, | 440 | NULL, |
438 | NULL, | 441 | learn_handlers); |
439 | NULL, | 442 | GNUNET_assert(NULL != p->core); |
440 | learn_handlers); | 443 | p->stats = GNUNET_STATISTICS_create("hostlist", |
441 | GNUNET_assert (NULL != p->core); | 444 | p->cfg); |
442 | p->stats = GNUNET_STATISTICS_create ("hostlist", | 445 | GNUNET_assert(NULL != p->stats); |
443 | p->cfg); | 446 | GNUNET_free(binary); |
444 | GNUNET_assert (NULL != p->stats); | ||
445 | GNUNET_free (binary); | ||
446 | } | 447 | } |
447 | 448 | ||
448 | 449 | ||
449 | static void | 450 | static void |
450 | setup_adv_peer (struct PeerContext *p, | 451 | setup_adv_peer(struct PeerContext *p, |
451 | const char *cfgname) | 452 | const char *cfgname) |
452 | { | 453 | { |
453 | char *binary; | 454 | char *binary; |
454 | 455 | ||
455 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 456 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
456 | p->cfg = GNUNET_CONFIGURATION_create (); | 457 | p->cfg = GNUNET_CONFIGURATION_create(); |
457 | p->arm_proc = | 458 | p->arm_proc = |
458 | GNUNET_OS_start_process (GNUNET_YES, | 459 | GNUNET_OS_start_process(GNUNET_YES, |
459 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 460 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
460 | NULL, NULL, NULL, | 461 | NULL, NULL, NULL, |
461 | binary, | 462 | binary, |
462 | "gnunet-service-arm", | 463 | "gnunet-service-arm", |
463 | "-c", cfgname, NULL); | 464 | "-c", cfgname, NULL); |
464 | GNUNET_assert (GNUNET_OK == | 465 | GNUNET_assert(GNUNET_OK == |
465 | GNUNET_CONFIGURATION_load (p->cfg, | 466 | GNUNET_CONFIGURATION_load(p->cfg, |
466 | cfgname)); | 467 | cfgname)); |
467 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 468 | p->stats = GNUNET_STATISTICS_create("hostlist", p->cfg); |
468 | GNUNET_assert (NULL != p->stats); | 469 | GNUNET_assert(NULL != p->stats); |
469 | GNUNET_free (binary); | 470 | GNUNET_free(binary); |
470 | } | 471 | } |
471 | 472 | ||
472 | 473 | ||
473 | static void | 474 | static void |
474 | run (void *cls, | 475 | run(void *cls, |
475 | char *const *args, | 476 | char *const *args, |
476 | const char *cfgfile, | 477 | const char *cfgfile, |
477 | const struct GNUNET_CONFIGURATION_Handle *c) | 478 | const struct GNUNET_CONFIGURATION_Handle *c) |
478 | { | 479 | { |
479 | timeout = GNUNET_NO; | 480 | timeout = GNUNET_NO; |
480 | adv_sent = GNUNET_NO; | 481 | adv_sent = GNUNET_NO; |
@@ -485,22 +486,22 @@ run (void *cls, | |||
485 | 486 | ||
486 | cfg = c; | 487 | cfg = c; |
487 | 488 | ||
488 | setup_adv_peer (&adv_peer, | 489 | setup_adv_peer(&adv_peer, |
489 | "test_learning_adv_peer.conf"); | 490 | "test_learning_adv_peer.conf"); |
490 | setup_learn_peer (&learn_peer, | 491 | setup_learn_peer(&learn_peer, |
491 | "test_learning_learn_peer.conf"); | 492 | "test_learning_learn_peer.conf"); |
492 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 493 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
493 | &timeout_error, | 494 | &timeout_error, |
494 | NULL); | 495 | NULL); |
495 | check_task = | 496 | check_task = |
496 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVAL, | 497 | GNUNET_SCHEDULER_add_delayed(CHECK_INTERVAL, |
497 | &check_statistics, | 498 | &check_statistics, |
498 | NULL); | 499 | NULL); |
499 | } | 500 | } |
500 | 501 | ||
501 | 502 | ||
502 | static int | 503 | static int |
503 | check () | 504 | check() |
504 | { | 505 | { |
505 | unsigned int failed; | 506 | unsigned int failed; |
506 | 507 | ||
@@ -513,44 +514,44 @@ check () | |||
513 | GNUNET_GETOPT_OPTION_END | 514 | GNUNET_GETOPT_OPTION_END |
514 | }; | 515 | }; |
515 | 516 | ||
516 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 517 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
517 | argv, | 518 | argv, |
518 | "test-gnunet-daemon-hostlist-learning", | 519 | "test-gnunet-daemon-hostlist-learning", |
519 | "nohelp", | 520 | "nohelp", |
520 | options, | 521 | options, |
521 | &run, | 522 | &run, |
522 | NULL); | 523 | NULL); |
523 | failed = GNUNET_NO; | 524 | failed = GNUNET_NO; |
524 | if (timeout == GNUNET_YES) | 525 | if (timeout == GNUNET_YES) |
525 | { | 526 | { |
526 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 527 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
527 | "Testcase timeout\n"); | 528 | "Testcase timeout\n"); |
528 | failed = GNUNET_YES; | 529 | failed = GNUNET_YES; |
529 | } | 530 | } |
530 | if (adv_arrived != GNUNET_YES) | 531 | if (adv_arrived != GNUNET_YES) |
531 | { | 532 | { |
532 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 533 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
533 | "Learning peer did not receive advertisement from server\n"); | 534 | "Learning peer did not receive advertisement from server\n"); |
534 | failed = GNUNET_YES; | 535 | failed = GNUNET_YES; |
535 | } | 536 | } |
536 | if (learned_hostlist_saved == GNUNET_NO) | 537 | if (learned_hostlist_saved == GNUNET_NO) |
537 | { | 538 | { |
538 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 539 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
539 | "Advertised hostlist was not saved in datastore\n"); | 540 | "Advertised hostlist was not saved in datastore\n"); |
540 | failed = GNUNET_YES; | 541 | failed = GNUNET_YES; |
541 | } | 542 | } |
542 | if (learned_hostlist_downloaded == GNUNET_NO) | 543 | if (learned_hostlist_downloaded == GNUNET_NO) |
543 | { | 544 | { |
544 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 545 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
545 | "Advertised hostlist could not be downloaded from server\n"); | 546 | "Advertised hostlist could not be downloaded from server\n"); |
546 | failed = GNUNET_YES; | 547 | failed = GNUNET_YES; |
547 | } | 548 | } |
548 | if (adv_sent == GNUNET_NO) | 549 | if (adv_sent == GNUNET_NO) |
549 | { | 550 | { |
550 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 551 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
551 | "Advertised was not sent from server to client\n"); | 552 | "Advertised was not sent from server to client\n"); |
552 | failed = GNUNET_YES; | 553 | failed = GNUNET_YES; |
553 | } | 554 | } |
554 | if (GNUNET_YES == failed) | 555 | if (GNUNET_YES == failed) |
555 | return GNUNET_YES; | 556 | return GNUNET_YES; |
556 | return GNUNET_NO; | 557 | return GNUNET_NO; |
@@ -558,29 +559,29 @@ check () | |||
558 | 559 | ||
559 | 560 | ||
560 | int | 561 | int |
561 | main (int argc, char *argv[]) | 562 | main(int argc, char *argv[]) |
562 | { | 563 | { |
563 | int ret; | 564 | int ret; |
564 | 565 | ||
565 | GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf", | 566 | GNUNET_DISK_purge_cfg_dir("test_learning_learn_peer.conf", |
566 | "GNUNET_TEST_HOME"); | 567 | "GNUNET_TEST_HOME"); |
567 | GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf", | 568 | GNUNET_DISK_purge_cfg_dir("test_learning_adv_peer.conf", |
568 | "GNUNET_TEST_HOME"); | 569 | "GNUNET_TEST_HOME"); |
569 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", | 570 | GNUNET_log_setup("test-gnunet-daemon-hostlist", |
570 | "WARNING", | 571 | "WARNING", |
571 | NULL); | 572 | NULL); |
572 | ret = check (); | 573 | ret = check(); |
573 | GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf", | 574 | GNUNET_DISK_purge_cfg_dir("test_learning_learn_peer.conf", |
574 | "GNUNET_TEST_HOME"); | 575 | "GNUNET_TEST_HOME"); |
575 | GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf", | 576 | GNUNET_DISK_purge_cfg_dir("test_learning_adv_peer.conf", |
576 | "GNUNET_TEST_HOME"); | 577 | "GNUNET_TEST_HOME"); |
577 | if (GNUNET_YES == | 578 | if (GNUNET_YES == |
578 | GNUNET_DISK_file_test ("hostlists_learn_peer.file")) | 579 | GNUNET_DISK_file_test("hostlists_learn_peer.file")) |
579 | { | 580 | { |
580 | if (0 == unlink ("hostlists_learn_peer.file")) | 581 | if (0 == unlink("hostlists_learn_peer.file")) |
581 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 582 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
582 | "Hostlist file hostlists_learn_peer.file was removed\n"); | 583 | "Hostlist file hostlists_learn_peer.file was removed\n"); |
583 | } | 584 | } |
584 | return ret; | 585 | return ret; |
585 | } | 586 | } |
586 | 587 | ||
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 6aaa7ae2e..783da1d20 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file hostlist/test_gnunet_daemon_hostlist_reconnect.c | 21 | * @file hostlist/test_gnunet_daemon_hostlist_reconnect.c |
22 | * @brief test for gnunet-daemon-hostslist.c; tries to re-start the peers | 22 | * @brief test for gnunet-daemon-hostslist.c; tries to re-start the peers |
@@ -32,14 +32,13 @@ | |||
32 | /** | 32 | /** |
33 | * How long until we give up on transmitting the message? | 33 | * How long until we give up on transmitting the message? |
34 | */ | 34 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 150) |
36 | 36 | ||
37 | static int ok; | 37 | static int ok; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *timeout_task; | 39 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
40 | 40 | ||
41 | struct PeerContext | 41 | struct PeerContext { |
42 | { | ||
43 | struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | struct GNUNET_CONFIGURATION_Handle *cfg; |
44 | struct GNUNET_TRANSPORT_CoreHandle *th; | 43 | struct GNUNET_TRANSPORT_CoreHandle *th; |
45 | struct GNUNET_MessageHeader *hello; | 44 | struct GNUNET_MessageHeader *hello; |
@@ -56,12 +55,12 @@ static struct PeerContext p2; | |||
56 | * Timeout, give up. | 55 | * Timeout, give up. |
57 | */ | 56 | */ |
58 | static void | 57 | static void |
59 | timeout_error (void *cls) | 58 | timeout_error(void *cls) |
60 | { | 59 | { |
61 | timeout_task = NULL; | 60 | timeout_task = NULL; |
62 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 61 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
63 | "Timeout trying to connect peers, test failed.\n"); | 62 | "Timeout trying to connect peers, test failed.\n"); |
64 | GNUNET_SCHEDULER_shutdown (); | 63 | GNUNET_SCHEDULER_shutdown(); |
65 | } | 64 | } |
66 | 65 | ||
67 | 66 | ||
@@ -75,87 +74,87 @@ timeout_error (void *cls) | |||
75 | * @return NULL | 74 | * @return NULL |
76 | */ | 75 | */ |
77 | static void * | 76 | static void * |
78 | notify_connect (void *cls, | 77 | notify_connect(void *cls, |
79 | const struct GNUNET_PeerIdentity *peer, | 78 | const struct GNUNET_PeerIdentity *peer, |
80 | struct GNUNET_MQ_Handle *mq) | 79 | struct GNUNET_MQ_Handle *mq) |
81 | { | 80 | { |
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); | 81 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
83 | ok = 0; | 82 | ok = 0; |
84 | GNUNET_SCHEDULER_shutdown (); | 83 | GNUNET_SCHEDULER_shutdown(); |
85 | return NULL; | 84 | return NULL; |
86 | } | 85 | } |
87 | 86 | ||
88 | 87 | ||
89 | static void | 88 | static void |
90 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) | 89 | process_hello(void *cls, const struct GNUNET_MessageHeader *message) |
91 | { | 90 | { |
92 | struct PeerContext *p = cls; | 91 | struct PeerContext *p = cls; |
93 | 92 | ||
94 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); | 93 | GNUNET_TRANSPORT_hello_get_cancel(p->ghh); |
95 | p->ghh = NULL; | 94 | p->ghh = NULL; |
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 95 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
97 | "Received HELLO, starting hostlist service.\n"); | 96 | "Received HELLO, starting hostlist service.\n"); |
98 | } | 97 | } |
99 | 98 | ||
100 | 99 | ||
101 | static void | 100 | static void |
102 | setup_peer (struct PeerContext *p, const char *cfgname) | 101 | setup_peer(struct PeerContext *p, const char *cfgname) |
103 | { | 102 | { |
104 | char *binary; | 103 | char *binary; |
105 | 104 | ||
106 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 105 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
107 | p->cfg = GNUNET_CONFIGURATION_create (); | 106 | p->cfg = GNUNET_CONFIGURATION_create(); |
108 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, | 107 | p->arm_proc = GNUNET_OS_start_process(GNUNET_YES, |
109 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 108 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
110 | NULL, | 109 | NULL, |
111 | NULL, | 110 | NULL, |
112 | NULL, | 111 | NULL, |
113 | binary, | 112 | binary, |
114 | "gnunet-service-arm", | 113 | "gnunet-service-arm", |
115 | "-c", | 114 | "-c", |
116 | cfgname, | 115 | cfgname, |
117 | NULL); | 116 | NULL); |
118 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 117 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname)); |
119 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, | 118 | p->th = GNUNET_TRANSPORT_core_connect(p->cfg, |
120 | NULL, | 119 | NULL, |
121 | NULL, | 120 | NULL, |
122 | p, | 121 | p, |
123 | ¬ify_connect, | 122 | ¬ify_connect, |
124 | NULL, | 123 | NULL, |
125 | NULL); | 124 | NULL); |
126 | GNUNET_assert (NULL != p->th); | 125 | GNUNET_assert(NULL != p->th); |
127 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, | 126 | p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, |
128 | GNUNET_TRANSPORT_AC_ANY, | 127 | GNUNET_TRANSPORT_AC_ANY, |
129 | &process_hello, | 128 | &process_hello, |
130 | p); | 129 | p); |
131 | GNUNET_free (binary); | 130 | GNUNET_free(binary); |
132 | } | 131 | } |
133 | 132 | ||
134 | 133 | ||
135 | static void | 134 | static void |
136 | waitpid_task (void *cls) | 135 | waitpid_task(void *cls) |
137 | { | 136 | { |
138 | struct PeerContext *p = cls; | 137 | struct PeerContext *p = cls; |
139 | 138 | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | 139 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
141 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | 140 | if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG)) |
142 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 141 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
143 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) | 142 | if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) |
144 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 143 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
146 | "ARM process %u stopped\n", | 145 | "ARM process %u stopped\n", |
147 | GNUNET_OS_process_get_pid (p->arm_proc)); | 146 | GNUNET_OS_process_get_pid(p->arm_proc)); |
148 | GNUNET_OS_process_destroy (p->arm_proc); | 147 | GNUNET_OS_process_destroy(p->arm_proc); |
149 | p->arm_proc = NULL; | 148 | p->arm_proc = NULL; |
150 | GNUNET_CONFIGURATION_destroy (p->cfg); | 149 | GNUNET_CONFIGURATION_destroy(p->cfg); |
151 | } | 150 | } |
152 | 151 | ||
153 | 152 | ||
154 | static void | 153 | static void |
155 | stop_arm (struct PeerContext *p) | 154 | stop_arm(struct PeerContext *p) |
156 | { | 155 | { |
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); | 156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); | 157 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
159 | } | 158 | } |
160 | 159 | ||
161 | 160 | ||
@@ -163,98 +162,99 @@ stop_arm (struct PeerContext *p) | |||
163 | * Try again to connect to transport service. | 162 | * Try again to connect to transport service. |
164 | */ | 163 | */ |
165 | static void | 164 | static void |
166 | shutdown_task (void *cls) | 165 | shutdown_task(void *cls) |
167 | { | 166 | { |
168 | if (NULL != timeout_task) | 167 | if (NULL != timeout_task) |
169 | { | 168 | { |
170 | GNUNET_SCHEDULER_cancel (timeout_task); | 169 | GNUNET_SCHEDULER_cancel(timeout_task); |
171 | timeout_task = NULL; | 170 | timeout_task = NULL; |
172 | } | 171 | } |
173 | if (NULL != p1.ghh) | 172 | if (NULL != p1.ghh) |
174 | { | 173 | { |
175 | GNUNET_TRANSPORT_hello_get_cancel (p1.ghh); | 174 | GNUNET_TRANSPORT_hello_get_cancel(p1.ghh); |
176 | p1.ghh = NULL; | 175 | p1.ghh = NULL; |
177 | } | 176 | } |
178 | if (NULL != p1.th) | 177 | if (NULL != p1.th) |
179 | { | 178 | { |
180 | GNUNET_TRANSPORT_core_disconnect (p1.th); | 179 | GNUNET_TRANSPORT_core_disconnect(p1.th); |
181 | p1.th = NULL; | 180 | p1.th = NULL; |
182 | } | 181 | } |
183 | if (NULL != p2.ghh) | 182 | if (NULL != p2.ghh) |
184 | { | 183 | { |
185 | GNUNET_TRANSPORT_hello_get_cancel (p2.ghh); | 184 | GNUNET_TRANSPORT_hello_get_cancel(p2.ghh); |
186 | p2.ghh = NULL; | 185 | p2.ghh = NULL; |
187 | } | 186 | } |
188 | if (NULL != p2.th) | 187 | if (NULL != p2.th) |
189 | { | 188 | { |
190 | GNUNET_TRANSPORT_core_disconnect (p2.th); | 189 | GNUNET_TRANSPORT_core_disconnect(p2.th); |
191 | p2.th = NULL; | 190 | p2.th = NULL; |
192 | } | 191 | } |
193 | stop_arm (&p1); | 192 | stop_arm(&p1); |
194 | stop_arm (&p2); | 193 | stop_arm(&p2); |
195 | } | 194 | } |
196 | 195 | ||
197 | 196 | ||
198 | static void | 197 | static void |
199 | run (void *cls, | 198 | run(void *cls, |
200 | char *const *args, | 199 | char *const *args, |
201 | const char *cfgfile, | 200 | const char *cfgfile, |
202 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 201 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
203 | { | 202 | { |
204 | GNUNET_assert (ok == 1); | 203 | GNUNET_assert(ok == 1); |
205 | ok++; | 204 | ok++; |
206 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); | 205 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL); |
207 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 206 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
208 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 207 | setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
209 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 208 | setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
210 | } | 209 | } |
211 | 210 | ||
212 | 211 | ||
213 | int | 212 | int |
214 | main (int argcx, char *argvx[]) | 213 | main(int argcx, char *argvx[]) |
215 | { | 214 | { |
216 | static char *const argv[] = {"test-gnunet-daemon-hostlist", | 215 | static char *const argv[] = { "test-gnunet-daemon-hostlist", |
217 | "-c", | 216 | "-c", |
218 | "test_gnunet_daemon_hostlist_data.conf", | 217 | "test_gnunet_daemon_hostlist_data.conf", |
219 | NULL}; | 218 | NULL }; |
220 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 219 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
221 | GNUNET_GETOPT_OPTION_END}; | 220 | GNUNET_GETOPT_OPTION_END |
222 | 221 | }; | |
223 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 222 | |
224 | "GNUNET_TEST_HOME"); | 223 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", |
225 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", | 224 | "GNUNET_TEST_HOME"); |
226 | "GNUNET_TEST_HOME"); | 225 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", |
227 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 226 | "GNUNET_TEST_HOME"); |
228 | "GNUNET_TEST_HOME"); | 227 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", |
229 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); | 228 | "GNUNET_TEST_HOME"); |
229 | GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL); | ||
230 | ok = 1; | 230 | ok = 1; |
231 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 231 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
232 | argv, | 232 | argv, |
233 | "test-gnunet-daemon-hostlist", | 233 | "test-gnunet-daemon-hostlist", |
234 | "nohelp", | 234 | "nohelp", |
235 | options, | 235 | options, |
236 | &run, | 236 | &run, |
237 | &ok); | 237 | &ok); |
238 | if (0 == ok) | 238 | if (0 == ok) |
239 | { | 239 | { |
240 | fprintf (stderr, "%s", "."); | 240 | fprintf(stderr, "%s", "."); |
241 | /* now do it again */ | 241 | /* now do it again */ |
242 | ok = 1; | 242 | ok = 1; |
243 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 243 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
244 | argv, | 244 | argv, |
245 | "test-gnunet-daemon-hostlist", | 245 | "test-gnunet-daemon-hostlist", |
246 | "nohelp", | 246 | "nohelp", |
247 | options, | 247 | options, |
248 | &run, | 248 | &run, |
249 | &ok); | 249 | &ok); |
250 | fprintf (stderr, "%s", ".\n"); | 250 | fprintf(stderr, "%s", ".\n"); |
251 | } | 251 | } |
252 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 252 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", |
253 | "GNUNET_TEST_HOME"); | 253 | "GNUNET_TEST_HOME"); |
254 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", | 254 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", |
255 | "GNUNET_TEST_HOME"); | 255 | "GNUNET_TEST_HOME"); |
256 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 256 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", |
257 | "GNUNET_TEST_HOME"); | 257 | "GNUNET_TEST_HOME"); |
258 | return ok; | 258 | return ok; |
259 | } | 259 | } |
260 | 260 | ||