diff options
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r-- | src/hostlist/hostlist-client.c | 1377 |
1 files changed, 661 insertions, 716 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index f104e79d4..422855f0e 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c | |||
@@ -58,12 +58,12 @@ struct Hostlist | |||
58 | /** | 58 | /** |
59 | * previous entry, used to manage entries in a double linked list | 59 | * previous entry, used to manage entries in a double linked list |
60 | */ | 60 | */ |
61 | struct Hostlist * prev; | 61 | struct Hostlist *prev; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * next entry, used to manage entries in a double linked list | 64 | * next entry, used to manage entries in a double linked list |
65 | */ | 65 | */ |
66 | struct Hostlist * next; | 66 | struct Hostlist *next; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * URI where hostlist can be obtained | 69 | * URI where hostlist can be obtained |
@@ -111,13 +111,13 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
111 | /** | 111 | /** |
112 | * Statistics handle. | 112 | * Statistics handle. |
113 | */ | 113 | */ |
114 | static struct GNUNET_STATISTICS_Handle *stats; | 114 | static struct GNUNET_STATISTICS_Handle *stats; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Transport handle. | 117 | * Transport handle. |
118 | */ | 118 | */ |
119 | static struct GNUNET_TRANSPORT_Handle *transport; | 119 | static struct GNUNET_TRANSPORT_Handle *transport; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Proxy that we are using (can be NULL). | 122 | * Proxy that we are using (can be NULL). |
123 | */ | 123 | */ |
@@ -186,17 +186,17 @@ static struct GNUNET_TIME_Absolute end_time; | |||
186 | /** | 186 | /** |
187 | * Head of the linked list used to store hostlists | 187 | * Head of the linked list used to store hostlists |
188 | */ | 188 | */ |
189 | static struct Hostlist * linked_list_head; | 189 | static struct Hostlist *linked_list_head; |
190 | 190 | ||
191 | /** | 191 | /** |
192 | * Tail of the linked list used to store hostlists | 192 | * Tail of the linked list used to store hostlists |
193 | */ | 193 | */ |
194 | static struct Hostlist * linked_list_tail; | 194 | static struct Hostlist *linked_list_tail; |
195 | 195 | ||
196 | /** | 196 | /** |
197 | * Current hostlist used for downloading | 197 | * Current hostlist used for downloading |
198 | */ | 198 | */ |
199 | static struct Hostlist * current_hostlist; | 199 | static struct Hostlist *current_hostlist; |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Size of the linke list used to store hostlists | 202 | * Size of the linke list used to store hostlists |
@@ -206,7 +206,7 @@ static unsigned int linked_list_size; | |||
206 | /** | 206 | /** |
207 | * Head of the linked list used to store hostlists | 207 | * Head of the linked list used to store hostlists |
208 | */ | 208 | */ |
209 | static struct Hostlist * hostlist_to_test; | 209 | static struct Hostlist *hostlist_to_test; |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * Set to GNUNET_YES if the current URL had some problems. | 212 | * Set to GNUNET_YES if the current URL had some problems. |
@@ -232,6 +232,7 @@ static int stat_download_in_progress; | |||
232 | * Value saying if a preconfigured bootstrap server is used | 232 | * Value saying if a preconfigured bootstrap server is used |
233 | */ | 233 | */ |
234 | static unsigned int stat_use_bootstrap; | 234 | static unsigned int stat_use_bootstrap; |
235 | |||
235 | /** | 236 | /** |
236 | * Set if we are allowed to learn new hostlists and use them | 237 | * Set if we are allowed to learn new hostlists and use them |
237 | */ | 238 | */ |
@@ -263,13 +264,10 @@ static unsigned int stat_connection_count; | |||
263 | * @return number of bytes that were processed (always size*nmemb) | 264 | * @return number of bytes that were processed (always size*nmemb) |
264 | */ | 265 | */ |
265 | static size_t | 266 | static size_t |
266 | callback_download (void *ptr, | 267 | callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) |
267 | size_t size, | ||
268 | size_t nmemb, | ||
269 | void *ctx) | ||
270 | { | 268 | { |
271 | static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 269 | static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
272 | const char * cbuf = ptr; | 270 | const char *cbuf = ptr; |
273 | const struct GNUNET_MessageHeader *msg; | 271 | const struct GNUNET_MessageHeader *msg; |
274 | size_t total; | 272 | size_t total; |
275 | size_t cpy; | 273 | size_t cpy; |
@@ -278,85 +276,78 @@ callback_download (void *ptr, | |||
278 | 276 | ||
279 | total = size * nmemb; | 277 | total = size * nmemb; |
280 | stat_bytes_downloaded += total; | 278 | stat_bytes_downloaded += total; |
281 | if ( (total == 0) || (stat_bogus_url) ) | 279 | if ((total == 0) || (stat_bogus_url)) |
282 | { | 280 | { |
283 | return total; /* ok, no data or bogus data */ | 281 | return total; /* ok, no data or bogus data */ |
284 | } | 282 | } |
285 | 283 | ||
286 | GNUNET_STATISTICS_update (stats, | 284 | GNUNET_STATISTICS_update (stats, |
287 | gettext_noop ("# bytes downloaded from hostlist servers"), | 285 | gettext_noop |
288 | (int64_t) total, | 286 | ("# bytes downloaded from hostlist servers"), |
289 | GNUNET_NO); | 287 | (int64_t) total, GNUNET_NO); |
290 | left = total; | 288 | left = total; |
291 | while ( (left > 0) || | 289 | while ((left > 0) || (download_pos > 0)) |
292 | (download_pos > 0) ) | 290 | { |
291 | cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - download_pos); | ||
292 | memcpy (&download_buffer[download_pos], cbuf, cpy); | ||
293 | cbuf += cpy; | ||
294 | download_pos += cpy; | ||
295 | left -= cpy; | ||
296 | if (download_pos < sizeof (struct GNUNET_MessageHeader)) | ||
297 | { | ||
298 | GNUNET_assert (left == 0); | ||
299 | break; | ||
300 | } | ||
301 | msg = (const struct GNUNET_MessageHeader *) download_buffer; | ||
302 | msize = ntohs (msg->size); | ||
303 | if (msize < sizeof (struct GNUNET_MessageHeader)) | ||
304 | { | ||
305 | GNUNET_STATISTICS_update (stats, | ||
306 | gettext_noop | ||
307 | ("# invalid HELLOs downloaded from hostlist servers"), | ||
308 | 1, GNUNET_NO); | ||
309 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
310 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
311 | "HELLO", current_url); | ||
312 | stat_hellos_obtained++; | ||
313 | stat_bogus_url = 1; | ||
314 | return total; | ||
315 | } | ||
316 | if (download_pos < msize) | ||
317 | { | ||
318 | GNUNET_assert (left == 0); | ||
319 | break; | ||
320 | } | ||
321 | if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize) | ||
293 | { | 322 | { |
294 | cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - download_pos); | ||
295 | memcpy (&download_buffer[download_pos], | ||
296 | cbuf, | ||
297 | cpy); | ||
298 | cbuf += cpy; | ||
299 | download_pos += cpy; | ||
300 | left -= cpy; | ||
301 | if (download_pos < sizeof(struct GNUNET_MessageHeader)) | ||
302 | { | ||
303 | GNUNET_assert (left == 0); | ||
304 | break; | ||
305 | } | ||
306 | msg = (const struct GNUNET_MessageHeader *) download_buffer; | ||
307 | msize = ntohs(msg->size); | ||
308 | if (msize < sizeof(struct GNUNET_MessageHeader)) | ||
309 | { | ||
310 | GNUNET_STATISTICS_update (stats, | ||
311 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | ||
312 | 1, | ||
313 | GNUNET_NO); | ||
314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
315 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
316 | "HELLO", | ||
317 | current_url); | ||
318 | stat_hellos_obtained++; | ||
319 | stat_bogus_url = 1; | ||
320 | return total; | ||
321 | } | ||
322 | if (download_pos < msize) | ||
323 | { | ||
324 | GNUNET_assert (left == 0); | ||
325 | break; | ||
326 | } | ||
327 | if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*)msg) == msize) | ||
328 | { | ||
329 | #if DEBUG_HOSTLIST_CLIENT | 323 | #if DEBUG_HOSTLIST_CLIENT |
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
331 | "Received valid `%s' message from hostlist server.\n", | 325 | "Received valid `%s' message from hostlist server.\n", |
332 | "HELLO"); | 326 | "HELLO"); |
333 | #endif | 327 | #endif |
334 | GNUNET_STATISTICS_update (stats, | 328 | GNUNET_STATISTICS_update (stats, |
335 | gettext_noop ("# valid HELLOs downloaded from hostlist servers"), | 329 | gettext_noop |
336 | 1, | 330 | ("# valid HELLOs downloaded from hostlist servers"), |
337 | GNUNET_NO); | 331 | 1, GNUNET_NO); |
338 | stat_hellos_obtained++; | 332 | stat_hellos_obtained++; |
339 | GNUNET_TRANSPORT_offer_hello (transport, msg, NULL, NULL); | 333 | GNUNET_TRANSPORT_offer_hello (transport, msg, NULL, NULL); |
340 | } | ||
341 | else | ||
342 | { | ||
343 | GNUNET_STATISTICS_update (stats, | ||
344 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | ||
345 | 1, | ||
346 | GNUNET_NO); | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
348 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
349 | "HELLO", | ||
350 | current_url); | ||
351 | stat_bogus_url = GNUNET_YES; | ||
352 | stat_hellos_obtained++; | ||
353 | return total; | ||
354 | } | ||
355 | memmove (download_buffer, | ||
356 | &download_buffer[msize], | ||
357 | download_pos - msize); | ||
358 | download_pos -= msize; | ||
359 | } | 334 | } |
335 | else | ||
336 | { | ||
337 | GNUNET_STATISTICS_update (stats, | ||
338 | gettext_noop | ||
339 | ("# invalid HELLOs downloaded from hostlist servers"), | ||
340 | 1, GNUNET_NO); | ||
341 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
342 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
343 | "HELLO", current_url); | ||
344 | stat_bogus_url = GNUNET_YES; | ||
345 | stat_hellos_obtained++; | ||
346 | return total; | ||
347 | } | ||
348 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); | ||
349 | download_pos -= msize; | ||
350 | } | ||
360 | return total; | 351 | return total; |
361 | } | 352 | } |
362 | 353 | ||
@@ -374,55 +365,55 @@ get_bootstrap_server () | |||
374 | size_t urls; | 365 | size_t urls; |
375 | size_t pos; | 366 | size_t pos; |
376 | 367 | ||
377 | if (GNUNET_OK != | 368 | if (GNUNET_OK != |
378 | GNUNET_CONFIGURATION_get_value_string (cfg, | 369 | GNUNET_CONFIGURATION_get_value_string (cfg, |
379 | "HOSTLIST", | 370 | "HOSTLIST", "SERVERS", &servers)) |
380 | "SERVERS", | 371 | { |
381 | &servers)) | 372 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
382 | { | 373 | _ |
383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 374 | ("No `%s' specified in `%s' configuration, will not bootstrap.\n"), |
384 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), | 375 | "SERVERS", "HOSTLIST"); |
385 | "SERVERS", "HOSTLIST"); | 376 | return NULL; |
386 | return NULL; | 377 | } |
387 | } | ||
388 | 378 | ||
389 | urls = 0; | 379 | urls = 0; |
390 | if (strlen (servers) > 0) | 380 | if (strlen (servers) > 0) |
381 | { | ||
382 | urls++; | ||
383 | pos = strlen (servers) - 1; | ||
384 | while (pos > 0) | ||
391 | { | 385 | { |
392 | urls++; | 386 | if (servers[pos] == ' ') |
393 | pos = strlen (servers) - 1; | 387 | urls++; |
394 | while (pos > 0) | 388 | pos--; |
395 | { | ||
396 | if (servers[pos] == ' ') | ||
397 | urls++; | ||
398 | pos--; | ||
399 | } | ||
400 | } | 389 | } |
390 | } | ||
401 | if (urls == 0) | 391 | if (urls == 0) |
402 | { | 392 | { |
403 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 393 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
404 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), | 394 | _ |
405 | "SERVERS", "HOSTLIST"); | 395 | ("No `%s' specified in `%s' configuration, will not bootstrap.\n"), |
406 | GNUNET_free (servers); | 396 | "SERVERS", "HOSTLIST"); |
407 | return NULL; | 397 | GNUNET_free (servers); |
408 | } | 398 | return NULL; |
399 | } | ||
409 | 400 | ||
410 | urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; | 401 | urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; |
411 | pos = strlen (servers) - 1; | 402 | pos = strlen (servers) - 1; |
412 | while (pos > 0) | 403 | while (pos > 0) |
404 | { | ||
405 | if (servers[pos] == ' ') | ||
413 | { | 406 | { |
414 | if (servers[pos] == ' ') | 407 | urls--; |
415 | { | 408 | servers[pos] = '\0'; |
416 | urls--; | ||
417 | servers[pos] = '\0'; | ||
418 | } | ||
419 | if (urls == 0) | ||
420 | { | ||
421 | pos++; | ||
422 | break; | ||
423 | } | ||
424 | pos--; | ||
425 | } | 409 | } |
410 | if (urls == 0) | ||
411 | { | ||
412 | pos++; | ||
413 | break; | ||
414 | } | ||
415 | pos--; | ||
416 | } | ||
426 | ret = GNUNET_strdup (&servers[pos]); | 417 | ret = GNUNET_strdup (&servers[pos]); |
427 | GNUNET_free (servers); | 418 | GNUNET_free (servers); |
428 | return ret; | 419 | return ret; |
@@ -437,45 +428,44 @@ download_get_url () | |||
437 | { | 428 | { |
438 | uint32_t index; | 429 | uint32_t index; |
439 | unsigned int counter; | 430 | unsigned int counter; |
440 | struct Hostlist * pos; | 431 | struct Hostlist *pos; |
441 | 432 | ||
442 | if ( GNUNET_NO == stat_learning) | 433 | if (GNUNET_NO == stat_learning) |
443 | { | 434 | { |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
445 | "Using preconfigured bootstrap server\n"); | 436 | "Using preconfigured bootstrap server\n"); |
446 | current_hostlist = NULL; | 437 | current_hostlist = NULL; |
447 | return get_bootstrap_server(); | 438 | return get_bootstrap_server (); |
448 | } | 439 | } |
449 | 440 | ||
450 | if ( ( GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test) ) | 441 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) |
451 | { | 442 | { |
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
453 | "Testing new advertised hostlist if it is obtainable\n"); | 444 | "Testing new advertised hostlist if it is obtainable\n"); |
454 | current_hostlist = hostlist_to_test; | 445 | current_hostlist = hostlist_to_test; |
455 | return strdup(hostlist_to_test->hostlist_uri); | 446 | return strdup (hostlist_to_test->hostlist_uri); |
456 | } | 447 | } |
457 | 448 | ||
458 | if ( (GNUNET_YES == stat_use_bootstrap) || | 449 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) |
459 | (linked_list_size == 0) ) | ||
460 | { | 450 | { |
461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
462 | "Using preconfigured bootstrap server\n"); | 452 | "Using preconfigured bootstrap server\n"); |
463 | current_hostlist = NULL; | 453 | current_hostlist = NULL; |
464 | return get_bootstrap_server(); | 454 | return get_bootstrap_server (); |
465 | } | 455 | } |
466 | index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 456 | index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
467 | linked_list_size); | 457 | linked_list_size); |
468 | counter = 0; | 458 | counter = 0; |
469 | pos = linked_list_head; | 459 | pos = linked_list_head; |
470 | while ( counter < index ) | 460 | while (counter < index) |
471 | { | 461 | { |
472 | pos = pos->next; | 462 | pos = pos->next; |
473 | counter ++; | 463 | counter++; |
474 | } | 464 | } |
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
476 | "Using learned hostlist `%s'\n", pos->hostlist_uri); | 466 | "Using learned hostlist `%s'\n", pos->hostlist_uri); |
477 | current_hostlist = pos; | 467 | current_hostlist = pos; |
478 | return strdup(pos->hostlist_uri); | 468 | return strdup (pos->hostlist_uri); |
479 | } | 469 | } |
480 | 470 | ||
481 | 471 | ||
@@ -486,7 +476,7 @@ download_get_url () | |||
486 | * Method to save hostlist to a file during hostlist client shutdown | 476 | * Method to save hostlist to a file during hostlist client shutdown |
487 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 477 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
488 | */ | 478 | */ |
489 | static void save_hostlist_file ( int shutdown ); | 479 | static void save_hostlist_file (int shutdown); |
490 | 480 | ||
491 | 481 | ||
492 | /** | 482 | /** |
@@ -495,7 +485,8 @@ static void save_hostlist_file ( int shutdown ); | |||
495 | * @param val2 value 2 | 485 | * @param val2 value 2 |
496 | * @return result | 486 | * @return result |
497 | */ | 487 | */ |
498 | static uint64_t checked_add (uint64_t val1, uint64_t val2) | 488 | static uint64_t |
489 | checked_add (uint64_t val1, uint64_t val2) | ||
499 | { | 490 | { |
500 | static uint64_t temp; | 491 | static uint64_t temp; |
501 | static uint64_t maxv; | 492 | static uint64_t maxv; |
@@ -503,8 +494,8 @@ static uint64_t checked_add (uint64_t val1, uint64_t val2) | |||
503 | maxv = 0; | 494 | maxv = 0; |
504 | maxv--; | 495 | maxv--; |
505 | 496 | ||
506 | temp = val1+val2; | 497 | temp = val1 + val2; |
507 | if ( temp < val1) | 498 | if (temp < val1) |
508 | return maxv; | 499 | return maxv; |
509 | else | 500 | else |
510 | return temp; | 501 | return temp; |
@@ -516,14 +507,13 @@ static uint64_t checked_add (uint64_t val1, uint64_t val2) | |||
516 | * @param val2 value 2 | 507 | * @param val2 value 2 |
517 | * @return result | 508 | * @return result |
518 | */ | 509 | */ |
519 | static uint64_t | 510 | static uint64_t |
520 | checked_sub (uint64_t val1, | 511 | checked_sub (uint64_t val1, uint64_t val2) |
521 | uint64_t val2) | ||
522 | { | 512 | { |
523 | if ( val1 <= val2) | 513 | if (val1 <= val2) |
524 | return 0; | 514 | return 0; |
525 | else | 515 | else |
526 | return (val1-val2); | 516 | return (val1 - val2); |
527 | } | 517 | } |
528 | 518 | ||
529 | /** | 519 | /** |
@@ -532,17 +522,17 @@ checked_sub (uint64_t val1, | |||
532 | * @return GNUNET_YES if existing in linked list, GNUNET_NO if not | 522 | * @return GNUNET_YES if existing in linked list, GNUNET_NO if not |
533 | */ | 523 | */ |
534 | static int | 524 | static int |
535 | linked_list_contains (const char * uri) | 525 | linked_list_contains (const char *uri) |
536 | { | 526 | { |
537 | struct Hostlist * pos; | 527 | struct Hostlist *pos; |
538 | 528 | ||
539 | pos = linked_list_head; | 529 | pos = linked_list_head; |
540 | while (pos != NULL) | 530 | while (pos != NULL) |
541 | { | 531 | { |
542 | if (0 == strcmp(pos->hostlist_uri, uri) ) | 532 | if (0 == strcmp (pos->hostlist_uri, uri)) |
543 | return GNUNET_YES; | 533 | return GNUNET_YES; |
544 | pos = pos->next; | 534 | pos = pos->next; |
545 | } | 535 | } |
546 | return GNUNET_NO; | 536 | return GNUNET_NO; |
547 | } | 537 | } |
548 | 538 | ||
@@ -552,21 +542,21 @@ linked_list_contains (const char * uri) | |||
552 | * @return hostlist with lowest quality | 542 | * @return hostlist with lowest quality |
553 | */ | 543 | */ |
554 | static struct Hostlist * | 544 | static struct Hostlist * |
555 | linked_list_get_lowest_quality ( ) | 545 | linked_list_get_lowest_quality () |
556 | { | 546 | { |
557 | struct Hostlist * pos; | 547 | struct Hostlist *pos; |
558 | struct Hostlist * lowest; | 548 | struct Hostlist *lowest; |
559 | 549 | ||
560 | if (linked_list_size == 0) | 550 | if (linked_list_size == 0) |
561 | return NULL; | 551 | return NULL; |
562 | lowest = linked_list_head; | 552 | lowest = linked_list_head; |
563 | pos = linked_list_head->next; | 553 | pos = linked_list_head->next; |
564 | while (pos != NULL) | 554 | while (pos != NULL) |
565 | { | 555 | { |
566 | if (pos->quality < lowest->quality) | 556 | if (pos->quality < lowest->quality) |
567 | lowest = pos; | 557 | lowest = pos; |
568 | pos = pos->next; | 558 | pos = pos->next; |
569 | } | 559 | } |
570 | return lowest; | 560 | return lowest; |
571 | } | 561 | } |
572 | 562 | ||
@@ -579,29 +569,28 @@ linked_list_get_lowest_quality ( ) | |||
579 | static void | 569 | static void |
580 | insert_hostlist () | 570 | insert_hostlist () |
581 | { | 571 | { |
582 | struct Hostlist * lowest_quality; | 572 | struct Hostlist *lowest_quality; |
583 | 573 | ||
584 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) | 574 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) |
585 | { | 575 | { |
586 | /* No free entries available, replace existing entry */ | 576 | /* No free entries available, replace existing entry */ |
587 | lowest_quality = linked_list_get_lowest_quality(); | 577 | lowest_quality = linked_list_get_lowest_quality (); |
588 | GNUNET_assert (lowest_quality != NULL); | 578 | GNUNET_assert (lowest_quality != NULL); |
589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
590 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", | 580 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", |
591 | lowest_quality->hostlist_uri, | 581 | lowest_quality->hostlist_uri, |
592 | (unsigned long long) lowest_quality->quality); | 582 | (unsigned long long) lowest_quality->quality); |
593 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, lowest_quality); | 583 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, |
594 | linked_list_size--; | 584 | lowest_quality); |
595 | GNUNET_free (lowest_quality); | 585 | linked_list_size--; |
596 | } | 586 | GNUNET_free (lowest_quality); |
597 | GNUNET_CONTAINER_DLL_insert(linked_list_head, | 587 | } |
598 | linked_list_tail, | 588 | GNUNET_CONTAINER_DLL_insert (linked_list_head, |
599 | hostlist_to_test); | 589 | linked_list_tail, hostlist_to_test); |
600 | linked_list_size++; | 590 | linked_list_size++; |
601 | GNUNET_STATISTICS_set (stats, | 591 | GNUNET_STATISTICS_set (stats, |
602 | gettext_noop("# advertised hostlist URIs"), | 592 | gettext_noop ("# advertised hostlist URIs"), |
603 | linked_list_size, | 593 | linked_list_size, GNUNET_NO); |
604 | GNUNET_NO); | ||
605 | stat_testing_hostlist = GNUNET_NO; | 594 | stat_testing_hostlist = GNUNET_NO; |
606 | } | 595 | } |
607 | 596 | ||
@@ -609,33 +598,36 @@ insert_hostlist () | |||
609 | /** | 598 | /** |
610 | * Method updating hostlist statistics | 599 | * Method updating hostlist statistics |
611 | */ | 600 | */ |
612 | static void update_hostlist ( ) | 601 | static void |
602 | update_hostlist () | ||
613 | { | 603 | { |
614 | char *stat; | 604 | char *stat; |
615 | if ( ((stat_use_bootstrap == GNUNET_NO) && ( NULL != current_hostlist )) || | 605 | |
616 | ((stat_testing_hostlist == GNUNET_YES) && ( NULL != current_hostlist )) ) | 606 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || |
607 | ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist))) | ||
617 | { | 608 | { |
618 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 609 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
619 | "Updating hostlist statics for URI `%s'\n",current_hostlist->hostlist_uri ); | 610 | "Updating hostlist statics for URI `%s'\n", |
620 | current_hostlist->hello_count = stat_hellos_obtained; | 611 | current_hostlist->hostlist_uri); |
621 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get(); | 612 | current_hostlist->hello_count = stat_hellos_obtained; |
622 | current_hostlist->quality = checked_add ( current_hostlist->quality, (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); | 613 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get (); |
623 | if ( GNUNET_YES == stat_download_successful ) | 614 | current_hostlist->quality = |
624 | { | 615 | checked_add (current_hostlist->quality, |
625 | current_hostlist->times_used++; | 616 | (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); |
626 | current_hostlist->quality = checked_add ( current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); | 617 | if (GNUNET_YES == stat_download_successful) |
627 | GNUNET_asprintf (&stat, | 618 | { |
628 | gettext_noop("# advertised URI `%s' downloaded"), | 619 | current_hostlist->times_used++; |
629 | current_hostlist->hostlist_uri); | 620 | current_hostlist->quality = |
630 | 621 | checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); | |
631 | GNUNET_STATISTICS_update ( stats, | 622 | GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"), |
632 | stat, | 623 | current_hostlist->hostlist_uri); |
633 | 1, | 624 | |
634 | GNUNET_YES); | 625 | GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES); |
635 | GNUNET_free (stat); | 626 | GNUNET_free (stat); |
636 | } | 627 | } |
637 | else | 628 | else |
638 | current_hostlist->quality = checked_sub ( current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD ); | 629 | current_hostlist->quality = |
630 | checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); | ||
639 | } | 631 | } |
640 | current_hostlist = NULL; | 632 | current_hostlist = NULL; |
641 | /* Alternating the usage of preconfigured and learned hostlists */ | 633 | /* Alternating the usage of preconfigured and learned hostlists */ |
@@ -643,13 +635,13 @@ static void update_hostlist ( ) | |||
643 | if (stat_testing_hostlist == GNUNET_YES) | 635 | if (stat_testing_hostlist == GNUNET_YES) |
644 | return; | 636 | return; |
645 | 637 | ||
646 | if ( GNUNET_YES == stat_learning) | 638 | if (GNUNET_YES == stat_learning) |
647 | { | 639 | { |
648 | if (stat_use_bootstrap == GNUNET_YES) | 640 | if (stat_use_bootstrap == GNUNET_YES) |
649 | stat_use_bootstrap = GNUNET_NO; | 641 | stat_use_bootstrap = GNUNET_NO; |
650 | else | 642 | else |
651 | stat_use_bootstrap = GNUNET_YES; | 643 | stat_use_bootstrap = GNUNET_YES; |
652 | } | 644 | } |
653 | else | 645 | else |
654 | stat_use_bootstrap = GNUNET_YES; | 646 | stat_use_bootstrap = GNUNET_YES; |
655 | } | 647 | } |
@@ -658,53 +650,53 @@ static void update_hostlist ( ) | |||
658 | * Clean up the state from the task that downloaded the | 650 | * Clean up the state from the task that downloaded the |
659 | * hostlist and schedule the next task. | 651 | * hostlist and schedule the next task. |
660 | */ | 652 | */ |
661 | static void | 653 | static void |
662 | clean_up () | 654 | clean_up () |
663 | { | 655 | { |
664 | CURLMcode mret; | 656 | CURLMcode mret; |
665 | 657 | ||
666 | if ( (stat_testing_hostlist == GNUNET_YES) && | 658 | if ((stat_testing_hostlist == GNUNET_YES) && |
667 | (GNUNET_NO == stat_download_successful) && | 659 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) |
668 | (NULL != hostlist_to_test)) | ||
669 | { | 660 | { |
670 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 661 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
671 | _("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), | 662 | _ |
672 | hostlist_to_test->hostlist_uri); | 663 | ("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), |
664 | hostlist_to_test->hostlist_uri); | ||
673 | } | 665 | } |
674 | 666 | ||
675 | if (stat_testing_hostlist == GNUNET_YES) | 667 | if (stat_testing_hostlist == GNUNET_YES) |
676 | { | 668 | { |
677 | stat_testing_hostlist = GNUNET_NO; | 669 | stat_testing_hostlist = GNUNET_NO; |
678 | } | 670 | } |
679 | if ( NULL != hostlist_to_test) | 671 | if (NULL != hostlist_to_test) |
680 | { | 672 | { |
681 | GNUNET_free (hostlist_to_test); | 673 | GNUNET_free (hostlist_to_test); |
682 | hostlist_to_test = NULL; | 674 | hostlist_to_test = NULL; |
683 | } | 675 | } |
684 | 676 | ||
685 | if (multi != NULL) | 677 | if (multi != NULL) |
678 | { | ||
679 | mret = curl_multi_remove_handle (multi, curl); | ||
680 | if (mret != CURLM_OK) | ||
686 | { | 681 | { |
687 | mret = curl_multi_remove_handle (multi, curl); | 682 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
688 | if (mret != CURLM_OK) | 683 | _("%s failed at %s:%d: `%s'\n"), |
689 | { | 684 | "curl_multi_remove_handle", __FILE__, __LINE__, |
690 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 685 | curl_multi_strerror (mret)); |
691 | _("%s failed at %s:%d: `%s'\n"), | ||
692 | "curl_multi_remove_handle", __FILE__, __LINE__, | ||
693 | curl_multi_strerror (mret)); | ||
694 | } | ||
695 | mret = curl_multi_cleanup (multi); | ||
696 | if (mret != CURLM_OK) | ||
697 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
698 | _("%s failed at %s:%d: `%s'\n"), | ||
699 | "curl_multi_cleanup", __FILE__, __LINE__, | ||
700 | curl_multi_strerror (mret)); | ||
701 | multi = NULL; | ||
702 | } | 686 | } |
687 | mret = curl_multi_cleanup (multi); | ||
688 | if (mret != CURLM_OK) | ||
689 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
690 | _("%s failed at %s:%d: `%s'\n"), | ||
691 | "curl_multi_cleanup", __FILE__, __LINE__, | ||
692 | curl_multi_strerror (mret)); | ||
693 | multi = NULL; | ||
694 | } | ||
703 | if (curl != NULL) | 695 | if (curl != NULL) |
704 | { | 696 | { |
705 | curl_easy_cleanup (curl); | 697 | curl_easy_cleanup (curl); |
706 | curl = NULL; | 698 | curl = NULL; |
707 | } | 699 | } |
708 | GNUNET_free_non_null (current_url); | 700 | GNUNET_free_non_null (current_url); |
709 | current_url = NULL; | 701 | current_url = NULL; |
710 | stat_bytes_downloaded = 0; | 702 | stat_bytes_downloaded = 0; |
@@ -720,8 +712,7 @@ clean_up () | |||
720 | * @param tc task context, unused | 712 | * @param tc task context, unused |
721 | */ | 713 | */ |
722 | static void | 714 | static void |
723 | task_download (void *cls, | 715 | task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
724 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
725 | 716 | ||
726 | 717 | ||
727 | /** | 718 | /** |
@@ -747,27 +738,28 @@ download_prepare () | |||
747 | FD_ZERO (&es); | 738 | FD_ZERO (&es); |
748 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 739 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); |
749 | if (mret != CURLM_OK) | 740 | if (mret != CURLM_OK) |
750 | { | 741 | { |
751 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 742 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
752 | _("%s failed at %s:%d: `%s'\n"), | 743 | _("%s failed at %s:%d: `%s'\n"), |
753 | "curl_multi_fdset", __FILE__, __LINE__, | 744 | "curl_multi_fdset", __FILE__, __LINE__, |
754 | curl_multi_strerror (mret)); | 745 | curl_multi_strerror (mret)); |
755 | clean_up (); | 746 | clean_up (); |
756 | return; | 747 | return; |
757 | } | 748 | } |
758 | mret = curl_multi_timeout (multi, &timeout); | 749 | mret = curl_multi_timeout (multi, &timeout); |
759 | if (mret != CURLM_OK) | 750 | if (mret != CURLM_OK) |
760 | { | 751 | { |
761 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 752 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
762 | _("%s failed at %s:%d: `%s'\n"), | 753 | _("%s failed at %s:%d: `%s'\n"), |
763 | "curl_multi_timeout", __FILE__, __LINE__, | 754 | "curl_multi_timeout", __FILE__, __LINE__, |
764 | curl_multi_strerror (mret)); | 755 | curl_multi_strerror (mret)); |
765 | clean_up (); | 756 | clean_up (); |
766 | return; | 757 | return; |
767 | } | 758 | } |
768 | rtime = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time), | 759 | rtime = |
769 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 760 | GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time), |
770 | timeout)); | 761 | GNUNET_TIME_relative_multiply |
762 | (GNUNET_TIME_UNIT_MILLISECONDS, timeout)); | ||
771 | grs = GNUNET_NETWORK_fdset_create (); | 763 | grs = GNUNET_NETWORK_fdset_create (); |
772 | gws = GNUNET_NETWORK_fdset_create (); | 764 | gws = GNUNET_NETWORK_fdset_create (); |
773 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); | 765 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
@@ -777,13 +769,9 @@ download_prepare () | |||
777 | "Scheduling task for hostlist download using cURL\n"); | 769 | "Scheduling task for hostlist download using cURL\n"); |
778 | #endif | 770 | #endif |
779 | ti_download | 771 | ti_download |
780 | = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 772 | = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
781 | GNUNET_SCHEDULER_NO_TASK, | 773 | GNUNET_SCHEDULER_NO_TASK, |
782 | rtime, | 774 | rtime, grs, gws, &task_download, multi); |
783 | grs, | ||
784 | gws, | ||
785 | &task_download, | ||
786 | multi); | ||
787 | GNUNET_NETWORK_fdset_destroy (gws); | 775 | GNUNET_NETWORK_fdset_destroy (gws); |
788 | GNUNET_NETWORK_fdset_destroy (grs); | 776 | GNUNET_NETWORK_fdset_destroy (grs); |
789 | } | 777 | } |
@@ -797,108 +785,107 @@ download_prepare () | |||
797 | * @param tc task context, unused | 785 | * @param tc task context, unused |
798 | */ | 786 | */ |
799 | static void | 787 | static void |
800 | task_download (void *cls, | 788 | task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
801 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
802 | { | 789 | { |
803 | int running; | 790 | int running; |
804 | struct CURLMsg *msg; | 791 | struct CURLMsg *msg; |
805 | CURLMcode mret; | 792 | CURLMcode mret; |
806 | 793 | ||
807 | ti_download = GNUNET_SCHEDULER_NO_TASK; | 794 | ti_download = GNUNET_SCHEDULER_NO_TASK; |
808 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 795 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
809 | { | 796 | { |
810 | #if DEBUG_HOSTLIST_CLIENT | 797 | #if DEBUG_HOSTLIST_CLIENT |
811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
812 | "Shutdown requested while trying to download hostlist from `%s'\n", | 799 | "Shutdown requested while trying to download hostlist from `%s'\n", |
813 | current_url); | 800 | current_url); |
814 | #endif | 801 | #endif |
815 | update_hostlist(); | 802 | update_hostlist (); |
816 | clean_up (); | 803 | clean_up (); |
817 | return; | 804 | return; |
818 | } | 805 | } |
819 | if (GNUNET_TIME_absolute_get_remaining (end_time).rel_value == 0) | 806 | if (GNUNET_TIME_absolute_get_remaining (end_time).rel_value == 0) |
820 | { | 807 | { |
821 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 808 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
822 | _("Timeout trying to download hostlist from `%s'\n"), | 809 | _("Timeout trying to download hostlist from `%s'\n"), |
823 | current_url); | 810 | current_url); |
824 | update_hostlist(); | 811 | update_hostlist (); |
825 | clean_up (); | 812 | clean_up (); |
826 | return; | 813 | return; |
827 | } | 814 | } |
828 | #if DEBUG_HOSTLIST_CLIENT | 815 | #if DEBUG_HOSTLIST_CLIENT |
829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
830 | "Ready for processing hostlist client request\n"); | 817 | "Ready for processing hostlist client request\n"); |
831 | #endif | 818 | #endif |
832 | 819 | ||
833 | do | 820 | do |
821 | { | ||
822 | running = 0; | ||
823 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | ||
824 | { | ||
825 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
826 | _("Download limit of %u bytes exceeded, stopping download\n"), | ||
827 | MAX_BYTES_PER_HOSTLISTS); | ||
828 | clean_up (); | ||
829 | return; | ||
830 | } | ||
831 | mret = curl_multi_perform (multi, &running); | ||
832 | if (running == 0) | ||
834 | { | 833 | { |
835 | running = 0; | 834 | do |
836 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | 835 | { |
836 | msg = curl_multi_info_read (multi, &running); | ||
837 | GNUNET_break (msg != NULL); | ||
838 | if (msg == NULL) | ||
839 | break; | ||
840 | switch (msg->msg) | ||
837 | { | 841 | { |
838 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 842 | case CURLMSG_DONE: |
839 | _("Download limit of %u bytes exceeded, stopping download\n"), | 843 | if ((msg->data.result != CURLE_OK) && |
840 | MAX_BYTES_PER_HOSTLISTS); | 844 | (msg->data.result != CURLE_GOT_NOTHING)) |
841 | clean_up(); | 845 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
842 | return; | 846 | _("%s failed for `%s' at %s:%d: `%s'\n"), |
847 | "curl_multi_perform", | ||
848 | current_url, | ||
849 | __FILE__, | ||
850 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
851 | else | ||
852 | { | ||
853 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
854 | _("Download of hostlist `%s' completed.\n"), | ||
855 | current_url); | ||
856 | stat_download_successful = GNUNET_YES; | ||
857 | update_hostlist (); | ||
858 | if (GNUNET_YES == stat_testing_hostlist) | ||
859 | { | ||
860 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
861 | _ | ||
862 | ("Adding successfully tested hostlist `%s' datastore.\n"), | ||
863 | current_url); | ||
864 | insert_hostlist (); | ||
865 | hostlist_to_test = NULL; | ||
866 | stat_testing_hostlist = GNUNET_NO; | ||
867 | } | ||
868 | } | ||
869 | clean_up (); | ||
870 | return; | ||
871 | default: | ||
872 | break; | ||
843 | } | 873 | } |
844 | mret = curl_multi_perform (multi, &running); | 874 | |
845 | if (running == 0) | 875 | } |
846 | { | 876 | while ((running > 0)); |
847 | do | ||
848 | { | ||
849 | msg = curl_multi_info_read (multi, &running); | ||
850 | GNUNET_break (msg != NULL); | ||
851 | if (msg == NULL) | ||
852 | break; | ||
853 | switch (msg->msg) | ||
854 | { | ||
855 | case CURLMSG_DONE: | ||
856 | if ( (msg->data.result != CURLE_OK) && | ||
857 | (msg->data.result != CURLE_GOT_NOTHING) ) | ||
858 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
859 | _("%s failed for `%s' at %s:%d: `%s'\n"), | ||
860 | "curl_multi_perform", | ||
861 | current_url, | ||
862 | __FILE__, | ||
863 | __LINE__, | ||
864 | curl_easy_strerror (msg->data.result)); | ||
865 | else | ||
866 | { | ||
867 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
868 | _("Download of hostlist `%s' completed.\n"), | ||
869 | current_url); | ||
870 | stat_download_successful = GNUNET_YES; | ||
871 | update_hostlist(); | ||
872 | if (GNUNET_YES == stat_testing_hostlist) | ||
873 | { | ||
874 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
875 | _("Adding successfully tested hostlist `%s' datastore.\n"), | ||
876 | current_url); | ||
877 | insert_hostlist(); | ||
878 | hostlist_to_test = NULL; | ||
879 | stat_testing_hostlist = GNUNET_NO; | ||
880 | } | ||
881 | } | ||
882 | clean_up (); | ||
883 | return; | ||
884 | default: | ||
885 | break; | ||
886 | } | ||
887 | |||
888 | } | ||
889 | while ( (running > 0) ); | ||
890 | } | ||
891 | } | 877 | } |
878 | } | ||
892 | while (mret == CURLM_CALL_MULTI_PERFORM); | 879 | while (mret == CURLM_CALL_MULTI_PERFORM); |
893 | 880 | ||
894 | if (mret != CURLM_OK) | 881 | if (mret != CURLM_OK) |
895 | { | 882 | { |
896 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 883 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
897 | _("%s failed at %s:%d: `%s'\n"), | 884 | _("%s failed at %s:%d: `%s'\n"), |
898 | "curl_multi_perform", __FILE__, __LINE__, | 885 | "curl_multi_perform", __FILE__, __LINE__, |
899 | curl_multi_strerror (mret)); | 886 | curl_multi_strerror (mret)); |
900 | clean_up (); | 887 | clean_up (); |
901 | } | 888 | } |
902 | download_prepare (); | 889 | download_prepare (); |
903 | } | 890 | } |
904 | 891 | ||
@@ -908,7 +895,7 @@ task_download (void *cls, | |||
908 | * data. | 895 | * data. |
909 | */ | 896 | */ |
910 | static void | 897 | static void |
911 | download_hostlist () | 898 | download_hostlist () |
912 | { | 899 | { |
913 | CURLcode ret; | 900 | CURLcode ret; |
914 | CURLMcode mret; | 901 | CURLMcode mret; |
@@ -920,132 +907,110 @@ download_hostlist () | |||
920 | curl = curl_easy_init (); | 907 | curl = curl_easy_init (); |
921 | multi = NULL; | 908 | multi = NULL; |
922 | if (curl == NULL) | 909 | if (curl == NULL) |
923 | { | 910 | { |
924 | GNUNET_break (0); | 911 | GNUNET_break (0); |
925 | clean_up (); | 912 | clean_up (); |
926 | return; | 913 | return; |
927 | } | 914 | } |
928 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 915 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
929 | _("Bootstrapping using hostlist at `%s'.\n"), | 916 | _("Bootstrapping using hostlist at `%s'.\n"), current_url); |
930 | current_url); | ||
931 | 917 | ||
932 | stat_download_in_progress = GNUNET_YES; | 918 | stat_download_in_progress = GNUNET_YES; |
933 | stat_download_successful = GNUNET_NO; | 919 | stat_download_successful = GNUNET_NO; |
934 | stat_hellos_obtained = 0; | 920 | stat_hellos_obtained = 0; |
935 | stat_bytes_downloaded = 0; | 921 | stat_bytes_downloaded = 0; |
936 | 922 | ||
937 | GNUNET_STATISTICS_update (stats, | 923 | GNUNET_STATISTICS_update (stats, |
938 | gettext_noop ("# hostlist downloads initiated"), | 924 | gettext_noop ("# hostlist downloads initiated"), |
939 | 1, | 925 | 1, GNUNET_NO); |
940 | GNUNET_NO); | ||
941 | if (proxy != NULL) | 926 | if (proxy != NULL) |
942 | CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); | 927 | CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); |
943 | download_pos = 0; | 928 | download_pos = 0; |
944 | stat_bogus_url = 0; | 929 | stat_bogus_url = 0; |
945 | CURL_EASY_SETOPT (curl, | 930 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download); |
946 | CURLOPT_WRITEFUNCTION, | ||
947 | &callback_download); | ||
948 | if (ret != CURLE_OK) | 931 | if (ret != CURLE_OK) |
949 | { | 932 | { |
950 | clean_up (); | 933 | clean_up (); |
951 | return; | 934 | return; |
952 | } | 935 | } |
953 | CURL_EASY_SETOPT (curl, | 936 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL); |
954 | CURLOPT_WRITEDATA, | ||
955 | NULL); | ||
956 | if (ret != CURLE_OK) | 937 | if (ret != CURLE_OK) |
957 | { | 938 | { |
958 | clean_up (); | 939 | clean_up (); |
959 | return; | 940 | return; |
960 | } | 941 | } |
961 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); | 942 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); |
962 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); | 943 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); |
963 | /* no need to abort if the above failed */ | 944 | /* no need to abort if the above failed */ |
964 | CURL_EASY_SETOPT (curl, | 945 | CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url); |
965 | CURLOPT_URL, | ||
966 | current_url); | ||
967 | if (ret != CURLE_OK) | 946 | if (ret != CURLE_OK) |
968 | { | 947 | { |
969 | clean_up (); | 948 | clean_up (); |
970 | return; | 949 | return; |
971 | } | 950 | } |
972 | CURL_EASY_SETOPT (curl, | 951 | CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1); |
973 | CURLOPT_FAILONERROR, | ||
974 | 1); | ||
975 | #if 0 | 952 | #if 0 |
976 | CURL_EASY_SETOPT (curl, | 953 | CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1); |
977 | CURLOPT_VERBOSE, | ||
978 | 1); | ||
979 | #endif | 954 | #endif |
980 | CURL_EASY_SETOPT (curl, | 955 | CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE); |
981 | CURLOPT_BUFFERSIZE, | ||
982 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
983 | if (0 == strncmp (current_url, "http", 4)) | 956 | if (0 == strncmp (current_url, "http", 4)) |
984 | CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet"); | 957 | CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet"); |
985 | CURL_EASY_SETOPT (curl, | 958 | CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L); |
986 | CURLOPT_CONNECTTIMEOUT, | 959 | CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L); |
987 | 60L); | ||
988 | CURL_EASY_SETOPT (curl, | ||
989 | CURLOPT_TIMEOUT, | ||
990 | 60L); | ||
991 | #if 0 | 960 | #if 0 |
992 | /* this should no longer be needed; we're now single-threaded! */ | 961 | /* this should no longer be needed; we're now single-threaded! */ |
993 | CURL_EASY_SETOPT (curl, | 962 | CURL_EASY_SETOPT (curl, CURLOPT_NOSIGNAL, 1); |
994 | CURLOPT_NOSIGNAL, | ||
995 | 1); | ||
996 | #endif | 963 | #endif |
997 | multi = curl_multi_init (); | 964 | multi = curl_multi_init (); |
998 | if (multi == NULL) | 965 | if (multi == NULL) |
999 | { | 966 | { |
1000 | GNUNET_break (0); | 967 | GNUNET_break (0); |
1001 | /* clean_up (); */ | 968 | /* clean_up (); */ |
1002 | return; | 969 | return; |
1003 | } | 970 | } |
1004 | mret = curl_multi_add_handle (multi, curl); | 971 | mret = curl_multi_add_handle (multi, curl); |
1005 | if (mret != CURLM_OK) | 972 | if (mret != CURLM_OK) |
1006 | { | 973 | { |
974 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
975 | _("%s failed at %s:%d: `%s'\n"), | ||
976 | "curl_multi_add_handle", __FILE__, __LINE__, | ||
977 | curl_multi_strerror (mret)); | ||
978 | mret = curl_multi_cleanup (multi); | ||
979 | if (mret != CURLM_OK) | ||
1007 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 980 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1008 | _("%s failed at %s:%d: `%s'\n"), | 981 | _("%s failed at %s:%d: `%s'\n"), |
1009 | "curl_multi_add_handle", __FILE__, __LINE__, | 982 | "curl_multi_cleanup", __FILE__, __LINE__, |
1010 | curl_multi_strerror (mret)); | 983 | curl_multi_strerror (mret)); |
1011 | mret = curl_multi_cleanup (multi); | 984 | multi = NULL; |
1012 | if (mret != CURLM_OK) | 985 | clean_up (); |
1013 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 986 | return; |
1014 | _("%s failed at %s:%d: `%s'\n"), | 987 | } |
1015 | "curl_multi_cleanup", __FILE__, __LINE__, | ||
1016 | curl_multi_strerror (mret)); | ||
1017 | multi = NULL; | ||
1018 | clean_up (); | ||
1019 | return; | ||
1020 | } | ||
1021 | end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 988 | end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
1022 | download_prepare (); | 989 | download_prepare (); |
1023 | } | 990 | } |
1024 | 991 | ||
1025 | 992 | ||
1026 | static void | 993 | static void |
1027 | task_download_dispatcher (void *cls, | 994 | task_download_dispatcher (void *cls, |
1028 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 995 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1029 | { | 996 | { |
1030 | ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; | 997 | ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; |
1031 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 998 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1032 | return; | 999 | return; |
1033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); |
1034 | "Download is initiated...\n"); | 1001 | if (GNUNET_NO == stat_download_in_progress) |
1035 | if ( GNUNET_NO == stat_download_in_progress ) | 1002 | { |
1036 | { | 1003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); |
1037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1004 | download_hostlist (); |
1038 | "Download can start immediately...\n"); | 1005 | } |
1039 | download_hostlist(); | 1006 | else |
1040 | } | 1007 | { |
1041 | else | 1008 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1042 | { | 1009 | "Download in progess, have to wait...\n"); |
1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1010 | ti_download_dispatcher_task = |
1044 | "Download in progess, have to wait...\n"); | 1011 | GNUNET_SCHEDULER_add_delayed (WAITING_INTERVALL, |
1045 | ti_download_dispatcher_task = GNUNET_SCHEDULER_add_delayed (WAITING_INTERVALL, | 1012 | &task_download_dispatcher, NULL); |
1046 | &task_download_dispatcher, | 1013 | } |
1047 | NULL); | ||
1048 | } | ||
1049 | } | 1014 | } |
1050 | 1015 | ||
1051 | /** | 1016 | /** |
@@ -1054,8 +1019,7 @@ task_download_dispatcher (void *cls, | |||
1054 | * this task again for a later time. | 1019 | * this task again for a later time. |
1055 | */ | 1020 | */ |
1056 | static void | 1021 | static void |
1057 | task_check (void *cls, | 1022 | task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1058 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1059 | { | 1023 | { |
1060 | static int once; | 1024 | static int once; |
1061 | struct GNUNET_TIME_Relative delay; | 1025 | struct GNUNET_TIME_Relative delay; |
@@ -1066,40 +1030,40 @@ task_check (void *cls, | |||
1066 | 1030 | ||
1067 | if (stat_connection_count < MIN_CONNECTIONS) | 1031 | if (stat_connection_count < MIN_CONNECTIONS) |
1068 | { | 1032 | { |
1069 | ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (&task_download_dispatcher, | 1033 | ti_download_dispatcher_task = |
1070 | NULL); | 1034 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1071 | } | 1035 | } |
1072 | 1036 | ||
1073 | if (stats == NULL) | 1037 | if (stats == NULL) |
1074 | { | 1038 | { |
1075 | curl_global_cleanup (); | 1039 | curl_global_cleanup (); |
1076 | return; /* in shutdown */ | 1040 | return; /* in shutdown */ |
1077 | } | 1041 | } |
1078 | delay = hostlist_delay; | 1042 | delay = hostlist_delay; |
1079 | if (hostlist_delay.rel_value == 0) | 1043 | if (hostlist_delay.rel_value == 0) |
1080 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; | 1044 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; |
1081 | else | 1045 | else |
1082 | hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2); | 1046 | hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2); |
1083 | if (hostlist_delay.rel_value > GNUNET_TIME_UNIT_HOURS.rel_value * (1 + stat_connection_count)) | 1047 | if (hostlist_delay.rel_value > |
1084 | hostlist_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, | 1048 | GNUNET_TIME_UNIT_HOURS.rel_value * (1 + stat_connection_count)) |
1085 | (1 + stat_connection_count)); | 1049 | hostlist_delay = |
1050 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, | ||
1051 | (1 + stat_connection_count)); | ||
1086 | GNUNET_STATISTICS_set (stats, | 1052 | GNUNET_STATISTICS_set (stats, |
1087 | gettext_noop("# milliseconds between hostlist downloads"), | 1053 | gettext_noop |
1088 | hostlist_delay.rel_value, | 1054 | ("# milliseconds between hostlist downloads"), |
1089 | GNUNET_YES); | 1055 | hostlist_delay.rel_value, GNUNET_YES); |
1090 | if (0 == once) | 1056 | if (0 == once) |
1091 | { | 1057 | { |
1092 | delay = GNUNET_TIME_UNIT_ZERO; | 1058 | delay = GNUNET_TIME_UNIT_ZERO; |
1093 | once = 1; | 1059 | once = 1; |
1094 | } | 1060 | } |
1095 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1061 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1096 | _("Have %u/%u connections. Will consider downloading hostlist in %llums\n"), | 1062 | _ |
1097 | stat_connection_count, | 1063 | ("Have %u/%u connections. Will consider downloading hostlist in %llums\n"), |
1098 | MIN_CONNECTIONS, | 1064 | stat_connection_count, MIN_CONNECTIONS, |
1099 | (unsigned long long) delay.rel_value); | 1065 | (unsigned long long) delay.rel_value); |
1100 | ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, | 1066 | ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); |
1101 | &task_check, | ||
1102 | NULL); | ||
1103 | } | 1067 | } |
1104 | 1068 | ||
1105 | 1069 | ||
@@ -1111,14 +1075,14 @@ task_check (void *cls, | |||
1111 | */ | 1075 | */ |
1112 | static void | 1076 | static void |
1113 | task_testing_intervall_reset (void *cls, | 1077 | task_testing_intervall_reset (void *cls, |
1114 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1078 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1115 | { | 1079 | { |
1116 | ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; | 1080 | ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; |
1117 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1081 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1118 | return; | 1082 | return; |
1119 | stat_testing_allowed = GNUNET_OK; | 1083 | stat_testing_allowed = GNUNET_OK; |
1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1121 | "Testing new hostlist advertisements is allowed again\n"); | 1085 | "Testing new hostlist advertisements is allowed again\n"); |
1122 | } | 1086 | } |
1123 | 1087 | ||
1124 | 1088 | ||
@@ -1129,22 +1093,19 @@ task_testing_intervall_reset (void *cls, | |||
1129 | * @param tc TaskContext | 1093 | * @param tc TaskContext |
1130 | */ | 1094 | */ |
1131 | static void | 1095 | static void |
1132 | task_hostlist_saving (void *cls, | 1096 | task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1133 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1134 | { | 1097 | { |
1135 | ti_saving_task = GNUNET_SCHEDULER_NO_TASK; | 1098 | ti_saving_task = GNUNET_SCHEDULER_NO_TASK; |
1136 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1099 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1137 | return; | 1100 | return; |
1138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Scheduled saving of hostlists\n")); |
1139 | _("Scheduled saving of hostlists\n")); | 1102 | save_hostlist_file (GNUNET_NO); |
1140 | save_hostlist_file ( GNUNET_NO ); | ||
1141 | 1103 | ||
1142 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1104 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1143 | _("Hostlists will be saved to file again in %llums\n"), | 1105 | _("Hostlists will be saved to file again in %llums\n"), |
1144 | (unsigned long long) SAVING_INTERVALL.rel_value); | 1106 | (unsigned long long) SAVING_INTERVALL.rel_value); |
1145 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, | 1107 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, |
1146 | &task_hostlist_saving, | 1108 | &task_hostlist_saving, NULL); |
1147 | NULL); | ||
1148 | } | 1109 | } |
1149 | 1110 | ||
1150 | 1111 | ||
@@ -1157,16 +1118,15 @@ task_hostlist_saving (void *cls, | |||
1157 | */ | 1118 | */ |
1158 | static void | 1119 | static void |
1159 | handler_connect (void *cls, | 1120 | handler_connect (void *cls, |
1160 | const struct | 1121 | const struct |
1161 | GNUNET_PeerIdentity * peer, | 1122 | GNUNET_PeerIdentity *peer, |
1162 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1123 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1163 | { | 1124 | { |
1164 | GNUNET_assert (stat_connection_count < UINT_MAX); | 1125 | GNUNET_assert (stat_connection_count < UINT_MAX); |
1165 | stat_connection_count++; | 1126 | stat_connection_count++; |
1166 | GNUNET_STATISTICS_update (stats, | 1127 | GNUNET_STATISTICS_update (stats, |
1167 | gettext_noop ("# active connections"), | 1128 | gettext_noop ("# active connections"), |
1168 | 1, | 1129 | 1, GNUNET_NO); |
1169 | GNUNET_NO); | ||
1170 | } | 1130 | } |
1171 | 1131 | ||
1172 | 1132 | ||
@@ -1177,16 +1137,13 @@ handler_connect (void *cls, | |||
1177 | * @param peer peer identity this notification is about | 1137 | * @param peer peer identity this notification is about |
1178 | */ | 1138 | */ |
1179 | static void | 1139 | static void |
1180 | handler_disconnect (void *cls, | 1140 | handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
1181 | const struct | ||
1182 | GNUNET_PeerIdentity * peer) | ||
1183 | { | 1141 | { |
1184 | GNUNET_assert (stat_connection_count > 0); | 1142 | GNUNET_assert (stat_connection_count > 0); |
1185 | stat_connection_count--; | 1143 | stat_connection_count--; |
1186 | GNUNET_STATISTICS_update (stats, | 1144 | GNUNET_STATISTICS_update (stats, |
1187 | gettext_noop ("# active connections"), | 1145 | gettext_noop ("# active connections"), |
1188 | -1, | 1146 | -1, GNUNET_NO); |
1189 | GNUNET_NO); | ||
1190 | } | 1147 | } |
1191 | 1148 | ||
1192 | 1149 | ||
@@ -1202,76 +1159,74 @@ handler_disconnect (void *cls, | |||
1202 | */ | 1159 | */ |
1203 | static int | 1160 | static int |
1204 | handler_advertisement (void *cls, | 1161 | handler_advertisement (void *cls, |
1205 | const struct GNUNET_PeerIdentity * peer, | 1162 | const struct GNUNET_PeerIdentity *peer, |
1206 | const struct GNUNET_MessageHeader * message, | 1163 | const struct GNUNET_MessageHeader *message, |
1207 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1164 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1208 | { | 1165 | { |
1209 | size_t size; | 1166 | size_t size; |
1210 | size_t uri_size; | 1167 | size_t uri_size; |
1211 | const struct GNUNET_MessageHeader * incoming; | 1168 | const struct GNUNET_MessageHeader *incoming; |
1212 | const char *uri; | 1169 | const char *uri; |
1213 | struct Hostlist * hostlist; | 1170 | struct Hostlist *hostlist; |
1214 | 1171 | ||
1215 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 1172 | GNUNET_assert (ntohs (message->type) == |
1173 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | ||
1216 | size = ntohs (message->size); | 1174 | size = ntohs (message->size); |
1217 | if (size <= sizeof(struct GNUNET_MessageHeader)) | 1175 | if (size <= sizeof (struct GNUNET_MessageHeader)) |
1218 | { | 1176 | { |
1219 | GNUNET_break_op (0); | 1177 | GNUNET_break_op (0); |
1220 | return GNUNET_SYSERR; | 1178 | return GNUNET_SYSERR; |
1221 | } | 1179 | } |
1222 | incoming = (const struct GNUNET_MessageHeader *) message; | 1180 | incoming = (const struct GNUNET_MessageHeader *) message; |
1223 | uri = (const char*) &incoming[1]; | 1181 | uri = (const char *) &incoming[1]; |
1224 | uri_size = size - sizeof (struct GNUNET_MessageHeader); | 1182 | uri_size = size - sizeof (struct GNUNET_MessageHeader); |
1225 | if (uri [uri_size - 1] != '\0') | 1183 | if (uri[uri_size - 1] != '\0') |
1226 | { | 1184 | { |
1227 | GNUNET_break_op (0); | 1185 | GNUNET_break_op (0); |
1228 | return GNUNET_SYSERR; | 1186 | return GNUNET_SYSERR; |
1229 | } | 1187 | } |
1230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1231 | "Hostlist client recieved advertisement from `%s' containing URI `%s'\n", | 1189 | "Hostlist client recieved advertisement from `%s' containing URI `%s'\n", |
1232 | GNUNET_i2s (peer), | 1190 | GNUNET_i2s (peer), uri); |
1233 | uri); | ||
1234 | if (GNUNET_NO != linked_list_contains (uri)) | 1191 | if (GNUNET_NO != linked_list_contains (uri)) |
1235 | { | 1192 | { |
1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); |
1237 | "URI `%s' is already known\n", | 1194 | return GNUNET_OK; |
1238 | uri); | 1195 | } |
1239 | return GNUNET_OK; | ||
1240 | } | ||
1241 | 1196 | ||
1242 | if ( GNUNET_NO == stat_testing_allowed ) | 1197 | if (GNUNET_NO == stat_testing_allowed) |
1243 | { | 1198 | { |
1244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1245 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); | 1200 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); |
1246 | return GNUNET_SYSERR; | 1201 | return GNUNET_SYSERR; |
1247 | } | 1202 | } |
1248 | if ( GNUNET_YES == stat_testing_hostlist ) | 1203 | if (GNUNET_YES == stat_testing_hostlist) |
1249 | { | 1204 | { |
1250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1251 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); | 1206 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); |
1252 | return GNUNET_SYSERR; | 1207 | return GNUNET_SYSERR; |
1253 | } | 1208 | } |
1254 | 1209 | ||
1255 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); | 1210 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); |
1256 | hostlist->hostlist_uri = (const char*) &hostlist[1]; | 1211 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1257 | memcpy (&hostlist[1], uri, uri_size); | 1212 | memcpy (&hostlist[1], uri, uri_size); |
1258 | hostlist->time_creation = GNUNET_TIME_absolute_get(); | 1213 | hostlist->time_creation = GNUNET_TIME_absolute_get (); |
1259 | hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero(); | 1214 | hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero (); |
1260 | hostlist->quality = HOSTLIST_INITIAL; | 1215 | hostlist->quality = HOSTLIST_INITIAL; |
1261 | hostlist_to_test = hostlist; | 1216 | hostlist_to_test = hostlist; |
1262 | 1217 | ||
1263 | stat_testing_hostlist = GNUNET_YES; | 1218 | stat_testing_hostlist = GNUNET_YES; |
1264 | stat_testing_allowed = GNUNET_NO; | 1219 | stat_testing_allowed = GNUNET_NO; |
1265 | ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, | 1220 | ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, |
1266 | &task_testing_intervall_reset, | 1221 | &task_testing_intervall_reset, |
1267 | NULL); | 1222 | NULL); |
1268 | 1223 | ||
1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Testing new hostlist advertisements is locked for the next %u ms\n", | 1225 | "Testing new hostlist advertisements is locked for the next %u ms\n", |
1271 | TESTING_INTERVAL.rel_value); | 1226 | TESTING_INTERVAL.rel_value); |
1272 | 1227 | ||
1273 | ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (&task_download_dispatcher, | 1228 | ti_download_dispatcher_task = |
1274 | NULL); | 1229 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1275 | 1230 | ||
1276 | return GNUNET_OK; | 1231 | return GNUNET_OK; |
1277 | } | 1232 | } |
@@ -1290,26 +1245,23 @@ static void | |||
1290 | primary_task (void *cls, int success) | 1245 | primary_task (void *cls, int success) |
1291 | { | 1246 | { |
1292 | if (stats == NULL) | 1247 | if (stats == NULL) |
1293 | return; /* in shutdown */ | 1248 | return; /* in shutdown */ |
1294 | #if DEBUG_HOSTLIST_CLIENT | 1249 | #if DEBUG_HOSTLIST_CLIENT |
1295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1296 | "Statistics request done, scheduling hostlist download\n"); | 1251 | "Statistics request done, scheduling hostlist download\n"); |
1297 | #endif | 1252 | #endif |
1298 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, | 1253 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1299 | NULL); | ||
1300 | } | 1254 | } |
1301 | 1255 | ||
1302 | 1256 | ||
1303 | static int | 1257 | static int |
1304 | process_stat (void *cls, | 1258 | process_stat (void *cls, |
1305 | const char *subsystem, | 1259 | const char *subsystem, |
1306 | const char *name, | 1260 | const char *name, uint64_t value, int is_persistent) |
1307 | uint64_t value, | ||
1308 | int is_persistent) | ||
1309 | { | 1261 | { |
1310 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1262 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1311 | _("Initial time between hostlist downloads is %llums\n"), | 1263 | _("Initial time between hostlist downloads is %llums\n"), |
1312 | (unsigned long long) value); | 1264 | (unsigned long long) value); |
1313 | hostlist_delay.rel_value = value; | 1265 | hostlist_delay.rel_value = value; |
1314 | return GNUNET_OK; | 1266 | return GNUNET_OK; |
1315 | } | 1267 | } |
@@ -1317,13 +1269,14 @@ process_stat (void *cls, | |||
1317 | /** | 1269 | /** |
1318 | * Method to load persistent hostlist file during hostlist client startup | 1270 | * Method to load persistent hostlist file during hostlist client startup |
1319 | */ | 1271 | */ |
1320 | static void | 1272 | static void |
1321 | load_hostlist_file () | 1273 | load_hostlist_file () |
1322 | { | 1274 | { |
1323 | char *filename; | 1275 | char *filename; |
1324 | char *uri; | 1276 | char *uri; |
1325 | char *emsg; | 1277 | char *emsg; |
1326 | struct Hostlist * hostlist; | 1278 | struct Hostlist *hostlist; |
1279 | |||
1327 | uri = NULL; | 1280 | uri = NULL; |
1328 | uint32_t times_used; | 1281 | uint32_t times_used; |
1329 | uint32_t hellos_returned; | 1282 | uint32_t hellos_returned; |
@@ -1333,74 +1286,75 @@ load_hostlist_file () | |||
1333 | uint32_t counter; | 1286 | uint32_t counter; |
1334 | 1287 | ||
1335 | if (GNUNET_OK != | 1288 | if (GNUNET_OK != |
1336 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1289 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1337 | "HOSTLIST", | 1290 | "HOSTLIST", |
1338 | "HOSTLISTFILE", | 1291 | "HOSTLISTFILE", &filename)) |
1339 | &filename)) | 1292 | { |
1340 | { | 1293 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1341 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1294 | _ |
1342 | _("No `%s' specified in `%s' configuration, cannot load hostlists from file.\n"), | 1295 | ("No `%s' specified in `%s' configuration, cannot load hostlists from file.\n"), |
1343 | "HOSTLISTFILE", "HOSTLIST"); | 1296 | "HOSTLISTFILE", "HOSTLIST"); |
1344 | return; | 1297 | return; |
1345 | } | 1298 | } |
1346 | 1299 | ||
1347 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1300 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1348 | _("Loading saved hostlist entries from file `%s' \n"), filename); | 1301 | _("Loading saved hostlist entries from file `%s' \n"), filename); |
1349 | if ( GNUNET_NO == GNUNET_DISK_file_test (filename) ) | 1302 | if (GNUNET_NO == GNUNET_DISK_file_test (filename)) |
1350 | { | 1303 | { |
1351 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1304 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1352 | _("Hostlist file `%s' is not existing\n"), filename); | 1305 | _("Hostlist file `%s' is not existing\n"), filename); |
1353 | GNUNET_free ( filename ); | 1306 | GNUNET_free (filename); |
1354 | return; | 1307 | return; |
1355 | } | 1308 | } |
1356 | 1309 | ||
1357 | struct GNUNET_BIO_ReadHandle * rh = GNUNET_BIO_read_open (filename); | 1310 | struct GNUNET_BIO_ReadHandle *rh = GNUNET_BIO_read_open (filename); |
1311 | |||
1358 | if (NULL == rh) | 1312 | if (NULL == rh) |
1359 | { | 1313 | { |
1360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1361 | _("Could not open file `%s' for reading to load hostlists: %s\n"), | 1315 | _ |
1362 | filename, | 1316 | ("Could not open file `%s' for reading to load hostlists: %s\n"), |
1363 | STRERROR (errno)); | 1317 | filename, STRERROR (errno)); |
1364 | GNUNET_free (filename); | 1318 | GNUNET_free (filename); |
1365 | return; | 1319 | return; |
1366 | } | 1320 | } |
1367 | 1321 | ||
1368 | counter = 0; | 1322 | counter = 0; |
1369 | while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri, MAX_URL_LEN)) && | 1323 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && |
1370 | (NULL != uri) && | 1324 | (NULL != uri) && |
1371 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && | 1325 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && |
1372 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && | 1326 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && |
1373 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && | 1327 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && |
1374 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && | 1328 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && |
1375 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)) ) | 1329 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) |
1376 | { | 1330 | { |
1377 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1); | 1331 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1); |
1378 | hostlist->hello_count = hellos_returned; | 1332 | hostlist->hello_count = hellos_returned; |
1379 | hostlist->hostlist_uri = (const char *) &hostlist[1]; | 1333 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1380 | memcpy (&hostlist[1], uri, strlen(uri)+1); | 1334 | memcpy (&hostlist[1], uri, strlen (uri) + 1); |
1381 | hostlist->quality = quality; | 1335 | hostlist->quality = quality; |
1382 | hostlist->time_creation.abs_value = created; | 1336 | hostlist->time_creation.abs_value = created; |
1383 | hostlist->time_last_usage.abs_value = last_used; | 1337 | hostlist->time_last_usage.abs_value = last_used; |
1384 | GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist); | 1338 | GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, hostlist); |
1385 | linked_list_size++; | 1339 | linked_list_size++; |
1386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1387 | "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri); | 1341 | "Added hostlist entry eith URI `%s' \n", |
1388 | GNUNET_free (uri); | 1342 | hostlist->hostlist_uri); |
1389 | uri = NULL; | 1343 | GNUNET_free (uri); |
1390 | counter++; | 1344 | uri = NULL; |
1391 | if ( counter >= MAX_NUMBER_HOSTLISTS ) break; | 1345 | counter++; |
1392 | } | 1346 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1347 | break; | ||
1348 | } | ||
1393 | 1349 | ||
1394 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1350 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1395 | _("%u hostlist URIs loaded from file\n"), counter); | 1351 | _("%u hostlist URIs loaded from file\n"), counter); |
1396 | GNUNET_STATISTICS_set (stats, | 1352 | GNUNET_STATISTICS_set (stats, |
1397 | gettext_noop("# hostlist URIs read from file"), | 1353 | gettext_noop ("# hostlist URIs read from file"), |
1398 | counter, | 1354 | counter, GNUNET_YES); |
1399 | GNUNET_YES); | ||
1400 | GNUNET_STATISTICS_set (stats, | 1355 | GNUNET_STATISTICS_set (stats, |
1401 | gettext_noop("# advertised hostlist URIs"), | 1356 | gettext_noop ("# advertised hostlist URIs"), |
1402 | linked_list_size, | 1357 | linked_list_size, GNUNET_NO); |
1403 | GNUNET_NO); | ||
1404 | 1358 | ||
1405 | GNUNET_free_non_null (uri); | 1359 | GNUNET_free_non_null (uri); |
1406 | emsg = NULL; | 1360 | emsg = NULL; |
@@ -1415,89 +1369,87 @@ load_hostlist_file () | |||
1415 | * Method to save persistent hostlist file during hostlist client shutdown | 1369 | * Method to save persistent hostlist file during hostlist client shutdown |
1416 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 1370 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
1417 | */ | 1371 | */ |
1418 | static void save_hostlist_file ( int shutdown ) | 1372 | static void |
1373 | save_hostlist_file (int shutdown) | ||
1419 | { | 1374 | { |
1420 | char *filename; | 1375 | char *filename; |
1421 | struct Hostlist *pos; | 1376 | struct Hostlist *pos; |
1422 | struct GNUNET_BIO_WriteHandle * wh; | 1377 | struct GNUNET_BIO_WriteHandle *wh; |
1423 | int ok; | 1378 | int ok; |
1424 | uint32_t counter; | 1379 | uint32_t counter; |
1425 | 1380 | ||
1426 | if (GNUNET_OK != | 1381 | if (GNUNET_OK != |
1427 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1382 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1428 | "HOSTLIST", | 1383 | "HOSTLIST", |
1429 | "HOSTLISTFILE", | 1384 | "HOSTLISTFILE", &filename)) |
1430 | &filename)) | 1385 | { |
1431 | { | 1386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1432 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1387 | _ |
1433 | _("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"), | 1388 | ("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"), |
1434 | "HOSTLISTFILE", "HOSTLIST"); | 1389 | "HOSTLISTFILE", "HOSTLIST"); |
1435 | return; | 1390 | return; |
1436 | } | 1391 | } |
1437 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) | 1392 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) |
1438 | { | 1393 | { |
1439 | GNUNET_free (filename); | 1394 | GNUNET_free (filename); |
1440 | return; | 1395 | return; |
1441 | } | 1396 | } |
1442 | wh = GNUNET_BIO_write_open (filename); | 1397 | wh = GNUNET_BIO_write_open (filename); |
1443 | if ( NULL == wh) | 1398 | if (NULL == wh) |
1444 | { | 1399 | { |
1445 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1400 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1446 | _("Could not open file `%s' for writing to save hostlists: %s\n"), | 1401 | _ |
1447 | filename, | 1402 | ("Could not open file `%s' for writing to save hostlists: %s\n"), |
1448 | STRERROR (errno)); | 1403 | filename, STRERROR (errno)); |
1449 | GNUNET_free (filename); | 1404 | GNUNET_free (filename); |
1450 | return; | 1405 | return; |
1451 | } | 1406 | } |
1452 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1407 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1453 | _("Writing %u hostlist URIs to `%s'\n" ), | 1408 | _("Writing %u hostlist URIs to `%s'\n"), |
1454 | linked_list_size, filename); | 1409 | linked_list_size, filename); |
1455 | /* add code to write hostlists to file using bio */ | 1410 | /* add code to write hostlists to file using bio */ |
1456 | ok = GNUNET_YES; | 1411 | ok = GNUNET_YES; |
1457 | counter = 0; | 1412 | counter = 0; |
1458 | while (NULL != (pos = linked_list_head)) | 1413 | while (NULL != (pos = linked_list_head)) |
1414 | { | ||
1415 | if (GNUNET_YES == shutdown) | ||
1416 | { | ||
1417 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); | ||
1418 | linked_list_size--; | ||
1419 | } | ||
1420 | if (GNUNET_YES == ok) | ||
1459 | { | 1421 | { |
1460 | if ( GNUNET_YES == shutdown) | 1422 | if ((GNUNET_OK != |
1423 | GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | ||
1424 | (GNUNET_OK != | ||
1425 | GNUNET_BIO_write_int32 (wh, pos->times_used)) || | ||
1426 | (GNUNET_OK != | ||
1427 | GNUNET_BIO_write_int64 (wh, pos->quality)) || | ||
1428 | (GNUNET_OK != | ||
1429 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) || | ||
1430 | (GNUNET_OK != | ||
1431 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value)) || | ||
1432 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) | ||
1461 | { | 1433 | { |
1462 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); | 1434 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1463 | linked_list_size--; | 1435 | _("Error writing hostlist URIs to file `%s'\n"), filename); |
1436 | ok = GNUNET_NO; | ||
1464 | } | 1437 | } |
1465 | if (GNUNET_YES == ok) | 1438 | } |
1466 | { | 1439 | |
1467 | if ( (GNUNET_OK != | 1440 | if (GNUNET_YES == shutdown) |
1468 | GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | 1441 | GNUNET_free (pos); |
1469 | (GNUNET_OK != | 1442 | counter++; |
1470 | GNUNET_BIO_write_int32 (wh, pos->times_used)) || | 1443 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1471 | (GNUNET_OK != | 1444 | break; |
1472 | GNUNET_BIO_write_int64 (wh, pos->quality)) || | 1445 | } |
1473 | (GNUNET_OK != | ||
1474 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) || | ||
1475 | (GNUNET_OK != | ||
1476 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value)) || | ||
1477 | (GNUNET_OK != | ||
1478 | GNUNET_BIO_write_int32 (wh, pos->hello_count))) | ||
1479 | { | ||
1480 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1481 | _("Error writing hostlist URIs to file `%s'\n"), | ||
1482 | filename); | ||
1483 | ok = GNUNET_NO; | ||
1484 | } | ||
1485 | } | ||
1486 | |||
1487 | if ( GNUNET_YES == shutdown) | ||
1488 | GNUNET_free (pos); | ||
1489 | counter ++; | ||
1490 | if ( counter >= MAX_NUMBER_HOSTLISTS) break; | ||
1491 | } | ||
1492 | GNUNET_STATISTICS_set (stats, | 1446 | GNUNET_STATISTICS_set (stats, |
1493 | gettext_noop("# hostlist URIs written to file"), | 1447 | gettext_noop ("# hostlist URIs written to file"), |
1494 | counter, | 1448 | counter, GNUNET_YES); |
1495 | GNUNET_YES); | ||
1496 | 1449 | ||
1497 | if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) | 1450 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
1498 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1451 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1499 | _("Error writing hostlist URIs to file `%s'\n"), | 1452 | _("Error writing hostlist URIs to file `%s'\n"), filename); |
1500 | filename); | ||
1501 | GNUNET_free (filename); | 1453 | GNUNET_free (filename); |
1502 | } | 1454 | } |
1503 | 1455 | ||
@@ -1506,33 +1458,30 @@ static void save_hostlist_file ( int shutdown ) | |||
1506 | */ | 1458 | */ |
1507 | int | 1459 | int |
1508 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | 1460 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, |
1509 | struct GNUNET_STATISTICS_Handle *st, | 1461 | struct GNUNET_STATISTICS_Handle *st, |
1510 | GNUNET_CORE_ConnectEventHandler *ch, | 1462 | GNUNET_CORE_ConnectEventHandler *ch, |
1511 | GNUNET_CORE_DisconnectEventHandler *dh, | 1463 | GNUNET_CORE_DisconnectEventHandler *dh, |
1512 | GNUNET_CORE_MessageCallback *msgh, | 1464 | GNUNET_CORE_MessageCallback *msgh, int learn) |
1513 | int learn) | ||
1514 | { | 1465 | { |
1515 | char *filename; | 1466 | char *filename; |
1516 | int result; | 1467 | int result; |
1517 | 1468 | ||
1518 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 1469 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
1519 | { | 1470 | { |
1520 | GNUNET_break (0); | 1471 | GNUNET_break (0); |
1521 | return GNUNET_SYSERR; | 1472 | return GNUNET_SYSERR; |
1522 | } | 1473 | } |
1523 | transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL); | 1474 | transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL); |
1524 | if (NULL == transport) | 1475 | if (NULL == transport) |
1525 | { | 1476 | { |
1526 | curl_global_cleanup (); | 1477 | curl_global_cleanup (); |
1527 | return GNUNET_SYSERR; | 1478 | return GNUNET_SYSERR; |
1528 | } | 1479 | } |
1529 | cfg = c; | 1480 | cfg = c; |
1530 | stats = st; | 1481 | stats = st; |
1531 | if (GNUNET_OK != | 1482 | if (GNUNET_OK != |
1532 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1483 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1533 | "HOSTLIST", | 1484 | "HOSTLIST", "HTTP-PROXY", &proxy)) |
1534 | "HTTP-PROXY", | ||
1535 | &proxy)) | ||
1536 | proxy = NULL; | 1485 | proxy = NULL; |
1537 | stat_learning = learn; | 1486 | stat_learning = learn; |
1538 | *ch = &handler_connect; | 1487 | *ch = &handler_connect; |
@@ -1543,51 +1492,49 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1543 | stat_testing_hostlist = GNUNET_NO; | 1492 | stat_testing_hostlist = GNUNET_NO; |
1544 | stat_testing_allowed = GNUNET_YES; | 1493 | stat_testing_allowed = GNUNET_YES; |
1545 | 1494 | ||
1546 | if ( GNUNET_YES == stat_learning ) | 1495 | if (GNUNET_YES == stat_learning) |
1547 | { | 1496 | { |
1548 | *msgh = &handler_advertisement; | 1497 | *msgh = &handler_advertisement; |
1549 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1498 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1550 | _("Learning is enabled on this peer\n")); | 1499 | _("Learning is enabled on this peer\n")); |
1551 | load_hostlist_file (); | 1500 | load_hostlist_file (); |
1552 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1501 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1553 | _("Hostlists will be saved to file again in %llums\n"), | 1502 | _("Hostlists will be saved to file again in %llums\n"), |
1554 | (unsigned long long) SAVING_INTERVALL.rel_value); | 1503 | (unsigned long long) SAVING_INTERVALL.rel_value); |
1555 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, | 1504 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, |
1556 | &task_hostlist_saving, | 1505 | &task_hostlist_saving, NULL); |
1557 | NULL); | ||
1558 | } | 1506 | } |
1559 | else | 1507 | else |
1560 | { | 1508 | { |
1561 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1509 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1562 | _("Learning is not enabled on this peer\n")); | 1510 | _("Learning is not enabled on this peer\n")); |
1563 | *msgh = NULL; | 1511 | *msgh = NULL; |
1564 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | 1512 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, |
1565 | "HOSTLIST", | 1513 | "HOSTLIST", |
1566 | "HOSTLISTFILE", | 1514 | "HOSTLISTFILE", |
1567 | &filename)) | 1515 | &filename)) |
1568 | { | 1516 | { |
1569 | if ( GNUNET_YES == GNUNET_DISK_file_test (filename) ) | 1517 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
1570 | { | 1518 | { |
1571 | result = remove (filename); | 1519 | result = remove (filename); |
1572 | if (result == 0) | 1520 | if (result == 0) |
1573 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1521 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1574 | _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), | 1522 | _ |
1575 | filename); | 1523 | ("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), |
1524 | filename); | ||
1576 | else | 1525 | else |
1577 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1526 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1578 | _("Hostlist file `%s' could not be removed\n"), | 1527 | _("Hostlist file `%s' could not be removed\n"), filename); |
1579 | filename); | ||
1580 | } | 1528 | } |
1581 | } | 1529 | } |
1582 | GNUNET_free ( filename ); | 1530 | GNUNET_free (filename); |
1583 | } | 1531 | } |
1584 | GNUNET_STATISTICS_get (stats, | 1532 | GNUNET_STATISTICS_get (stats, |
1585 | "hostlist", | 1533 | "hostlist", |
1586 | gettext_noop("# milliseconds between hostlist downloads"), | 1534 | gettext_noop |
1587 | GNUNET_TIME_UNIT_MINUTES, | 1535 | ("# milliseconds between hostlist downloads"), |
1588 | &primary_task, | 1536 | GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat, |
1589 | &process_stat, | 1537 | NULL); |
1590 | NULL); | ||
1591 | return GNUNET_OK; | 1538 | return GNUNET_OK; |
1592 | } | 1539 | } |
1593 | 1540 | ||
@@ -1598,42 +1545,40 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1598 | void | 1545 | void |
1599 | GNUNET_HOSTLIST_client_stop () | 1546 | GNUNET_HOSTLIST_client_stop () |
1600 | { | 1547 | { |
1601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1602 | "Hostlist client shutdown\n"); | ||
1603 | #if DEBUG_HOSTLIST_CLIENT | 1549 | #if DEBUG_HOSTLIST_CLIENT |
1604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1605 | "Hostlist client shutdown\n"); | ||
1606 | #endif | 1551 | #endif |
1607 | if ( GNUNET_YES == stat_learning ) | 1552 | if (GNUNET_YES == stat_learning) |
1608 | save_hostlist_file ( GNUNET_YES ); | 1553 | save_hostlist_file (GNUNET_YES); |
1609 | 1554 | ||
1610 | if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK) | 1555 | if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK) |
1611 | { | 1556 | { |
1612 | GNUNET_SCHEDULER_cancel (ti_saving_task); | 1557 | GNUNET_SCHEDULER_cancel (ti_saving_task); |
1613 | } | 1558 | } |
1614 | 1559 | ||
1615 | if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK) | 1560 | if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK) |
1616 | { | 1561 | { |
1617 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); | 1562 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); |
1618 | } | 1563 | } |
1619 | if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK) | 1564 | if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK) |
1620 | { | 1565 | { |
1621 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); | 1566 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); |
1622 | } | 1567 | } |
1623 | if (ti_download != GNUNET_SCHEDULER_NO_TASK) | 1568 | if (ti_download != GNUNET_SCHEDULER_NO_TASK) |
1624 | { | 1569 | { |
1625 | GNUNET_SCHEDULER_cancel (ti_download); | 1570 | GNUNET_SCHEDULER_cancel (ti_download); |
1626 | } | 1571 | } |
1627 | if (ti_check_download != GNUNET_SCHEDULER_NO_TASK) | 1572 | if (ti_check_download != GNUNET_SCHEDULER_NO_TASK) |
1628 | { | 1573 | { |
1629 | GNUNET_SCHEDULER_cancel (ti_check_download); | 1574 | GNUNET_SCHEDULER_cancel (ti_check_download); |
1630 | curl_global_cleanup (); | 1575 | curl_global_cleanup (); |
1631 | } | 1576 | } |
1632 | if (transport != NULL) | 1577 | if (transport != NULL) |
1633 | { | 1578 | { |
1634 | GNUNET_TRANSPORT_disconnect (transport); | 1579 | GNUNET_TRANSPORT_disconnect (transport); |
1635 | transport = NULL; | 1580 | transport = NULL; |
1636 | } | 1581 | } |
1637 | GNUNET_assert (NULL == transport); | 1582 | GNUNET_assert (NULL == transport); |
1638 | GNUNET_free_non_null (proxy); | 1583 | GNUNET_free_non_null (proxy); |
1639 | proxy = NULL; | 1584 | proxy = NULL; |