diff options
Diffstat (limited to 'src/ats-tool/gnunet-ats.c')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 96 |
1 files changed, 70 insertions, 26 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 56f8a17ac..83b9739ff 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -288,14 +288,33 @@ find_address_it (void *cls, | |||
288 | } | 288 | } |
289 | 289 | ||
290 | static void | 290 | static void |
291 | ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | 291 | ats_perf_mon_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, |
292 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 292 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
293 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 293 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
294 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | 294 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
295 | { | 295 | { |
296 | struct PendingResolutions * pr; | 296 | struct PendingResolutions *pr; |
297 | struct PendingResolutions *cur; | ||
298 | struct PendingResolutions *next; | ||
297 | 299 | ||
298 | if ((GNUNET_YES == op_monitor) && (GNUNET_NO == verbose)) | 300 | if (NULL == address) |
301 | { | ||
302 | /* ATS service temporarily disconnected, remove current state */ | ||
303 | next = head; | ||
304 | for (cur = next; NULL != cur; cur = next) | ||
305 | { | ||
306 | next = cur->next; | ||
307 | GNUNET_CONTAINER_DLL_remove (head, tail, cur); | ||
308 | GNUNET_TRANSPORT_address_to_string_cancel (cur->tats_ctx); | ||
309 | GNUNET_HELLO_address_free (cur->address); | ||
310 | GNUNET_free (cur); | ||
311 | } | ||
312 | |||
313 | GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL); | ||
314 | return; | ||
315 | } | ||
316 | |||
317 | if (GNUNET_NO == verbose) | ||
299 | { | 318 | { |
300 | struct AddressFindCtx actx; | 319 | struct AddressFindCtx actx; |
301 | 320 | ||
@@ -316,7 +335,6 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | |||
316 | actx.res->bandwidth_out = bandwidth_out; | 335 | actx.res->bandwidth_out = bandwidth_out; |
317 | } | 336 | } |
318 | } | 337 | } |
319 | |||
320 | struct ATSAddress *a = GNUNET_new (struct ATSAddress); | 338 | struct ATSAddress *a = GNUNET_new (struct ATSAddress); |
321 | a->address = GNUNET_HELLO_address_copy(address); | 339 | a->address = GNUNET_HELLO_address_copy(address); |
322 | a->bandwidth_in = bandwidth_in; | 340 | a->bandwidth_in = bandwidth_in; |
@@ -325,27 +343,35 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | |||
325 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 343 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
326 | } | 344 | } |
327 | 345 | ||
328 | if (NULL != address) | 346 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + |
329 | { | 347 | ats_count * sizeof (struct GNUNET_ATS_Information)); |
330 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + | 348 | |
331 | ats_count * sizeof (struct GNUNET_ATS_Information)); | 349 | pr->ats_count = ats_count; |
332 | 350 | pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; | |
333 | pr->ats_count = ats_count; | 351 | if (ats_count > 0) |
334 | pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; | 352 | memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information)); |
335 | if (ats_count > 0) | 353 | pr->address = GNUNET_HELLO_address_copy (address); |
336 | memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information)); | 354 | pr->bandwidth_in = bandwidth_in; |
337 | pr->address = GNUNET_HELLO_address_copy (address); | 355 | pr->bandwidth_out = bandwidth_out; |
338 | pr->bandwidth_in = bandwidth_in; | 356 | pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, |
339 | pr->bandwidth_out = bandwidth_out; | 357 | resolve_addresses_numeric, |
340 | pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, | 358 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), |
341 | resolve_addresses_numeric, | 359 | transport_addr_to_str_cb, pr); |
342 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 360 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); |
343 | transport_addr_to_str_cb, pr); | 361 | results++; |
344 | GNUNET_CONTAINER_DLL_insert(head, tail, pr); | 362 | pending++; |
345 | results++; | 363 | } |
346 | pending++; | 364 | |
347 | } | 365 | |
348 | else | 366 | static void |
367 | ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | ||
368 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
369 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
370 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
371 | { | ||
372 | struct PendingResolutions * pr; | ||
373 | |||
374 | if (NULL == address) | ||
349 | { | 375 | { |
350 | /* All messages received */ | 376 | /* All messages received */ |
351 | receive_done = GNUNET_YES; | 377 | receive_done = GNUNET_YES; |
@@ -358,6 +384,24 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | |||
358 | end_task = GNUNET_SCHEDULER_add_now (end, NULL ); | 384 | end_task = GNUNET_SCHEDULER_add_now (end, NULL ); |
359 | } | 385 | } |
360 | } | 386 | } |
387 | |||
388 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + | ||
389 | ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
390 | |||
391 | pr->ats_count = ats_count; | ||
392 | pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; | ||
393 | if (ats_count > 0) | ||
394 | memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information)); | ||
395 | pr->address = GNUNET_HELLO_address_copy (address); | ||
396 | pr->bandwidth_in = bandwidth_in; | ||
397 | pr->bandwidth_out = bandwidth_out; | ||
398 | pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, | ||
399 | resolve_addresses_numeric, | ||
400 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
401 | transport_addr_to_str_cb, pr); | ||
402 | GNUNET_CONTAINER_DLL_insert(head, tail, pr); | ||
403 | results++; | ||
404 | pending++; | ||
361 | } | 405 | } |
362 | 406 | ||
363 | static unsigned int | 407 | static unsigned int |
@@ -510,7 +554,7 @@ testservice_ats(void *cls, int result) | |||
510 | } | 554 | } |
511 | else if (op_monitor) | 555 | else if (op_monitor) |
512 | { | 556 | { |
513 | ph = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL ); | 557 | ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL ); |
514 | if (NULL == ph) | 558 | if (NULL == ph) |
515 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); | 559 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); |
516 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, | 560 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, |