diff options
Diffstat (limited to 'src/ats-tool/gnunet-ats.c')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 184 |
1 files changed, 112 insertions, 72 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 9ea603bc1..7a89adc73 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009--2013 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2009--2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -22,6 +22,7 @@ | |||
22 | * @file ats-tool/gnunet-ats.c | 22 | * @file ats-tool/gnunet-ats.c |
23 | * @brief ATS command line tool | 23 | * @brief ATS command line tool |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
@@ -105,11 +106,26 @@ static int stat_receive_done; | |||
105 | static int stat_pending; | 106 | static int stat_pending; |
106 | 107 | ||
107 | /** | 108 | /** |
109 | * Which peer should we connect to? | ||
110 | */ | ||
111 | static char *cpid_str; | ||
112 | |||
113 | /** | ||
108 | * ATS performance handle used | 114 | * ATS performance handle used |
109 | */ | 115 | */ |
110 | static struct GNUNET_ATS_PerformanceHandle *ph; | 116 | static struct GNUNET_ATS_PerformanceHandle *ph; |
111 | 117 | ||
112 | /** | 118 | /** |
119 | * Our connectivity handle. | ||
120 | */ | ||
121 | static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | ||
122 | |||
123 | /** | ||
124 | * Handle for address suggestion request. | ||
125 | */ | ||
126 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | ||
127 | |||
128 | /** | ||
113 | * ATS address list handle used | 129 | * ATS address list handle used |
114 | */ | 130 | */ |
115 | static struct GNUNET_ATS_AddressListHandle *alh; | 131 | static struct GNUNET_ATS_AddressListHandle *alh; |
@@ -234,7 +250,11 @@ free_addr_it (void *cls, | |||
234 | void *value) | 250 | void *value) |
235 | { | 251 | { |
236 | struct ATSAddress *a = value; | 252 | struct ATSAddress *a = value; |
237 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (addresses, key, value)); | 253 | |
254 | GNUNET_assert (GNUNET_OK == | ||
255 | GNUNET_CONTAINER_multipeermap_remove (addresses, | ||
256 | key, | ||
257 | value)); | ||
238 | GNUNET_HELLO_address_free (a->address); | 258 | GNUNET_HELLO_address_free (a->address); |
239 | GNUNET_free (a); | 259 | GNUNET_free (a); |
240 | return GNUNET_OK; | 260 | return GNUNET_OK; |
@@ -292,6 +312,17 @@ end (void *cls, | |||
292 | FPRINTF (stdout, | 312 | FPRINTF (stdout, |
293 | _("ATS returned stat_results for %u addresses\n"), | 313 | _("ATS returned stat_results for %u addresses\n"), |
294 | stat_results); | 314 | stat_results); |
315 | |||
316 | if (NULL != ats_sh) | ||
317 | { | ||
318 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); | ||
319 | ats_sh = NULL; | ||
320 | } | ||
321 | if (NULL != ats_ch) | ||
322 | { | ||
323 | GNUNET_ATS_connectivity_done (ats_ch); | ||
324 | ats_ch = NULL; | ||
325 | } | ||
295 | ret = 0; | 326 | ret = 0; |
296 | } | 327 | } |
297 | 328 | ||
@@ -685,38 +716,35 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
685 | 716 | ||
686 | 717 | ||
687 | /** | 718 | /** |
688 | * Function called with the result from the test if ATS is | 719 | * Main function that will be run by the scheduler. |
689 | * running. Runs the actual main logic. | ||
690 | * | 720 | * |
691 | * @param cls the `struct GNUNET_CONFIGURATION_Handle *` | 721 | * @param cls closure |
692 | * @param result result of the test, #GNUNET_YES if ATS is running | 722 | * @param args remaining command-line arguments |
723 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
724 | * @param my_cfg configuration | ||
693 | */ | 725 | */ |
694 | static void | 726 | static void |
695 | testservice_ats (void *cls, | 727 | run (void *cls, |
696 | int result) | 728 | char * const *args, |
729 | const char *cfgfile, | ||
730 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) | ||
697 | { | 731 | { |
698 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
699 | struct GNUNET_PeerIdentity pid; | 732 | struct GNUNET_PeerIdentity pid; |
733 | struct GNUNET_PeerIdentity cpid; | ||
700 | unsigned int c; | 734 | unsigned int c; |
701 | unsigned int type; | 735 | unsigned int type; |
702 | 736 | ||
737 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; | ||
703 | addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 738 | addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
704 | |||
705 | if (GNUNET_YES != result) | ||
706 | { | ||
707 | FPRINTF (stderr, | ||
708 | _("Service `%s' is not running\n"), | ||
709 | "ats"); | ||
710 | return; | ||
711 | } | ||
712 | |||
713 | stat_results = 0; | 739 | stat_results = 0; |
714 | 740 | ||
741 | c = 0; | ||
715 | if (NULL != opt_pid_str) | 742 | if (NULL != opt_pid_str) |
716 | { | 743 | { |
717 | if (GNUNET_OK | 744 | if (GNUNET_OK != |
718 | != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_pid_str, | 745 | GNUNET_CRYPTO_eddsa_public_key_from_string (opt_pid_str, |
719 | strlen (opt_pid_str), &pid.public_key)) | 746 | strlen (opt_pid_str), |
747 | &pid.public_key)) | ||
720 | { | 748 | { |
721 | FPRINTF (stderr, | 749 | FPRINTF (stderr, |
722 | _("Failed to parse peer identity `%s'\n"), | 750 | _("Failed to parse peer identity `%s'\n"), |
@@ -724,12 +752,27 @@ testservice_ats (void *cls, | |||
724 | return; | 752 | return; |
725 | } | 753 | } |
726 | } | 754 | } |
755 | if (NULL != cpid_str) | ||
756 | { | ||
757 | if (GNUNET_OK != | ||
758 | GNUNET_CRYPTO_eddsa_public_key_from_string (cpid_str, | ||
759 | strlen (cpid_str), | ||
760 | &cpid.public_key)) | ||
761 | { | ||
762 | FPRINTF (stderr, | ||
763 | _("Failed to parse peer identity `%s'\n"), | ||
764 | cpid_str); | ||
765 | return; | ||
766 | } | ||
767 | c++; | ||
768 | } | ||
769 | |||
770 | c += opt_list_all + opt_list_used + opt_monitor + opt_set_pref; | ||
727 | 771 | ||
728 | c = opt_list_all + opt_list_used + opt_monitor + opt_set_pref; | 772 | if (1 < c) |
729 | if ((1 < c)) | ||
730 | { | 773 | { |
731 | FPRINTF (stderr, | 774 | FPRINTF (stderr, |
732 | _("Please select one operation : %s or %s or %s or %s or %s\n"), | 775 | _("Please select one operation: %s or %s or %s or %s or %s\n"), |
733 | "--used", | 776 | "--used", |
734 | "--all", | 777 | "--all", |
735 | "--monitor", | 778 | "--monitor", |
@@ -737,7 +780,7 @@ testservice_ats (void *cls, | |||
737 | "--quotas"); | 780 | "--quotas"); |
738 | return; | 781 | return; |
739 | } | 782 | } |
740 | if ((0 == c)) | 783 | if (0 == c) |
741 | opt_list_used = GNUNET_YES; /* set default */ | 784 | opt_list_used = GNUNET_YES; /* set default */ |
742 | if (opt_print_quotas) | 785 | if (opt_print_quotas) |
743 | { | 786 | { |
@@ -754,7 +797,6 @@ testservice_ats (void *cls, | |||
754 | _("Cannot connect to ATS service, exiting...\n")); | 797 | _("Cannot connect to ATS service, exiting...\n")); |
755 | return; | 798 | return; |
756 | } | 799 | } |
757 | |||
758 | alh = GNUNET_ATS_performance_list_addresses (ph, | 800 | alh = GNUNET_ATS_performance_list_addresses (ph, |
759 | (NULL == opt_pid_str) ? NULL : &pid, | 801 | (NULL == opt_pid_str) ? NULL : &pid, |
760 | GNUNET_YES, | 802 | GNUNET_YES, |
@@ -768,10 +810,11 @@ testservice_ats (void *cls, | |||
768 | return; | 810 | return; |
769 | } | 811 | } |
770 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 812 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
771 | &end, | 813 | &end, |
772 | NULL); | 814 | NULL); |
815 | return; | ||
773 | } | 816 | } |
774 | else if (opt_list_used) | 817 | if (opt_list_used) |
775 | { | 818 | { |
776 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 819 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); |
777 | if (NULL == ph) | 820 | if (NULL == ph) |
@@ -796,8 +839,9 @@ testservice_ats (void *cls, | |||
796 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 839 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
797 | &end, | 840 | &end, |
798 | NULL); | 841 | NULL); |
842 | return; | ||
799 | } | 843 | } |
800 | else if (opt_monitor) | 844 | if (opt_monitor) |
801 | { | 845 | { |
802 | ph = GNUNET_ATS_performance_init (cfg, | 846 | ph = GNUNET_ATS_performance_init (cfg, |
803 | &ats_perf_mon_cb, | 847 | &ats_perf_mon_cb, |
@@ -807,11 +851,11 @@ testservice_ats (void *cls, | |||
807 | "%s", | 851 | "%s", |
808 | _("Cannot connect to ATS service, exiting...\n")); | 852 | _("Cannot connect to ATS service, exiting...\n")); |
809 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 853 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
810 | &end, | 854 | &end, |
811 | NULL); | 855 | NULL); |
812 | 856 | return; | |
813 | } | 857 | } |
814 | else if (opt_set_pref) | 858 | if (opt_set_pref) |
815 | { | 859 | { |
816 | if (NULL == opt_type_str) | 860 | if (NULL == opt_type_str) |
817 | { | 861 | { |
@@ -860,35 +904,27 @@ testservice_ats (void *cls, | |||
860 | GNUNET_ATS_PREFERENCE_END); | 904 | GNUNET_ATS_PREFERENCE_END); |
861 | 905 | ||
862 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 906 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
863 | &end, | 907 | &end, |
864 | NULL); | 908 | NULL); |
909 | return; | ||
910 | } | ||
911 | if (NULL != cpid_str) | ||
912 | { | ||
913 | ats_ch = GNUNET_ATS_connectivity_init (cfg); | ||
914 | ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch, | ||
915 | &cpid, | ||
916 | 1000); | ||
917 | shutdown_task | ||
918 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
919 | &end, | ||
920 | NULL); | ||
921 | return; | ||
865 | } | 922 | } |
866 | ret = 1; | 923 | ret = 1; |
867 | } | 924 | } |
868 | 925 | ||
869 | 926 | ||
870 | /** | 927 | /** |
871 | * Main function that will be run by the scheduler. | ||
872 | * | ||
873 | * @param cls closure | ||
874 | * @param args remaining command-line arguments | ||
875 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
876 | * @param my_cfg configuration | ||
877 | */ | ||
878 | static void | ||
879 | run (void *cls, | ||
880 | char * const *args, | ||
881 | const char *cfgfile, | ||
882 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) | ||
883 | { | ||
884 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; | ||
885 | GNUNET_CLIENT_service_test ("ats", cfg, | ||
886 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | ||
887 | &testservice_ats, (void *) cfg); | ||
888 | } | ||
889 | |||
890 | |||
891 | /** | ||
892 | * The main function. | 928 | * The main function. |
893 | * | 929 | * |
894 | * @param argc number of arguments from the command line | 930 | * @param argc number of arguments from the command line |
@@ -910,37 +946,42 @@ main (int argc, | |||
910 | stat_receive_done = GNUNET_NO; | 946 | stat_receive_done = GNUNET_NO; |
911 | opt_type_str = NULL; | 947 | opt_type_str = NULL; |
912 | 948 | ||
913 | static const struct GNUNET_GETOPT_CommandLineOption options[] = | 949 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
914 | { | 950 | { 'u', "used", NULL, |
915 | { 'u', "used", NULL, | ||
916 | gettext_noop ("get list of active addresses currently used"), 0, | 951 | gettext_noop ("get list of active addresses currently used"), 0, |
917 | &GNUNET_GETOPT_set_one, &opt_list_used }, | 952 | &GNUNET_GETOPT_set_one, &opt_list_used }, |
918 | { 'a', "all", NULL, gettext_noop ("get list of all active addresses"), 0, | 953 | { 'a', "all", NULL, gettext_noop ("get list of all active addresses"), 0, |
919 | &GNUNET_GETOPT_set_one, &opt_list_all }, | 954 | &GNUNET_GETOPT_set_one, &opt_list_all }, |
920 | { 'n', "numeric", NULL, | 955 | { 'C', "connect", "PEER", |
956 | gettext_noop ("connect to PEER"), 1, | ||
957 | &GNUNET_GETOPT_set_string, &cpid_str }, | ||
958 | { 'n', "numeric", NULL, | ||
921 | gettext_noop ("do not resolve IP addresses to hostnames"), 0, | 959 | gettext_noop ("do not resolve IP addresses to hostnames"), 0, |
922 | &GNUNET_GETOPT_set_one, &opt_resolve_addresses_numeric }, | 960 | &GNUNET_GETOPT_set_one, &opt_resolve_addresses_numeric }, |
923 | { 'm', "monitor", NULL, gettext_noop ("monitor mode"), 0, | 961 | { 'm', "monitor", NULL, gettext_noop ("monitor mode"), 0, |
924 | &GNUNET_GETOPT_set_one, &opt_monitor }, | 962 | &GNUNET_GETOPT_set_one, &opt_monitor }, |
925 | { 'p', "preference", NULL, gettext_noop ("set preference for the given peer"), | 963 | { 'p', "preference", NULL, gettext_noop ("set preference for the given peer"), |
926 | 0, &GNUNET_GETOPT_set_one, &opt_set_pref }, | 964 | 0, &GNUNET_GETOPT_set_one, &opt_set_pref }, |
927 | { 'q', "quotas", NULL, gettext_noop ("print all configured quotas"), 0, | 965 | { 'q', "quotas", NULL, gettext_noop ("print all configured quotas"), 0, |
928 | &GNUNET_GETOPT_set_one, &opt_print_quotas }, | 966 | &GNUNET_GETOPT_set_one, &opt_print_quotas }, |
929 | { 'i', "id", "TYPE", gettext_noop ("peer id"), 1, &GNUNET_GETOPT_set_string, | 967 | { 'i', "id", "TYPE", gettext_noop ("peer id"), 1, &GNUNET_GETOPT_set_string, |
930 | &opt_pid_str }, | 968 | &opt_pid_str }, |
931 | { 't', "type", "TYPE", | 969 | { 't', "type", "TYPE", |
932 | gettext_noop ("preference type to set: latency | bandwidth"), 1, | 970 | gettext_noop ("preference type to set: latency | bandwidth"), 1, |
933 | &GNUNET_GETOPT_set_string, &opt_type_str }, | 971 | &GNUNET_GETOPT_set_string, &opt_type_str }, |
934 | { 'k', "value", "VALUE", gettext_noop ("preference value"), 1, | 972 | { 'k', "value", "VALUE", gettext_noop ("preference value"), 1, |
935 | &GNUNET_GETOPT_set_uint, &opt_pref_value }, | 973 | &GNUNET_GETOPT_set_uint, &opt_pref_value }, |
936 | { 'V', "verbose", NULL, | 974 | { 'V', "verbose", NULL, |
937 | gettext_noop ("verbose output (include ATS address properties)"), 0, | 975 | gettext_noop ("verbose output (include ATS address properties)"), 0, |
938 | &GNUNET_GETOPT_set_one, &opt_verbose }, GNUNET_GETOPT_OPTION_END }; | 976 | &GNUNET_GETOPT_set_one, &opt_verbose }, |
977 | GNUNET_GETOPT_OPTION_END | ||
978 | }; | ||
939 | 979 | ||
940 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 980 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
941 | return 2; | 981 | return 2; |
942 | 982 | ||
943 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", | 983 | res = GNUNET_PROGRAM_run (argc, argv, |
984 | "gnunet-ats", | ||
944 | gettext_noop ("Print information about ATS state"), | 985 | gettext_noop ("Print information about ATS state"), |
945 | options, | 986 | options, |
946 | &run, NULL); | 987 | &run, NULL); |
@@ -952,7 +993,6 @@ main (int argc, | |||
952 | return ret; | 993 | return ret; |
953 | else | 994 | else |
954 | return 1; | 995 | return 1; |
955 | |||
956 | } | 996 | } |
957 | 997 | ||
958 | /* end of gnunet-ats.c */ | 998 | /* end of gnunet-ats.c */ |