diff options
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist_client.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 1765 |
1 files changed, 883 insertions, 882 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index af3fd6fce..564aef2bd 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c | |||
@@ -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,7 +91,8 @@ | |||
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 | { | ||
95 | /** | 96 | /** |
96 | * previous entry, used to manage entries in a double linked list | 97 | * previous entry, used to manage entries in a double linked list |
97 | */ | 98 | */ |
@@ -320,7 +321,7 @@ static struct GNUNET_PEERINFO_Handle *pi; | |||
320 | * @return number of bytes that were processed (always size*nmemb) | 321 | * @return number of bytes that were processed (always size*nmemb) |
321 | */ | 322 | */ |
322 | static size_t | 323 | static size_t |
323 | callback_download(void *ptr, size_t size, size_t nmemb, void *ctx) | 324 | callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) |
324 | { | 325 | { |
325 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; | 326 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; |
326 | const char *cbuf = ptr; | 327 | const char *cbuf = ptr; |
@@ -333,85 +334,85 @@ callback_download(void *ptr, size_t size, size_t nmemb, void *ctx) | |||
333 | total = size * nmemb; | 334 | total = size * nmemb; |
334 | stat_bytes_downloaded += total; | 335 | stat_bytes_downloaded += total; |
335 | if ((total == 0) || (stat_bogus_url)) | 336 | if ((total == 0) || (stat_bogus_url)) |
336 | { | 337 | { |
337 | return total; /* ok, no data or bogus data */ | 338 | return total; /* ok, no data or bogus data */ |
338 | } | 339 | } |
339 | 340 | ||
340 | GNUNET_STATISTICS_update(stats, | 341 | GNUNET_STATISTICS_update (stats, |
341 | gettext_noop( | 342 | gettext_noop ( |
342 | "# bytes downloaded from hostlist servers"), | 343 | "# bytes downloaded from hostlist servers"), |
343 | (int64_t)total, | 344 | (int64_t) total, |
344 | GNUNET_NO); | 345 | GNUNET_NO); |
345 | left = total; | 346 | left = total; |
346 | while ((left > 0) || (download_pos > 0)) | 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)) | ||
347 | { | 355 | { |
348 | cpy = GNUNET_MIN(left, GNUNET_MAX_MESSAGE_SIZE - 1 - download_pos); | 356 | GNUNET_assert (0 == left); |
349 | GNUNET_memcpy(&download_buffer[download_pos], cbuf, cpy); | 357 | break; |
350 | cbuf += cpy; | 358 | } |
351 | download_pos += cpy; | 359 | msg = (const struct GNUNET_MessageHeader *) download_buffer; |
352 | left -= cpy; | 360 | msize = ntohs (msg->size); |
353 | if (download_pos < sizeof(struct GNUNET_MessageHeader)) | 361 | if (msize < sizeof(struct GNUNET_MessageHeader)) |
354 | { | 362 | { |
355 | GNUNET_assert(0 == left); | 363 | GNUNET_STATISTICS_update ( |
356 | break; | 364 | stats, |
357 | } | 365 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), |
358 | msg = (const struct GNUNET_MessageHeader *)download_buffer; | 366 | 1, |
359 | msize = ntohs(msg->size); | 367 | GNUNET_NO); |
360 | if (msize < sizeof(struct GNUNET_MessageHeader)) | 368 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
361 | { | 369 | _ ("Invalid `%s' message received from hostlist at `%s'\n"), |
362 | GNUNET_STATISTICS_update( | 370 | "HELLO", |
363 | stats, | 371 | current_url); |
364 | gettext_noop("# invalid HELLOs downloaded from hostlist servers"), | 372 | stat_hellos_obtained++; |
365 | 1, | 373 | stat_bogus_url = 1; |
366 | GNUNET_NO); | 374 | return total; |
367 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 375 | } |
368 | _("Invalid `%s' message received from hostlist at `%s'\n"), | 376 | if (download_pos < msize) |
369 | "HELLO", | 377 | { |
370 | current_url); | 378 | GNUNET_assert (left == 0); |
371 | stat_hellos_obtained++; | 379 | break; |
372 | stat_bogus_url = 1; | 380 | } |
373 | return total; | 381 | if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize) |
374 | } | 382 | { |
375 | if (download_pos < msize) | 383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
376 | { | 384 | "Received valid `%s' message from hostlist server.\n", |
377 | GNUNET_assert(left == 0); | 385 | "HELLO"); |
378 | break; | 386 | GNUNET_STATISTICS_update ( |
379 | } | 387 | stats, |
380 | if (GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)msg) == msize) | 388 | gettext_noop ("# valid HELLOs downloaded from hostlist servers"), |
381 | { | 389 | 1, |
382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_NO); |
383 | "Received valid `%s' message from hostlist server.\n", | 391 | stat_hellos_obtained++; |
384 | "HELLO"); | 392 | (void) |
385 | GNUNET_STATISTICS_update( | 393 | GNUNET_PEERINFO_add_peer (pi, |
386 | stats, | 394 | (const struct GNUNET_HELLO_Message *) msg, |
387 | gettext_noop("# valid HELLOs downloaded from hostlist servers"), | 395 | NULL, |
388 | 1, | 396 | NULL); |
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; | ||
414 | } | 397 | } |
398 | else | ||
399 | { | ||
400 | GNUNET_STATISTICS_update ( | ||
401 | stats, | ||
402 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | ||
403 | 1, | ||
404 | GNUNET_NO); | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
406 | _ ("Invalid `%s' message received from hostlist at `%s'\n"), | ||
407 | "HELLO", | ||
408 | current_url); | ||
409 | stat_bogus_url = GNUNET_YES; | ||
410 | stat_hellos_obtained++; | ||
411 | return total; | ||
412 | } | ||
413 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); | ||
414 | download_pos -= msize; | ||
415 | } | ||
415 | return total; | 416 | return total; |
416 | } | 417 | } |
417 | 418 | ||
@@ -422,63 +423,63 @@ callback_download(void *ptr, size_t size, size_t nmemb, void *ctx) | |||
422 | * @return NULL if there is no URL available | 423 | * @return NULL if there is no URL available |
423 | */ | 424 | */ |
424 | static char * | 425 | static char * |
425 | get_bootstrap_server() | 426 | get_bootstrap_server () |
426 | { | 427 | { |
427 | char *servers; | 428 | char *servers; |
428 | char *ret; | 429 | char *ret; |
429 | size_t urls; | 430 | size_t urls; |
430 | size_t pos; | 431 | size_t pos; |
431 | 432 | ||
432 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 433 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
433 | "HOSTLIST", | 434 | "HOSTLIST", |
434 | "SERVERS", | 435 | "SERVERS", |
435 | &servers)) | 436 | &servers)) |
436 | { | 437 | { |
437 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 438 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
438 | "hostlist", | 439 | "hostlist", |
439 | "SERVERS"); | 440 | "SERVERS"); |
440 | return NULL; | 441 | return NULL; |
441 | } | 442 | } |
442 | 443 | ||
443 | urls = 0; | 444 | urls = 0; |
444 | if (strlen(servers) > 0) | 445 | if (strlen (servers) > 0) |
446 | { | ||
447 | urls++; | ||
448 | pos = strlen (servers) - 1; | ||
449 | while (pos > 0) | ||
445 | { | 450 | { |
446 | urls++; | 451 | if (servers[pos] == ' ') |
447 | pos = strlen(servers) - 1; | 452 | urls++; |
448 | while (pos > 0) | 453 | pos--; |
449 | { | ||
450 | if (servers[pos] == ' ') | ||
451 | urls++; | ||
452 | pos--; | ||
453 | } | ||
454 | } | 454 | } |
455 | } | ||
455 | if (urls == 0) | 456 | if (urls == 0) |
456 | { | 457 | { |
457 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 458 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
458 | "hostlist", | 459 | "hostlist", |
459 | "SERVERS"); | 460 | "SERVERS"); |
460 | GNUNET_free(servers); | 461 | GNUNET_free (servers); |
461 | return NULL; | 462 | return NULL; |
462 | } | 463 | } |
463 | 464 | ||
464 | urls = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; | 465 | urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; |
465 | pos = strlen(servers) - 1; | 466 | pos = strlen (servers) - 1; |
466 | while (pos > 0) | 467 | while (pos > 0) |
468 | { | ||
469 | if (servers[pos] == ' ') | ||
467 | { | 470 | { |
468 | if (servers[pos] == ' ') | 471 | urls--; |
469 | { | 472 | servers[pos] = '\0'; |
470 | urls--; | 473 | } |
471 | servers[pos] = '\0'; | 474 | if (urls == 0) |
472 | } | 475 | { |
473 | if (urls == 0) | 476 | pos++; |
474 | { | 477 | break; |
475 | pos++; | ||
476 | break; | ||
477 | } | ||
478 | pos--; | ||
479 | } | 478 | } |
480 | ret = GNUNET_strdup(&servers[pos]); | 479 | pos--; |
481 | GNUNET_free(servers); | 480 | } |
481 | ret = GNUNET_strdup (&servers[pos]); | ||
482 | GNUNET_free (servers); | ||
482 | return ret; | 483 | return ret; |
483 | } | 484 | } |
484 | 485 | ||
@@ -488,64 +489,64 @@ get_bootstrap_server() | |||
488 | * @return uri to use, NULL if there is no URL available | 489 | * @return uri to use, NULL if there is no URL available |
489 | */ | 490 | */ |
490 | static char * | 491 | static char * |
491 | download_get_url() | 492 | download_get_url () |
492 | { | 493 | { |
493 | uint32_t index; | 494 | uint32_t index; |
494 | unsigned int counter; | 495 | unsigned int counter; |
495 | struct Hostlist *pos; | 496 | struct Hostlist *pos; |
496 | 497 | ||
497 | if (GNUNET_NO == stat_learning) | 498 | if (GNUNET_NO == stat_learning) |
498 | { | 499 | { |
499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
500 | "Using preconfigured bootstrap server\n"); | 501 | "Using preconfigured bootstrap server\n"); |
501 | current_hostlist = NULL; | 502 | current_hostlist = NULL; |
502 | return get_bootstrap_server(); | 503 | return get_bootstrap_server (); |
503 | } | 504 | } |
504 | 505 | ||
505 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) | 506 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) |
506 | { | 507 | { |
507 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
508 | "Testing new advertised hostlist if it is obtainable\n"); | 509 | "Testing new advertised hostlist if it is obtainable\n"); |
509 | current_hostlist = hostlist_to_test; | 510 | current_hostlist = hostlist_to_test; |
510 | return GNUNET_strdup(hostlist_to_test->hostlist_uri); | 511 | return GNUNET_strdup (hostlist_to_test->hostlist_uri); |
511 | } | 512 | } |
512 | 513 | ||
513 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) | 514 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) |
514 | { | 515 | { |
515 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
516 | "Using preconfigured bootstrap server\n"); | 517 | "Using preconfigured bootstrap server\n"); |
517 | current_hostlist = NULL; | 518 | current_hostlist = NULL; |
518 | return get_bootstrap_server(); | 519 | return get_bootstrap_server (); |
519 | } | 520 | } |
520 | index = | 521 | index = |
521 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); | 522 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); |
522 | counter = 0; | 523 | counter = 0; |
523 | pos = linked_list_head; | 524 | pos = linked_list_head; |
524 | while (counter < index) | 525 | while (counter < index) |
525 | { | 526 | { |
526 | pos = pos->next; | 527 | pos = pos->next; |
527 | counter++; | 528 | counter++; |
528 | } | 529 | } |
529 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
530 | "Using learned hostlist `%s'\n", | 531 | "Using learned hostlist `%s'\n", |
531 | pos->hostlist_uri); | 532 | pos->hostlist_uri); |
532 | current_hostlist = pos; | 533 | current_hostlist = pos; |
533 | return GNUNET_strdup(pos->hostlist_uri); | 534 | return GNUNET_strdup (pos->hostlist_uri); |
534 | } | 535 | } |
535 | 536 | ||
536 | 537 | ||
537 | #define CURL_EASY_SETOPT(c, a, b) \ | 538 | #define CURL_EASY_SETOPT(c, a, b) \ |
538 | do \ | 539 | do \ |
539 | { \ | 540 | { \ |
540 | ret = curl_easy_setopt(c, a, b); \ | 541 | ret = curl_easy_setopt (c, a, b); \ |
541 | if (CURLE_OK != ret) \ | 542 | if (CURLE_OK != ret) \ |
542 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ | 543 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ |
543 | _("%s failed at %s:%d: `%s'\n"), \ | 544 | _ ("%s failed at %s:%d: `%s'\n"), \ |
544 | "curl_easy_setopt", \ | 545 | "curl_easy_setopt", \ |
545 | __FILE__, \ | 546 | __FILE__, \ |
546 | __LINE__, \ | 547 | __LINE__, \ |
547 | curl_easy_strerror(ret)); \ | 548 | curl_easy_strerror (ret)); \ |
548 | } while (0) | 549 | } while (0) |
549 | 550 | ||
550 | 551 | ||
551 | /** | 552 | /** |
@@ -554,7 +555,7 @@ download_get_url() | |||
554 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 555 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
555 | */ | 556 | */ |
556 | static void | 557 | static void |
557 | save_hostlist_file(int shutdown); | 558 | save_hostlist_file (int shutdown); |
558 | 559 | ||
559 | 560 | ||
560 | /** | 561 | /** |
@@ -565,7 +566,7 @@ save_hostlist_file(int shutdown); | |||
565 | * @return result | 566 | * @return result |
566 | */ | 567 | */ |
567 | static uint64_t | 568 | static uint64_t |
568 | checked_add(uint64_t val1, uint64_t val2) | 569 | checked_add (uint64_t val1, uint64_t val2) |
569 | { | 570 | { |
570 | static uint64_t temp; | 571 | static uint64_t temp; |
571 | static uint64_t maxv; | 572 | static uint64_t maxv; |
@@ -588,7 +589,7 @@ checked_add(uint64_t val1, uint64_t val2) | |||
588 | * @return result | 589 | * @return result |
589 | */ | 590 | */ |
590 | static uint64_t | 591 | static uint64_t |
591 | checked_sub(uint64_t val1, uint64_t val2) | 592 | checked_sub (uint64_t val1, uint64_t val2) |
592 | { | 593 | { |
593 | if (val1 <= val2) | 594 | if (val1 <= val2) |
594 | return 0; | 595 | return 0; |
@@ -603,17 +604,17 @@ checked_sub(uint64_t val1, uint64_t val2) | |||
603 | * @return #GNUNET_YES if existing in linked list, #GNUNET_NO if not | 604 | * @return #GNUNET_YES if existing in linked list, #GNUNET_NO if not |
604 | */ | 605 | */ |
605 | static int | 606 | static int |
606 | linked_list_contains(const char *uri) | 607 | linked_list_contains (const char *uri) |
607 | { | 608 | { |
608 | struct Hostlist *pos; | 609 | struct Hostlist *pos; |
609 | 610 | ||
610 | pos = linked_list_head; | 611 | pos = linked_list_head; |
611 | while (pos != NULL) | 612 | while (pos != NULL) |
612 | { | 613 | { |
613 | if (0 == strcmp(pos->hostlist_uri, uri)) | 614 | if (0 == strcmp (pos->hostlist_uri, uri)) |
614 | return GNUNET_YES; | 615 | return GNUNET_YES; |
615 | pos = pos->next; | 616 | pos = pos->next; |
616 | } | 617 | } |
617 | return GNUNET_NO; | 618 | return GNUNET_NO; |
618 | } | 619 | } |
619 | 620 | ||
@@ -623,7 +624,7 @@ linked_list_contains(const char *uri) | |||
623 | * @return hostlist with lowest quality | 624 | * @return hostlist with lowest quality |
624 | */ | 625 | */ |
625 | static struct Hostlist * | 626 | static struct Hostlist * |
626 | linked_list_get_lowest_quality() | 627 | linked_list_get_lowest_quality () |
627 | { | 628 | { |
628 | struct Hostlist *pos; | 629 | struct Hostlist *pos; |
629 | struct Hostlist *lowest; | 630 | struct Hostlist *lowest; |
@@ -633,11 +634,11 @@ linked_list_get_lowest_quality() | |||
633 | lowest = linked_list_head; | 634 | lowest = linked_list_head; |
634 | pos = linked_list_head->next; | 635 | pos = linked_list_head->next; |
635 | while (pos != NULL) | 636 | while (pos != NULL) |
636 | { | 637 | { |
637 | if (pos->quality < lowest->quality) | 638 | if (pos->quality < lowest->quality) |
638 | lowest = pos; | 639 | lowest = pos; |
639 | pos = pos->next; | 640 | pos = pos->next; |
640 | } | 641 | } |
641 | return lowest; | 642 | return lowest; |
642 | } | 643 | } |
643 | 644 | ||
@@ -648,34 +649,34 @@ linked_list_get_lowest_quality() | |||
648 | * quality is dismissed | 649 | * quality is dismissed |
649 | */ | 650 | */ |
650 | static void | 651 | static void |
651 | insert_hostlist() | 652 | insert_hostlist () |
652 | { | 653 | { |
653 | struct Hostlist *lowest_quality; | 654 | struct Hostlist *lowest_quality; |
654 | 655 | ||
655 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) | 656 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) |
656 | { | 657 | { |
657 | /* No free entries available, replace existing entry */ | 658 | /* No free entries available, replace existing entry */ |
658 | lowest_quality = linked_list_get_lowest_quality(); | 659 | lowest_quality = linked_list_get_lowest_quality (); |
659 | GNUNET_assert(lowest_quality != NULL); | 660 | GNUNET_assert (lowest_quality != NULL); |
660 | GNUNET_log( | 661 | GNUNET_log ( |
661 | GNUNET_ERROR_TYPE_DEBUG, | 662 | GNUNET_ERROR_TYPE_DEBUG, |
662 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", | 663 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", |
663 | lowest_quality->hostlist_uri, | 664 | lowest_quality->hostlist_uri, |
664 | (unsigned long long)lowest_quality->quality); | 665 | (unsigned long long) lowest_quality->quality); |
665 | GNUNET_CONTAINER_DLL_remove(linked_list_head, | 666 | GNUNET_CONTAINER_DLL_remove (linked_list_head, |
666 | linked_list_tail, | 667 | linked_list_tail, |
667 | lowest_quality); | 668 | lowest_quality); |
668 | linked_list_size--; | 669 | linked_list_size--; |
669 | GNUNET_free(lowest_quality); | 670 | GNUNET_free (lowest_quality); |
670 | } | 671 | } |
671 | GNUNET_CONTAINER_DLL_insert(linked_list_head, | 672 | GNUNET_CONTAINER_DLL_insert (linked_list_head, |
672 | linked_list_tail, | 673 | linked_list_tail, |
673 | hostlist_to_test); | 674 | hostlist_to_test); |
674 | linked_list_size++; | 675 | linked_list_size++; |
675 | GNUNET_STATISTICS_set(stats, | 676 | GNUNET_STATISTICS_set (stats, |
676 | gettext_noop("# advertised hostlist URIs"), | 677 | gettext_noop ("# advertised hostlist URIs"), |
677 | linked_list_size, | 678 | linked_list_size, |
678 | GNUNET_NO); | 679 | GNUNET_NO); |
679 | stat_testing_hostlist = GNUNET_NO; | 680 | stat_testing_hostlist = GNUNET_NO; |
680 | } | 681 | } |
681 | 682 | ||
@@ -684,37 +685,37 @@ insert_hostlist() | |||
684 | * Method updating hostlist statistics | 685 | * Method updating hostlist statistics |
685 | */ | 686 | */ |
686 | static void | 687 | static void |
687 | update_hostlist() | 688 | update_hostlist () |
688 | { | 689 | { |
689 | char *stat; | 690 | char *stat; |
690 | 691 | ||
691 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || | 692 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || |
692 | ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist))) | 693 | ((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) | ||
693 | { | 704 | { |
694 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 705 | current_hostlist->times_used++; |
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(); | ||
699 | current_hostlist->quality = | 706 | current_hostlist->quality = |
700 | checked_add(current_hostlist->quality, | 707 | checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); |
701 | (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); | 708 | GNUNET_asprintf (&stat, |
702 | if (GNUNET_YES == stat_download_successful) | 709 | gettext_noop ("# advertised URI `%s' downloaded"), |
703 | { | 710 | current_hostlist->hostlist_uri); |
704 | current_hostlist->times_used++; | 711 | |
705 | current_hostlist->quality = | 712 | GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES); |
706 | checked_add(current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); | 713 | GNUNET_free (stat); |
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); | ||
717 | } | 714 | } |
715 | else | ||
716 | current_hostlist->quality = | ||
717 | checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); | ||
718 | } | ||
718 | current_hostlist = NULL; | 719 | current_hostlist = NULL; |
719 | /* Alternating the usage of preconfigured and learned hostlists */ | 720 | /* Alternating the usage of preconfigured and learned hostlists */ |
720 | 721 | ||
@@ -722,12 +723,12 @@ update_hostlist() | |||
722 | return; | 723 | return; |
723 | 724 | ||
724 | if (GNUNET_YES == stat_learning) | 725 | if (GNUNET_YES == stat_learning) |
725 | { | 726 | { |
726 | if (stat_use_bootstrap == GNUNET_YES) | 727 | if (stat_use_bootstrap == GNUNET_YES) |
727 | stat_use_bootstrap = GNUNET_NO; | 728 | stat_use_bootstrap = GNUNET_NO; |
728 | else | 729 | else |
729 | stat_use_bootstrap = GNUNET_YES; | 730 | stat_use_bootstrap = GNUNET_YES; |
730 | } | 731 | } |
731 | else | 732 | else |
732 | stat_use_bootstrap = GNUNET_YES; | 733 | stat_use_bootstrap = GNUNET_YES; |
733 | } | 734 | } |
@@ -738,58 +739,58 @@ update_hostlist() | |||
738 | * hostlist and schedule the next task. | 739 | * hostlist and schedule the next task. |
739 | */ | 740 | */ |
740 | static void | 741 | static void |
741 | clean_up() | 742 | clean_up () |
742 | { | 743 | { |
743 | CURLMcode mret; | 744 | CURLMcode mret; |
744 | 745 | ||
745 | if ((stat_testing_hostlist == GNUNET_YES) && | 746 | if ((stat_testing_hostlist == GNUNET_YES) && |
746 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) | 747 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) |
747 | { | 748 | { |
748 | GNUNET_log( | 749 | GNUNET_log ( |
749 | GNUNET_ERROR_TYPE_INFO, | 750 | GNUNET_ERROR_TYPE_INFO, |
750 | _( | 751 | _ ( |
751 | "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), | 752 | "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), |
752 | hostlist_to_test->hostlist_uri); | 753 | hostlist_to_test->hostlist_uri); |
753 | } | 754 | } |
754 | 755 | ||
755 | if (stat_testing_hostlist == GNUNET_YES) | 756 | if (stat_testing_hostlist == GNUNET_YES) |
756 | { | 757 | { |
757 | stat_testing_hostlist = GNUNET_NO; | 758 | stat_testing_hostlist = GNUNET_NO; |
758 | } | 759 | } |
759 | if (NULL != hostlist_to_test) | 760 | if (NULL != hostlist_to_test) |
760 | { | 761 | { |
761 | GNUNET_free(hostlist_to_test); | 762 | GNUNET_free (hostlist_to_test); |
762 | hostlist_to_test = NULL; | 763 | hostlist_to_test = NULL; |
763 | } | 764 | } |
764 | 765 | ||
765 | if (NULL != multi) | 766 | if (NULL != multi) |
767 | { | ||
768 | mret = curl_multi_remove_handle (multi, curl); | ||
769 | if (mret != CURLM_OK) | ||
766 | { | 770 | { |
767 | mret = curl_multi_remove_handle(multi, curl); | 771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
768 | if (mret != CURLM_OK) | 772 | _ ("%s failed at %s:%d: `%s'\n"), |
769 | { | 773 | "curl_multi_remove_handle", |
770 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 774 | __FILE__, |
771 | _("%s failed at %s:%d: `%s'\n"), | 775 | __LINE__, |
772 | "curl_multi_remove_handle", | 776 | curl_multi_strerror (mret)); |
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; | ||
786 | } | 777 | } |
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 | } | ||
787 | if (NULL != curl) | 788 | if (NULL != curl) |
788 | { | 789 | { |
789 | curl_easy_cleanup(curl); | 790 | curl_easy_cleanup (curl); |
790 | curl = NULL; | 791 | curl = NULL; |
791 | } | 792 | } |
792 | GNUNET_free_non_null(current_url); | 793 | GNUNET_free_non_null (current_url); |
793 | current_url = NULL; | 794 | current_url = NULL; |
794 | stat_bytes_downloaded = 0; | 795 | stat_bytes_downloaded = 0; |
795 | stat_download_in_progress = GNUNET_NO; | 796 | stat_download_in_progress = GNUNET_NO; |
@@ -804,7 +805,7 @@ clean_up() | |||
804 | * @param tc task context, unused | 805 | * @param tc task context, unused |
805 | */ | 806 | */ |
806 | static void | 807 | static void |
807 | task_download(void *cls); | 808 | task_download (void *cls); |
808 | 809 | ||
809 | 810 | ||
810 | /** | 811 | /** |
@@ -812,7 +813,7 @@ task_download(void *cls); | |||
812 | * receiving task with the scheduler. | 813 | * receiving task with the scheduler. |
813 | */ | 814 | */ |
814 | static void | 815 | static void |
815 | download_prepare() | 816 | download_prepare () |
816 | { | 817 | { |
817 | CURLMcode mret; | 818 | CURLMcode mret; |
818 | fd_set rs; | 819 | fd_set rs; |
@@ -825,50 +826,50 @@ download_prepare() | |||
825 | struct GNUNET_TIME_Relative rtime; | 826 | struct GNUNET_TIME_Relative rtime; |
826 | 827 | ||
827 | max = -1; | 828 | max = -1; |
828 | FD_ZERO(&rs); | 829 | FD_ZERO (&rs); |
829 | FD_ZERO(&ws); | 830 | FD_ZERO (&ws); |
830 | FD_ZERO(&es); | 831 | FD_ZERO (&es); |
831 | mret = curl_multi_fdset(multi, &rs, &ws, &es, &max); | 832 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); |
832 | if (mret != CURLM_OK) | 833 | if (mret != CURLM_OK) |
833 | { | 834 | { |
834 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 835 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
835 | _("%s failed at %s:%d: `%s'\n"), | 836 | _ ("%s failed at %s:%d: `%s'\n"), |
836 | "curl_multi_fdset", | 837 | "curl_multi_fdset", |
837 | __FILE__, | 838 | __FILE__, |
838 | __LINE__, | 839 | __LINE__, |
839 | curl_multi_strerror(mret)); | 840 | curl_multi_strerror (mret)); |
840 | clean_up(); | 841 | clean_up (); |
841 | return; | 842 | return; |
842 | } | 843 | } |
843 | mret = curl_multi_timeout(multi, &timeout); | 844 | mret = curl_multi_timeout (multi, &timeout); |
844 | if (mret != CURLM_OK) | 845 | if (mret != CURLM_OK) |
845 | { | 846 | { |
846 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
847 | _("%s failed at %s:%d: `%s'\n"), | 848 | _ ("%s failed at %s:%d: `%s'\n"), |
848 | "curl_multi_timeout", | 849 | "curl_multi_timeout", |
849 | __FILE__, | 850 | __FILE__, |
850 | __LINE__, | 851 | __LINE__, |
851 | curl_multi_strerror(mret)); | 852 | curl_multi_strerror (mret)); |
852 | clean_up(); | 853 | clean_up (); |
853 | return; | 854 | return; |
854 | } | 855 | } |
855 | rtime = GNUNET_TIME_relative_min( | 856 | rtime = GNUNET_TIME_relative_min ( |
856 | GNUNET_TIME_absolute_get_remaining(end_time), | 857 | GNUNET_TIME_absolute_get_remaining (end_time), |
857 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, timeout)); | 858 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout)); |
858 | grs = GNUNET_NETWORK_fdset_create(); | 859 | grs = GNUNET_NETWORK_fdset_create (); |
859 | gws = GNUNET_NETWORK_fdset_create(); | 860 | gws = GNUNET_NETWORK_fdset_create (); |
860 | GNUNET_NETWORK_fdset_copy_native(grs, &rs, max + 1); | 861 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
861 | GNUNET_NETWORK_fdset_copy_native(gws, &ws, max + 1); | 862 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); |
862 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
863 | "Scheduling task for hostlist download using cURL\n"); | 864 | "Scheduling task for hostlist download using cURL\n"); |
864 | ti_download = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 865 | ti_download = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
865 | rtime, | 866 | rtime, |
866 | grs, | 867 | grs, |
867 | gws, | 868 | gws, |
868 | &task_download, | 869 | &task_download, |
869 | multi); | 870 | multi); |
870 | GNUNET_NETWORK_fdset_destroy(gws); | 871 | GNUNET_NETWORK_fdset_destroy (gws); |
871 | GNUNET_NETWORK_fdset_destroy(grs); | 872 | GNUNET_NETWORK_fdset_destroy (grs); |
872 | } | 873 | } |
873 | 874 | ||
874 | 875 | ||
@@ -879,95 +880,95 @@ download_prepare() | |||
879 | * @param cls closure, unused | 880 | * @param cls closure, unused |
880 | */ | 881 | */ |
881 | static void | 882 | static void |
882 | task_download(void *cls) | 883 | task_download (void *cls) |
883 | { | 884 | { |
884 | int running; | 885 | int running; |
885 | struct CURLMsg *msg; | 886 | struct CURLMsg *msg; |
886 | CURLMcode mret; | 887 | CURLMcode mret; |
887 | 888 | ||
888 | ti_download = NULL; | 889 | ti_download = NULL; |
889 | if (0 == GNUNET_TIME_absolute_get_remaining(end_time).rel_value_us) | 890 | 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) | ||
890 | { | 905 | { |
891 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 906 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
892 | _("Timeout trying to download hostlist from `%s'\n"), | 907 | _ ( |
893 | current_url); | 908 | "Download limit of %u bytes exceeded, stopping download\n"), |
894 | update_hostlist(); | 909 | MAX_BYTES_PER_HOSTLISTS); |
895 | clean_up(); | 910 | clean_up (); |
896 | return; | 911 | return; |
897 | } | 912 | } |
898 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 913 | mret = curl_multi_perform (multi, &running); |
899 | "Ready for processing hostlist client request\n"); | 914 | if (running == 0) |
900 | do | ||
901 | { | 915 | { |
902 | running = 0; | 916 | do |
903 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | 917 | { |
904 | { | 918 | msg = curl_multi_info_read (multi, &running); |
905 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 919 | GNUNET_break (msg != NULL); |
906 | _( | 920 | if (msg == NULL) |
907 | "Download limit of %u bytes exceeded, stopping download\n"), | 921 | break; |
908 | MAX_BYTES_PER_HOSTLISTS); | 922 | switch (msg->msg) |
909 | clean_up(); | ||
910 | return; | ||
911 | } | ||
912 | mret = curl_multi_perform(multi, &running); | ||
913 | if (running == 0) | ||
914 | { | 923 | { |
915 | do | 924 | case CURLMSG_DONE: |
925 | if ((msg->data.result != CURLE_OK) && | ||
926 | (msg->data.result != CURLE_GOT_NOTHING)) | ||
927 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
928 | _ ("Download of hostlist from `%s' failed: `%s'\n"), | ||
929 | current_url, | ||
930 | curl_easy_strerror (msg->data.result)); | ||
931 | else | ||
932 | { | ||
933 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
934 | _ ("Download of hostlist `%s' completed.\n"), | ||
935 | current_url); | ||
936 | stat_download_successful = GNUNET_YES; | ||
937 | update_hostlist (); | ||
938 | if (GNUNET_YES == stat_testing_hostlist) | ||
916 | { | 939 | { |
917 | msg = curl_multi_info_read(multi, &running); | 940 | GNUNET_log ( |
918 | GNUNET_break(msg != NULL); | 941 | GNUNET_ERROR_TYPE_INFO, |
919 | if (msg == NULL) | 942 | _ ("Adding successfully tested hostlist `%s' datastore.\n"), |
920 | break; | 943 | current_url); |
921 | switch (msg->msg) | 944 | insert_hostlist (); |
922 | { | 945 | hostlist_to_test = NULL; |
923 | case CURLMSG_DONE: | 946 | stat_testing_hostlist = GNUNET_NO; |
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 | } | ||
954 | } | 947 | } |
955 | while ((running > 0)); | 948 | } |
949 | clean_up (); | ||
950 | return; | ||
951 | |||
952 | default: | ||
953 | break; | ||
956 | } | 954 | } |
955 | } | ||
956 | while ((running > 0)); | ||
957 | } | 957 | } |
958 | } | ||
958 | while (mret == CURLM_CALL_MULTI_PERFORM); | 959 | while (mret == CURLM_CALL_MULTI_PERFORM); |
959 | 960 | ||
960 | if (mret != CURLM_OK) | 961 | if (mret != CURLM_OK) |
961 | { | 962 | { |
962 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 963 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
963 | _("%s failed at %s:%d: `%s'\n"), | 964 | _ ("%s failed at %s:%d: `%s'\n"), |
964 | "curl_multi_perform", | 965 | "curl_multi_perform", |
965 | __FILE__, | 966 | __FILE__, |
966 | __LINE__, | 967 | __LINE__, |
967 | curl_multi_strerror(mret)); | 968 | curl_multi_strerror (mret)); |
968 | clean_up(); | 969 | clean_up (); |
969 | } | 970 | } |
970 | download_prepare(); | 971 | download_prepare (); |
971 | } | 972 | } |
972 | 973 | ||
973 | 974 | ||
@@ -976,133 +977,133 @@ task_download(void *cls) | |||
976 | * data. | 977 | * data. |
977 | */ | 978 | */ |
978 | static void | 979 | static void |
979 | download_hostlist() | 980 | download_hostlist () |
980 | { | 981 | { |
981 | CURLcode ret; | 982 | CURLcode ret; |
982 | CURLMcode mret; | 983 | CURLMcode mret; |
983 | 984 | ||
984 | 985 | ||
985 | current_url = download_get_url(); | 986 | current_url = download_get_url (); |
986 | if (current_url == NULL) | 987 | if (current_url == NULL) |
987 | return; | 988 | return; |
988 | curl = curl_easy_init(); | 989 | curl = curl_easy_init (); |
989 | multi = NULL; | 990 | multi = NULL; |
990 | if (curl == NULL) | 991 | if (curl == NULL) |
991 | { | 992 | { |
992 | GNUNET_break(0); | 993 | GNUNET_break (0); |
993 | clean_up(); | 994 | clean_up (); |
994 | return; | 995 | return; |
995 | } | 996 | } |
996 | GNUNET_log(GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 997 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
997 | _("Bootstrapping using hostlist at `%s'.\n"), | 998 | _ ("Bootstrapping using hostlist at `%s'.\n"), |
998 | current_url); | 999 | current_url); |
999 | 1000 | ||
1000 | stat_download_in_progress = GNUNET_YES; | 1001 | stat_download_in_progress = GNUNET_YES; |
1001 | stat_download_successful = GNUNET_NO; | 1002 | stat_download_successful = GNUNET_NO; |
1002 | stat_hellos_obtained = 0; | 1003 | stat_hellos_obtained = 0; |
1003 | stat_bytes_downloaded = 0; | 1004 | stat_bytes_downloaded = 0; |
1004 | 1005 | ||
1005 | GNUNET_STATISTICS_update(stats, | 1006 | GNUNET_STATISTICS_update (stats, |
1006 | gettext_noop("# hostlist downloads initiated"), | 1007 | gettext_noop ("# hostlist downloads initiated"), |
1007 | 1, | 1008 | 1, |
1008 | GNUNET_NO); | 1009 | GNUNET_NO); |
1009 | if (NULL != proxy) | 1010 | if (NULL != proxy) |
1010 | { | 1011 | { |
1011 | CURL_EASY_SETOPT(curl, CURLOPT_PROXY, proxy); | 1012 | CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); |
1012 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYTYPE, proxy_type); | 1013 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYTYPE, proxy_type); |
1013 | if (NULL != proxy_username) | 1014 | if (NULL != proxy_username) |
1014 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYUSERNAME, proxy_username); | 1015 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYUSERNAME, proxy_username); |
1015 | if (NULL != proxy_password) | 1016 | if (NULL != proxy_password) |
1016 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYPASSWORD, proxy_password); | 1017 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYPASSWORD, proxy_password); |
1017 | } | 1018 | } |
1018 | download_pos = 0; | 1019 | download_pos = 0; |
1019 | stat_bogus_url = 0; | 1020 | stat_bogus_url = 0; |
1020 | CURL_EASY_SETOPT(curl, CURLOPT_WRITEFUNCTION, &callback_download); | 1021 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download); |
1021 | if (ret != CURLE_OK) | 1022 | if (ret != CURLE_OK) |
1022 | { | 1023 | { |
1023 | clean_up(); | 1024 | clean_up (); |
1024 | return; | 1025 | return; |
1025 | } | 1026 | } |
1026 | CURL_EASY_SETOPT(curl, CURLOPT_WRITEDATA, NULL); | 1027 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL); |
1027 | if (ret != CURLE_OK) | 1028 | if (ret != CURLE_OK) |
1028 | { | 1029 | { |
1029 | clean_up(); | 1030 | clean_up (); |
1030 | return; | 1031 | return; |
1031 | } | 1032 | } |
1032 | CURL_EASY_SETOPT(curl, CURLOPT_FOLLOWLOCATION, 1); | 1033 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); |
1033 | CURL_EASY_SETOPT(curl, | 1034 | CURL_EASY_SETOPT (curl, |
1034 | CURLOPT_REDIR_PROTOCOLS, | 1035 | CURLOPT_REDIR_PROTOCOLS, |
1035 | CURLPROTO_HTTP | CURLPROTO_HTTPS); | 1036 | CURLPROTO_HTTP | CURLPROTO_HTTPS); |
1036 | CURL_EASY_SETOPT(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); | 1037 | CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
1037 | CURL_EASY_SETOPT(curl, CURLOPT_MAXREDIRS, 4); | 1038 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); |
1038 | /* no need to abort if the above failed */ | 1039 | /* no need to abort if the above failed */ |
1039 | CURL_EASY_SETOPT(curl, CURLOPT_URL, current_url); | 1040 | CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url); |
1040 | if (ret != CURLE_OK) | 1041 | if (ret != CURLE_OK) |
1041 | { | 1042 | { |
1042 | clean_up(); | 1043 | clean_up (); |
1043 | return; | 1044 | return; |
1044 | } | 1045 | } |
1045 | CURL_EASY_SETOPT(curl, CURLOPT_FAILONERROR, 1); | 1046 | CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1); |
1046 | #if 0 | 1047 | #if 0 |
1047 | CURL_EASY_SETOPT(curl, CURLOPT_VERBOSE, 1); | 1048 | CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1); |
1048 | #endif | 1049 | #endif |
1049 | CURL_EASY_SETOPT(curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE); | 1050 | CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE); |
1050 | if (0 == strncmp(current_url, "http", 4)) | 1051 | if (0 == strncmp (current_url, "http", 4)) |
1051 | CURL_EASY_SETOPT(curl, CURLOPT_USERAGENT, "GNUnet"); | 1052 | CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet"); |
1052 | CURL_EASY_SETOPT(curl, CURLOPT_CONNECTTIMEOUT, 60L); | 1053 | CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L); |
1053 | CURL_EASY_SETOPT(curl, CURLOPT_TIMEOUT, 60L); | 1054 | CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L); |
1054 | multi = curl_multi_init(); | 1055 | multi = curl_multi_init (); |
1055 | if (multi == NULL) | 1056 | if (multi == NULL) |
1056 | { | 1057 | { |
1057 | GNUNET_break(0); | 1058 | GNUNET_break (0); |
1058 | /* clean_up (); */ | 1059 | /* clean_up (); */ |
1059 | return; | 1060 | return; |
1060 | } | 1061 | } |
1061 | mret = curl_multi_add_handle(multi, curl); | 1062 | mret = curl_multi_add_handle (multi, curl); |
1062 | if (mret != CURLM_OK) | 1063 | if (mret != CURLM_OK) |
1063 | { | 1064 | { |
1064 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1065 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1065 | _("%s failed at %s:%d: `%s'\n"), | 1066 | _ ("%s failed at %s:%d: `%s'\n"), |
1066 | "curl_multi_add_handle", | 1067 | "curl_multi_add_handle", |
1067 | __FILE__, | 1068 | __FILE__, |
1068 | __LINE__, | 1069 | __LINE__, |
1069 | curl_multi_strerror(mret)); | 1070 | curl_multi_strerror (mret)); |
1070 | mret = curl_multi_cleanup(multi); | 1071 | mret = curl_multi_cleanup (multi); |
1071 | if (mret != CURLM_OK) | 1072 | if (mret != CURLM_OK) |
1072 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1073 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1073 | _("%s failed at %s:%d: `%s'\n"), | 1074 | _ ("%s failed at %s:%d: `%s'\n"), |
1074 | "curl_multi_cleanup", | 1075 | "curl_multi_cleanup", |
1075 | __FILE__, | 1076 | __FILE__, |
1076 | __LINE__, | 1077 | __LINE__, |
1077 | curl_multi_strerror(mret)); | 1078 | curl_multi_strerror (mret)); |
1078 | multi = NULL; | 1079 | multi = NULL; |
1079 | clean_up(); | 1080 | clean_up (); |
1080 | return; | 1081 | return; |
1081 | } | 1082 | } |
1082 | end_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); | 1083 | end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
1083 | download_prepare(); | 1084 | download_prepare (); |
1084 | } | 1085 | } |
1085 | 1086 | ||
1086 | 1087 | ||
1087 | static void | 1088 | static void |
1088 | task_download_dispatcher(void *cls) | 1089 | task_download_dispatcher (void *cls) |
1089 | { | 1090 | { |
1090 | ti_download_dispatcher_task = NULL; | 1091 | ti_download_dispatcher_task = NULL; |
1091 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); | 1092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); |
1092 | if (GNUNET_NO == stat_download_in_progress) | 1093 | if (GNUNET_NO == stat_download_in_progress) |
1093 | { | 1094 | { |
1094 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); | 1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); |
1095 | download_hostlist(); | 1096 | download_hostlist (); |
1096 | } | 1097 | } |
1097 | else | 1098 | else |
1098 | { | 1099 | { |
1099 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1100 | "Download in progess, have to wait...\n"); | 1101 | "Download in progess, have to wait...\n"); |
1101 | ti_download_dispatcher_task = | 1102 | ti_download_dispatcher_task = |
1102 | GNUNET_SCHEDULER_add_delayed(WAITING_INTERVAL, | 1103 | GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL, |
1103 | &task_download_dispatcher, | 1104 | &task_download_dispatcher, |
1104 | NULL); | 1105 | NULL); |
1105 | } | 1106 | } |
1106 | } | 1107 | } |
1107 | 1108 | ||
1108 | 1109 | ||
@@ -1112,49 +1113,49 @@ task_download_dispatcher(void *cls) | |||
1112 | * this task again for a later time. | 1113 | * this task again for a later time. |
1113 | */ | 1114 | */ |
1114 | static void | 1115 | static void |
1115 | task_check(void *cls) | 1116 | task_check (void *cls) |
1116 | { | 1117 | { |
1117 | static int once; | 1118 | static int once; |
1118 | struct GNUNET_TIME_Relative delay; | 1119 | struct GNUNET_TIME_Relative delay; |
1119 | 1120 | ||
1120 | ti_check_download = NULL; | 1121 | ti_check_download = NULL; |
1121 | if (stats == NULL) | 1122 | if (stats == NULL) |
1122 | { | 1123 | { |
1123 | curl_global_cleanup(); | 1124 | curl_global_cleanup (); |
1124 | return; /* in shutdown */ | 1125 | return; /* in shutdown */ |
1125 | } | 1126 | } |
1126 | if ((stat_connection_count < MIN_CONNECTIONS) && | 1127 | if ((stat_connection_count < MIN_CONNECTIONS) && |
1127 | (NULL == ti_download_dispatcher_task)) | 1128 | (NULL == ti_download_dispatcher_task)) |
1128 | ti_download_dispatcher_task = | 1129 | ti_download_dispatcher_task = |
1129 | GNUNET_SCHEDULER_add_now(&task_download_dispatcher, NULL); | 1130 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1130 | 1131 | ||
1131 | delay = hostlist_delay; | 1132 | delay = hostlist_delay; |
1132 | if (0 == hostlist_delay.rel_value_us) | 1133 | if (0 == hostlist_delay.rel_value_us) |
1133 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; | 1134 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; |
1134 | else | 1135 | else |
1135 | hostlist_delay = GNUNET_TIME_relative_multiply(hostlist_delay, 2); | 1136 | hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2); |
1136 | if (hostlist_delay.rel_value_us > | 1137 | if (hostlist_delay.rel_value_us > |
1137 | GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) | 1138 | GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) |
1138 | hostlist_delay = | 1139 | hostlist_delay = |
1139 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, | 1140 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, |
1140 | (1 + stat_connection_count)); | 1141 | (1 + stat_connection_count)); |
1141 | GNUNET_STATISTICS_set(stats, | 1142 | GNUNET_STATISTICS_set (stats, |
1142 | gettext_noop( | 1143 | gettext_noop ( |
1143 | "# milliseconds between hostlist downloads"), | 1144 | "# milliseconds between hostlist downloads"), |
1144 | hostlist_delay.rel_value_us / 1000LL, | 1145 | hostlist_delay.rel_value_us / 1000LL, |
1145 | GNUNET_YES); | 1146 | GNUNET_YES); |
1146 | if (0 == once) | 1147 | if (0 == once) |
1147 | { | 1148 | { |
1148 | delay = GNUNET_TIME_UNIT_ZERO; | 1149 | delay = GNUNET_TIME_UNIT_ZERO; |
1149 | once = 1; | 1150 | once = 1; |
1150 | } | 1151 | } |
1151 | GNUNET_log( | 1152 | GNUNET_log ( |
1152 | GNUNET_ERROR_TYPE_INFO, | 1153 | GNUNET_ERROR_TYPE_INFO, |
1153 | _("Have %u/%u connections. Will consider downloading hostlist in %s\n"), | 1154 | _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"), |
1154 | stat_connection_count, | 1155 | stat_connection_count, |
1155 | MIN_CONNECTIONS, | 1156 | MIN_CONNECTIONS, |
1156 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); | 1157 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); |
1157 | ti_check_download = GNUNET_SCHEDULER_add_delayed(delay, &task_check, NULL); | 1158 | ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); |
1158 | } | 1159 | } |
1159 | 1160 | ||
1160 | 1161 | ||
@@ -1164,12 +1165,12 @@ task_check(void *cls) | |||
1164 | * @param cls closure | 1165 | * @param cls closure |
1165 | */ | 1166 | */ |
1166 | static void | 1167 | static void |
1167 | task_testing_intervall_reset(void *cls) | 1168 | task_testing_intervall_reset (void *cls) |
1168 | { | 1169 | { |
1169 | ti_testing_intervall_task = NULL; | 1170 | ti_testing_intervall_task = NULL; |
1170 | stat_testing_allowed = GNUNET_OK; | 1171 | stat_testing_allowed = GNUNET_OK; |
1171 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1172 | "Testing new hostlist advertisements is allowed again\n"); | 1173 | "Testing new hostlist advertisements is allowed again\n"); |
1173 | } | 1174 | } |
1174 | 1175 | ||
1175 | 1176 | ||
@@ -1179,17 +1180,17 @@ task_testing_intervall_reset(void *cls) | |||
1179 | * @param cls closure | 1180 | * @param cls closure |
1180 | */ | 1181 | */ |
1181 | static void | 1182 | static void |
1182 | task_hostlist_saving(void *cls) | 1183 | task_hostlist_saving (void *cls) |
1183 | { | 1184 | { |
1184 | ti_saving_task = NULL; | 1185 | ti_saving_task = NULL; |
1185 | save_hostlist_file(GNUNET_NO); | 1186 | save_hostlist_file (GNUNET_NO); |
1186 | 1187 | ||
1187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1188 | "Hostlists will be saved to file again in %s\n", | 1189 | "Hostlists will be saved to file again in %s\n", |
1189 | GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, | 1190 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, |
1190 | GNUNET_YES)); | 1191 | GNUNET_YES)); |
1191 | ti_saving_task = | 1192 | ti_saving_task = |
1192 | GNUNET_SCHEDULER_add_delayed(SAVING_INTERVAL, &task_hostlist_saving, NULL); | 1193 | GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, NULL); |
1193 | } | 1194 | } |
1194 | 1195 | ||
1195 | 1196 | ||
@@ -1201,16 +1202,16 @@ task_hostlist_saving(void *cls) | |||
1201 | * @param mq message queue for transmissions to @a peer | 1202 | * @param mq message queue for transmissions to @a peer |
1202 | */ | 1203 | */ |
1203 | static void * | 1204 | static void * |
1204 | handler_connect(void *cls, | 1205 | handler_connect (void *cls, |
1205 | const struct GNUNET_PeerIdentity *peer, | 1206 | const struct GNUNET_PeerIdentity *peer, |
1206 | struct GNUNET_MQ_Handle *mq) | 1207 | struct GNUNET_MQ_Handle *mq) |
1207 | { | 1208 | { |
1208 | GNUNET_assert(stat_connection_count < UINT_MAX); | 1209 | GNUNET_assert (stat_connection_count < UINT_MAX); |
1209 | stat_connection_count++; | 1210 | stat_connection_count++; |
1210 | GNUNET_STATISTICS_update(stats, | 1211 | GNUNET_STATISTICS_update (stats, |
1211 | gettext_noop("# active connections"), | 1212 | gettext_noop ("# active connections"), |
1212 | 1, | 1213 | 1, |
1213 | GNUNET_NO); | 1214 | GNUNET_NO); |
1214 | return NULL; | 1215 | return NULL; |
1215 | } | 1216 | } |
1216 | 1217 | ||
@@ -1222,16 +1223,16 @@ handler_connect(void *cls, | |||
1222 | * @param peer peer identity this notification is about | 1223 | * @param peer peer identity this notification is about |
1223 | */ | 1224 | */ |
1224 | static void | 1225 | static void |
1225 | handler_disconnect(void *cls, | 1226 | handler_disconnect (void *cls, |
1226 | const struct GNUNET_PeerIdentity *peer, | 1227 | const struct GNUNET_PeerIdentity *peer, |
1227 | void *internal_cls) | 1228 | void *internal_cls) |
1228 | { | 1229 | { |
1229 | GNUNET_assert(stat_connection_count > 0); | 1230 | GNUNET_assert (stat_connection_count > 0); |
1230 | stat_connection_count--; | 1231 | stat_connection_count--; |
1231 | GNUNET_STATISTICS_update(stats, | 1232 | GNUNET_STATISTICS_update (stats, |
1232 | gettext_noop("# active connections"), | 1233 | gettext_noop ("# active connections"), |
1233 | -1, | 1234 | -1, |
1234 | GNUNET_NO); | 1235 | GNUNET_NO); |
1235 | } | 1236 | } |
1236 | 1237 | ||
1237 | 1238 | ||
@@ -1241,57 +1242,57 @@ handler_disconnect(void *cls, | |||
1241 | * @param uri the advertised URI | 1242 | * @param uri the advertised URI |
1242 | */ | 1243 | */ |
1243 | static void | 1244 | static void |
1244 | handler_advertisement(const char *uri) | 1245 | handler_advertisement (const char *uri) |
1245 | { | 1246 | { |
1246 | size_t uri_size; | 1247 | size_t uri_size; |
1247 | struct Hostlist *hostlist; | 1248 | struct Hostlist *hostlist; |
1248 | 1249 | ||
1249 | uri_size = strlen(uri) + 1; | 1250 | uri_size = strlen (uri) + 1; |
1250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1251 | "Hostlist client recieved advertisement containing URI `%s'\n", | 1252 | "Hostlist client recieved advertisement containing URI `%s'\n", |
1252 | uri); | 1253 | uri); |
1253 | if (GNUNET_NO != linked_list_contains(uri)) | 1254 | if (GNUNET_NO != linked_list_contains (uri)) |
1254 | { | 1255 | { |
1255 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); | 1256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); |
1256 | return; | 1257 | return; |
1257 | } | 1258 | } |
1258 | 1259 | ||
1259 | if (GNUNET_NO == stat_testing_allowed) | 1260 | if (GNUNET_NO == stat_testing_allowed) |
1260 | { | 1261 | { |
1261 | GNUNET_log( | 1262 | GNUNET_log ( |
1262 | GNUNET_ERROR_TYPE_DEBUG, | 1263 | GNUNET_ERROR_TYPE_DEBUG, |
1263 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); | 1264 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); |
1264 | return; | 1265 | return; |
1265 | } | 1266 | } |
1266 | if (GNUNET_YES == stat_testing_hostlist) | 1267 | if (GNUNET_YES == stat_testing_hostlist) |
1267 | { | 1268 | { |
1268 | GNUNET_log( | 1269 | GNUNET_log ( |
1269 | GNUNET_ERROR_TYPE_DEBUG, | 1270 | GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); | 1271 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); |
1271 | return; | 1272 | return; |
1272 | } | 1273 | } |
1273 | 1274 | ||
1274 | hostlist = GNUNET_malloc(sizeof(struct Hostlist) + uri_size); | 1275 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + uri_size); |
1275 | hostlist->hostlist_uri = (const char *)&hostlist[1]; | 1276 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1276 | GNUNET_memcpy(&hostlist[1], uri, uri_size); | 1277 | GNUNET_memcpy (&hostlist[1], uri, uri_size); |
1277 | hostlist->time_creation = GNUNET_TIME_absolute_get(); | 1278 | hostlist->time_creation = GNUNET_TIME_absolute_get (); |
1278 | hostlist->quality = HOSTLIST_INITIAL; | 1279 | hostlist->quality = HOSTLIST_INITIAL; |
1279 | hostlist_to_test = hostlist; | 1280 | hostlist_to_test = hostlist; |
1280 | 1281 | ||
1281 | stat_testing_hostlist = GNUNET_YES; | 1282 | stat_testing_hostlist = GNUNET_YES; |
1282 | stat_testing_allowed = GNUNET_NO; | 1283 | stat_testing_allowed = GNUNET_NO; |
1283 | ti_testing_intervall_task = | 1284 | ti_testing_intervall_task = |
1284 | GNUNET_SCHEDULER_add_delayed(TESTING_INTERVAL, | 1285 | GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, |
1285 | &task_testing_intervall_reset, | 1286 | &task_testing_intervall_reset, |
1286 | NULL); | 1287 | NULL); |
1287 | 1288 | ||
1288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1289 | "Testing new hostlist advertisements is locked for the next %s\n", | 1290 | "Testing new hostlist advertisements is locked for the next %s\n", |
1290 | GNUNET_STRINGS_relative_time_to_string(TESTING_INTERVAL, | 1291 | GNUNET_STRINGS_relative_time_to_string (TESTING_INTERVAL, |
1291 | GNUNET_YES)); | 1292 | GNUNET_YES)); |
1292 | 1293 | ||
1293 | ti_download_dispatcher_task = | 1294 | ti_download_dispatcher_task = |
1294 | GNUNET_SCHEDULER_add_now(&task_download_dispatcher, NULL); | 1295 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1295 | } | 1296 | } |
1296 | 1297 | ||
1297 | 1298 | ||
@@ -1304,18 +1305,18 @@ handler_advertisement(const char *uri) | |||
1304 | * successfully obtained, #GNUNET_SYSERR if not. | 1305 | * successfully obtained, #GNUNET_SYSERR if not. |
1305 | */ | 1306 | */ |
1306 | static void | 1307 | static void |
1307 | primary_task(void *cls, int success) | 1308 | primary_task (void *cls, int success) |
1308 | { | 1309 | { |
1309 | if (NULL != ti_check_download) | 1310 | if (NULL != ti_check_download) |
1310 | { | 1311 | { |
1311 | GNUNET_SCHEDULER_cancel(ti_check_download); | 1312 | GNUNET_SCHEDULER_cancel (ti_check_download); |
1312 | ti_check_download = NULL; | 1313 | ti_check_download = NULL; |
1313 | } | 1314 | } |
1314 | sget = NULL; | 1315 | sget = NULL; |
1315 | GNUNET_assert(NULL != stats); | 1316 | GNUNET_assert (NULL != stats); |
1316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1317 | "Statistics request done, scheduling hostlist download\n"); | 1318 | "Statistics request done, scheduling hostlist download\n"); |
1318 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); | 1319 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1319 | } | 1320 | } |
1320 | 1321 | ||
1321 | 1322 | ||
@@ -1328,11 +1329,11 @@ primary_task(void *cls, int success) | |||
1328 | * successfully obtained, #GNUNET_SYSERR if not. | 1329 | * successfully obtained, #GNUNET_SYSERR if not. |
1329 | */ | 1330 | */ |
1330 | static void | 1331 | static void |
1331 | stat_timeout_task(void *cls) | 1332 | stat_timeout_task (void *cls) |
1332 | { | 1333 | { |
1333 | GNUNET_STATISTICS_get_cancel(sget); | 1334 | GNUNET_STATISTICS_get_cancel (sget); |
1334 | sget = NULL; | 1335 | sget = NULL; |
1335 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); | 1336 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1336 | } | 1337 | } |
1337 | 1338 | ||
1338 | 1339 | ||
@@ -1346,17 +1347,17 @@ stat_timeout_task(void *cls) | |||
1346 | * @param is_persistent unused, will be #GNUNET_YES | 1347 | * @param is_persistent unused, will be #GNUNET_YES |
1347 | */ | 1348 | */ |
1348 | static int | 1349 | static int |
1349 | process_stat(void *cls, | 1350 | process_stat (void *cls, |
1350 | const char *subsystem, | 1351 | const char *subsystem, |
1351 | const char *name, | 1352 | const char *name, |
1352 | uint64_t value, | 1353 | uint64_t value, |
1353 | int is_persistent) | 1354 | int is_persistent) |
1354 | { | 1355 | { |
1355 | hostlist_delay.rel_value_us = value * 1000LL; | 1356 | hostlist_delay.rel_value_us = value * 1000LL; |
1356 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1357 | "Initial time between hostlist downloads is %s\n", | 1358 | "Initial time between hostlist downloads is %s\n", |
1358 | GNUNET_STRINGS_relative_time_to_string(hostlist_delay, | 1359 | GNUNET_STRINGS_relative_time_to_string (hostlist_delay, |
1359 | GNUNET_YES)); | 1360 | GNUNET_YES)); |
1360 | return GNUNET_OK; | 1361 | return GNUNET_OK; |
1361 | } | 1362 | } |
1362 | 1363 | ||
@@ -1365,7 +1366,7 @@ process_stat(void *cls, | |||
1365 | * Method to load persistent hostlist file during hostlist client startup | 1366 | * Method to load persistent hostlist file during hostlist client startup |
1366 | */ | 1367 | */ |
1367 | static void | 1368 | static void |
1368 | load_hostlist_file() | 1369 | load_hostlist_file () |
1369 | { | 1370 | { |
1370 | char *filename; | 1371 | char *filename; |
1371 | char *uri; | 1372 | char *uri; |
@@ -1380,87 +1381,87 @@ load_hostlist_file() | |||
1380 | struct GNUNET_BIO_ReadHandle *rh; | 1381 | struct GNUNET_BIO_ReadHandle *rh; |
1381 | 1382 | ||
1382 | uri = NULL; | 1383 | uri = NULL; |
1383 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, | 1384 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
1384 | "HOSTLIST", | 1385 | "HOSTLIST", |
1385 | "HOSTLISTFILE", | 1386 | "HOSTLISTFILE", |
1386 | &filename)) | 1387 | &filename)) |
1387 | { | 1388 | { |
1388 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 1389 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
1389 | "hostlist", | 1390 | "hostlist", |
1390 | "HOSTLISTFILE"); | 1391 | "HOSTLISTFILE"); |
1391 | return; | 1392 | return; |
1392 | } | 1393 | } |
1393 | 1394 | ||
1394 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1395 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1395 | _("Loading saved hostlist entries from file `%s' \n"), | 1396 | _ ("Loading saved hostlist entries from file `%s' \n"), |
1396 | filename); | 1397 | filename); |
1397 | if (GNUNET_NO == GNUNET_DISK_file_test(filename)) | 1398 | if (GNUNET_NO == GNUNET_DISK_file_test (filename)) |
1398 | { | 1399 | { |
1399 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1400 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1400 | _("Hostlist file `%s' does not exist\n"), | 1401 | _ ("Hostlist file `%s' does not exist\n"), |
1401 | filename); | 1402 | filename); |
1402 | GNUNET_free(filename); | 1403 | GNUNET_free (filename); |
1403 | return; | 1404 | return; |
1404 | } | 1405 | } |
1405 | 1406 | ||
1406 | rh = GNUNET_BIO_read_open(filename); | 1407 | rh = GNUNET_BIO_read_open (filename); |
1407 | if (NULL == rh) | 1408 | if (NULL == rh) |
1408 | { | 1409 | { |
1409 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1410 | _( | 1411 | _ ( |
1411 | "Could not open file `%s' for reading to load hostlists: %s\n"), | 1412 | "Could not open file `%s' for reading to load hostlists: %s\n"), |
1412 | filename, | 1413 | filename, |
1413 | strerror(errno)); | 1414 | strerror (errno)); |
1414 | GNUNET_free(filename); | 1415 | GNUNET_free (filename); |
1415 | return; | 1416 | return; |
1416 | } | 1417 | } |
1417 | 1418 | ||
1418 | counter = 0; | 1419 | counter = 0; |
1419 | while ((GNUNET_OK == GNUNET_BIO_read_string(rh, "url", &uri, MAX_URL_LEN)) && | 1420 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && |
1420 | (NULL != uri) && | 1421 | (NULL != uri) && |
1421 | (GNUNET_OK == GNUNET_BIO_read_int32(rh, ×_used)) && | 1422 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && |
1422 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &quality)) && | 1423 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && |
1423 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &last_used)) && | 1424 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && |
1424 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &created)) && | 1425 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && |
1425 | (GNUNET_OK == GNUNET_BIO_read_int32(rh, &hellos_returned))) | 1426 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) |
1426 | { | 1427 | { |
1427 | hostlist = GNUNET_malloc(sizeof(struct Hostlist) + strlen(uri) + 1); | 1428 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1); |
1428 | hostlist->hello_count = hellos_returned; | 1429 | hostlist->hello_count = hellos_returned; |
1429 | hostlist->hostlist_uri = (const char *)&hostlist[1]; | 1430 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1430 | GNUNET_memcpy(&hostlist[1], uri, strlen(uri) + 1); | 1431 | GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1); |
1431 | hostlist->quality = quality; | 1432 | hostlist->quality = quality; |
1432 | hostlist->time_creation.abs_value_us = created; | 1433 | hostlist->time_creation.abs_value_us = created; |
1433 | hostlist->time_last_usage.abs_value_us = last_used; | 1434 | hostlist->time_last_usage.abs_value_us = last_used; |
1434 | GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist); | 1435 | GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, hostlist); |
1435 | linked_list_size++; | 1436 | linked_list_size++; |
1436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1437 | "Added hostlist entry eith URI `%s' \n", | 1438 | "Added hostlist entry eith URI `%s' \n", |
1438 | hostlist->hostlist_uri); | 1439 | hostlist->hostlist_uri); |
1439 | GNUNET_free(uri); | 1440 | GNUNET_free (uri); |
1440 | uri = NULL; | 1441 | uri = NULL; |
1441 | counter++; | 1442 | counter++; |
1442 | if (counter >= MAX_NUMBER_HOSTLISTS) | 1443 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1443 | break; | 1444 | break; |
1444 | } | 1445 | } |
1445 | 1446 | ||
1446 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1447 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1447 | _("%u hostlist URIs loaded from file\n"), | 1448 | _ ("%u hostlist URIs loaded from file\n"), |
1448 | counter); | 1449 | counter); |
1449 | GNUNET_STATISTICS_set(stats, | 1450 | GNUNET_STATISTICS_set (stats, |
1450 | gettext_noop("# hostlist URIs read from file"), | 1451 | gettext_noop ("# hostlist URIs read from file"), |
1451 | counter, | 1452 | counter, |
1452 | GNUNET_YES); | 1453 | GNUNET_YES); |
1453 | GNUNET_STATISTICS_set(stats, | 1454 | GNUNET_STATISTICS_set (stats, |
1454 | gettext_noop("# advertised hostlist URIs"), | 1455 | gettext_noop ("# advertised hostlist URIs"), |
1455 | linked_list_size, | 1456 | linked_list_size, |
1456 | GNUNET_NO); | 1457 | GNUNET_NO); |
1457 | 1458 | ||
1458 | GNUNET_free_non_null(uri); | 1459 | GNUNET_free_non_null (uri); |
1459 | emsg = NULL; | 1460 | emsg = NULL; |
1460 | (void)GNUNET_BIO_read_close(rh, &emsg); | 1461 | (void) GNUNET_BIO_read_close (rh, &emsg); |
1461 | if (emsg != NULL) | 1462 | if (emsg != NULL) |
1462 | GNUNET_free(emsg); | 1463 | GNUNET_free (emsg); |
1463 | GNUNET_free(filename); | 1464 | GNUNET_free (filename); |
1464 | } | 1465 | } |
1465 | 1466 | ||
1466 | 1467 | ||
@@ -1470,7 +1471,7 @@ load_hostlist_file() | |||
1470 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 1471 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
1471 | */ | 1472 | */ |
1472 | static void | 1473 | static void |
1473 | save_hostlist_file(int shutdown) | 1474 | save_hostlist_file (int shutdown) |
1474 | { | 1475 | { |
1475 | char *filename; | 1476 | char *filename; |
1476 | struct Hostlist *pos; | 1477 | struct Hostlist *pos; |
@@ -1478,80 +1479,80 @@ save_hostlist_file(int shutdown) | |||
1478 | int ok; | 1479 | int ok; |
1479 | uint32_t counter; | 1480 | uint32_t counter; |
1480 | 1481 | ||
1481 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, | 1482 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
1482 | "HOSTLIST", | 1483 | "HOSTLIST", |
1483 | "HOSTLISTFILE", | 1484 | "HOSTLISTFILE", |
1484 | &filename)) | 1485 | &filename)) |
1485 | { | 1486 | { |
1486 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 1487 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
1487 | "hostlist", | 1488 | "hostlist", |
1488 | "HOSTLISTFILE"); | 1489 | "HOSTLISTFILE"); |
1489 | return; | 1490 | return; |
1490 | } | 1491 | } |
1491 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file(filename)) | 1492 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) |
1492 | { | 1493 | { |
1493 | GNUNET_free(filename); | 1494 | GNUNET_free (filename); |
1494 | return; | 1495 | return; |
1495 | } | 1496 | } |
1496 | wh = GNUNET_BIO_write_open(filename); | 1497 | wh = GNUNET_BIO_write_open (filename); |
1497 | if (NULL == wh) | 1498 | if (NULL == wh) |
1498 | { | 1499 | { |
1499 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1500 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1500 | _( | 1501 | _ ( |
1501 | "Could not open file `%s' for writing to save hostlists: %s\n"), | 1502 | "Could not open file `%s' for writing to save hostlists: %s\n"), |
1502 | filename, | 1503 | filename, |
1503 | strerror(errno)); | 1504 | strerror (errno)); |
1504 | GNUNET_free(filename); | 1505 | GNUNET_free (filename); |
1505 | return; | 1506 | return; |
1506 | } | 1507 | } |
1507 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1508 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1508 | _("Writing %u hostlist URIs to `%s'\n"), | 1509 | _ ("Writing %u hostlist URIs to `%s'\n"), |
1509 | linked_list_size, | 1510 | linked_list_size, |
1510 | filename); | 1511 | filename); |
1511 | /* add code to write hostlists to file using bio */ | 1512 | /* add code to write hostlists to file using bio */ |
1512 | ok = GNUNET_YES; | 1513 | ok = GNUNET_YES; |
1513 | counter = 0; | 1514 | counter = 0; |
1514 | while (NULL != (pos = linked_list_head)) | 1515 | while (NULL != (pos = linked_list_head)) |
1516 | { | ||
1517 | if (GNUNET_YES == shutdown) | ||
1515 | { | 1518 | { |
1516 | if (GNUNET_YES == shutdown) | 1519 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); |
1517 | { | 1520 | linked_list_size--; |
1518 | GNUNET_CONTAINER_DLL_remove(linked_list_head, linked_list_tail, pos); | 1521 | } |
1519 | linked_list_size--; | 1522 | if (GNUNET_YES == ok) |
1520 | } | 1523 | { |
1521 | if (GNUNET_YES == ok) | 1524 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || |
1522 | { | 1525 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) || |
1523 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, pos->hostlist_uri)) || | 1526 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) || |
1524 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pos->times_used)) || | 1527 | (GNUNET_OK != |
1525 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, pos->quality)) || | 1528 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value_us)) || |
1526 | (GNUNET_OK != | 1529 | (GNUNET_OK != |
1527 | GNUNET_BIO_write_int64(wh, pos->time_last_usage.abs_value_us)) || | 1530 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value_us)) || |
1528 | (GNUNET_OK != | 1531 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) |
1529 | GNUNET_BIO_write_int64(wh, pos->time_creation.abs_value_us)) || | 1532 | { |
1530 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pos->hello_count))) | 1533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1531 | { | 1534 | _ ("Error writing hostlist URIs to file `%s'\n"), |
1532 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1535 | filename); |
1533 | _("Error writing hostlist URIs to file `%s'\n"), | 1536 | ok = GNUNET_NO; |
1534 | filename); | 1537 | } |
1535 | ok = GNUNET_NO; | ||
1536 | } | ||
1537 | } | ||
1538 | |||
1539 | if (GNUNET_YES == shutdown) | ||
1540 | GNUNET_free(pos); | ||
1541 | counter++; | ||
1542 | if (counter >= MAX_NUMBER_HOSTLISTS) | ||
1543 | break; | ||
1544 | } | 1538 | } |
1545 | GNUNET_STATISTICS_set(stats, | 1539 | |
1546 | gettext_noop("# hostlist URIs written to file"), | 1540 | if (GNUNET_YES == shutdown) |
1547 | counter, | 1541 | GNUNET_free (pos); |
1548 | GNUNET_YES); | 1542 | counter++; |
1549 | 1543 | if (counter >= MAX_NUMBER_HOSTLISTS) | |
1550 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) | 1544 | break; |
1551 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1545 | } |
1552 | _("Error writing hostlist URIs to file `%s'\n"), | 1546 | GNUNET_STATISTICS_set (stats, |
1553 | filename); | 1547 | gettext_noop ("# hostlist URIs written to file"), |
1554 | GNUNET_free(filename); | 1548 | counter, |
1549 | GNUNET_YES); | ||
1550 | |||
1551 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | ||
1552 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1553 | _ ("Error writing hostlist URIs to file `%s'\n"), | ||
1554 | filename); | ||
1555 | GNUNET_free (filename); | ||
1555 | } | 1556 | } |
1556 | 1557 | ||
1557 | 1558 | ||
@@ -1567,94 +1568,94 @@ save_hostlist_file(int shutdown) | |||
1567 | * @return #GNUNET_OK on success | 1568 | * @return #GNUNET_OK on success |
1568 | */ | 1569 | */ |
1569 | int | 1570 | int |
1570 | GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, | 1571 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, |
1571 | struct GNUNET_STATISTICS_Handle *st, | 1572 | struct GNUNET_STATISTICS_Handle *st, |
1572 | GNUNET_CORE_ConnectEventHandler *ch, | 1573 | GNUNET_CORE_ConnectEventHandler *ch, |
1573 | GNUNET_CORE_DisconnectEventHandler *dh, | 1574 | GNUNET_CORE_DisconnectEventHandler *dh, |
1574 | GNUNET_HOSTLIST_UriHandler *msgh, | 1575 | GNUNET_HOSTLIST_UriHandler *msgh, |
1575 | int learn) | 1576 | int learn) |
1576 | { | 1577 | { |
1577 | char *filename; | 1578 | char *filename; |
1578 | char *proxytype_str; | 1579 | char *proxytype_str; |
1579 | int result; | 1580 | int result; |
1580 | 1581 | ||
1581 | GNUNET_assert(NULL != st); | 1582 | GNUNET_assert (NULL != st); |
1582 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) | 1583 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
1583 | { | 1584 | { |
1584 | GNUNET_break(0); | 1585 | GNUNET_break (0); |
1585 | return GNUNET_SYSERR; | 1586 | return GNUNET_SYSERR; |
1586 | } | 1587 | } |
1587 | cfg = c; | 1588 | cfg = c; |
1588 | stats = st; | 1589 | stats = st; |
1589 | 1590 | ||
1590 | /* Read proxy configuration */ | 1591 | /* Read proxy configuration */ |
1591 | pi = GNUNET_PEERINFO_connect(c); | 1592 | pi = GNUNET_PEERINFO_connect (c); |
1592 | if (GNUNET_OK == | 1593 | if (GNUNET_OK == |
1593 | GNUNET_CONFIGURATION_get_value_string(cfg, "HOSTLIST", "PROXY", &proxy)) | 1594 | GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy)) |
1595 | { | ||
1596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy); | ||
1597 | /* proxy username */ | ||
1598 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1599 | "HOSTLIST", | ||
1600 | "PROXY_USERNAME", | ||
1601 | &proxy_username)) | ||
1594 | { | 1602 | { |
1595 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy); | 1603 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1596 | /* proxy username */ | 1604 | "Found proxy username name: `%s'\n", |
1597 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, | 1605 | proxy_username); |
1598 | "HOSTLIST", | 1606 | } |
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 | } | ||
1606 | 1607 | ||
1607 | /* proxy password */ | 1608 | /* proxy password */ |
1608 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, | 1609 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, |
1609 | "HOSTLIST", | 1610 | "HOSTLIST", |
1610 | "PROXY_PASSWORD", | 1611 | "PROXY_PASSWORD", |
1611 | &proxy_password)) | 1612 | &proxy_password)) |
1612 | { | 1613 | { |
1613 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1614 | "Found proxy password name: `%s'\n", | 1615 | "Found proxy password name: `%s'\n", |
1615 | proxy_password); | 1616 | proxy_password); |
1616 | } | 1617 | } |
1617 | 1618 | ||
1618 | /* proxy type */ | 1619 | /* proxy type */ |
1619 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, | 1620 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, |
1620 | "HOSTLIST", | 1621 | "HOSTLIST", |
1621 | "PROXY_TYPE", | 1622 | "PROXY_TYPE", |
1622 | &proxytype_str)) | 1623 | &proxytype_str)) |
1623 | { | 1624 | { |
1624 | GNUNET_STRINGS_utf8_toupper(proxytype_str, proxytype_str); | 1625 | GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str); |
1625 | proxy_type = CURLPROXY_HTTP; | 1626 | proxy_type = CURLPROXY_HTTP; |
1626 | if (0 == strcmp(proxytype_str, "HTTP")) | 1627 | if (0 == strcmp (proxytype_str, "HTTP")) |
1627 | proxy_type = CURLPROXY_HTTP; | 1628 | proxy_type = CURLPROXY_HTTP; |
1628 | else if (0 == strcmp(proxytype_str, "HTTP_1_0")) | 1629 | else if (0 == strcmp (proxytype_str, "HTTP_1_0")) |
1629 | proxy_type = CURLPROXY_HTTP_1_0; | 1630 | proxy_type = CURLPROXY_HTTP_1_0; |
1630 | else if (0 == strcmp(proxytype_str, "SOCKS4")) | 1631 | else if (0 == strcmp (proxytype_str, "SOCKS4")) |
1631 | proxy_type = CURLPROXY_SOCKS4; | 1632 | proxy_type = CURLPROXY_SOCKS4; |
1632 | else if (0 == strcmp(proxytype_str, "SOCKS5")) | 1633 | else if (0 == strcmp (proxytype_str, "SOCKS5")) |
1633 | proxy_type = CURLPROXY_SOCKS5; | 1634 | proxy_type = CURLPROXY_SOCKS5; |
1634 | else if (0 == strcmp(proxytype_str, "SOCKS4A")) | 1635 | else if (0 == strcmp (proxytype_str, "SOCKS4A")) |
1635 | proxy_type = CURLPROXY_SOCKS4A; | 1636 | proxy_type = CURLPROXY_SOCKS4A; |
1636 | else if (0 == strcmp(proxytype_str, "SOCKS5_HOSTNAME")) | 1637 | else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME")) |
1637 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; | 1638 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; |
1638 | else | 1639 | else |
1639 | { | 1640 | { |
1640 | GNUNET_log( | 1641 | GNUNET_log ( |
1641 | GNUNET_ERROR_TYPE_ERROR, | 1642 | GNUNET_ERROR_TYPE_ERROR, |
1642 | _( | 1643 | _ ( |
1643 | "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), | 1644 | "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), |
1644 | proxytype_str); | 1645 | proxytype_str); |
1645 | GNUNET_free(proxytype_str); | 1646 | GNUNET_free (proxytype_str); |
1646 | GNUNET_free(proxy); | 1647 | GNUNET_free (proxy); |
1647 | proxy = NULL; | 1648 | proxy = NULL; |
1648 | GNUNET_free_non_null(proxy_username); | 1649 | GNUNET_free_non_null (proxy_username); |
1649 | proxy_username = NULL; | 1650 | proxy_username = NULL; |
1650 | GNUNET_free_non_null(proxy_password); | 1651 | GNUNET_free_non_null (proxy_password); |
1651 | proxy_password = NULL; | 1652 | proxy_password = NULL; |
1652 | 1653 | ||
1653 | return GNUNET_SYSERR; | 1654 | return GNUNET_SYSERR; |
1654 | } | 1655 | } |
1655 | } | ||
1656 | GNUNET_free_non_null(proxytype_str); | ||
1657 | } | 1656 | } |
1657 | GNUNET_free_non_null (proxytype_str); | ||
1658 | } | ||
1658 | 1659 | ||
1659 | stat_learning = learn; | 1660 | stat_learning = learn; |
1660 | *ch = &handler_connect; | 1661 | *ch = &handler_connect; |
@@ -1666,67 +1667,67 @@ GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
1666 | stat_testing_allowed = GNUNET_YES; | 1667 | stat_testing_allowed = GNUNET_YES; |
1667 | 1668 | ||
1668 | if (GNUNET_YES == stat_learning) | 1669 | if (GNUNET_YES == stat_learning) |
1669 | { | 1670 | { |
1670 | *msgh = &handler_advertisement; | 1671 | *msgh = &handler_advertisement; |
1671 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1672 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1672 | _("Learning is enabled on this peer\n")); | 1673 | _ ("Learning is enabled on this peer\n")); |
1673 | load_hostlist_file(); | 1674 | load_hostlist_file (); |
1674 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1675 | "Hostlists will be saved to file again in %s\n", | 1676 | "Hostlists will be saved to file again in %s\n", |
1676 | GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, | 1677 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, |
1677 | GNUNET_YES)); | 1678 | GNUNET_YES)); |
1678 | ti_saving_task = GNUNET_SCHEDULER_add_delayed(SAVING_INTERVAL, | 1679 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, |
1679 | &task_hostlist_saving, | 1680 | &task_hostlist_saving, |
1680 | NULL); | 1681 | NULL); |
1681 | } | 1682 | } |
1682 | else | 1683 | else |
1684 | { | ||
1685 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1686 | _ ("Learning is not enabled on this peer\n")); | ||
1687 | *msgh = NULL; | ||
1688 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
1689 | "HOSTLIST", | ||
1690 | "HOSTLISTFILE", | ||
1691 | &filename)) | ||
1683 | { | 1692 | { |
1684 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1693 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
1685 | _("Learning is not enabled on this peer\n")); | 1694 | { |
1686 | *msgh = NULL; | 1695 | result = remove (filename); |
1687 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, | 1696 | if (0 == result) |
1688 | "HOSTLIST", | 1697 | GNUNET_log ( |
1689 | "HOSTLISTFILE", | 1698 | GNUNET_ERROR_TYPE_INFO, |
1690 | &filename)) | 1699 | _ ( |
1691 | { | 1700 | "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), |
1692 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) | 1701 | filename); |
1693 | { | 1702 | else |
1694 | result = remove(filename); | 1703 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
1695 | if (0 == result) | 1704 | "remove", |
1696 | GNUNET_log( | 1705 | filename); |
1697 | GNUNET_ERROR_TYPE_INFO, | 1706 | } |
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); | ||
1708 | } | 1707 | } |
1709 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1708 | GNUNET_free (filename); |
1710 | "Loading stats value on hostlist download frequency\n"); | 1709 | } |
1711 | sget = GNUNET_STATISTICS_get(stats, | 1710 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1712 | "hostlist", | 1711 | "Loading stats value on hostlist download frequency\n"); |
1713 | gettext_noop( | 1712 | sget = GNUNET_STATISTICS_get (stats, |
1714 | "# milliseconds between hostlist downloads"), | 1713 | "hostlist", |
1715 | &primary_task, | 1714 | gettext_noop ( |
1716 | &process_stat, | 1715 | "# milliseconds between hostlist downloads"), |
1717 | NULL); | 1716 | &primary_task, |
1717 | &process_stat, | ||
1718 | NULL); | ||
1718 | if (NULL == sget) | 1719 | if (NULL == sget) |
1719 | { | 1720 | { |
1720 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1721 | "Statistics request failed, scheduling hostlist download\n"); | 1722 | "Statistics request failed, scheduling hostlist download\n"); |
1722 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); | 1723 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1723 | } | 1724 | } |
1724 | else | 1725 | else |
1725 | { | 1726 | { |
1726 | ti_check_download = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 1727 | ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
1727 | &stat_timeout_task, | 1728 | &stat_timeout_task, |
1728 | NULL); | 1729 | NULL); |
1729 | } | 1730 | } |
1730 | return GNUNET_OK; | 1731 | return GNUNET_OK; |
1731 | } | 1732 | } |
1732 | 1733 | ||
@@ -1735,56 +1736,56 @@ GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
1735 | * Stop downloading hostlists from hostlist servers as necessary. | 1736 | * Stop downloading hostlists from hostlist servers as necessary. |
1736 | */ | 1737 | */ |
1737 | void | 1738 | void |
1738 | GNUNET_HOSTLIST_client_stop() | 1739 | GNUNET_HOSTLIST_client_stop () |
1739 | { | 1740 | { |
1740 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); | 1741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1741 | if (NULL != sget) | 1742 | if (NULL != sget) |
1742 | { | 1743 | { |
1743 | GNUNET_STATISTICS_get_cancel(sget); | 1744 | GNUNET_STATISTICS_get_cancel (sget); |
1744 | sget = NULL; | 1745 | sget = NULL; |
1745 | } | 1746 | } |
1746 | stats = NULL; | 1747 | stats = NULL; |
1747 | if (GNUNET_YES == stat_learning) | 1748 | if (GNUNET_YES == stat_learning) |
1748 | save_hostlist_file(GNUNET_YES); | 1749 | save_hostlist_file (GNUNET_YES); |
1749 | if (NULL != ti_saving_task) | 1750 | if (NULL != ti_saving_task) |
1750 | { | 1751 | { |
1751 | GNUNET_SCHEDULER_cancel(ti_saving_task); | 1752 | GNUNET_SCHEDULER_cancel (ti_saving_task); |
1752 | ti_saving_task = NULL; | 1753 | ti_saving_task = NULL; |
1753 | } | 1754 | } |
1754 | if (NULL != ti_download_dispatcher_task) | 1755 | if (NULL != ti_download_dispatcher_task) |
1755 | { | 1756 | { |
1756 | GNUNET_SCHEDULER_cancel(ti_download_dispatcher_task); | 1757 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); |
1757 | ti_download_dispatcher_task = NULL; | 1758 | ti_download_dispatcher_task = NULL; |
1758 | } | 1759 | } |
1759 | if (NULL != ti_testing_intervall_task) | 1760 | if (NULL != ti_testing_intervall_task) |
1760 | { | 1761 | { |
1761 | GNUNET_SCHEDULER_cancel(ti_testing_intervall_task); | 1762 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); |
1762 | ti_testing_intervall_task = NULL; | 1763 | ti_testing_intervall_task = NULL; |
1763 | } | 1764 | } |
1764 | if (NULL != ti_download) | 1765 | if (NULL != ti_download) |
1765 | { | 1766 | { |
1766 | GNUNET_SCHEDULER_cancel(ti_download); | 1767 | GNUNET_SCHEDULER_cancel (ti_download); |
1767 | ti_download = NULL; | 1768 | ti_download = NULL; |
1768 | update_hostlist(); | 1769 | update_hostlist (); |
1769 | clean_up(); | 1770 | clean_up (); |
1770 | } | 1771 | } |
1771 | if (NULL != ti_check_download) | 1772 | if (NULL != ti_check_download) |
1772 | { | 1773 | { |
1773 | GNUNET_SCHEDULER_cancel(ti_check_download); | 1774 | GNUNET_SCHEDULER_cancel (ti_check_download); |
1774 | ti_check_download = NULL; | 1775 | ti_check_download = NULL; |
1775 | curl_global_cleanup(); | 1776 | curl_global_cleanup (); |
1776 | } | 1777 | } |
1777 | GNUNET_free_non_null(proxy); | 1778 | GNUNET_free_non_null (proxy); |
1778 | proxy = NULL; | 1779 | proxy = NULL; |
1779 | GNUNET_free_non_null(proxy_username); | 1780 | GNUNET_free_non_null (proxy_username); |
1780 | proxy_username = NULL; | 1781 | proxy_username = NULL; |
1781 | GNUNET_free_non_null(proxy_password); | 1782 | GNUNET_free_non_null (proxy_password); |
1782 | proxy_password = NULL; | 1783 | proxy_password = NULL; |
1783 | if (NULL != pi) | 1784 | if (NULL != pi) |
1784 | { | 1785 | { |
1785 | GNUNET_PEERINFO_disconnect(pi); | 1786 | GNUNET_PEERINFO_disconnect (pi); |
1786 | pi = NULL; | 1787 | pi = NULL; |
1787 | } | 1788 | } |
1788 | cfg = NULL; | 1789 | cfg = NULL; |
1789 | } | 1790 | } |
1790 | 1791 | ||