diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-10-25 13:56:15 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-10-25 13:56:15 +0000 |
commit | d02ab50a92b6af0ed638febb147d9a2fab447dd5 (patch) | |
tree | bedc67a9dccc7fdb9a8f547bb2d7c5daa8bc1c41 | |
parent | c9400b76b1fddb659973c4f51f88e631436fa516 (diff) | |
download | gnunet-d02ab50a92b6af0ed638febb147d9a2fab447dd5.tar.gz gnunet-d02ab50a92b6af0ed638febb147d9a2fab447dd5.zip |
gnunet-ats /w address printing support
-rw-r--r-- | src/ats/Makefile.am | 2 | ||||
-rw-r--r-- | src/ats/gnunet-ats.c | 90 |
2 files changed, 83 insertions, 9 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 06d4f1dfe..ade8f69f6 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -60,6 +60,8 @@ gnunet_ats_SOURCES = \ | |||
60 | gnunet_ats_LDADD = \ | 60 | gnunet_ats_LDADD = \ |
61 | $(top_builddir)/src/util/libgnunetutil.la \ | 61 | $(top_builddir)/src/util/libgnunetutil.la \ |
62 | $(top_builddir)/src/ats/libgnunetats.la \ | 62 | $(top_builddir)/src/ats/libgnunetats.la \ |
63 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
64 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
63 | $(GN_LIBINTL) | 65 | $(GN_LIBINTL) |
64 | gnunet_ats_DEPENDENCIES = \ | 66 | gnunet_ats_DEPENDENCIES = \ |
65 | libgnunetats.la | 67 | libgnunetats.la |
diff --git a/src/ats/gnunet-ats.c b/src/ats/gnunet-ats.c index 2de08e2d1..a443778a4 100644 --- a/src/ats/gnunet-ats.c +++ b/src/ats/gnunet-ats.c | |||
@@ -26,17 +26,57 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_ats_service.h" | 28 | #include "gnunet_ats_service.h" |
29 | #include "gnunet_transport_service.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | ||
29 | 32 | ||
30 | /** | 33 | /** |
31 | * Final status code. | 34 | * Final status code. |
32 | */ | 35 | */ |
33 | static int ret; | 36 | static int ret; |
34 | static int results; | 37 | static int results; |
38 | static int resolve_addresses_numeric; | ||
35 | 39 | ||
36 | static struct GNUNET_ATS_PerformanceHandle *ph; | 40 | static struct GNUNET_ATS_PerformanceHandle *ph; |
37 | 41 | ||
42 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
43 | |||
38 | GNUNET_SCHEDULER_TaskIdentifier end_task; | 44 | GNUNET_SCHEDULER_TaskIdentifier end_task; |
39 | 45 | ||
46 | struct PendingResolutions | ||
47 | { | ||
48 | struct PendingResolutions *next; | ||
49 | struct PendingResolutions *prev; | ||
50 | |||
51 | struct GNUNET_HELLO_Address *address; | ||
52 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; | ||
53 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | ||
54 | |||
55 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; | ||
56 | }; | ||
57 | |||
58 | struct PendingResolutions *head; | ||
59 | struct PendingResolutions *tail; | ||
60 | |||
61 | void transport_addr_to_str_cb (void *cls, const char *address) | ||
62 | { | ||
63 | struct PendingResolutions * pr = cls; | ||
64 | if (NULL != address) | ||
65 | { | ||
66 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bandwidth out: %u Bytes/s, bandwidth in %u Bytes/s\n"), | ||
67 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, | ||
68 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__)); | ||
69 | } | ||
70 | else if (NULL != pr) | ||
71 | { | ||
72 | /* We're done */ | ||
73 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | ||
74 | GNUNET_free (pr->address); | ||
75 | GNUNET_free (pr); | ||
76 | } | ||
77 | |||
78 | } | ||
79 | |||
40 | void ats_perf_cb (void *cls, | 80 | void ats_perf_cb (void *cls, |
41 | const struct | 81 | const struct |
42 | GNUNET_HELLO_Address * | 82 | GNUNET_HELLO_Address * |
@@ -51,22 +91,47 @@ void ats_perf_cb (void *cls, | |||
51 | GNUNET_ATS_Information * | 91 | GNUNET_ATS_Information * |
52 | ats, uint32_t ats_count) | 92 | ats, uint32_t ats_count) |
53 | { | 93 | { |
54 | fprintf (stderr, "Peer `%s' plugin `%s', bandwidth out: %u Bytes/s, bandwidth in %u Bytes/s\n", | 94 | struct PendingResolutions * pr; |
55 | GNUNET_i2s (&address->peer), address->transport_name, | 95 | |
56 | ntohl (bandwidth_out.value__), ntohl (bandwidth_in.value__)); | 96 | pr = GNUNET_malloc (sizeof (struct PendingResolutions)); |
97 | pr->address = GNUNET_HELLO_address_copy (address); | ||
98 | pr->bandwidth_in = bandwidth_in; | ||
99 | pr->bandwidth_out = bandwidth_out; | ||
100 | pr->tats_ctx = GNUNET_TRANSPORT_address_to_string(cfg, address, | ||
101 | resolve_addresses_numeric, GNUNET_TIME_UNIT_FOREVER_REL, transport_addr_to_str_cb, pr); | ||
102 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); | ||
57 | results++; | 103 | results++; |
58 | } | 104 | } |
59 | 105 | ||
60 | void end (void *cls, | 106 | void end (void *cls, |
61 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 107 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
62 | { | 108 | { |
109 | struct PendingResolutions * pr; | ||
110 | struct PendingResolutions * next; | ||
111 | unsigned int pending; | ||
112 | |||
63 | GNUNET_ATS_performance_done (ph); | 113 | GNUNET_ATS_performance_done (ph); |
64 | ph = NULL; | 114 | ph = NULL; |
65 | fprintf (stderr, "ATS returned results for %u addresses\n", results); | 115 | |
116 | pending = 0; | ||
117 | next = head; | ||
118 | while (NULL != (pr = next)) | ||
119 | { | ||
120 | next = pr->next; | ||
121 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | ||
122 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); | ||
123 | GNUNET_free (pr->address); | ||
124 | GNUNET_free (pr); | ||
125 | pending ++; | ||
126 | } | ||
127 | if (0 < pending) | ||
128 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | ||
129 | |||
130 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); | ||
66 | ret = 0; | 131 | ret = 0; |
67 | } | 132 | } |
68 | 133 | ||
69 | void testservice_task (void *cls, | 134 | void testservice_ats (void *cls, |
70 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 135 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
71 | { | 136 | { |
72 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 137 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -77,11 +142,12 @@ void testservice_task (void *cls, | |||
77 | return; | 142 | return; |
78 | } | 143 | } |
79 | 144 | ||
145 | results = 0; | ||
80 | ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL); | 146 | ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL); |
81 | if (NULL == ph) | 147 | if (NULL == ph) |
82 | fprintf (stderr, "Cannot connect to ATS service, exiting...\n"); | 148 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); |
83 | 149 | ||
84 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); | 150 | end_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end, NULL); |
85 | ret = 1; | 151 | ret = 1; |
86 | } | 152 | } |
87 | 153 | ||
@@ -95,11 +161,12 @@ void testservice_task (void *cls, | |||
95 | */ | 161 | */ |
96 | static void | 162 | static void |
97 | run (void *cls, char *const *args, const char *cfgfile, | 163 | run (void *cls, char *const *args, const char *cfgfile, |
98 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 164 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) |
99 | { | 165 | { |
166 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; | ||
100 | GNUNET_CLIENT_service_test ("ats", cfg, | 167 | GNUNET_CLIENT_service_test ("ats", cfg, |
101 | GNUNET_TIME_UNIT_MINUTES, | 168 | GNUNET_TIME_UNIT_MINUTES, |
102 | &testservice_task, | 169 | &testservice_ats, |
103 | (void *) cfg); | 170 | (void *) cfg); |
104 | } | 171 | } |
105 | 172 | ||
@@ -115,7 +182,12 @@ int | |||
115 | main (int argc, char *const *argv) | 182 | main (int argc, char *const *argv) |
116 | { | 183 | { |
117 | int res; | 184 | int res; |
185 | resolve_addresses_numeric = GNUNET_NO; | ||
186 | |||
118 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 187 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
188 | {'n', "numeric", NULL, | ||
189 | gettext_noop ("do not resolve hostnames"), | ||
190 | 0, &GNUNET_GETOPT_set_one, &resolve_addresses_numeric}, | ||
119 | GNUNET_GETOPT_OPTION_END | 191 | GNUNET_GETOPT_OPTION_END |
120 | }; | 192 | }; |
121 | 193 | ||