aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tool/gnunet-ats.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
committerng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
commit6e599264ad13e8fc105493d74d7c11d46f8739ed (patch)
tree169bef1ecbade5a659831fb169f3ae6943af127f /src/ats-tool/gnunet-ats.c
parent4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff)
downloadgnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz
gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip
first step to remove plibc
Diffstat (limited to 'src/ats-tool/gnunet-ats.c')
-rw-r--r--src/ats-tool/gnunet-ats.c427
1 files changed, 196 insertions, 231 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c
index 88c3c41e9..519f77af8 100644
--- a/src/ats-tool/gnunet-ats.c
+++ b/src/ats-tool/gnunet-ats.c
@@ -221,7 +221,6 @@ struct ATSAddress
221 * Is this an active address? 221 * Is this an active address?
222 */ 222 */
223 int active; 223 int active;
224
225}; 224};
226 225
227 226
@@ -245,16 +244,12 @@ static struct PendingResolutions *tail;
245 * @return #GNUNET_YES (always) 244 * @return #GNUNET_YES (always)
246 */ 245 */
247static int 246static int
248free_addr_it (void *cls, 247free_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
249 const struct GNUNET_PeerIdentity *key,
250 void *value)
251{ 248{
252 struct ATSAddress *a = value; 249 struct ATSAddress *a = value;
253 250
254 GNUNET_assert (GNUNET_OK == 251 GNUNET_assert (GNUNET_OK ==
255 GNUNET_CONTAINER_multipeermap_remove (addresses, 252 GNUNET_CONTAINER_multipeermap_remove (addresses, key, value));
256 key,
257 value));
258 GNUNET_HELLO_address_free (a->address); 253 GNUNET_HELLO_address_free (a->address);
259 GNUNET_free (a); 254 GNUNET_free (a);
260 return GNUNET_OK; 255 return GNUNET_OK;
@@ -269,8 +264,8 @@ free_addr_it (void *cls,
269static void 264static void
270end (void *cls) 265end (void *cls)
271{ 266{
272 struct PendingResolutions * pr; 267 struct PendingResolutions *pr;
273 struct PendingResolutions * next; 268 struct PendingResolutions *next;
274 unsigned int pending; 269 unsigned int pending;
275 270
276 if (NULL != alh) 271 if (NULL != alh)
@@ -290,25 +285,21 @@ end (void *cls)
290 while (NULL != (pr = next)) 285 while (NULL != (pr = next))
291 { 286 {
292 next = pr->next; 287 next = pr->next;
293 GNUNET_CONTAINER_DLL_remove(head, tail, pr); 288 GNUNET_CONTAINER_DLL_remove (head, tail, pr);
294 GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); 289 GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx);
295 GNUNET_free(pr->address); 290 GNUNET_free (pr->address);
296 GNUNET_free(pr); 291 GNUNET_free (pr);
297 pending++; 292 pending++;
298 } 293 }
299 GNUNET_CONTAINER_multipeermap_iterate (addresses, 294 GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL);
300 &free_addr_it,
301 NULL);
302 GNUNET_CONTAINER_multipeermap_destroy (addresses); 295 GNUNET_CONTAINER_multipeermap_destroy (addresses);
303 addresses = NULL; 296 addresses = NULL;
304 297
305 if (0 < pending) 298 if (0 < pending)
306 FPRINTF (stdout, 299 fprintf (stdout, _ ("%u address resolutions had a timeout\n"), pending);
307 _("%u address resolutions had a timeout\n"),
308 pending);
309 if (opt_list_used || opt_list_all) 300 if (opt_list_used || opt_list_all)
310 FPRINTF (stdout, 301 fprintf (stdout,
311 _("ATS returned stat_results for %u addresses\n"), 302 _ ("ATS returned stat_results for %u addresses\n"),
312 stat_results); 303 stat_results);
313 304
314 if (NULL != ats_sh) 305 if (NULL != ats_sh)
@@ -342,18 +333,14 @@ end (void *cls)
342 * if #GNUNET_SYSERR: communication error (IPC error) 333 * if #GNUNET_SYSERR: communication error (IPC error)
343 */ 334 */
344static void 335static void
345transport_addr_to_str_cb (void *cls, 336transport_addr_to_str_cb (void *cls, const char *address, int res)
346 const char *address,
347 int res)
348{ 337{
349 struct PendingResolutions *pr = cls; 338 struct PendingResolutions *pr = cls;
350 339
351 if (NULL == address) 340 if (NULL == address)
352 { 341 {
353 /* We're done */ 342 /* We're done */
354 GNUNET_CONTAINER_DLL_remove (head, 343 GNUNET_CONTAINER_DLL_remove (head, tail, pr);
355 tail,
356 pr);
357 GNUNET_free (pr->address); 344 GNUNET_free (pr->address);
358 GNUNET_free (pr); 345 GNUNET_free (pr);
359 stat_pending--; 346 stat_pending--;
@@ -370,18 +357,20 @@ transport_addr_to_str_cb (void *cls,
370 switch (res) 357 switch (res)
371 { 358 {
372 case GNUNET_SYSERR: 359 case GNUNET_SYSERR:
373 FPRINTF (stderr, 360 fprintf (
374 "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n", 361 stderr,
375 GNUNET_i2s (&pr->address->peer), 362 "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n",
376 pr->address->transport_name, 363 GNUNET_i2s (&pr->address->peer),
377 (unsigned int) pr->address->address_length); 364 pr->address->transport_name,
365 (unsigned int) pr->address->address_length);
378 return; 366 return;
379 case GNUNET_NO: 367 case GNUNET_NO:
380 FPRINTF (stderr, 368 fprintf (
381 "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n", 369 stderr,
382 GNUNET_i2s (&pr->address->peer), 370 "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n",
383 pr->address->transport_name, 371 GNUNET_i2s (&pr->address->peer),
384 (unsigned int) pr->address->address_length); 372 pr->address->transport_name,
373 (unsigned int) pr->address->address_length);
385 return; 374 return;
386 case GNUNET_OK: 375 case GNUNET_OK:
387 /* continues below */ 376 /* continues below */
@@ -391,15 +380,17 @@ transport_addr_to_str_cb (void *cls,
391 return; 380 return;
392 } 381 }
393 382
394 FPRINTF (stdout, 383 fprintf (
395 _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), 384 stdout,
396 GNUNET_i2s (&pr->address->peer), 385 _ (
397 pr->address->transport_name, 386 "Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
398 address, 387 GNUNET_i2s (&pr->address->peer),
399 GNUNET_NT_to_string (pr->properties.scope), 388 pr->address->transport_name,
400 ntohl (pr->bandwidth_out.value__), 389 address,
401 ntohl (pr->bandwidth_in.value__), 390 GNUNET_NT_to_string (pr->properties.scope),
402 pr->active ? _("active ") : _("inactive ")); 391 ntohl (pr->bandwidth_out.value__),
392 ntohl (pr->bandwidth_in.value__),
393 pr->active ? _ ("active ") : _ ("inactive "));
403} 394}
404 395
405 396
@@ -429,9 +420,7 @@ struct AddressFindCtx
429 * @return #GNUNET_NO if we found a match, #GNUNET_YES if not 420 * @return #GNUNET_NO if we found a match, #GNUNET_YES if not
430 */ 421 */
431static int 422static int
432find_address_it (void *cls, 423find_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
433 const struct GNUNET_PeerIdentity *key,
434 void *value)
435{ 424{
436 struct AddressFindCtx *actx = cls; 425 struct AddressFindCtx *actx = cls;
437 struct ATSAddress *exist = value; 426 struct ATSAddress *exist = value;
@@ -445,7 +434,6 @@ find_address_it (void *cls,
445} 434}
446 435
447 436
448
449/** 437/**
450 * Signature of a function that is called with QoS information about an address. 438 * Signature of a function that is called with QoS information about an address.
451 * 439 *
@@ -483,9 +471,7 @@ ats_perf_mon_cb (void *cls,
483 GNUNET_HELLO_address_free (cur->address); 471 GNUNET_HELLO_address_free (cur->address);
484 GNUNET_free (cur); 472 GNUNET_free (cur);
485 } 473 }
486 GNUNET_CONTAINER_multipeermap_iterate (addresses, 474 GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL);
487 &free_addr_it,
488 NULL);
489 return; 475 return;
490 } 476 }
491 if (GNUNET_SYSERR == active) 477 if (GNUNET_SYSERR == active)
@@ -504,12 +490,12 @@ ats_perf_mon_cb (void *cls,
504 GNUNET_break (0); 490 GNUNET_break (0);
505 return; 491 return;
506 } 492 }
507 GNUNET_break(GNUNET_OK == 493 GNUNET_break (GNUNET_OK ==
508 GNUNET_CONTAINER_multipeermap_remove (addresses, 494 GNUNET_CONTAINER_multipeermap_remove (addresses,
509 &address->peer, 495 &address->peer,
510 actx.res)); 496 actx.res));
511 FPRINTF (stdout, 497 fprintf (stdout,
512 _("Removed address of peer `%s' with plugin `%s'\n"), 498 _ ("Removed address of peer `%s' with plugin `%s'\n"),
513 GNUNET_i2s (&address->peer), 499 GNUNET_i2s (&address->peer),
514 actx.res->address->transport_name); 500 actx.res->address->transport_name);
515 GNUNET_HELLO_address_free (actx.res); 501 GNUNET_HELLO_address_free (actx.res);
@@ -545,14 +531,15 @@ ats_perf_mon_cb (void *cls,
545 { 531 {
546 a = GNUNET_new (struct ATSAddress); 532 a = GNUNET_new (struct ATSAddress);
547 533
548 a->address = GNUNET_HELLO_address_copy(address); 534 a->address = GNUNET_HELLO_address_copy (address);
549 a->bandwidth_in = bandwidth_in; 535 a->bandwidth_in = bandwidth_in;
550 a->bandwidth_out = bandwidth_out; 536 a->bandwidth_out = bandwidth_out;
551 a->active = active; 537 a->active = active;
552 GNUNET_CONTAINER_multipeermap_put (addresses, 538 GNUNET_CONTAINER_multipeermap_put (
553 &address->peer, 539 addresses,
554 a, 540 &address->peer,
555 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 541 a,
542 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
556 } 543 }
557 } 544 }
558 545
@@ -562,11 +549,13 @@ ats_perf_mon_cb (void *cls,
562 pr->bandwidth_in = bandwidth_in; 549 pr->bandwidth_in = bandwidth_in;
563 pr->bandwidth_out = bandwidth_out; 550 pr->bandwidth_out = bandwidth_out;
564 pr->active = active; 551 pr->active = active;
565 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, 552 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (
566 opt_resolve_addresses_numeric, 553 cfg,
567 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 554 address,
568 &transport_addr_to_str_cb, 555 opt_resolve_addresses_numeric,
569 pr); 556 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
557 &transport_addr_to_str_cb,
558 pr);
570 GNUNET_CONTAINER_DLL_insert (head, tail, pr); 559 GNUNET_CONTAINER_DLL_insert (head, tail, pr);
571 stat_results++; 560 stat_results++;
572 stat_pending++; 561 stat_pending++;
@@ -615,10 +604,13 @@ ats_perf_cb (void *cls,
615 pr->bandwidth_in = bandwidth_in; 604 pr->bandwidth_in = bandwidth_in;
616 pr->bandwidth_out = bandwidth_out; 605 pr->bandwidth_out = bandwidth_out;
617 pr->active = active; 606 pr->active = active;
618 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, 607 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (
619 opt_resolve_addresses_numeric, 608 cfg,
620 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 609 address,
621 &transport_addr_to_str_cb, pr); 610 opt_resolve_addresses_numeric,
611 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
612 &transport_addr_to_str_cb,
613 pr);
622 GNUNET_CONTAINER_DLL_insert (head, tail, pr); 614 GNUNET_CONTAINER_DLL_insert (head, tail, pr);
623 stat_results++; 615 stat_results++;
624 stat_pending++; 616 stat_pending++;
@@ -635,10 +627,10 @@ ats_perf_cb (void *cls,
635static unsigned int 627static unsigned int
636print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) 628print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
637{ 629{
638 char * entry_in = NULL; 630 char *entry_in = NULL;
639 char * entry_out = NULL; 631 char *entry_out = NULL;
640 char * quota_out_str; 632 char *quota_out_str;
641 char * quota_in_str; 633 char *quota_in_str;
642 unsigned long long int quota_out; 634 unsigned long long int quota_out;
643 unsigned long long int quota_in; 635 unsigned long long int quota_in;
644 int c; 636 int c;
@@ -646,32 +638,26 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
646 for (c = 0; (c < GNUNET_NT_COUNT); c++) 638 for (c = 0; (c < GNUNET_NT_COUNT); c++)
647 { 639 {
648 640
649 GNUNET_asprintf (&entry_out, 641 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", GNUNET_NT_to_string (c));
650 "%s_QUOTA_OUT", 642 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", GNUNET_NT_to_string (c));
651 GNUNET_NT_to_string (c));
652 GNUNET_asprintf (&entry_in,
653 "%s_QUOTA_IN",
654 GNUNET_NT_to_string (c));
655 643
656 /* quota out */ 644 /* quota out */
657 if (GNUNET_OK == 645 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
658 GNUNET_CONFIGURATION_get_value_string (cfg, 646 "ats",
659 "ats", 647 entry_out,
660 entry_out, 648 &quota_out_str))
661 &quota_out_str))
662 { 649 {
663 if (0 == strcmp (quota_out_str, UNLIMITED_STRING) 650 if (0 == strcmp (quota_out_str, UNLIMITED_STRING) ||
664 || (GNUNET_SYSERR == 651 (GNUNET_SYSERR ==
665 GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, 652 GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &quota_out)))
666 &quota_out)))
667 quota_out = UINT32_MAX; 653 quota_out = UINT32_MAX;
668 654
669 GNUNET_free(quota_out_str); 655 GNUNET_free (quota_out_str);
670 GNUNET_asprintf (&quota_out_str, "%llu", quota_out); 656 GNUNET_asprintf (&quota_out_str, "%llu", quota_out);
671 } 657 }
672 else 658 else
673 { 659 {
674 FPRINTF (stderr, 660 fprintf (stderr,
675 "Outbound quota for network `%11s' not configured!\n", 661 "Outbound quota for network `%11s' not configured!\n",
676 GNUNET_NT_to_string (c)); 662 GNUNET_NT_to_string (c));
677 GNUNET_asprintf (&quota_out_str, "-"); 663 GNUNET_asprintf (&quota_out_str, "-");
@@ -679,35 +665,34 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
679 GNUNET_free (entry_out); 665 GNUNET_free (entry_out);
680 666
681 /* quota in */ 667 /* quota in */
682 if (GNUNET_OK == 668 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
683 GNUNET_CONFIGURATION_get_value_string (cfg, 669 "ats",
684 "ats", 670 entry_in,
685 entry_in, 671 &quota_in_str))
686 &quota_in_str))
687 { 672 {
688 if (0 == strcmp (quota_in_str, UNLIMITED_STRING) 673 if (0 == strcmp (quota_in_str, UNLIMITED_STRING) ||
689 || (GNUNET_SYSERR == 674 (GNUNET_SYSERR ==
690 GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in))) 675 GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in)))
691 quota_in = UINT32_MAX; 676 quota_in = UINT32_MAX;
692 GNUNET_free (quota_in_str); 677 GNUNET_free (quota_in_str);
693 GNUNET_asprintf (&quota_in_str, "%llu", quota_in); 678 GNUNET_asprintf (&quota_in_str, "%llu", quota_in);
694 } 679 }
695 else 680 else
696 { 681 {
697 FPRINTF (stderr, 682 fprintf (stderr,
698 "Inbound quota for network `%11s' not configured!\n", 683 "Inbound quota for network `%11s' not configured!\n",
699 GNUNET_NT_to_string (c)); 684 GNUNET_NT_to_string (c));
700 GNUNET_asprintf (&quota_in_str, "-"); 685 GNUNET_asprintf (&quota_in_str, "-");
701 } 686 }
702 GNUNET_free(entry_in); 687 GNUNET_free (entry_in);
703 688
704 FPRINTF (stdout, 689 fprintf (stdout,
705 _("Quota for network `%11s' (in/out): %10s / %10s\n"), 690 _ ("Quota for network `%11s' (in/out): %10s / %10s\n"),
706 GNUNET_NT_to_string (c), 691 GNUNET_NT_to_string (c),
707 quota_in_str, 692 quota_in_str,
708 quota_out_str); 693 quota_out_str);
709 GNUNET_free(quota_out_str); 694 GNUNET_free (quota_out_str);
710 GNUNET_free(quota_in_str); 695 GNUNET_free (quota_in_str);
711 } 696 }
712 return GNUNET_NT_COUNT; 697 return GNUNET_NT_COUNT;
713} 698}
@@ -723,7 +708,7 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
723 */ 708 */
724static void 709static void
725run (void *cls, 710run (void *cls,
726 char * const *args, 711 char *const *args,
727 const char *cfgfile, 712 const char *cfgfile,
728 const struct GNUNET_CONFIGURATION_Handle *my_cfg) 713 const struct GNUNET_CONFIGURATION_Handle *my_cfg)
729{ 714{
@@ -744,9 +729,7 @@ run (void *cls,
744 strlen (opt_pid_str), 729 strlen (opt_pid_str),
745 &pid.public_key)) 730 &pid.public_key))
746 { 731 {
747 FPRINTF (stderr, 732 fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), opt_pid_str);
748 _("Failed to parse peer identity `%s'\n"),
749 opt_pid_str);
750 return; 733 return;
751 } 734 }
752 } 735 }
@@ -757,9 +740,7 @@ run (void *cls,
757 strlen (cpid_str), 740 strlen (cpid_str),
758 &cpid.public_key)) 741 &cpid.public_key))
759 { 742 {
760 FPRINTF (stderr, 743 fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), cpid_str);
761 _("Failed to parse peer identity `%s'\n"),
762 cpid_str);
763 return; 744 return;
764 } 745 }
765 c++; 746 c++;
@@ -769,8 +750,8 @@ run (void *cls,
769 750
770 if (1 < c) 751 if (1 < c)
771 { 752 {
772 FPRINTF (stderr, 753 fprintf (stderr,
773 _("Please select one operation: %s or %s or %s or %s or %s\n"), 754 _ ("Please select one operation: %s or %s or %s or %s or %s\n"),
774 "--used", 755 "--used",
775 "--all", 756 "--all",
776 "--monitor", 757 "--monitor",
@@ -790,65 +771,56 @@ run (void *cls,
790 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 771 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
791 if (NULL == ph) 772 if (NULL == ph)
792 { 773 {
793 FPRINTF (stderr, 774 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
794 "%s",
795 _("Cannot connect to ATS service, exiting...\n"));
796 return; 775 return;
797 } 776 }
798 alh = GNUNET_ATS_performance_list_addresses (ph, 777 alh = GNUNET_ATS_performance_list_addresses (ph,
799 (NULL == opt_pid_str) ? NULL : &pid, 778 (NULL == opt_pid_str) ? NULL
779 : &pid,
800 GNUNET_YES, 780 GNUNET_YES,
801 &ats_perf_cb, NULL); 781 &ats_perf_cb,
782 NULL);
802 if (NULL == alh) 783 if (NULL == alh)
803 { 784 {
804 FPRINTF (stderr, 785 fprintf (stderr,
805 "%s", 786 "%s",
806 _("Cannot issue request to ATS service, exiting...\n")); 787 _ ("Cannot issue request to ATS service, exiting...\n"));
807 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 788 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
808 return; 789 return;
809 } 790 }
810 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, 791 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
811 NULL);
812 return; 792 return;
813 } 793 }
814 if (opt_list_used) 794 if (opt_list_used)
815 { 795 {
816 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 796 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
817 if (NULL == ph) 797 if (NULL == ph)
818 FPRINTF (stderr, 798 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
819 "%s",
820 _("Cannot connect to ATS service, exiting...\n"));
821 799
822 alh = GNUNET_ATS_performance_list_addresses (ph, 800 alh = GNUNET_ATS_performance_list_addresses (ph,
823 (NULL == opt_pid_str) 801 (NULL == opt_pid_str) ? NULL
824 ? NULL 802 : &pid,
825 : &pid,
826 GNUNET_NO, 803 GNUNET_NO,
827 &ats_perf_cb, NULL); 804 &ats_perf_cb,
805 NULL);
828 if (NULL == alh) 806 if (NULL == alh)
829 { 807 {
830 FPRINTF (stderr, 808 fprintf (stderr,
831 "%s", 809 "%s",
832 _("Cannot issue request to ATS service, exiting...\n")); 810 _ ("Cannot issue request to ATS service, exiting...\n"));
833 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 811 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
834 return; 812 return;
835 } 813 }
836 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, 814 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
837 NULL);
838 return; 815 return;
839 } 816 }
840 if (opt_monitor) 817 if (opt_monitor)
841 { 818 {
842 ph = GNUNET_ATS_performance_init (cfg, 819 ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL);
843 &ats_perf_mon_cb, 820 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
844 NULL);
845 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
846 NULL);
847 if (NULL == ph) 821 if (NULL == ph)
848 { 822 {
849 FPRINTF (stderr, 823 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
850 "%s",
851 _("Cannot connect to ATS service, exiting...\n"));
852 GNUNET_SCHEDULER_shutdown (); 824 GNUNET_SCHEDULER_shutdown ();
853 } 825 }
854 return; 826 return;
@@ -857,16 +829,12 @@ run (void *cls,
857 { 829 {
858 if (NULL == opt_type_str) 830 if (NULL == opt_type_str)
859 { 831 {
860 FPRINTF (stderr, 832 fprintf (stderr, "%s", _ ("No preference type given!\n"));
861 "%s",
862 _("No preference type given!\n"));
863 return; 833 return;
864 } 834 }
865 if (NULL == opt_pid_str) 835 if (NULL == opt_pid_str)
866 { 836 {
867 FPRINTF (stderr, 837 fprintf (stderr, "%s", _ ("No peer given!\n"));
868 "%s",
869 _("No peer given!\n"));
870 return; 838 return;
871 } 839 }
872 840
@@ -882,18 +850,14 @@ run (void *cls,
882 type = GNUNET_ATS_PREFERENCE_BANDWIDTH; 850 type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
883 else 851 else
884 { 852 {
885 FPRINTF (stderr, 853 fprintf (stderr, "%s", _ ("Valid type required\n"));
886 "%s",
887 _("Valid type required\n"));
888 return; 854 return;
889 } 855 }
890 856
891 /* set */ 857 /* set */
892 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 858 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
893 if (NULL == ph) 859 if (NULL == ph)
894 FPRINTF (stderr, 860 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
895 "%s",
896 _("Cannot connect to ATS service, exiting...\n"));
897 861
898 GNUNET_ATS_performance_change_preference (ph, 862 GNUNET_ATS_performance_change_preference (ph,
899 &pid, 863 &pid,
@@ -901,21 +865,16 @@ run (void *cls,
901 (double) opt_pref_value, 865 (double) opt_pref_value,
902 GNUNET_ATS_PREFERENCE_END); 866 GNUNET_ATS_PREFERENCE_END);
903 867
904 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 868 shutdown_task =
905 &end, 869 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
906 NULL);
907 return; 870 return;
908 } 871 }
909 if (NULL != cpid_str) 872 if (NULL != cpid_str)
910 { 873 {
911 ats_ch = GNUNET_ATS_connectivity_init (cfg); 874 ats_ch = GNUNET_ATS_connectivity_init (cfg);
912 ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch, 875 ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch, &cpid, 1000);
913 &cpid, 876 shutdown_task =
914 1000); 877 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
915 shutdown_task
916 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
917 &end,
918 NULL);
919 return; 878 return;
920 } 879 }
921 ret = 1; 880 ret = 1;
@@ -930,8 +889,7 @@ run (void *cls,
930 * @return 0 ok, 1 on error 889 * @return 0 ok, 1 on error
931 */ 890 */
932int 891int
933main (int argc, 892main (int argc, char *const *argv)
934 char * const *argv)
935{ 893{
936 int res; 894 int res;
937 895
@@ -944,76 +902,83 @@ main (int argc,
944 stat_receive_done = GNUNET_NO; 902 stat_receive_done = GNUNET_NO;
945 opt_type_str = NULL; 903 opt_type_str = NULL;
946 904
947 struct GNUNET_GETOPT_CommandLineOption options[] = { 905 struct GNUNET_GETOPT_CommandLineOption options[] =
948 GNUNET_GETOPT_option_flag ('u', 906 {GNUNET_GETOPT_option_flag ('u',
949 "used", 907 "used",
950 gettext_noop ("get list of active addresses currently used"), 908 gettext_noop (
951 &opt_list_used), 909 "get list of active addresses currently used"),
952 GNUNET_GETOPT_option_flag ('a', 910 &opt_list_used),
953 "all", 911 GNUNET_GETOPT_option_flag ('a',
954 gettext_noop ("get list of all active addresses"), 912 "all",
955 &opt_list_all), 913 gettext_noop (
956 914 "get list of all active addresses"),
957 GNUNET_GETOPT_option_string ('C', 915 &opt_list_all),
958 "connect", 916
959 NULL, 917 GNUNET_GETOPT_option_string ('C',
960 gettext_noop ("connect to PEER"), 918 "connect",
961 &cpid_str), 919 NULL,
962 GNUNET_GETOPT_option_flag ('n', 920 gettext_noop ("connect to PEER"),
963 "numeric", 921 &cpid_str),
964 gettext_noop ("do not resolve IP addresses to hostnames"), 922 GNUNET_GETOPT_option_flag ('n',
965 &opt_resolve_addresses_numeric), 923 "numeric",
966 924 gettext_noop (
967 GNUNET_GETOPT_option_flag ('m', 925 "do not resolve IP addresses to hostnames"),
968 "monitor", 926 &opt_resolve_addresses_numeric),
969 gettext_noop ("monitor mode"), 927
970 &opt_monitor), 928 GNUNET_GETOPT_option_flag ('m',
971 929 "monitor",
972 GNUNET_GETOPT_option_flag ('p', 930 gettext_noop ("monitor mode"),
973 "preference", 931 &opt_monitor),
974 gettext_noop ("set preference for the given peer"), 932
975 &opt_set_pref), 933 GNUNET_GETOPT_option_flag ('p',
976 934 "preference",
977 GNUNET_GETOPT_option_flag ('q', 935 gettext_noop (
978 "quotas", 936 "set preference for the given peer"),
979 gettext_noop ("print all configured quotas"), 937 &opt_set_pref),
980 &opt_print_quotas), 938
981 GNUNET_GETOPT_option_string ('i', 939 GNUNET_GETOPT_option_flag ('q',
982 "id", 940 "quotas",
983 "TYPE", 941 gettext_noop ("print all configured quotas"),
984 gettext_noop ("peer id"), 942 &opt_print_quotas),
985 &opt_pid_str), 943 GNUNET_GETOPT_option_string ('i',
986 944 "id",
987 GNUNET_GETOPT_option_string ('t', 945 "TYPE",
988 "type", 946 gettext_noop ("peer id"),
989 "TYPE", 947 &opt_pid_str),
990 gettext_noop ("preference type to set: latency | bandwidth"), 948
991 &opt_type_str), 949 GNUNET_GETOPT_option_string ('t',
992 950 "type",
993 GNUNET_GETOPT_option_uint ('k', 951 "TYPE",
994 "value", 952 gettext_noop (
995 "VALUE", 953 "preference type to set: latency | bandwidth"),
996 gettext_noop ("preference value"), 954 &opt_type_str),
997 &opt_pref_value), 955
998 956 GNUNET_GETOPT_option_uint ('k',
999 GNUNET_GETOPT_option_flag ('V', 957 "value",
1000 "verbose", 958 "VALUE",
1001 gettext_noop ("verbose output (include ATS address properties)"), 959 gettext_noop ("preference value"),
1002 &opt_verbose), 960 &opt_pref_value),
1003 GNUNET_GETOPT_OPTION_END 961
1004 }; 962 GNUNET_GETOPT_option_flag (
963 'V',
964 "verbose",
965 gettext_noop ("verbose output (include ATS address properties)"),
966 &opt_verbose),
967 GNUNET_GETOPT_OPTION_END};
1005 968
1006 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 969 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1007 return 2; 970 return 2;
1008 971
1009 res = GNUNET_PROGRAM_run (argc, argv, 972 res = GNUNET_PROGRAM_run (argc,
973 argv,
1010 "gnunet-ats", 974 "gnunet-ats",
1011 gettext_noop ("Print information about ATS state"), 975 gettext_noop ("Print information about ATS state"),
1012 options, 976 options,
1013 &run, NULL); 977 &run,
1014 GNUNET_free_non_null(opt_pid_str); 978 NULL);
1015 GNUNET_free_non_null(opt_type_str); 979 GNUNET_free_non_null (opt_pid_str);
1016 GNUNET_free((void *) argv); 980 GNUNET_free_non_null (opt_type_str);
981 GNUNET_free ((void *) argv);
1017 982
1018 if (GNUNET_OK == res) 983 if (GNUNET_OK == res)
1019 return ret; 984 return ret;