aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tool/gnunet-ats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats-tool/gnunet-ats.c')
-rw-r--r--src/ats-tool/gnunet-ats.c141
1 files changed, 38 insertions, 103 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c
index 612eb20ff..2d19df737 100644
--- a/src/ats-tool/gnunet-ats.c
+++ b/src/ats-tool/gnunet-ats.c
@@ -84,8 +84,6 @@ static char *opt_type_str;
84 */ 84 */
85static unsigned int opt_pref_value; 85static unsigned int opt_pref_value;
86 86
87
88
89/** 87/**
90 * Final status code. 88 * Final status code.
91 */ 89 */
@@ -124,7 +122,7 @@ static struct GNUNET_CONFIGURATION_Handle *cfg;
124/** 122/**
125 * Shutdown task 123 * Shutdown task
126 */ 124 */
127static struct GNUNET_SCHEDULER_Task * shutdown_task; 125static struct GNUNET_SCHEDULER_Task *shutdown_task;
128 126
129/** 127/**
130 * Hashmap to store addresses 128 * Hashmap to store addresses
@@ -161,14 +159,9 @@ struct PendingResolutions
161 struct GNUNET_TRANSPORT_AddressToStringContext *tats_ctx; 159 struct GNUNET_TRANSPORT_AddressToStringContext *tats_ctx;
162 160
163 /** 161 /**
164 * Array of performance data. 162 * Performance data.
165 */ 163 */
166 struct GNUNET_ATS_Information *ats; 164 struct GNUNET_ATS_Properties properties;
167
168 /**
169 * Length of the @e ats array.
170 */
171 uint32_t ats_count;
172 165
173 /** 166 /**
174 * Amount of outbound bandwidth assigned by ATS. 167 * Amount of outbound bandwidth assigned by ATS.
@@ -325,20 +318,15 @@ transport_addr_to_str_cb (void *cls,
325 int res) 318 int res)
326{ 319{
327 struct PendingResolutions *pr = cls; 320 struct PendingResolutions *pr = cls;
328 char *ats_str;
329 char *ats_tmp;
330 char *ats_prop_value;
331 unsigned int c;
332 uint32_t ats_type;
333 uint32_t ats_value;
334 uint32_t network;
335 321
336 if (NULL == address) 322 if (NULL == address)
337 { 323 {
338 /* We're done */ 324 /* We're done */
339 GNUNET_CONTAINER_DLL_remove(head, tail, pr); 325 GNUNET_CONTAINER_DLL_remove (head,
340 GNUNET_free(pr->address); 326 tail,
341 GNUNET_free(pr); 327 pr);
328 GNUNET_free (pr->address);
329 GNUNET_free (pr);
342 stat_pending--; 330 stat_pending--;
343 331
344 if ((GNUNET_YES == stat_receive_done) && (0 == stat_pending)) 332 if ((GNUNET_YES == stat_receive_done) && (0 == stat_pending))
@@ -374,64 +362,15 @@ transport_addr_to_str_cb (void *cls,
374 return; 362 return;
375 } 363 }
376 364
377 ats_str = GNUNET_strdup (pr->active ? _("active ") : _("inactive "));
378 network = GNUNET_ATS_NET_UNSPECIFIED;
379 for (c = 0; c < pr->ats_count; c++)
380 {
381 ats_tmp = ats_str;
382
383 ats_type = ntohl (pr->ats[c].type);
384 ats_value = ntohl (pr->ats[c].value);
385
386 if (ats_type > GNUNET_ATS_PropertyCount)
387 {
388 FPRINTF (stderr,
389 "Invalid ATS property type %u %u for address %s\n",
390 ats_type,
391 pr->ats[c].type,
392 address);
393 continue;
394 }
395
396 switch (ats_type)
397 {
398 case GNUNET_ATS_NETWORK_TYPE:
399 if (ats_value > GNUNET_ATS_NetworkTypeCount)
400 {
401 GNUNET_break(0);
402 continue;
403 }
404 network = ats_value;
405 GNUNET_asprintf (&ats_prop_value,
406 "%s",
407 GNUNET_ATS_print_network_type (ats_value));
408 break;
409 default:
410 GNUNET_asprintf (&ats_prop_value, "%u", ats_value);
411 break;
412 }
413 if ((opt_verbose) && (ats_type < GNUNET_ATS_PropertyCount))
414 {
415 GNUNET_asprintf (&ats_str,
416 "%s%s=%s, ",
417 ats_tmp,
418 GNUNET_ATS_print_property_type (ats_type),
419 ats_prop_value);
420 GNUNET_free(ats_tmp);
421 }
422 GNUNET_free(ats_prop_value);
423 }
424
425 FPRINTF (stderr, 365 FPRINTF (stderr,
426 _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), 366 _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
427 GNUNET_i2s (&pr->address->peer), 367 GNUNET_i2s (&pr->address->peer),
428 pr->address->transport_name, 368 pr->address->transport_name,
429 address, 369 address,
430 GNUNET_ATS_print_network_type (network), 370 GNUNET_ATS_print_network_type (pr->properties.scope),
431 ntohl (pr->bandwidth_out.value__), 371 ntohl (pr->bandwidth_out.value__),
432 ntohl (pr->bandwidth_in.value__), 372 ntohl (pr->bandwidth_in.value__),
433 ats_str); 373 pr->active ? _("active ") : _("inactive "));
434 GNUNET_free (ats_str);
435} 374}
436 375
437 376
@@ -489,8 +428,7 @@ find_address_it (void *cls,
489 * #GNUNET_SYSERR if this address is no longer available for ATS 428 * #GNUNET_SYSERR if this address is no longer available for ATS
490 * @param bandwidth_out assigned outbound bandwidth for the connection 429 * @param bandwidth_out assigned outbound bandwidth for the connection
491 * @param bandwidth_in assigned inbound bandwidth for the connection 430 * @param bandwidth_in assigned inbound bandwidth for the connection
492 * @param ats performance data for the address (as far as known) 431 * @param prop performance data for the address (as far as known)
493 * @param ats_count number of performance records in @a ats
494 */ 432 */
495static void 433static void
496ats_perf_mon_cb (void *cls, 434ats_perf_mon_cb (void *cls,
@@ -498,8 +436,7 @@ ats_perf_mon_cb (void *cls,
498 int active, 436 int active,
499 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 437 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
500 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 438 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
501 const struct GNUNET_ATS_Information *ats, 439 const struct GNUNET_ATS_Properties *prop)
502 uint32_t ats_count)
503{ 440{
504 struct PendingResolutions *pr; 441 struct PendingResolutions *pr;
505 struct PendingResolutions *cur; 442 struct PendingResolutions *cur;
@@ -517,7 +454,6 @@ ats_perf_mon_cb (void *cls,
517 GNUNET_HELLO_address_free (cur->address); 454 GNUNET_HELLO_address_free (cur->address);
518 GNUNET_free (cur); 455 GNUNET_free (cur);
519 } 456 }
520
521 GNUNET_CONTAINER_multipeermap_iterate (addresses, 457 GNUNET_CONTAINER_multipeermap_iterate (addresses,
522 &free_addr_it, 458 &free_addr_it,
523 NULL); 459 NULL);
@@ -530,15 +466,19 @@ ats_perf_mon_cb (void *cls,
530 466
531 actx.src = address; 467 actx.src = address;
532 actx.res = NULL; 468 actx.res = NULL;
533 GNUNET_CONTAINER_multipeermap_get_multiple (addresses, &address->peer, 469 GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
534 &find_address_it, &actx); 470 &address->peer,
471 &find_address_it,
472 &actx);
535 if (NULL == actx.res) 473 if (NULL == actx.res)
536 { 474 {
537 GNUNET_break (0); 475 GNUNET_break (0);
538 return; 476 return;
539 } 477 }
540 GNUNET_break( 478 GNUNET_break(GNUNET_OK ==
541 GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (addresses, &address->peer, actx.res)); 479 GNUNET_CONTAINER_multipeermap_remove (addresses,
480 &address->peer,
481 actx.res));
542 FPRINTF (stderr, 482 FPRINTF (stderr,
543 _("Removed address of peer `%s' with plugin `%s'\n"), 483 _("Removed address of peer `%s' with plugin `%s'\n"),
544 GNUNET_i2s (&address->peer), 484 GNUNET_i2s (&address->peer),
@@ -554,8 +494,10 @@ ats_perf_mon_cb (void *cls,
554 494
555 actx.src = address; 495 actx.src = address;
556 actx.res = NULL; 496 actx.res = NULL;
557 GNUNET_CONTAINER_multipeermap_get_multiple (addresses, &address->peer, 497 GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
558 &find_address_it, &actx); 498 &address->peer,
499 &find_address_it,
500 &actx);
559 if ((NULL != actx.res)) 501 if ((NULL != actx.res))
560 { 502 {
561 if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) && 503 if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) &&
@@ -578,18 +520,15 @@ ats_perf_mon_cb (void *cls,
578 a->bandwidth_in = bandwidth_in; 520 a->bandwidth_in = bandwidth_in;
579 a->bandwidth_out = bandwidth_out; 521 a->bandwidth_out = bandwidth_out;
580 a->active = active; 522 a->active = active;
581 GNUNET_CONTAINER_multipeermap_put (addresses, &address->peer, a, 523 GNUNET_CONTAINER_multipeermap_put (addresses,
582 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 524 &address->peer,
525 a,
526 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
583 } 527 }
584 } 528 }
585 529
586 pr = GNUNET_malloc (sizeof (struct PendingResolutions) + 530 pr = GNUNET_new (struct PendingResolutions);
587 ats_count * sizeof (struct GNUNET_ATS_Information)); 531 pr->properties = *prop;
588
589 pr->ats_count = ats_count;
590 pr->ats = (struct GNUNET_ATS_Information *) &pr[1];
591 if (ats_count > 0)
592 memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information));
593 pr->address = GNUNET_HELLO_address_copy (address); 532 pr->address = GNUNET_HELLO_address_copy (address);
594 pr->bandwidth_in = bandwidth_in; 533 pr->bandwidth_in = bandwidth_in;
595 pr->bandwidth_out = bandwidth_out; 534 pr->bandwidth_out = bandwidth_out;
@@ -614,8 +553,7 @@ ats_perf_mon_cb (void *cls,
614 to a peer 553 to a peer
615 * @param bandwidth_out assigned outbound bandwidth for the connection 554 * @param bandwidth_out assigned outbound bandwidth for the connection
616 * @param bandwidth_in assigned inbound bandwidth for the connection 555 * @param bandwidth_in assigned inbound bandwidth for the connection
617 * @param ats performance data for the address (as far as known) 556 * @param prop performance data for the address (as far as known)
618 * @param ats_count number of performance records in @a ats
619 */ 557 */
620static void 558static void
621ats_perf_cb (void *cls, 559ats_perf_cb (void *cls,
@@ -623,8 +561,7 @@ ats_perf_cb (void *cls,
623 int active, 561 int active,
624 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 562 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
625 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 563 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
626 const struct GNUNET_ATS_Information *ats, 564 const struct GNUNET_ATS_Properties *prop)
627 uint32_t ats_count)
628{ 565{
629 struct PendingResolutions *pr; 566 struct PendingResolutions *pr;
630 567
@@ -643,13 +580,8 @@ ats_perf_cb (void *cls,
643 return; 580 return;
644 } 581 }
645 582
646 pr = GNUNET_malloc (sizeof (struct PendingResolutions) + 583 pr = GNUNET_new (struct PendingResolutions);
647 ats_count * sizeof (struct GNUNET_ATS_Information)); 584 pr->properties = *prop;
648
649 pr->ats_count = ats_count;
650 pr->ats = (struct GNUNET_ATS_Information *) &pr[1];
651 if (ats_count > 0)
652 memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information));
653 pr->address = GNUNET_HELLO_address_copy (address); 585 pr->address = GNUNET_HELLO_address_copy (address);
654 pr->bandwidth_in = bandwidth_in; 586 pr->bandwidth_in = bandwidth_in;
655 pr->bandwidth_out = bandwidth_out; 587 pr->bandwidth_out = bandwidth_out;
@@ -921,7 +853,10 @@ testservice_ats (void *cls,
921 "%s", 853 "%s",
922 _("Cannot connect to ATS service, exiting...\n")); 854 _("Cannot connect to ATS service, exiting...\n"));
923 855
924 GNUNET_ATS_performance_change_preference (ph, &pid, type, (double) opt_pref_value, 856 GNUNET_ATS_performance_change_preference (ph,
857 &pid,
858 type,
859 (double) opt_pref_value,
925 GNUNET_ATS_PREFERENCE_END); 860 GNUNET_ATS_PREFERENCE_END);
926 861
927 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 862 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,