diff options
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist_client.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 1771 |
1 files changed, 886 insertions, 885 deletions
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 | ||