aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_client.c530
-rw-r--r--src/mysql/mysql.c2
-rw-r--r--src/nat-auto/gnunet-nat-auto_legacy.c208
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c128
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c42
-rw-r--r--src/transport/gnunet-transport-wlan-sender.c127
6 files changed, 527 insertions, 510 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c
index 539760966..0428e64b8 100644
--- a/src/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/hostlist/gnunet-daemon-hostlist_client.c
@@ -34,7 +34,6 @@
34#include "gnunet_curl_lib.h" 34#include "gnunet_curl_lib.h"
35 35
36 36
37
38/** 37/**
39 * Number of connections that we must have to NOT download 38 * Number of connections that we must have to NOT download
40 * hostlists anymore. 39 * hostlists anymore.
@@ -49,17 +48,20 @@
49/** 48/**
50 * Time interval hostlists are saved to disk 49 * Time interval hostlists are saved to disk
51 */ 50 */
52#define SAVING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) 51#define SAVING_INTERVAL \
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 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) 57#define TESTING_INTERVAL \
58 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
58 59
59/** 60/**
60 * Time interval for download dispatcher before a download is re-scheduled 61 * Time interval for download dispatcher before a download is re-scheduled
61 */ 62 */
62#define WAITING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 63#define WAITING_INTERVAL \
64 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
63 65
64/** 66/**
65 * Defines concerning the hostlist quality metric 67 * Defines concerning the hostlist quality metric
@@ -86,7 +88,6 @@
86#define HOSTLIST_SUCCESSFUL_HELLO 1 88#define HOSTLIST_SUCCESSFUL_HELLO 1
87 89
88 90
89
90/** 91/**
91 * A single hostlist obtained by hostlist advertisements 92 * A single hostlist obtained by hostlist advertisements
92 */ 93 */
@@ -136,7 +137,6 @@ struct Hostlist
136 * Number of times the hostlist was successfully obtained 137 * Number of times the hostlist was successfully obtained
137 */ 138 */
138 uint32_t times_used; 139 uint32_t times_used;
139
140}; 140};
141 141
142 142
@@ -321,10 +321,7 @@ static struct GNUNET_PEERINFO_Handle *pi;
321 * @return number of bytes that were processed (always size*nmemb) 321 * @return number of bytes that were processed (always size*nmemb)
322 */ 322 */
323static size_t 323static size_t
324callback_download (void *ptr, 324callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
325 size_t size,
326 size_t nmemb,
327 void *ctx)
328{ 325{
329 static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; 326 static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1];
330 const char *cbuf = ptr; 327 const char *cbuf = ptr;
@@ -338,13 +335,14 @@ callback_download (void *ptr,
338 stat_bytes_downloaded += total; 335 stat_bytes_downloaded += total;
339 if ((total == 0) || (stat_bogus_url)) 336 if ((total == 0) || (stat_bogus_url))
340 { 337 {
341 return total; /* ok, no data or bogus data */ 338 return total; /* ok, no data or bogus data */
342 } 339 }
343 340
344 GNUNET_STATISTICS_update (stats, 341 GNUNET_STATISTICS_update (stats,
345 gettext_noop 342 gettext_noop (
346 ("# bytes downloaded from hostlist servers"), 343 "# bytes downloaded from hostlist servers"),
347 (int64_t) total, GNUNET_NO); 344 (int64_t) total,
345 GNUNET_NO);
348 left = total; 346 left = total;
349 while ((left > 0) || (download_pos > 0)) 347 while ((left > 0) || (download_pos > 0))
350 { 348 {
@@ -362,13 +360,15 @@ callback_download (void *ptr,
362 msize = ntohs (msg->size); 360 msize = ntohs (msg->size);
363 if (msize < sizeof (struct GNUNET_MessageHeader)) 361 if (msize < sizeof (struct GNUNET_MessageHeader))
364 { 362 {
365 GNUNET_STATISTICS_update (stats, 363 GNUNET_STATISTICS_update (
366 gettext_noop 364 stats,
367 ("# invalid HELLOs downloaded from hostlist servers"), 365 gettext_noop ("# invalid HELLOs downloaded from hostlist servers"),
368 1, GNUNET_NO); 366 1,
367 GNUNET_NO);
369 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 368 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
370 _("Invalid `%s' message received from hostlist at `%s'\n"), 369 _ ("Invalid `%s' message received from hostlist at `%s'\n"),
371 "HELLO", current_url); 370 "HELLO",
371 current_url);
372 stat_hellos_obtained++; 372 stat_hellos_obtained++;
373 stat_bogus_url = 1; 373 stat_bogus_url = 1;
374 return total; 374 return total;
@@ -383,32 +383,34 @@ callback_download (void *ptr,
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
384 "Received valid `%s' message from hostlist server.\n", 384 "Received valid `%s' message from hostlist server.\n",
385 "HELLO"); 385 "HELLO");
386 GNUNET_STATISTICS_update (stats, 386 GNUNET_STATISTICS_update (
387 gettext_noop 387 stats,
388 ("# valid HELLOs downloaded from hostlist servers"), 388 gettext_noop ("# valid HELLOs downloaded from hostlist servers"),
389 1, GNUNET_NO); 389 1,
390 GNUNET_NO);
390 stat_hellos_obtained++; 391 stat_hellos_obtained++;
391 (void) GNUNET_PEERINFO_add_peer (pi, 392 (void)
392 (const struct GNUNET_HELLO_Message *) msg, 393 GNUNET_PEERINFO_add_peer (pi,
393 NULL, 394 (const struct GNUNET_HELLO_Message *) msg,
394 NULL); 395 NULL,
396 NULL);
395 } 397 }
396 else 398 else
397 { 399 {
398 GNUNET_STATISTICS_update (stats, 400 GNUNET_STATISTICS_update (
399 gettext_noop 401 stats,
400 ("# invalid HELLOs downloaded from hostlist servers"), 402 gettext_noop ("# invalid HELLOs downloaded from hostlist servers"),
401 1, GNUNET_NO); 403 1,
404 GNUNET_NO);
402 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 405 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
403 _("Invalid `%s' message received from hostlist at `%s'\n"), 406 _ ("Invalid `%s' message received from hostlist at `%s'\n"),
404 "HELLO", current_url); 407 "HELLO",
408 current_url);
405 stat_bogus_url = GNUNET_YES; 409 stat_bogus_url = GNUNET_YES;
406 stat_hellos_obtained++; 410 stat_hellos_obtained++;
407 return total; 411 return total;
408 } 412 }
409 memmove (download_buffer, 413 memmove (download_buffer, &download_buffer[msize], download_pos - msize);
410 &download_buffer[msize],
411 download_pos - msize);
412 download_pos -= msize; 414 download_pos -= msize;
413 } 415 }
414 return total; 416 return total;
@@ -428,12 +430,14 @@ get_bootstrap_server ()
428 size_t urls; 430 size_t urls;
429 size_t pos; 431 size_t pos;
430 432
431 if (GNUNET_OK != 433 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
432 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "SERVERS", 434 "HOSTLIST",
433 &servers)) 435 "SERVERS",
436 &servers))
434 { 437 {
435 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 438 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
436 "hostlist", "SERVERS"); 439 "hostlist",
440 "SERVERS");
437 return NULL; 441 return NULL;
438 } 442 }
439 443
@@ -452,7 +456,8 @@ get_bootstrap_server ()
452 if (urls == 0) 456 if (urls == 0)
453 { 457 {
454 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 458 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
455 "hostlist", "SERVERS"); 459 "hostlist",
460 "SERVERS");
456 GNUNET_free (servers); 461 GNUNET_free (servers);
457 return NULL; 462 return NULL;
458 } 463 }
@@ -514,7 +519,7 @@ download_get_url ()
514 return get_bootstrap_server (); 519 return get_bootstrap_server ();
515 } 520 }
516 index = 521 index =
517 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); 522 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size);
518 counter = 0; 523 counter = 0;
519 pos = linked_list_head; 524 pos = linked_list_head;
520 while (counter < index) 525 while (counter < index)
@@ -522,14 +527,26 @@ download_get_url ()
522 pos = pos->next; 527 pos = pos->next;
523 counter++; 528 counter++;
524 } 529 }
525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using learned hostlist `%s'\n", 530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
531 "Using learned hostlist `%s'\n",
526 pos->hostlist_uri); 532 pos->hostlist_uri);
527 current_hostlist = pos; 533 current_hostlist = pos;
528 return GNUNET_strdup (pos->hostlist_uri); 534 return GNUNET_strdup (pos->hostlist_uri);
529} 535}
530 536
531 537
532#define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt (c, a, b); if (CURLE_OK != ret) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror (ret)); } while (0) 538#define CURL_EASY_SETOPT(c, a, b) \
539 do \
540 { \
541 ret = curl_easy_setopt (c, a, b); \
542 if (CURLE_OK != ret) \
543 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
544 _ ("%s failed at %s:%d: `%s'\n"), \
545 "curl_easy_setopt", \
546 __FILE__, \
547 __LINE__, \
548 curl_easy_strerror (ret)); \
549 } while (0)
533 550
534 551
535/** 552/**
@@ -549,8 +566,7 @@ save_hostlist_file (int shutdown);
549 * @return result 566 * @return result
550 */ 567 */
551static uint64_t 568static uint64_t
552checked_add (uint64_t val1, 569checked_add (uint64_t val1, uint64_t val2)
553 uint64_t val2)
554{ 570{
555 static uint64_t temp; 571 static uint64_t temp;
556 static uint64_t maxv; 572 static uint64_t maxv;
@@ -573,8 +589,7 @@ checked_add (uint64_t val1,
573 * @return result 589 * @return result
574 */ 590 */
575static uint64_t 591static uint64_t
576checked_sub (uint64_t val1, 592checked_sub (uint64_t val1, uint64_t val2)
577 uint64_t val2)
578{ 593{
579 if (val1 <= val2) 594 if (val1 <= val2)
580 return 0; 595 return 0;
@@ -643,20 +658,25 @@ insert_hostlist ()
643 /* No free entries available, replace existing entry */ 658 /* No free entries available, replace existing entry */
644 lowest_quality = linked_list_get_lowest_quality (); 659 lowest_quality = linked_list_get_lowest_quality ();
645 GNUNET_assert (lowest_quality != NULL); 660 GNUNET_assert (lowest_quality != NULL);
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 661 GNUNET_log (
647 "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", 662 GNUNET_ERROR_TYPE_DEBUG,
648 lowest_quality->hostlist_uri, 663 "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n",
649 (unsigned long long) lowest_quality->quality); 664 lowest_quality->hostlist_uri,
650 GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, 665 (unsigned long long) lowest_quality->quality);
666 GNUNET_CONTAINER_DLL_remove (linked_list_head,
667 linked_list_tail,
651 lowest_quality); 668 lowest_quality);
652 linked_list_size--; 669 linked_list_size--;
653 GNUNET_free (lowest_quality); 670 GNUNET_free (lowest_quality);
654 } 671 }
655 GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, 672 GNUNET_CONTAINER_DLL_insert (linked_list_head,
673 linked_list_tail,
656 hostlist_to_test); 674 hostlist_to_test);
657 linked_list_size++; 675 linked_list_size++;
658 GNUNET_STATISTICS_set (stats, gettext_noop ("# advertised hostlist URIs"), 676 GNUNET_STATISTICS_set (stats,
659 linked_list_size, GNUNET_NO); 677 gettext_noop ("# advertised hostlist URIs"),
678 linked_list_size,
679 GNUNET_NO);
660 stat_testing_hostlist = GNUNET_NO; 680 stat_testing_hostlist = GNUNET_NO;
661} 681}
662 682
@@ -678,14 +698,15 @@ update_hostlist ()
678 current_hostlist->hello_count = stat_hellos_obtained; 698 current_hostlist->hello_count = stat_hellos_obtained;
679 current_hostlist->time_last_usage = GNUNET_TIME_absolute_get (); 699 current_hostlist->time_last_usage = GNUNET_TIME_absolute_get ();
680 current_hostlist->quality = 700 current_hostlist->quality =
681 checked_add (current_hostlist->quality, 701 checked_add (current_hostlist->quality,
682 (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); 702 (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO));
683 if (GNUNET_YES == stat_download_successful) 703 if (GNUNET_YES == stat_download_successful)
684 { 704 {
685 current_hostlist->times_used++; 705 current_hostlist->times_used++;
686 current_hostlist->quality = 706 current_hostlist->quality =
687 checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); 707 checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD);
688 GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"), 708 GNUNET_asprintf (&stat,
709 gettext_noop ("# advertised URI `%s' downloaded"),
689 current_hostlist->hostlist_uri); 710 current_hostlist->hostlist_uri);
690 711
691 GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES); 712 GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES);
@@ -693,7 +714,7 @@ update_hostlist ()
693 } 714 }
694 else 715 else
695 current_hostlist->quality = 716 current_hostlist->quality =
696 checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); 717 checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD);
697 } 718 }
698 current_hostlist = NULL; 719 current_hostlist = NULL;
699 /* Alternating the usage of preconfigured and learned hostlists */ 720 /* Alternating the usage of preconfigured and learned hostlists */
@@ -722,14 +743,14 @@ clean_up ()
722{ 743{
723 CURLMcode mret; 744 CURLMcode mret;
724 745
725 if ( (stat_testing_hostlist == GNUNET_YES) && 746 if ((stat_testing_hostlist == GNUNET_YES) &&
726 (GNUNET_NO == stat_download_successful) && 747 (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test))
727 (NULL != hostlist_to_test) )
728 { 748 {
729 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 749 GNUNET_log (
730 _ 750 GNUNET_ERROR_TYPE_INFO,
731 ("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), 751 _ (
732 hostlist_to_test->hostlist_uri); 752 "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"),
753 hostlist_to_test->hostlist_uri);
733 } 754 }
734 755
735 if (stat_testing_hostlist == GNUNET_YES) 756 if (stat_testing_hostlist == GNUNET_YES)
@@ -747,14 +768,20 @@ clean_up ()
747 mret = curl_multi_remove_handle (multi, curl); 768 mret = curl_multi_remove_handle (multi, curl);
748 if (mret != CURLM_OK) 769 if (mret != CURLM_OK)
749 { 770 {
750 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), 771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
751 "curl_multi_remove_handle", __FILE__, __LINE__, 772 _ ("%s failed at %s:%d: `%s'\n"),
773 "curl_multi_remove_handle",
774 __FILE__,
775 __LINE__,
752 curl_multi_strerror (mret)); 776 curl_multi_strerror (mret));
753 } 777 }
754 mret = curl_multi_cleanup (multi); 778 mret = curl_multi_cleanup (multi);
755 if (mret != CURLM_OK) 779 if (mret != CURLM_OK)
756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), 780 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
757 "curl_multi_cleanup", __FILE__, __LINE__, 781 _ ("%s failed at %s:%d: `%s'\n"),
782 "curl_multi_cleanup",
783 __FILE__,
784 __LINE__,
758 curl_multi_strerror (mret)); 785 curl_multi_strerror (mret));
759 multi = NULL; 786 multi = NULL;
760 } 787 }
@@ -805,8 +832,11 @@ download_prepare ()
805 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 832 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
806 if (mret != CURLM_OK) 833 if (mret != CURLM_OK)
807 { 834 {
808 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), 835 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
809 "curl_multi_fdset", __FILE__, __LINE__, 836 _ ("%s failed at %s:%d: `%s'\n"),
837 "curl_multi_fdset",
838 __FILE__,
839 __LINE__,
810 curl_multi_strerror (mret)); 840 curl_multi_strerror (mret));
811 clean_up (); 841 clean_up ();
812 return; 842 return;
@@ -814,26 +844,30 @@ download_prepare ()
814 mret = curl_multi_timeout (multi, &timeout); 844 mret = curl_multi_timeout (multi, &timeout);
815 if (mret != CURLM_OK) 845 if (mret != CURLM_OK)
816 { 846 {
817 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), 847 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
818 "curl_multi_timeout", __FILE__, __LINE__, 848 _ ("%s failed at %s:%d: `%s'\n"),
849 "curl_multi_timeout",
850 __FILE__,
851 __LINE__,
819 curl_multi_strerror (mret)); 852 curl_multi_strerror (mret));
820 clean_up (); 853 clean_up ();
821 return; 854 return;
822 } 855 }
823 rtime = 856 rtime = GNUNET_TIME_relative_min (
824 GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time), 857 GNUNET_TIME_absolute_get_remaining (end_time),
825 GNUNET_TIME_relative_multiply 858 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout));
826 (GNUNET_TIME_UNIT_MILLISECONDS, timeout));
827 grs = GNUNET_NETWORK_fdset_create (); 859 grs = GNUNET_NETWORK_fdset_create ();
828 gws = GNUNET_NETWORK_fdset_create (); 860 gws = GNUNET_NETWORK_fdset_create ();
829 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 861 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
830 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 862 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
832 "Scheduling task for hostlist download using cURL\n"); 864 "Scheduling task for hostlist download using cURL\n");
833 ti_download = 865 ti_download = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
834 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 866 rtime,
835 rtime, grs, gws, 867 grs,
836 &task_download, multi); 868 gws,
869 &task_download,
870 multi);
837 GNUNET_NETWORK_fdset_destroy (gws); 871 GNUNET_NETWORK_fdset_destroy (gws);
838 GNUNET_NETWORK_fdset_destroy (grs); 872 GNUNET_NETWORK_fdset_destroy (grs);
839} 873}
@@ -856,7 +890,7 @@ task_download (void *cls)
856 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)
857 { 891 {
858 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 892 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
859 _("Timeout trying to download hostlist from `%s'\n"), 893 _ ("Timeout trying to download hostlist from `%s'\n"),
860 current_url); 894 current_url);
861 update_hostlist (); 895 update_hostlist ();
862 clean_up (); 896 clean_up ();
@@ -870,7 +904,8 @@ task_download (void *cls)
870 if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) 904 if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS)
871 { 905 {
872 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 906 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
873 _("Download limit of %u bytes exceeded, stopping download\n"), 907 _ (
908 "Download limit of %u bytes exceeded, stopping download\n"),
874 MAX_BYTES_PER_HOSTLISTS); 909 MAX_BYTES_PER_HOSTLISTS);
875 clean_up (); 910 clean_up ();
876 return; 911 return;
@@ -890,22 +925,22 @@ task_download (void *cls)
890 if ((msg->data.result != CURLE_OK) && 925 if ((msg->data.result != CURLE_OK) &&
891 (msg->data.result != CURLE_GOT_NOTHING)) 926 (msg->data.result != CURLE_GOT_NOTHING))
892 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 927 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
893 _("Download of hostlist from `%s' failed: `%s'\n"), 928 _ ("Download of hostlist from `%s' failed: `%s'\n"),
894 current_url, 929 current_url,
895 curl_easy_strerror (msg->data.result)); 930 curl_easy_strerror (msg->data.result));
896 else 931 else
897 { 932 {
898 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 933 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
899 _("Download of hostlist `%s' completed.\n"), 934 _ ("Download of hostlist `%s' completed.\n"),
900 current_url); 935 current_url);
901 stat_download_successful = GNUNET_YES; 936 stat_download_successful = GNUNET_YES;
902 update_hostlist (); 937 update_hostlist ();
903 if (GNUNET_YES == stat_testing_hostlist) 938 if (GNUNET_YES == stat_testing_hostlist)
904 { 939 {
905 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 940 GNUNET_log (
906 _ 941 GNUNET_ERROR_TYPE_INFO,
907 ("Adding successfully tested hostlist `%s' datastore.\n"), 942 _ ("Adding successfully tested hostlist `%s' datastore.\n"),
908 current_url); 943 current_url);
909 insert_hostlist (); 944 insert_hostlist ();
910 hostlist_to_test = NULL; 945 hostlist_to_test = NULL;
911 stat_testing_hostlist = GNUNET_NO; 946 stat_testing_hostlist = GNUNET_NO;
@@ -917,16 +952,17 @@ task_download (void *cls)
917 break; 952 break;
918 } 953 }
919 954
920 } 955 } while ((running > 0));
921 while ((running > 0));
922 } 956 }
923 } 957 } while (mret == CURLM_CALL_MULTI_PERFORM);
924 while (mret == CURLM_CALL_MULTI_PERFORM);
925 958
926 if (mret != CURLM_OK) 959 if (mret != CURLM_OK)
927 { 960 {
928 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%s failed at %s:%d: `%s'\n"), 961 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
929 "curl_multi_perform", __FILE__, __LINE__, 962 _ ("%s failed at %s:%d: `%s'\n"),
963 "curl_multi_perform",
964 __FILE__,
965 __LINE__,
930 curl_multi_strerror (mret)); 966 curl_multi_strerror (mret));
931 clean_up (); 967 clean_up ();
932 } 968 }
@@ -957,7 +993,8 @@ download_hostlist ()
957 return; 993 return;
958 } 994 }
959 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 995 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
960 _("Bootstrapping using hostlist at `%s'.\n"), current_url); 996 _ ("Bootstrapping using hostlist at `%s'.\n"),
997 current_url);
961 998
962 stat_download_in_progress = GNUNET_YES; 999 stat_download_in_progress = GNUNET_YES;
963 stat_download_successful = GNUNET_NO; 1000 stat_download_successful = GNUNET_NO;
@@ -965,7 +1002,8 @@ download_hostlist ()
965 stat_bytes_downloaded = 0; 1002 stat_bytes_downloaded = 0;
966 1003
967 GNUNET_STATISTICS_update (stats, 1004 GNUNET_STATISTICS_update (stats,
968 gettext_noop ("# hostlist downloads initiated"), 1, 1005 gettext_noop ("# hostlist downloads initiated"),
1006 1,
969 GNUNET_NO); 1007 GNUNET_NO);
970 if (NULL != proxy) 1008 if (NULL != proxy)
971 { 1009 {
@@ -991,7 +1029,9 @@ download_hostlist ()
991 return; 1029 return;
992 } 1030 }
993 CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); 1031 CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
994 CURL_EASY_SETOPT (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); 1032 CURL_EASY_SETOPT (curl,
1033 CURLOPT_REDIR_PROTOCOLS,
1034 CURLPROTO_HTTP | CURLPROTO_HTTPS);
995 CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); 1035 CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
996 CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); 1036 CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
997 /* no need to abort if the above failed */ 1037 /* no need to abort if the above failed */
@@ -1020,13 +1060,19 @@ download_hostlist ()
1020 mret = curl_multi_add_handle (multi, curl); 1060 mret = curl_multi_add_handle (multi, curl);
1021 if (mret != CURLM_OK) 1061 if (mret != CURLM_OK)
1022 { 1062 {
1023 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), 1063 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1024 "curl_multi_add_handle", __FILE__, __LINE__, 1064 _ ("%s failed at %s:%d: `%s'\n"),
1065 "curl_multi_add_handle",
1066 __FILE__,
1067 __LINE__,
1025 curl_multi_strerror (mret)); 1068 curl_multi_strerror (mret));
1026 mret = curl_multi_cleanup (multi); 1069 mret = curl_multi_cleanup (multi);
1027 if (mret != CURLM_OK) 1070 if (mret != CURLM_OK)
1028 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), 1071 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1029 "curl_multi_cleanup", __FILE__, __LINE__, 1072 _ ("%s failed at %s:%d: `%s'\n"),
1073 "curl_multi_cleanup",
1074 __FILE__,
1075 __LINE__,
1030 curl_multi_strerror (mret)); 1076 curl_multi_strerror (mret));
1031 multi = NULL; 1077 multi = NULL;
1032 clean_up (); 1078 clean_up ();
@@ -1052,8 +1098,9 @@ task_download_dispatcher (void *cls)
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 "Download in progess, have to wait...\n"); 1099 "Download in progess, have to wait...\n");
1054 ti_download_dispatcher_task = 1100 ti_download_dispatcher_task =
1055 GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL, 1101 GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL,
1056 &task_download_dispatcher, NULL); 1102 &task_download_dispatcher,
1103 NULL);
1057 } 1104 }
1058} 1105}
1059 1106
@@ -1073,12 +1120,12 @@ task_check (void *cls)
1073 if (stats == NULL) 1120 if (stats == NULL)
1074 { 1121 {
1075 curl_global_cleanup (); 1122 curl_global_cleanup ();
1076 return; /* in shutdown */ 1123 return; /* in shutdown */
1077 } 1124 }
1078 if ( (stat_connection_count < MIN_CONNECTIONS) && 1125 if ((stat_connection_count < MIN_CONNECTIONS) &&
1079 (NULL == ti_download_dispatcher_task) ) 1126 (NULL == ti_download_dispatcher_task))
1080 ti_download_dispatcher_task = 1127 ti_download_dispatcher_task =
1081 GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); 1128 GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
1082 1129
1083 delay = hostlist_delay; 1130 delay = hostlist_delay;
1084 if (0 == hostlist_delay.rel_value_us) 1131 if (0 == hostlist_delay.rel_value_us)
@@ -1088,24 +1135,25 @@ task_check (void *cls)
1088 if (hostlist_delay.rel_value_us > 1135 if (hostlist_delay.rel_value_us >
1089 GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) 1136 GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count))
1090 hostlist_delay = 1137 hostlist_delay =
1091 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1138 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS,
1092 (1 + stat_connection_count)); 1139 (1 + stat_connection_count));
1093 GNUNET_STATISTICS_set (stats, 1140 GNUNET_STATISTICS_set (stats,
1094 gettext_noop 1141 gettext_noop (
1095 ("# milliseconds between hostlist downloads"), 1142 "# milliseconds between hostlist downloads"),
1096 hostlist_delay.rel_value_us / 1000LL, 1143 hostlist_delay.rel_value_us / 1000LL,
1097 GNUNET_YES); 1144 GNUNET_YES);
1098 if (0 == once) 1145 if (0 == once)
1099 { 1146 {
1100 delay = GNUNET_TIME_UNIT_ZERO; 1147 delay = GNUNET_TIME_UNIT_ZERO;
1101 once = 1; 1148 once = 1;
1102 } 1149 }
1103 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1150 GNUNET_log (
1104 _("Have %u/%u connections. Will consider downloading hostlist in %s\n"), 1151 GNUNET_ERROR_TYPE_INFO,
1105 stat_connection_count, MIN_CONNECTIONS, 1152 _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
1106 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1153 stat_connection_count,
1107 ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, 1154 MIN_CONNECTIONS,
1108 &task_check, NULL); 1155 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1156 ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
1109} 1157}
1110 1158
1111 1159
@@ -1137,11 +1185,10 @@ task_hostlist_saving (void *cls)
1137 1185
1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1139 "Hostlists will be saved to file again in %s\n", 1187 "Hostlists will be saved to file again in %s\n",
1140 GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES)); 1188 GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL,
1189 GNUNET_YES));
1141 ti_saving_task = 1190 ti_saving_task =
1142 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, 1191 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, NULL);
1143 &task_hostlist_saving,
1144 NULL);
1145} 1192}
1146 1193
1147 1194
@@ -1154,14 +1201,14 @@ task_hostlist_saving (void *cls)
1154 */ 1201 */
1155static void * 1202static void *
1156handler_connect (void *cls, 1203handler_connect (void *cls,
1157 const struct GNUNET_PeerIdentity *peer, 1204 const struct GNUNET_PeerIdentity *peer,
1158 struct GNUNET_MQ_Handle *mq) 1205 struct GNUNET_MQ_Handle *mq)
1159{ 1206{
1160 GNUNET_assert (stat_connection_count < UINT_MAX); 1207 GNUNET_assert (stat_connection_count < UINT_MAX);
1161 stat_connection_count++; 1208 stat_connection_count++;
1162 GNUNET_STATISTICS_update (stats, 1209 GNUNET_STATISTICS_update (stats,
1163 gettext_noop ("# active connections"), 1210 gettext_noop ("# active connections"),
1164 1, 1211 1,
1165 GNUNET_NO); 1212 GNUNET_NO);
1166 return NULL; 1213 return NULL;
1167} 1214}
@@ -1175,14 +1222,14 @@ handler_connect (void *cls,
1175 */ 1222 */
1176static void 1223static void
1177handler_disconnect (void *cls, 1224handler_disconnect (void *cls,
1178 const struct GNUNET_PeerIdentity *peer, 1225 const struct GNUNET_PeerIdentity *peer,
1179 void *internal_cls) 1226 void *internal_cls)
1180{ 1227{
1181 GNUNET_assert (stat_connection_count > 0); 1228 GNUNET_assert (stat_connection_count > 0);
1182 stat_connection_count--; 1229 stat_connection_count--;
1183 GNUNET_STATISTICS_update (stats, 1230 GNUNET_STATISTICS_update (stats,
1184 gettext_noop ("# active connections"), 1231 gettext_noop ("# active connections"),
1185 -1, 1232 -1,
1186 GNUNET_NO); 1233 GNUNET_NO);
1187} 1234}
1188 1235
@@ -1201,33 +1248,31 @@ handler_advertisement (const char *uri)
1201 uri_size = strlen (uri) + 1; 1248 uri_size = strlen (uri) + 1;
1202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1203 "Hostlist client recieved advertisement containing URI `%s'\n", 1250 "Hostlist client recieved advertisement containing URI `%s'\n",
1204 uri); 1251 uri);
1205 if (GNUNET_NO != linked_list_contains (uri)) 1252 if (GNUNET_NO != linked_list_contains (uri))
1206 { 1253 {
1207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri);
1208 "URI `%s' is already known\n",
1209 uri);
1210 return; 1255 return;
1211 } 1256 }
1212 1257
1213 if (GNUNET_NO == stat_testing_allowed) 1258 if (GNUNET_NO == stat_testing_allowed)
1214 { 1259 {
1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1260 GNUNET_log (
1216 "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); 1261 GNUNET_ERROR_TYPE_DEBUG,
1262 "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
1217 return; 1263 return;
1218 } 1264 }
1219 if (GNUNET_YES == stat_testing_hostlist) 1265 if (GNUNET_YES == stat_testing_hostlist)
1220 { 1266 {
1221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1267 GNUNET_log (
1222 "Currently not accepting new advertisements: we are already testing a hostlist\n"); 1268 GNUNET_ERROR_TYPE_DEBUG,
1269 "Currently not accepting new advertisements: we are already testing a hostlist\n");
1223 return; 1270 return;
1224 } 1271 }
1225 1272
1226 hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); 1273 hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size);
1227 hostlist->hostlist_uri = (const char *) &hostlist[1]; 1274 hostlist->hostlist_uri = (const char *) &hostlist[1];
1228 GNUNET_memcpy (&hostlist[1], 1275 GNUNET_memcpy (&hostlist[1], uri, uri_size);
1229 uri,
1230 uri_size);
1231 hostlist->time_creation = GNUNET_TIME_absolute_get (); 1276 hostlist->time_creation = GNUNET_TIME_absolute_get ();
1232 hostlist->quality = HOSTLIST_INITIAL; 1277 hostlist->quality = HOSTLIST_INITIAL;
1233 hostlist_to_test = hostlist; 1278 hostlist_to_test = hostlist;
@@ -1235,18 +1280,17 @@ handler_advertisement (const char *uri)
1235 stat_testing_hostlist = GNUNET_YES; 1280 stat_testing_hostlist = GNUNET_YES;
1236 stat_testing_allowed = GNUNET_NO; 1281 stat_testing_allowed = GNUNET_NO;
1237 ti_testing_intervall_task = 1282 ti_testing_intervall_task =
1238 GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, 1283 GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL,
1239 &task_testing_intervall_reset, 1284 &task_testing_intervall_reset,
1240 NULL); 1285 NULL);
1241 1286
1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1243 "Testing new hostlist advertisements is locked for the next %s\n", 1288 "Testing new hostlist advertisements is locked for the next %s\n",
1244 GNUNET_STRINGS_relative_time_to_string (TESTING_INTERVAL, 1289 GNUNET_STRINGS_relative_time_to_string (TESTING_INTERVAL,
1245 GNUNET_YES)); 1290 GNUNET_YES));
1246 1291
1247 ti_download_dispatcher_task = 1292 ti_download_dispatcher_task =
1248 GNUNET_SCHEDULER_add_now (&task_download_dispatcher, 1293 GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
1249 NULL);
1250} 1294}
1251 1295
1252 1296
@@ -1259,8 +1303,7 @@ handler_advertisement (const char *uri)
1259 * successfully obtained, #GNUNET_SYSERR if not. 1303 * successfully obtained, #GNUNET_SYSERR if not.
1260 */ 1304 */
1261static void 1305static void
1262primary_task (void *cls, 1306primary_task (void *cls, int success)
1263 int success)
1264{ 1307{
1265 if (NULL != ti_check_download) 1308 if (NULL != ti_check_download)
1266 { 1309 {
@@ -1288,8 +1331,7 @@ stat_timeout_task (void *cls)
1288{ 1331{
1289 GNUNET_STATISTICS_get_cancel (sget); 1332 GNUNET_STATISTICS_get_cancel (sget);
1290 sget = NULL; 1333 sget = NULL;
1291 ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, 1334 ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL);
1292 NULL);
1293} 1335}
1294 1336
1295 1337
@@ -1337,22 +1379,25 @@ load_hostlist_file ()
1337 struct GNUNET_BIO_ReadHandle *rh; 1379 struct GNUNET_BIO_ReadHandle *rh;
1338 1380
1339 uri = NULL; 1381 uri = NULL;
1340 if (GNUNET_OK != 1382 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1341 GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE", 1383 "HOSTLIST",
1342 &filename)) 1384 "HOSTLISTFILE",
1385 &filename))
1343 { 1386 {
1344 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 1387 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
1345 "hostlist", "HOSTLISTFILE"); 1388 "hostlist",
1389 "HOSTLISTFILE");
1346 return; 1390 return;
1347 } 1391 }
1348 1392
1349 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1393 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1350 _("Loading saved hostlist entries from file `%s' \n"), 1394 _ ("Loading saved hostlist entries from file `%s' \n"),
1351 filename); 1395 filename);
1352 if (GNUNET_NO == GNUNET_DISK_file_test (filename)) 1396 if (GNUNET_NO == GNUNET_DISK_file_test (filename))
1353 { 1397 {
1354 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1398 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1355 _("Hostlist file `%s' does not exist\n"), filename); 1399 _ ("Hostlist file `%s' does not exist\n"),
1400 filename);
1356 GNUNET_free (filename); 1401 GNUNET_free (filename);
1357 return; 1402 return;
1358 } 1403 }
@@ -1361,16 +1406,19 @@ load_hostlist_file ()
1361 if (NULL == rh) 1406 if (NULL == rh)
1362 { 1407 {
1363 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1408 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1364 _("Could not open file `%s' for reading to load hostlists: %s\n"), 1409 _ (
1365 filename, STRERROR (errno)); 1410 "Could not open file `%s' for reading to load hostlists: %s\n"),
1411 filename,
1412 strerror (errno));
1366 GNUNET_free (filename); 1413 GNUNET_free (filename);
1367 return; 1414 return;
1368 } 1415 }
1369 1416
1370 counter = 0; 1417 counter = 0;
1371 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && 1418 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) &&
1372 (NULL != uri) && (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used)) 1419 (NULL != uri) &&
1373 && (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && 1420 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used)) &&
1421 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
1374 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && 1422 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
1375 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && 1423 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
1376 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) 1424 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)))
@@ -1395,14 +1443,16 @@ load_hostlist_file ()
1395 } 1443 }
1396 1444
1397 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1445 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1398 _("%u hostlist URIs loaded from file\n"), 1446 _ ("%u hostlist URIs loaded from file\n"),
1399 counter); 1447 counter);
1400 GNUNET_STATISTICS_set (stats, 1448 GNUNET_STATISTICS_set (stats,
1401 gettext_noop ("# hostlist URIs read from file"), 1449 gettext_noop ("# hostlist URIs read from file"),
1402 counter, GNUNET_YES); 1450 counter,
1451 GNUNET_YES);
1403 GNUNET_STATISTICS_set (stats, 1452 GNUNET_STATISTICS_set (stats,
1404 gettext_noop ("# advertised hostlist URIs"), 1453 gettext_noop ("# advertised hostlist URIs"),
1405 linked_list_size, GNUNET_NO); 1454 linked_list_size,
1455 GNUNET_NO);
1406 1456
1407 GNUNET_free_non_null (uri); 1457 GNUNET_free_non_null (uri);
1408 emsg = NULL; 1458 emsg = NULL;
@@ -1427,12 +1477,14 @@ save_hostlist_file (int shutdown)
1427 int ok; 1477 int ok;
1428 uint32_t counter; 1478 uint32_t counter;
1429 1479
1430 if (GNUNET_OK != 1480 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1431 GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE", 1481 "HOSTLIST",
1432 &filename)) 1482 "HOSTLISTFILE",
1483 &filename))
1433 { 1484 {
1434 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 1485 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
1435 "hostlist", "HOSTLISTFILE"); 1486 "hostlist",
1487 "HOSTLISTFILE");
1436 return; 1488 return;
1437 } 1489 }
1438 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) 1490 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
@@ -1444,15 +1496,17 @@ save_hostlist_file (int shutdown)
1444 if (NULL == wh) 1496 if (NULL == wh)
1445 { 1497 {
1446 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1498 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1447 _("Could not open file `%s' for writing to save hostlists: %s\n"), 1499 _ (
1500 "Could not open file `%s' for writing to save hostlists: %s\n"),
1448 filename, 1501 filename,
1449 STRERROR (errno)); 1502 strerror (errno));
1450 GNUNET_free (filename); 1503 GNUNET_free (filename);
1451 return; 1504 return;
1452 } 1505 }
1453 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1506 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1454 _("Writing %u hostlist URIs to `%s'\n"), 1507 _ ("Writing %u hostlist URIs to `%s'\n"),
1455 linked_list_size, filename); 1508 linked_list_size,
1509 filename);
1456 /* add code to write hostlists to file using bio */ 1510 /* add code to write hostlists to file using bio */
1457 ok = GNUNET_YES; 1511 ok = GNUNET_YES;
1458 counter = 0; 1512 counter = 0;
@@ -1475,7 +1529,8 @@ save_hostlist_file (int shutdown)
1475 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) 1529 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count)))
1476 { 1530 {
1477 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1531 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1478 _("Error writing hostlist URIs to file `%s'\n"), filename); 1532 _ ("Error writing hostlist URIs to file `%s'\n"),
1533 filename);
1479 ok = GNUNET_NO; 1534 ok = GNUNET_NO;
1480 } 1535 }
1481 } 1536 }
@@ -1488,11 +1543,13 @@ save_hostlist_file (int shutdown)
1488 } 1543 }
1489 GNUNET_STATISTICS_set (stats, 1544 GNUNET_STATISTICS_set (stats,
1490 gettext_noop ("# hostlist URIs written to file"), 1545 gettext_noop ("# hostlist URIs written to file"),
1491 counter, GNUNET_YES); 1546 counter,
1547 GNUNET_YES);
1492 1548
1493 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 1549 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1494 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1550 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1495 _("Error writing hostlist URIs to file `%s'\n"), filename); 1551 _ ("Error writing hostlist URIs to file `%s'\n"),
1552 filename);
1496 GNUNET_free (filename); 1553 GNUNET_free (filename);
1497} 1554}
1498 1555
@@ -1532,47 +1589,38 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1532 /* Read proxy configuration */ 1589 /* Read proxy configuration */
1533 pi = GNUNET_PEERINFO_connect (c); 1590 pi = GNUNET_PEERINFO_connect (c);
1534 if (GNUNET_OK == 1591 if (GNUNET_OK ==
1535 GNUNET_CONFIGURATION_get_value_string (cfg, 1592 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
1536 "HOSTLIST",
1537 "PROXY",
1538 &proxy))
1539 { 1593 {
1540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
1541 "Found proxy host: `%s'\n",
1542 proxy);
1543 /* proxy username */ 1595 /* proxy username */
1544 if (GNUNET_OK == 1596 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
1545 GNUNET_CONFIGURATION_get_value_string (cfg, 1597 "HOSTLIST",
1546 "HOSTLIST", 1598 "PROXY_USERNAME",
1547 "PROXY_USERNAME", 1599 &proxy_username))
1548 &proxy_username))
1549 { 1600 {
1550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1551 "Found proxy username name: `%s'\n", 1602 "Found proxy username name: `%s'\n",
1552 proxy_username); 1603 proxy_username);
1553 } 1604 }
1554 1605
1555 /* proxy password */ 1606 /* proxy password */
1556 if (GNUNET_OK == 1607 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
1557 GNUNET_CONFIGURATION_get_value_string (cfg, 1608 "HOSTLIST",
1558 "HOSTLIST", 1609 "PROXY_PASSWORD",
1559 "PROXY_PASSWORD", 1610 &proxy_password))
1560 &proxy_password))
1561 { 1611 {
1562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1563 "Found proxy password name: `%s'\n", 1613 "Found proxy password name: `%s'\n",
1564 proxy_password); 1614 proxy_password);
1565 } 1615 }
1566 1616
1567 /* proxy type */ 1617 /* proxy type */
1568 if (GNUNET_OK == 1618 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
1569 GNUNET_CONFIGURATION_get_value_string (cfg, 1619 "HOSTLIST",
1570 "HOSTLIST", 1620 "PROXY_TYPE",
1571 "PROXY_TYPE", 1621 &proxytype_str))
1572 &proxytype_str))
1573 { 1622 {
1574 GNUNET_STRINGS_utf8_toupper (proxytype_str, 1623 GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str);
1575 proxytype_str);
1576 proxy_type = CURLPROXY_HTTP; 1624 proxy_type = CURLPROXY_HTTP;
1577 if (0 == strcmp (proxytype_str, "HTTP")) 1625 if (0 == strcmp (proxytype_str, "HTTP"))
1578 proxy_type = CURLPROXY_HTTP; 1626 proxy_type = CURLPROXY_HTTP;
@@ -1588,9 +1636,11 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1588 proxy_type = CURLPROXY_SOCKS5_HOSTNAME; 1636 proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1589 else 1637 else
1590 { 1638 {
1591 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1639 GNUNET_log (
1592 _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), 1640 GNUNET_ERROR_TYPE_ERROR,
1593 proxytype_str); 1641 _ (
1642 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
1643 proxytype_str);
1594 GNUNET_free (proxytype_str); 1644 GNUNET_free (proxytype_str);
1595 GNUNET_free (proxy); 1645 GNUNET_free (proxy);
1596 proxy = NULL; 1646 proxy = NULL;
@@ -1618,35 +1668,35 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1618 { 1668 {
1619 *msgh = &handler_advertisement; 1669 *msgh = &handler_advertisement;
1620 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1670 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1621 _("Learning is enabled on this peer\n")); 1671 _ ("Learning is enabled on this peer\n"));
1622 load_hostlist_file (); 1672 load_hostlist_file ();
1623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1624 "Hostlists will be saved to file again in %s\n", 1674 "Hostlists will be saved to file again in %s\n",
1625 GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, 1675 GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL,
1626 GNUNET_YES)); 1676 GNUNET_YES));
1627 ti_saving_task = 1677 ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
1628 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, 1678 &task_hostlist_saving,
1629 &task_hostlist_saving, 1679 NULL);
1630 NULL);
1631 } 1680 }
1632 else 1681 else
1633 { 1682 {
1634 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1683 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1635 _("Learning is not enabled on this peer\n")); 1684 _ ("Learning is not enabled on this peer\n"));
1636 *msgh = NULL; 1685 *msgh = NULL;
1637 if (GNUNET_OK == 1686 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
1638 GNUNET_CONFIGURATION_get_value_filename (cfg, 1687 "HOSTLIST",
1639 "HOSTLIST", 1688 "HOSTLISTFILE",
1640 "HOSTLISTFILE", 1689 &filename))
1641 &filename))
1642 { 1690 {
1643 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 1691 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
1644 { 1692 {
1645 result = remove (filename); 1693 result = remove (filename);
1646 if (0 == result) 1694 if (0 == result)
1647 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1695 GNUNET_log (
1648 _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), 1696 GNUNET_ERROR_TYPE_INFO,
1649 filename); 1697 _ (
1698 "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1699 filename);
1650 else 1700 else
1651 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 1701 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1652 "remove", 1702 "remove",
@@ -1657,25 +1707,24 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1657 } 1707 }
1658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1659 "Loading stats value on hostlist download frequency\n"); 1709 "Loading stats value on hostlist download frequency\n");
1660 sget = GNUNET_STATISTICS_get (stats, "hostlist", 1710 sget = GNUNET_STATISTICS_get (stats,
1661 gettext_noop 1711 "hostlist",
1662 ("# milliseconds between hostlist downloads"), 1712 gettext_noop (
1713 "# milliseconds between hostlist downloads"),
1663 &primary_task, 1714 &primary_task,
1664 &process_stat, 1715 &process_stat,
1665 NULL); 1716 NULL);
1666 if (NULL == sget) 1717 if (NULL == sget)
1667 { 1718 {
1668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1669 "Statistics request failed, scheduling hostlist download\n"); 1720 "Statistics request failed, scheduling hostlist download\n");
1670 ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, 1721 ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL);
1671 NULL);
1672 } 1722 }
1673 else 1723 else
1674 { 1724 {
1675 ti_check_download 1725 ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1676 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1726 &stat_timeout_task,
1677 &stat_timeout_task, 1727 NULL);
1678 NULL);
1679 } 1728 }
1680 return GNUNET_OK; 1729 return GNUNET_OK;
1681} 1730}
@@ -1687,8 +1736,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1687void 1736void
1688GNUNET_HOSTLIST_client_stop () 1737GNUNET_HOSTLIST_client_stop ()
1689{ 1738{
1690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1691 "Hostlist client shutdown\n");
1692 if (NULL != sget) 1740 if (NULL != sget)
1693 { 1741 {
1694 GNUNET_STATISTICS_get_cancel (sget); 1742 GNUNET_STATISTICS_get_cancel (sget);
@@ -1703,7 +1751,7 @@ GNUNET_HOSTLIST_client_stop ()
1703 ti_saving_task = NULL; 1751 ti_saving_task = NULL;
1704 } 1752 }
1705 if (NULL != ti_download_dispatcher_task) 1753 if (NULL != ti_download_dispatcher_task)
1706 { 1754 {
1707 GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); 1755 GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
1708 ti_download_dispatcher_task = NULL; 1756 ti_download_dispatcher_task = NULL;
1709 } 1757 }
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index 652d7e7d8..c78fbeb4b 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -208,7 +208,7 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
208 "mysql", 208 "mysql",
209 _ ("Could not access file `%s': %s\n"), 209 _ ("Could not access file `%s': %s\n"),
210 cnffile, 210 cnffile,
211 STRERROR (errno)); 211 strerror (errno));
212 GNUNET_free (cnffile); 212 GNUNET_free (cnffile);
213 return NULL; 213 return NULL;
214 } 214 }
diff --git a/src/nat-auto/gnunet-nat-auto_legacy.c b/src/nat-auto/gnunet-nat-auto_legacy.c
index 4a24223fd..93b544343 100644
--- a/src/nat-auto/gnunet-nat-auto_legacy.c
+++ b/src/nat-auto/gnunet-nat-auto_legacy.c
@@ -28,9 +28,10 @@
28#include "gnunet_nat_lib.h" 28#include "gnunet_nat_lib.h"
29#include "nat.h" 29#include "nat.h"
30 30
31#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
32 32
33#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 33#define NAT_SERVER_TIMEOUT \
34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
34 35
35/** 36/**
36 * Entry we keep for each incoming connection. 37 * Entry we keep for each incoming connection.
@@ -88,7 +89,6 @@ struct ClientActivity
88 * Handle to overall NAT test. 89 * Handle to overall NAT test.
89 */ 90 */
90 struct GNUNET_NAT_Test *h; 91 struct GNUNET_NAT_Test *h;
91
92}; 92};
93 93
94 94
@@ -184,9 +184,7 @@ struct GNUNET_NAT_Test
184 * @param addrlen actual lenght of the @a addr 184 * @param addrlen actual lenght of the @a addr
185 */ 185 */
186static void 186static void
187reversal_cb (void *cls, 187reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen)
188 const struct sockaddr *addr,
189 socklen_t addrlen)
190{ 188{
191 struct GNUNET_NAT_Test *h = cls; 189 struct GNUNET_NAT_Test *h = cls;
192 const struct sockaddr_in *sa; 190 const struct sockaddr_in *sa;
@@ -198,11 +196,10 @@ reversal_cb (void *cls,
198 { 196 {
199 LOG (GNUNET_ERROR_TYPE_DEBUG, 197 LOG (GNUNET_ERROR_TYPE_DEBUG,
200 "Received connection reversal request for wrong port\n"); 198 "Received connection reversal request for wrong port\n");
201 return; /* wrong port */ 199 return; /* wrong port */
202 } 200 }
203 /* report success */ 201 /* report success */
204 h->report (h->report_cls, 202 h->report (h->report_cls, GNUNET_NAT_ERROR_SUCCESS);
205 GNUNET_NAT_ERROR_SUCCESS);
206} 203}
207 204
208 205
@@ -220,22 +217,17 @@ do_udp_read (void *cls)
220 const struct GNUNET_SCHEDULER_TaskContext *tc; 217 const struct GNUNET_SCHEDULER_TaskContext *tc;
221 218
222 tc = GNUNET_SCHEDULER_get_task_context (); 219 tc = GNUNET_SCHEDULER_get_task_context ();
223 tst->ltask = 220 tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
224 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 221 tst->lsock,
225 tst->lsock, 222 &do_udp_read,
226 &do_udp_read, 223 tst);
227 tst);
228 if ((NULL != tc->write_ready) && 224 if ((NULL != tc->write_ready) &&
229 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 225 (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) &&
230 tst->lsock)) &&
231 (sizeof (data) == 226 (sizeof (data) ==
232 GNUNET_NETWORK_socket_recv (tst->lsock, 227 GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data))))
233 &data,
234 sizeof (data))))
235 { 228 {
236 if (data == tst->data) 229 if (data == tst->data)
237 tst->report (tst->report_cls, 230 tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
238 GNUNET_NAT_ERROR_SUCCESS);
239 else 231 else
240 LOG (GNUNET_ERROR_TYPE_DEBUG, 232 LOG (GNUNET_ERROR_TYPE_DEBUG,
241 "Received data mismatches expected value\n"); 233 "Received data mismatches expected value\n");
@@ -263,20 +255,14 @@ do_read (void *cls)
263 tc = GNUNET_SCHEDULER_get_task_context (); 255 tc = GNUNET_SCHEDULER_get_task_context ();
264 na->rtask = NULL; 256 na->rtask = NULL;
265 tst = na->h; 257 tst = na->h;
266 GNUNET_CONTAINER_DLL_remove (tst->na_head, 258 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
267 tst->na_tail,
268 na);
269 if ((NULL != tc->write_ready) && 259 if ((NULL != tc->write_ready) &&
270 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 260 (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) &&
271 na->sock)) &&
272 (sizeof (data) == 261 (sizeof (data) ==
273 GNUNET_NETWORK_socket_recv (na->sock, 262 GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data))))
274 &data,
275 sizeof (data))))
276 { 263 {
277 if (data == tst->data) 264 if (data == tst->data)
278 tst->report (tst->report_cls, 265 tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
279 GNUNET_NAT_ERROR_SUCCESS);
280 else 266 else
281 LOG (GNUNET_ERROR_TYPE_DEBUG, 267 LOG (GNUNET_ERROR_TYPE_DEBUG,
282 "Received data does not match expected value\n"); 268 "Received data does not match expected value\n");
@@ -306,28 +292,22 @@ do_accept (void *cls)
306 tst->lsock, 292 tst->lsock,
307 &do_accept, 293 &do_accept,
308 tst); 294 tst);
309 s = GNUNET_NETWORK_socket_accept (tst->lsock, 295 s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
310 NULL,
311 NULL);
312 if (NULL == s) 296 if (NULL == s)
313 { 297 {
314 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, 298 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept");
315 "accept"); 299 return; /* odd error */
316 return; /* odd error */
317 } 300 }
318 LOG (GNUNET_ERROR_TYPE_DEBUG, 301 LOG (GNUNET_ERROR_TYPE_DEBUG,
319 "Got an inbound connection, waiting for data\n"); 302 "Got an inbound connection, waiting for data\n");
320 wl = GNUNET_new (struct NatActivity); 303 wl = GNUNET_new (struct NatActivity);
321 wl->sock = s; 304 wl->sock = s;
322 wl->h = tst; 305 wl->h = tst;
323 wl->rtask = 306 wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
324 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 307 wl->sock,
325 wl->sock, 308 &do_read,
326 &do_read, 309 wl);
327 wl); 310 GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
328 GNUNET_CONTAINER_DLL_insert (tst->na_head,
329 tst->na_tail,
330 wl);
331} 311}
332 312
333 313
@@ -339,15 +319,12 @@ do_accept (void *cls)
339 * @param error error code 319 * @param error error code
340 */ 320 */
341static void 321static void
342mq_error_handler (void *cls, 322mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
343 enum GNUNET_MQ_Error error)
344{ 323{
345 struct ClientActivity *ca = cls; 324 struct ClientActivity *ca = cls;
346 struct GNUNET_NAT_Test *tst = ca->h; 325 struct GNUNET_NAT_Test *tst = ca->h;
347 326
348 GNUNET_CONTAINER_DLL_remove (tst->ca_head, 327 GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, ca);
349 tst->ca_tail,
350 ca);
351 GNUNET_MQ_destroy (ca->mq); 328 GNUNET_MQ_destroy (ca->mq);
352 GNUNET_free (ca); 329 GNUNET_free (ca);
353} 330}
@@ -379,15 +356,13 @@ addr_cb (void *cls,
379 if (addrlen != sizeof (struct sockaddr_in)) 356 if (addrlen != sizeof (struct sockaddr_in))
380 { 357 {
381 LOG (GNUNET_ERROR_TYPE_DEBUG, 358 LOG (GNUNET_ERROR_TYPE_DEBUG,
382 "NAT test ignores IPv6 address `%s' returned from NAT library\n", 359 "NAT test ignores IPv6 address `%s' returned from NAT library\n",
383 GNUNET_a2s (addr, 360 GNUNET_a2s (addr, addrlen));
384 addrlen)); 361 return; /* ignore IPv6 here */
385 return; /* ignore IPv6 here */
386 } 362 }
387 LOG (GNUNET_ERROR_TYPE_INFO, 363 LOG (GNUNET_ERROR_TYPE_INFO,
388 "Asking gnunet-nat-server to connect to `%s'\n", 364 "Asking gnunet-nat-server to connect to `%s'\n",
389 GNUNET_a2s (addr, 365 GNUNET_a2s (addr, addrlen));
390 addrlen));
391 366
392 ca = GNUNET_new (struct ClientActivity); 367 ca = GNUNET_new (struct ClientActivity);
393 ca->h = h; 368 ca->h = h;
@@ -400,21 +375,17 @@ addr_cb (void *cls,
400 { 375 {
401 GNUNET_free (ca); 376 GNUNET_free (ca);
402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 377 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
403 _("Failed to connect to `gnunet-nat-server'\n")); 378 _ ("Failed to connect to `gnunet-nat-server'\n"));
404 return; 379 return;
405 } 380 }
406 GNUNET_CONTAINER_DLL_insert (h->ca_head, 381 GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
407 h->ca_tail,
408 ca);
409 sa = (const struct sockaddr_in *) addr; 382 sa = (const struct sockaddr_in *) addr;
410 env = GNUNET_MQ_msg (msg, 383 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAT_TEST);
411 GNUNET_MESSAGE_TYPE_NAT_TEST);
412 msg->dst_ipv4 = sa->sin_addr.s_addr; 384 msg->dst_ipv4 = sa->sin_addr.s_addr;
413 msg->dport = sa->sin_port; 385 msg->dport = sa->sin_port;
414 msg->data = h->data; 386 msg->data = h->data;
415 msg->is_tcp = htonl ((uint32_t) h->is_tcp); 387 msg->is_tcp = htonl ((uint32_t) h->is_tcp);
416 GNUNET_MQ_send (ca->mq, 388 GNUNET_MQ_send (ca->mq, env);
417 env);
418} 389}
419 390
420 391
@@ -434,8 +405,8 @@ do_timeout (void *cls)
434 nh->ttask = NULL; 405 nh->ttask = NULL;
435 nh->report (nh->report_cls, 406 nh->report (nh->report_cls,
436 (GNUNET_NAT_ERROR_SUCCESS == nh->status) 407 (GNUNET_NAT_ERROR_SUCCESS == nh->status)
437 ? GNUNET_NAT_ERROR_TIMEOUT 408 ? GNUNET_NAT_ERROR_TIMEOUT
438 : nh->status); 409 : nh->status);
439} 410}
440 411
441 412
@@ -465,12 +436,8 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
465{ 436{
466 struct GNUNET_NAT_Test *nh; 437 struct GNUNET_NAT_Test *nh;
467 struct sockaddr_in sa; 438 struct sockaddr_in sa;
468 const struct sockaddr *addrs[] = { 439 const struct sockaddr *addrs[] = {(const struct sockaddr *) &sa};
469 (const struct sockaddr *) &sa 440 const socklen_t addrlens[] = {sizeof (sa)};
470 };
471 const socklen_t addrlens[] = {
472 sizeof (sa)
473 };
474 441
475 memset (&sa, 0, sizeof (sa)); 442 memset (&sa, 0, sizeof (sa));
476 sa.sin_family = AF_INET; 443 sa.sin_family = AF_INET;
@@ -489,69 +456,62 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
489 nh->status = GNUNET_NAT_ERROR_SUCCESS; 456 nh->status = GNUNET_NAT_ERROR_SUCCESS;
490 if (0 == bnd_port) 457 if (0 == bnd_port)
491 { 458 {
492 nh->nat 459 nh->nat = GNUNET_NAT_register (cfg,
493 = GNUNET_NAT_register (cfg, 460 is_tcp,
494 is_tcp, 461 0,
495 0, 462 0,
496 0, 463 NULL,
497 NULL, 464 NULL,
498 NULL, 465 &addr_cb,
499 &addr_cb, 466 &reversal_cb,
500 &reversal_cb, 467 nh,
501 nh, 468 NULL);
502 NULL);
503 } 469 }
504 else 470 else
505 { 471 {
506 nh->lsock = 472 nh->lsock =
507 GNUNET_NETWORK_socket_create (AF_INET, 473 GNUNET_NETWORK_socket_create (AF_INET,
508 (is_tcp == 474 (is_tcp == GNUNET_YES) ? SOCK_STREAM
509 GNUNET_YES) ? SOCK_STREAM : SOCK_DGRAM, 475 : SOCK_DGRAM,
510 0); 476 0);
511 if ((nh->lsock == NULL) || 477 if ((nh->lsock == NULL) ||
512 (GNUNET_OK != 478 (GNUNET_OK != GNUNET_NETWORK_socket_bind (nh->lsock,
513 GNUNET_NETWORK_socket_bind (nh->lsock, 479 (const struct sockaddr *) &sa,
514 (const struct sockaddr *) &sa, 480 sizeof (sa))))
515 sizeof (sa))))
516 { 481 {
517 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 482 GNUNET_log (
518 _("Failed to create listen socket bound to `%s' for NAT test: %s\n"), 483 GNUNET_ERROR_TYPE_ERROR,
519 GNUNET_a2s ((const struct sockaddr *) &sa, 484 _ ("Failed to create listen socket bound to `%s' for NAT test: %s\n"),
520 sizeof (sa)), 485 GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)),
521 STRERROR (errno)); 486 strerror (errno));
522 if (NULL != nh->lsock) 487 if (NULL != nh->lsock)
523 { 488 {
524 GNUNET_NETWORK_socket_close (nh->lsock); 489 GNUNET_NETWORK_socket_close (nh->lsock);
525 nh->lsock = NULL; 490 nh->lsock = NULL;
526 } 491 }
527 nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR; 492 nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR;
528 nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, 493 nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh);
529 nh);
530 return nh; 494 return nh;
531 } 495 }
532 if (GNUNET_YES == is_tcp) 496 if (GNUNET_YES == is_tcp)
533 { 497 {
534 GNUNET_break (GNUNET_OK == 498 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (nh->lsock, 5));
535 GNUNET_NETWORK_socket_listen (nh->lsock, 499 nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
536 5)); 500 nh->lsock,
537 nh->ltask = 501 &do_accept,
538 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 502 nh);
539 nh->lsock,
540 &do_accept,
541 nh);
542 } 503 }
543 else 504 else
544 { 505 {
545 nh->ltask = 506 nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
546 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 507 nh->lsock,
547 nh->lsock, 508 &do_udp_read,
548 &do_udp_read, 509 nh);
549 nh);
550 } 510 }
551 LOG (GNUNET_ERROR_TYPE_INFO, 511 LOG (GNUNET_ERROR_TYPE_INFO,
552 "NAT test listens on port %u (%s)\n", 512 "NAT test listens on port %u (%s)\n",
553 bnd_port, 513 bnd_port,
554 (GNUNET_YES == is_tcp) ? "tcp" : "udp"); 514 (GNUNET_YES == is_tcp) ? "tcp" : "udp");
555 nh->nat = GNUNET_NAT_register (cfg, 515 nh->nat = GNUNET_NAT_register (cfg,
556 is_tcp, 516 is_tcp,
557 adv_port, 517 adv_port,
@@ -565,7 +525,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
565 if (NULL == nh->nat) 525 if (NULL == nh->nat)
566 { 526 {
567 LOG (GNUNET_ERROR_TYPE_INFO, 527 LOG (GNUNET_ERROR_TYPE_INFO,
568 _("NAT test failed to start NAT library\n")); 528 _ ("NAT test failed to start NAT library\n"));
569 if (NULL != nh->ltask) 529 if (NULL != nh->ltask)
570 { 530 {
571 GNUNET_SCHEDULER_cancel (nh->ltask); 531 GNUNET_SCHEDULER_cancel (nh->ltask);
@@ -577,14 +537,11 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
577 nh->lsock = NULL; 537 nh->lsock = NULL;
578 } 538 }
579 nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED; 539 nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED;
580 nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, 540 nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh);
581 nh);
582 return nh; 541 return nh;
583 } 542 }
584 } 543 }
585 nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, 544 nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, nh);
586 &do_timeout,
587 nh);
588 return nh; 545 return nh;
589} 546}
590 547
@@ -600,21 +557,16 @@ GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst)
600 struct NatActivity *pos; 557 struct NatActivity *pos;
601 struct ClientActivity *cpos; 558 struct ClientActivity *cpos;
602 559
603 LOG (GNUNET_ERROR_TYPE_DEBUG, 560 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping NAT test\n");
604 "Stopping NAT test\n");
605 while (NULL != (cpos = tst->ca_head)) 561 while (NULL != (cpos = tst->ca_head))
606 { 562 {
607 GNUNET_CONTAINER_DLL_remove (tst->ca_head, 563 GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos);
608 tst->ca_tail,
609 cpos);
610 GNUNET_MQ_destroy (cpos->mq); 564 GNUNET_MQ_destroy (cpos->mq);
611 GNUNET_free (cpos); 565 GNUNET_free (cpos);
612 } 566 }
613 while (NULL != (pos = tst->na_head)) 567 while (NULL != (pos = tst->na_head))
614 { 568 {
615 GNUNET_CONTAINER_DLL_remove (tst->na_head, 569 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos);
616 tst->na_tail,
617 pos);
618 GNUNET_SCHEDULER_cancel (pos->rtask); 570 GNUNET_SCHEDULER_cancel (pos->rtask);
619 GNUNET_NETWORK_socket_close (pos->sock); 571 GNUNET_NETWORK_socket_close (pos->sock);
620 GNUNET_free (pos); 572 GNUNET_free (pos);
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index c7ed1b903..0adf8f6a5 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -104,13 +104,14 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
104 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 104 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
105 105
106 GNUNET_memcpy (&macmsg.mac, 106 GNUNET_memcpy (&macmsg.mac,
107 (char *) mac, 107 (char *) mac,
108 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 108 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
109 macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 109 macmsg.hdr.size =
110 htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
110 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 111 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
111 GNUNET_memcpy (buffer, 112 GNUNET_memcpy (buffer,
112 &macmsg, 113 &macmsg,
113 sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 114 sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
114 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); 115 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
115} 116}
116 117
@@ -126,8 +127,7 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
126 * #GNUNET_SYSERR to stop further processing with error 127 * #GNUNET_SYSERR to stop further processing with error
127 */ 128 */
128static int 129static int
129stdin_send (void *cls, 130stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
130 const struct GNUNET_MessageHeader *hdr)
131{ 131{
132 struct SendBuffer *write_pout = cls; 132 struct SendBuffer *write_pout = cls;
133 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; 133 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
@@ -137,16 +137,19 @@ stdin_send (void *cls,
137 137
138 sendsize = ntohs (hdr->size); 138 sendsize = ntohs (hdr->size);
139 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; 139 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
140 if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || 140 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) 141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize))
142 { 142 {
143 fprintf (stderr, "%s", "Received malformed message\n"); 143 fprintf (stderr, "%s", "Received malformed message\n");
144 exit (1); 144 exit (1);
145 } 145 }
146 payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); 146 payload_size =
147 if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) 147 sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
148 if ((payload_size +
149 sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) +
150 write_pout->size) > MAXLINE * 2)
148 { 151 {
149 fprintf (stderr, "%s", "Packet too big for buffer\n"); 152 fprintf (stderr, "%s", "Packet too big for buffer\n");
150 exit (1); 153 exit (1);
151 } 154 }
152 memset (&newheader, 0, sizeof (newheader)); 155 memset (&newheader, 0, sizeof (newheader));
@@ -154,12 +157,10 @@ stdin_send (void *cls,
154 newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); 157 newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
155 newheader.frame = in->frame; 158 newheader.frame = in->frame;
156 GNUNET_memcpy (write_pout->buf + write_pout->size, 159 GNUNET_memcpy (write_pout->buf + write_pout->size,
157 &newheader, 160 &newheader,
158 sizeof (newheader)); 161 sizeof (newheader));
159 write_pout->size += sizeof (newheader); 162 write_pout->size += sizeof (newheader);
160 GNUNET_memcpy (write_pout->buf + write_pout->size, 163 GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size);
161 &in[1],
162 payload_size);
163 write_pout->size += payload_size; 164 write_pout->size += payload_size;
164 return GNUNET_OK; 165 return GNUNET_OK;
165} 166}
@@ -175,8 +176,7 @@ stdin_send (void *cls,
175 * #GNUNET_SYSERR to stop further processing with error 176 * #GNUNET_SYSERR to stop further processing with error
176 */ 177 */
177static int 178static int
178file_in_send (void *cls, 179file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr)
179 const struct GNUNET_MessageHeader *hdr)
180{ 180{
181 struct SendBuffer *write_std = cls; 181 struct SendBuffer *write_std = cls;
182 uint16_t sendsize; 182 uint16_t sendsize;
@@ -224,45 +224,46 @@ main (int argc, char *argv[])
224 struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; 224 struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr;
225 int first; 225 int first;
226 226
227 if ( (2 != argc) || 227 if ((2 != argc) ||
228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) ) 228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))))
229 { 229 {
230 fprintf (stderr, 230 fprintf (
231 "%s", 231 stderr,
232 "This program must be started with the operating mode (1 or 2) as the only argument.\n"); 232 "%s",
233 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
233 return 1; 234 return 1;
234 } 235 }
235 236
236 /* make the fifos if needed */ 237 /* make the fifos if needed */
237 umask (0); 238 umask (0);
238 if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || 239 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
239 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) ) 240 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)))
240 { 241 {
241 fprintf (stderr, 242 fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
242 "Failed to create directory for file `%s'\n",
243 FIFO_FILE1);
244 return 1; 243 return 1;
245 } 244 }
246 if (0 == strcmp (argv[1], "1") ) 245 if (0 == strcmp (argv[1], "1"))
247 { 246 {
248 if (0 != stat (FIFO_FILE1, &st)) 247 if (0 != stat (FIFO_FILE1, &st))
249 { 248 {
250 erg = mkfifo (FIFO_FILE1, 0666); 249 erg = mkfifo (FIFO_FILE1, 0666);
251 if ( (0 != erg) && (EEXIST != errno) ) 250 if ((0 != erg) && (EEXIST != errno))
252 fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, 251 fprintf (stderr,
253 strerror (errno)); 252 "Error in mkfifo(%s): %s\n",
253 FIFO_FILE1,
254 strerror (errno));
254 } 255 }
255 } 256 }
256 else 257 else
257 { 258 {
258 if (0 != stat (FIFO_FILE2, &st)) 259 if (0 != stat (FIFO_FILE2, &st))
259 { 260 {
260 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); 261 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
261 if ( (0 != erg) && (EEXIST != errno) ) 262 if ((0 != erg) && (EEXIST != errno))
262 fprintf (stderr, 263 fprintf (stderr,
263 "Error in mkfifo(%s): %s\n", 264 "Error in mkfifo(%s): %s\n",
264 FIFO_FILE2, 265 FIFO_FILE2,
265 strerror (errno)); 266 strerror (errno));
266 } 267 }
267 } 268 }
268 269
@@ -274,7 +275,7 @@ main (int argc, char *argv[])
274 { 275 {
275 fprintf (stderr, 276 fprintf (stderr,
276 "fopen of read FIFO_FILE1 failed: %s\n", 277 "fopen of read FIFO_FILE1 failed: %s\n",
277 STRERROR (errno)); 278 strerror (errno));
278 goto end; 279 goto end;
279 } 280 }
280 if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) 281 if (NULL == (fpout = fopen (FIFO_FILE2, "w")))
@@ -286,7 +287,7 @@ main (int argc, char *argv[])
286 { 287 {
287 fprintf (stderr, 288 fprintf (stderr,
288 "fopen of write FIFO_FILE2 failed: %s\n", 289 "fopen of write FIFO_FILE2 failed: %s\n",
289 STRERROR (errno)); 290 strerror (errno));
290 goto end; 291 goto end;
291 } 292 }
292 } 293 }
@@ -295,14 +296,14 @@ main (int argc, char *argv[])
295 first = 0; 296 first = 0;
296 if (NULL == (fpout = fopen (FIFO_FILE1, "w"))) 297 if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
297 { 298 {
298 GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); 299 GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666));
299 fpout = fopen (FIFO_FILE1, "w"); 300 fpout = fopen (FIFO_FILE1, "w");
300 } 301 }
301 if (NULL == fpout) 302 if (NULL == fpout)
302 { 303 {
303 fprintf (stderr, 304 fprintf (stderr,
304 "fopen of write FIFO_FILE1 failed: %s\n", 305 "fopen of write FIFO_FILE1 failed: %s\n",
305 STRERROR (errno)); 306 strerror (errno));
306 goto end; 307 goto end;
307 } 308 }
308 fpin = fopen (FIFO_FILE2, "r"); 309 fpin = fopen (FIFO_FILE2, "r");
@@ -310,7 +311,7 @@ main (int argc, char *argv[])
310 { 311 {
311 fprintf (stderr, 312 fprintf (stderr,
312 "fopen of read FIFO_FILE2 failed: %s\n", 313 "fopen of read FIFO_FILE2 failed: %s\n",
313 STRERROR (errno)); 314 strerror (errno));
314 goto end; 315 goto end;
315 } 316 }
316 } 317 }
@@ -395,21 +396,22 @@ main (int argc, char *argv[])
395 continue; 396 continue;
396 if (0 > retval) 397 if (0 > retval)
397 { 398 {
398 fprintf (stderr, "select failed: %s\n", STRERROR (errno)); 399 fprintf (stderr, "select failed: %s\n", strerror (errno));
399 closeprog = 1; 400 closeprog = 1;
400 break; 401 break;
401 } 402 }
402 403
403 if (FD_ISSET (STDOUT_FILENO, &wfds)) 404 if (FD_ISSET (STDOUT_FILENO, &wfds))
404 { 405 {
405 ret = 406 ret = write (STDOUT_FILENO,
406 write (STDOUT_FILENO, write_std.buf + write_std.pos, 407 write_std.buf + write_std.pos,
407 write_std.size - write_std.pos); 408 write_std.size - write_std.pos);
408 if (0 > ret) 409 if (0 > ret)
409 { 410 {
410 closeprog = 1; 411 closeprog = 1;
411 fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n", 412 fprintf (stderr,
412 STRERROR (errno)); 413 "Write ERROR to STDOUT_FILENO: %s\n",
414 strerror (errno));
413 break; 415 break;
414 } 416 }
415 else 417 else
@@ -426,14 +428,16 @@ main (int argc, char *argv[])
426 428
427 if (FD_ISSET (fdpout, &wfds)) 429 if (FD_ISSET (fdpout, &wfds))
428 { 430 {
429 ret = 431 ret = write (fdpout,
430 write (fdpout, write_pout.buf + write_pout.pos, 432 write_pout.buf + write_pout.pos,
431 write_pout.size - write_pout.pos); 433 write_pout.size - write_pout.pos);
432 434
433 if (0 > ret) 435 if (0 > ret)
434 { 436 {
435 closeprog = 1; 437 closeprog = 1;
436 fprintf (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno)); 438 fprintf (stderr,
439 "Write ERROR to fdpout failed: %s\n",
440 strerror (errno));
437 } 441 }
438 else 442 else
439 { 443 {
@@ -454,15 +458,17 @@ main (int argc, char *argv[])
454 if (0 > readsize) 458 if (0 > readsize)
455 { 459 {
456 closeprog = 1; 460 closeprog = 1;
457 fprintf (stderr, "Error reading from STDIN_FILENO: %s\n", 461 fprintf (stderr,
458 STRERROR (errno)); 462 "Error reading from STDIN_FILENO: %s\n",
463 strerror (errno));
459 } 464 }
460 else if (0 < readsize) 465 else if (0 < readsize)
461 { 466 {
462 GNUNET_MST_from_buffer (stdin_mst, 467 GNUNET_MST_from_buffer (stdin_mst,
463 readbuf, readsize, 468 readbuf,
464 GNUNET_NO, GNUNET_NO); 469 readsize,
465 470 GNUNET_NO,
471 GNUNET_NO);
466 } 472 }
467 else 473 else
468 { 474 {
@@ -477,14 +483,16 @@ main (int argc, char *argv[])
477 if (0 > readsize) 483 if (0 > readsize)
478 { 484 {
479 closeprog = 1; 485 closeprog = 1;
480 fprintf (stderr, "Error reading from fdpin: %s\n", STRERROR (errno)); 486 fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno));
481 break; 487 break;
482 } 488 }
483 else if (0 < readsize) 489 else if (0 < readsize)
484 { 490 {
485 GNUNET_MST_from_buffer (file_in_mst, 491 GNUNET_MST_from_buffer (file_in_mst,
486 readbuf, readsize, 492 readbuf,
487 GNUNET_NO, GNUNET_NO); 493 readsize,
494 GNUNET_NO,
495 GNUNET_NO);
488 } 496 }
489 else 497 else
490 { 498 {
diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c
index 04f30a683..9b31377e7 100644
--- a/src/transport/gnunet-transport-wlan-receiver.c
+++ b/src/transport/gnunet-transport-wlan-receiver.c
@@ -37,7 +37,7 @@ main (int argc, char *argv[])
37 time_t akt; 37 time_t akt;
38 ssize_t ret; 38 ssize_t ret;
39 pid_t pid; 39 pid_t pid;
40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */ 40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
41 41
42 if (2 != argc) 42 if (2 != argc)
43 { 43 {
@@ -46,34 +46,30 @@ main (int argc, char *argv[])
46 fprintf (stderr, 46 fprintf (stderr,
47 "Usage: %s interface-name\n" 47 "Usage: %s interface-name\n"
48 "e.g. %s mon0\n", 48 "e.g. %s mon0\n",
49 argv[0], argv[0]); 49 argv[0],
50 argv[0]);
50 return 1; 51 return 1;
51 } 52 }
52 53
53 /* Setup communication pipeline first */ 54 /* Setup communication pipeline first */
54 if (pipe (commpipe)) 55 if (pipe (commpipe))
55 { 56 {
56 fprintf (stderr, 57 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
57 "Failed to create pipe: %s\n",
58 STRERROR (errno));
59 exit (1); 58 exit (1);
60 } 59 }
61 60
62 /* Attempt to fork and check for errors */ 61 /* Attempt to fork and check for errors */
63 if ((pid = fork ()) == -1) 62 if ((pid = fork ()) == -1)
64 { 63 {
65 fprintf (stderr, "Failed to fork: %s\n", 64 fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
66 STRERROR (errno));
67 exit (1); 65 exit (1);
68 } 66 }
69 67
70 if (pid) 68 if (pid)
71 { 69 {
72 /* A positive (non-negative) PID indicates the parent process */ 70 /* A positive (non-negative) PID indicates the parent process */
73 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */ 71 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */
74 fprintf (stderr, 72 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
75 "Failed to close fd: %s\n",
76 strerror (errno));
77 start = time (NULL); 73 start = time (NULL);
78 count = 0; 74 count = 0;
79 while (1) 75 while (1)
@@ -81,18 +77,18 @@ main (int argc, char *argv[])
81 ret = read (commpipe[0], msg_buf, sizeof (msg_buf)); 77 ret = read (commpipe[0], msg_buf, sizeof (msg_buf));
82 if (0 > ret) 78 if (0 > ret)
83 { 79 {
84 fprintf (stderr, "read failed: %s\n", strerror (errno)); 80 fprintf (stderr, "read failed: %s\n", strerror (errno));
85 break; 81 break;
86 } 82 }
87 count += ret; 83 count += ret;
88 akt = time (NULL); 84 akt = time (NULL);
89 if (akt - start > 30) 85 if (akt - start > 30)
90 { 86 {
91 bytes_per_s = count / (akt - start); 87 bytes_per_s = count / (akt - start);
92 bytes_per_s /= 1024; 88 bytes_per_s /= 1024;
93 printf ("recv %f kb/s\n", bytes_per_s); 89 printf ("recv %f kb/s\n", bytes_per_s);
94 start = akt; 90 start = akt;
95 count = 0; 91 count = 0;
96 } 92 }
97 } 93 }
98 } 94 }
@@ -100,13 +96,15 @@ main (int argc, char *argv[])
100 { 96 {
101 /* A zero PID indicates that this is the child process */ 97 /* A zero PID indicates that this is the child process */
102 (void) close (1); 98 (void) close (1);
103 if (-1 == dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ 99 if (-1 ==
100 dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
104 fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); 101 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
105 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */ 102 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */
106 /* Replace the child fork with a new process */ 103 /* Replace the child fork with a new process */
107 if (execlp 104 if (execlp ("gnunet-helper-transport-wlan",
108 ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", 105 "gnunet-helper-transport-wlan",
109 argv[1], NULL) == -1) 106 argv[1],
107 NULL) == -1)
110 { 108 {
111 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); 109 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
112 _exit (1); 110 _exit (1);
diff --git a/src/transport/gnunet-transport-wlan-sender.c b/src/transport/gnunet-transport-wlan-sender.c
index 36d26f8dc..36273f765 100644
--- a/src/transport/gnunet-transport-wlan-sender.c
+++ b/src/transport/gnunet-transport-wlan-sender.c
@@ -35,16 +35,16 @@
35#define WLAN_LLC_DSAP_FIELD 0x1f 35#define WLAN_LLC_DSAP_FIELD 0x1f
36#define WLAN_LLC_SSAP_FIELD 0x1f 36#define WLAN_LLC_SSAP_FIELD 0x1f
37 37
38#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ 38#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
39 39
40#define IEEE80211_FC0_VERSION_MASK 0x03 40#define IEEE80211_FC0_VERSION_MASK 0x03
41#define IEEE80211_FC0_VERSION_SHIFT 0 41#define IEEE80211_FC0_VERSION_SHIFT 0
42#define IEEE80211_FC0_VERSION_0 0x00 42#define IEEE80211_FC0_VERSION_0 0x00
43#define IEEE80211_FC0_TYPE_MASK 0x0c 43#define IEEE80211_FC0_TYPE_MASK 0x0c
44#define IEEE80211_FC0_TYPE_SHIFT 2 44#define IEEE80211_FC0_TYPE_SHIFT 2
45#define IEEE80211_FC0_TYPE_MGT 0x00 45#define IEEE80211_FC0_TYPE_MGT 0x00
46#define IEEE80211_FC0_TYPE_CTL 0x04 46#define IEEE80211_FC0_TYPE_CTL 0x04
47#define IEEE80211_FC0_TYPE_DATA 0x08 47#define IEEE80211_FC0_TYPE_DATA 0x08
48 48
49 49
50/** 50/**
@@ -55,7 +55,7 @@
55 */ 55 */
56static int 56static int
57getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, 57getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
58 uint16_t size) 58 uint16_t size)
59{ 59{
60 header->header.size = htons (size); 60 header->header.size = htons (size);
61 header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); 61 header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
@@ -75,8 +75,9 @@ getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
75 */ 75 */
76static int 76static int
77getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, 77getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header,
78 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, 78 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
79 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, unsigned int size) 79 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac,
80 unsigned int size)
80{ 81{
81 const int rate = 11000000; 82 const int rate = 11000000;
82 83
@@ -109,21 +110,27 @@ main (int argc, char *argv[])
109 int i; 110 int i;
110 ssize_t ret; 111 ssize_t ret;
111 pid_t pid; 112 pid_t pid;
112 int commpipe[2]; /* This holds the fd for the input & output of the pipe */ 113 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
113 int macpipe[2]; /* This holds the fd for the input & output of the pipe */ 114 int macpipe[2]; /* This holds the fd for the input & output of the pipe */
114 115
115 if (4 != argc) 116 if (4 != argc)
116 { 117 {
117 fprintf (stderr, 118 fprintf (
118 "This program must be started with the interface and the targets and source mac as argument.\n"); 119 stderr,
120 "This program must be started with the interface and the targets and source mac as argument.\n");
119 fprintf (stderr, 121 fprintf (stderr,
120 "Usage: interface-name mac-DST mac-SRC\n" 122 "Usage: interface-name mac-DST mac-SRC\n"
121 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 123 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
122 return 1; 124 return 1;
123 } 125 }
124 if (6 != 126 if (6 != SSCANF (argv[2],
125 SSCANF (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], 127 "%x-%x-%x-%x-%x-%x",
126 &temp[3], &temp[4], &temp[5])) 128 &temp[0],
129 &temp[1],
130 &temp[2],
131 &temp[3],
132 &temp[4],
133 &temp[5]))
127 { 134 {
128 fprintf (stderr, 135 fprintf (stderr,
129 "Usage: interface-name mac-DST mac-SRC\n" 136 "Usage: interface-name mac-DST mac-SRC\n"
@@ -132,9 +139,14 @@ main (int argc, char *argv[])
132 } 139 }
133 for (i = 0; i < 6; i++) 140 for (i = 0; i < 6; i++)
134 outmac.mac[i] = temp[i]; 141 outmac.mac[i] = temp[i];
135 if (6 != 142 if (6 != SSCANF (argv[3],
136 SSCANF (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], 143 "%x-%x-%x-%x-%x-%x",
137 &temp[3], &temp[4], &temp[5])) 144 &temp[0],
145 &temp[1],
146 &temp[2],
147 &temp[3],
148 &temp[4],
149 &temp[5]))
138 { 150 {
139 fprintf (stderr, 151 fprintf (stderr,
140 "Usage: interface-name mac-DST mac-SRC\n" 152 "Usage: interface-name mac-DST mac-SRC\n"
@@ -148,51 +160,47 @@ main (int argc, char *argv[])
148 /* Setup communication pipeline first */ 160 /* Setup communication pipeline first */
149 if (pipe (commpipe)) 161 if (pipe (commpipe))
150 { 162 {
151 fprintf (stderr, 163 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
152 "Failed to create pipe: %s\n",
153 STRERROR (errno));
154 exit (1); 164 exit (1);
155 } 165 }
156 if (pipe (macpipe)) 166 if (pipe (macpipe))
157 { 167 {
158 fprintf (stderr, 168 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
159 "Failed to create pipe: %s\n",
160 STRERROR (errno));
161 exit (1); 169 exit (1);
162 } 170 }
163 171
164 /* Attempt to fork and check for errors */ 172 /* Attempt to fork and check for errors */
165 if ((pid = fork ()) == -1) 173 if ((pid = fork ()) == -1)
166 { 174 {
167 fprintf (stderr, "Failed to fork: %s\n", 175 fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
168 STRERROR (errno));
169 exit (1); 176 exit (1);
170 } 177 }
171 memset (msg_buf, 0x42, sizeof (msg_buf)); 178 memset (msg_buf, 0x42, sizeof (msg_buf));
172 if (pid) 179 if (pid)
173 { 180 {
174 /* A positive (non-negative) PID indicates the parent process */ 181 /* A positive (non-negative) PID indicates the parent process */
175 if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */ 182 if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */
176 fprintf (stderr, 183 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
177 "Failed to close fd: %s\n", 184 setvbuf (stdout,
178 strerror (errno)); 185 (char *) NULL,
179 setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ 186 _IONBF,
187 0); /* Set non-buffered output on stdout */
180 188
181 if (0 != close (macpipe[1])) 189 if (0 != close (macpipe[1]))
182 fprintf (stderr, 190 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
183 "Failed to close fd: %s\n",
184 strerror (errno));
185 if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm))) 191 if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm)))
186 fprintf (stderr, 192 fprintf (stderr, "Failed to read hcm...\n");
187 "Failed to read hcm...\n");
188 fprintf (stderr, 193 fprintf (stderr,
189 "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", 194 "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
190 hcm.mac.mac[0], hcm.mac.mac[1], 195 hcm.mac.mac[0],
191 hcm.mac.mac[2], hcm.mac.mac[3], hcm.mac.mac[4], hcm.mac.mac[5]); 196 hcm.mac.mac[1],
197 hcm.mac.mac[2],
198 hcm.mac.mac[3],
199 hcm.mac.mac[4],
200 hcm.mac.mac[5]);
192 radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf; 201 radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf;
193 getRadiotapHeader (radiotap, WLAN_MTU); 202 getRadiotapHeader (radiotap, WLAN_MTU);
194 getWlanHeader (&radiotap->frame, &outmac, &inmac, 203 getWlanHeader (&radiotap->frame, &outmac, &inmac, WLAN_MTU);
195 WLAN_MTU);
196 start = time (NULL); 204 start = time (NULL);
197 count = 0; 205 count = 0;
198 while (1) 206 while (1)
@@ -200,18 +208,18 @@ main (int argc, char *argv[])
200 ret = write (commpipe[1], msg_buf, WLAN_MTU); 208 ret = write (commpipe[1], msg_buf, WLAN_MTU);
201 if (0 > ret) 209 if (0 > ret)
202 { 210 {
203 fprintf (stderr, "write failed: %s\n", strerror (errno)); 211 fprintf (stderr, "write failed: %s\n", strerror (errno));
204 break; 212 break;
205 } 213 }
206 count += ret; 214 count += ret;
207 akt = time (NULL); 215 akt = time (NULL);
208 if (akt - start > 30) 216 if (akt - start > 30)
209 { 217 {
210 bytes_per_s = count / (akt - start); 218 bytes_per_s = count / (akt - start);
211 bytes_per_s /= 1024; 219 bytes_per_s /= 1024;
212 printf ("send %f kbytes/s\n", bytes_per_s); 220 printf ("send %f kbytes/s\n", bytes_per_s);
213 start = akt; 221 start = akt;
214 count = 0; 222 count = 0;
215 } 223 }
216 } 224 }
217 } 225 }
@@ -220,16 +228,19 @@ main (int argc, char *argv[])
220 /* A zero PID indicates that this is the child process */ 228 /* A zero PID indicates that this is the child process */
221 (void) close (0); 229 (void) close (0);
222 (void) close (1); 230 (void) close (1);
223 if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ 231 if (-1 ==
232 dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
224 fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); 233 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
225 if (-1 == dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ 234 if (-1 ==
235 dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */
226 fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); 236 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
227 (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ 237 (void) close (commpipe[1]); /* Close unused side of pipe (out side) */
228 (void) close (macpipe[0]); /* Close unused side of pipe (in side) */ 238 (void) close (macpipe[0]); /* Close unused side of pipe (in side) */
229 /* Replace the child fork with a new process */ 239 /* Replace the child fork with a new process */
230 if (execlp 240 if (execlp ("gnunet-helper-transport-wlan",
231 ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", 241 "gnunet-helper-transport-wlan",
232 argv[1], NULL) == -1) 242 argv[1],
243 NULL) == -1)
233 { 244 {
234 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); 245 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
235 _exit (1); 246 _exit (1);