diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-20 14:30:14 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-20 14:30:14 +0000 |
commit | 184c653a98dd3674d2607f72b9db9f13dcdeae8b (patch) | |
tree | 080b8636d03f57edc225aea0dfb5fb08847c2c34 /src/ats-tool | |
parent | d5764ce0391a8089341a57e9c8cba41b15cc6c7b (diff) | |
download | gnunet-184c653a98dd3674d2607f72b9db9f13dcdeae8b.tar.gz gnunet-184c653a98dd3674d2607f72b9db9f13dcdeae8b.zip |
- changes
Diffstat (limited to 'src/ats-tool')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 187 |
1 files changed, 106 insertions, 81 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 27dfd4dca..2219363d5 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -36,6 +36,8 @@ | |||
36 | static int ret; | 36 | static int ret; |
37 | static int results; | 37 | static int results; |
38 | static int resolve_addresses_numeric; | 38 | static int resolve_addresses_numeric; |
39 | static int receive_done; | ||
40 | |||
39 | /** | 41 | /** |
40 | * For which peer should we change preference values? | 42 | * For which peer should we change preference values? |
41 | */ | 43 | */ |
@@ -43,6 +45,7 @@ static char *pid_str; | |||
43 | 45 | ||
44 | static char *type_str; | 46 | static char *type_str; |
45 | static unsigned int value; | 47 | static unsigned int value; |
48 | static int pending; | ||
46 | 49 | ||
47 | /** | 50 | /** |
48 | * Print verbose ATS information | 51 | * Print verbose ATS information |
@@ -97,6 +100,44 @@ struct PendingResolutions | |||
97 | struct PendingResolutions *head; | 100 | struct PendingResolutions *head; |
98 | struct PendingResolutions *tail; | 101 | struct PendingResolutions *tail; |
99 | 102 | ||
103 | void end (void *cls, | ||
104 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
105 | { | ||
106 | struct PendingResolutions * pr; | ||
107 | struct PendingResolutions * next; | ||
108 | unsigned int pending; | ||
109 | |||
110 | if (NULL != alh) | ||
111 | { | ||
112 | GNUNET_ATS_performance_list_addresses_cancel (alh); | ||
113 | alh = NULL; | ||
114 | } | ||
115 | |||
116 | if (NULL != ph) | ||
117 | { | ||
118 | GNUNET_ATS_performance_done (ph); | ||
119 | ph = NULL; | ||
120 | } | ||
121 | |||
122 | pending = 0; | ||
123 | next = head; | ||
124 | while (NULL != (pr = next)) | ||
125 | { | ||
126 | next = pr->next; | ||
127 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | ||
128 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); | ||
129 | GNUNET_free (pr->address); | ||
130 | GNUNET_free (pr); | ||
131 | pending ++; | ||
132 | } | ||
133 | if (0 < pending) | ||
134 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | ||
135 | |||
136 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); | ||
137 | ret = 0; | ||
138 | } | ||
139 | |||
140 | |||
100 | void transport_addr_to_str_cb (void *cls, const char *address) | 141 | void transport_addr_to_str_cb (void *cls, const char *address) |
101 | { | 142 | { |
102 | struct PendingResolutions * pr = cls; | 143 | struct PendingResolutions * pr = cls; |
@@ -108,58 +149,65 @@ void transport_addr_to_str_cb (void *cls, const char *address) | |||
108 | unsigned int c; | 149 | unsigned int c; |
109 | uint32_t ats_type; | 150 | uint32_t ats_type; |
110 | uint32_t ats_value; | 151 | uint32_t ats_value; |
111 | |||
112 | if (NULL != address) | 152 | if (NULL != address) |
113 | { | 153 | { |
114 | ats_str = GNUNET_strdup(""); | 154 | ats_str = GNUNET_strdup(""); |
115 | if (verbose) | 155 | if (verbose) |
116 | { | 156 | { |
117 | for (c = 0; c < pr->ats_count; c++) | 157 | for (c = 0; c < pr->ats_count; c++) |
118 | { | 158 | { |
119 | ats_tmp = ats_str; | 159 | ats_tmp = ats_str; |
120 | 160 | ||
121 | ats_type = ntohl(pr->ats[c].type); | 161 | ats_type = ntohl(pr->ats[c].type); |
122 | ats_value = ntohl(pr->ats[c].value); | 162 | ats_value = ntohl(pr->ats[c].value); |
123 | 163 | ||
124 | if (ats_type > GNUNET_ATS_PropertyCount) | 164 | if (ats_type > GNUNET_ATS_PropertyCount) |
125 | { | 165 | { |
126 | GNUNET_break (0); | 166 | GNUNET_break (0); |
127 | continue; | 167 | continue; |
128 | } | 168 | } |
129 | 169 | ||
130 | switch (ats_type) { | 170 | switch (ats_type) { |
131 | case GNUNET_ATS_NETWORK_TYPE: | 171 | case GNUNET_ATS_NETWORK_TYPE: |
132 | if (ats_value > GNUNET_ATS_NetworkTypeCount) | 172 | if (ats_value > GNUNET_ATS_NetworkTypeCount) |
133 | { | 173 | { |
134 | GNUNET_break (0); | 174 | GNUNET_break (0); |
135 | continue; | 175 | continue; |
136 | } | 176 | } |
137 | GNUNET_asprintf (&ats_prop_value, "%s", ats_net_arr[ats_value]); | 177 | GNUNET_asprintf (&ats_prop_value, "%s", ats_net_arr[ats_value]); |
138 | break; | 178 | break; |
139 | default: | 179 | default: |
140 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); | 180 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); |
141 | break; | 181 | break; |
142 | } | ||
143 | |||
144 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type] , ats_prop_value); | ||
145 | GNUNET_free (ats_tmp); | ||
146 | GNUNET_free (ats_prop_value); | ||
147 | } | 182 | } |
183 | |||
184 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type] , ats_prop_value); | ||
185 | GNUNET_free (ats_tmp); | ||
186 | GNUNET_free (ats_prop_value); | ||
148 | } | 187 | } |
188 | } | ||
149 | 189 | ||
150 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), | 190 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), |
151 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, | 191 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, |
152 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),ats_str); | 192 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),ats_str); |
153 | GNUNET_free (ats_str); | 193 | GNUNET_free (ats_str); |
154 | } | 194 | } |
155 | else if (NULL != pr) | 195 | else |
156 | { | 196 | { |
157 | /* We're done */ | 197 | /* We're done */ |
158 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | 198 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); |
159 | GNUNET_free (pr->address); | 199 | GNUNET_free (pr->address); |
160 | GNUNET_free (pr); | 200 | GNUNET_free (pr); |
161 | } | 201 | pending--; |
162 | 202 | ||
203 | if ((GNUNET_YES == receive_done) && (0 == pending)) | ||
204 | { | ||
205 | /* All messages received and no resolutions pending*/ | ||
206 | if (end_task != GNUNET_SCHEDULER_NO_TASK) | ||
207 | GNUNET_SCHEDULER_cancel (end_task); | ||
208 | end_task = GNUNET_SCHEDULER_add_now (end, NULL); | ||
209 | } | ||
210 | } | ||
163 | } | 211 | } |
164 | 212 | ||
165 | void ats_perf_cb (void *cls, | 213 | void ats_perf_cb (void *cls, |
@@ -195,44 +243,23 @@ void ats_perf_cb (void *cls, | |||
195 | resolve_addresses_numeric, GNUNET_TIME_UNIT_FOREVER_REL, transport_addr_to_str_cb, pr); | 243 | resolve_addresses_numeric, GNUNET_TIME_UNIT_FOREVER_REL, transport_addr_to_str_cb, pr); |
196 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); | 244 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); |
197 | results++; | 245 | results++; |
246 | pending++; | ||
198 | } | 247 | } |
199 | } | 248 | else |
200 | |||
201 | |||
202 | void end (void *cls, | ||
203 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
204 | { | ||
205 | struct PendingResolutions * pr; | ||
206 | struct PendingResolutions * next; | ||
207 | unsigned int pending; | ||
208 | |||
209 | if (NULL != alh) | ||
210 | { | ||
211 | GNUNET_ATS_performance_list_addresses_cancel (alh); | ||
212 | alh = NULL; | ||
213 | } | ||
214 | |||
215 | GNUNET_ATS_performance_done (ph); | ||
216 | ph = NULL; | ||
217 | |||
218 | pending = 0; | ||
219 | next = head; | ||
220 | while (NULL != (pr = next)) | ||
221 | { | 249 | { |
222 | next = pr->next; | 250 | /* All messages received */ |
223 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | 251 | receive_done = GNUNET_YES; |
224 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); | 252 | if (0 == pending) |
225 | GNUNET_free (pr->address); | 253 | { |
226 | GNUNET_free (pr); | 254 | /* All messages received and no resolutions pending*/ |
227 | pending ++; | 255 | if (end_task != GNUNET_SCHEDULER_NO_TASK) |
256 | GNUNET_SCHEDULER_cancel (end_task); | ||
257 | end_task = GNUNET_SCHEDULER_add_now (end, NULL); | ||
258 | } | ||
228 | } | 259 | } |
229 | if (0 < pending) | ||
230 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | ||
231 | |||
232 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); | ||
233 | ret = 0; | ||
234 | } | 260 | } |
235 | 261 | ||
262 | |||
236 | void testservice_ats (void *cls, | 263 | void testservice_ats (void *cls, |
237 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 264 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
238 | { | 265 | { |
@@ -292,9 +319,7 @@ void testservice_ats (void *cls, | |||
292 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); | 319 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); |
293 | return; | 320 | return; |
294 | } | 321 | } |
295 | |||
296 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | 322 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); |
297 | |||
298 | } | 323 | } |
299 | else if (op_list_used) | 324 | else if (op_list_used) |
300 | { | 325 | { |
@@ -311,8 +336,6 @@ void testservice_ats (void *cls, | |||
311 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); | 336 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); |
312 | return; | 337 | return; |
313 | } | 338 | } |
314 | |||
315 | |||
316 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | 339 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); |
317 | } | 340 | } |
318 | else if (op_monitor) | 341 | else if (op_monitor) |
@@ -388,6 +411,8 @@ main (int argc, char *const *argv) | |||
388 | op_monitor = GNUNET_NO; | 411 | op_monitor = GNUNET_NO; |
389 | op_list_all = GNUNET_NO; | 412 | op_list_all = GNUNET_NO; |
390 | op_list_used = GNUNET_NO; | 413 | op_list_used = GNUNET_NO; |
414 | pending = 0; | ||
415 | receive_done = GNUNET_NO; | ||
391 | 416 | ||
392 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 417 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
393 | {'u', "used", NULL, | 418 | {'u', "used", NULL, |