diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-16 06:16:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-16 06:16:10 +0000 |
commit | ca86c832ab602853100a7e0c559aacd162046678 (patch) | |
tree | 8dfa87bcd74bf77564e483c7ca6a0729b986ff25 /src/ats-tool | |
parent | 59ea282dc94ac377f098d117e215321989d572b8 (diff) | |
download | gnunet-ca86c832ab602853100a7e0c559aacd162046678.tar.gz gnunet-ca86c832ab602853100a7e0c559aacd162046678.zip |
-indentation
Diffstat (limited to 'src/ats-tool')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 160 |
1 files changed, 106 insertions, 54 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 55132f8ef..7360e4c50 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -118,21 +118,27 @@ static struct PendingResolutions *head; | |||
118 | 118 | ||
119 | static struct PendingResolutions *tail; | 119 | static struct PendingResolutions *tail; |
120 | 120 | ||
121 | |||
121 | static int | 122 | static int |
122 | free_addr_it (void *cls, | 123 | free_addr_it (void *cls, |
123 | const struct GNUNET_PeerIdentity *key, | 124 | const struct GNUNET_PeerIdentity *key, |
124 | void *value) | 125 | void *value) |
125 | { | 126 | { |
126 | struct ATSAddress *a = value; | 127 | struct ATSAddress *a = value; |
127 | GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (addresses, | 128 | |
128 | key, a)); | 129 | GNUNET_break (GNUNET_OK == |
130 | GNUNET_CONTAINER_multipeermap_remove (addresses, | ||
131 | key, | ||
132 | a)); | ||
129 | GNUNET_HELLO_address_free (a->address); | 133 | GNUNET_HELLO_address_free (a->address); |
130 | GNUNET_free (a); | 134 | GNUNET_free (a); |
131 | return GNUNET_OK; | 135 | return GNUNET_OK; |
132 | } | 136 | } |
133 | 137 | ||
138 | |||
134 | static void | 139 | static void |
135 | end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 140 | end (void *cls, |
141 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
136 | { | 142 | { |
137 | struct PendingResolutions * pr; | 143 | struct PendingResolutions * pr; |
138 | struct PendingResolutions * next; | 144 | struct PendingResolutions * next; |
@@ -172,8 +178,11 @@ end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
172 | ret = 0; | 178 | ret = 0; |
173 | } | 179 | } |
174 | 180 | ||
181 | |||
175 | static void | 182 | static void |
176 | transport_addr_to_str_cb(void *cls, const char *address, int res) | 183 | transport_addr_to_str_cb (void *cls, |
184 | const char *address, | ||
185 | int res) | ||
177 | { | 186 | { |
178 | struct PendingResolutions * pr = cls; | 187 | struct PendingResolutions * pr = cls; |
179 | char *ats_str; | 188 | char *ats_str; |
@@ -187,10 +196,11 @@ transport_addr_to_str_cb(void *cls, const char *address, int res) | |||
187 | 196 | ||
188 | if (res == GNUNET_SYSERR) | 197 | if (res == GNUNET_SYSERR) |
189 | { | 198 | { |
190 | fprintf (stderr, "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", | 199 | fprintf (stderr, |
191 | GNUNET_i2s (&pr->address->peer), | 200 | "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", |
192 | pr->address->transport_name, | 201 | GNUNET_i2s (&pr->address->peer), |
193 | pr->address->address_length ); | 202 | pr->address->transport_name, |
203 | pr->address->address_length ); | ||
194 | return; | 204 | return; |
195 | } | 205 | } |
196 | 206 | ||
@@ -224,8 +234,11 @@ transport_addr_to_str_cb(void *cls, const char *address, int res) | |||
224 | 234 | ||
225 | if (ats_type > GNUNET_ATS_PropertyCount) | 235 | if (ats_type > GNUNET_ATS_PropertyCount) |
226 | { | 236 | { |
227 | fprintf (stderr, "Invalid ATS property type %u %u for address %s\n", ats_type, pr->ats[c].type, | 237 | fprintf (stderr, |
228 | address); | 238 | "Invalid ATS property type %u %u for address %s\n", |
239 | ats_type, | ||
240 | pr->ats[c].type, | ||
241 | address); | ||
229 | continue; | 242 | continue; |
230 | } | 243 | } |
231 | 244 | ||
@@ -238,8 +251,9 @@ transport_addr_to_str_cb(void *cls, const char *address, int res) | |||
238 | continue; | 251 | continue; |
239 | } | 252 | } |
240 | network = ats_value; | 253 | network = ats_value; |
241 | GNUNET_asprintf (&ats_prop_value, "%s", | 254 | GNUNET_asprintf (&ats_prop_value, |
242 | GNUNET_ATS_print_network_type (ats_value)); | 255 | "%s", |
256 | GNUNET_ATS_print_network_type (ats_value)); | ||
243 | break; | 257 | break; |
244 | default: | 258 | default: |
245 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); | 259 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); |
@@ -247,19 +261,25 @@ transport_addr_to_str_cb(void *cls, const char *address, int res) | |||
247 | } | 261 | } |
248 | if ((verbose) && (ats_type < GNUNET_ATS_PropertyCount)) | 262 | if ((verbose) && (ats_type < GNUNET_ATS_PropertyCount)) |
249 | { | 263 | { |
250 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type], | 264 | GNUNET_asprintf (&ats_str, |
251 | ats_prop_value); | 265 | "%s%s=%s, ", |
266 | ats_tmp, | ||
267 | ats_prop_arr[ats_type], | ||
268 | ats_prop_value); | ||
252 | GNUNET_free(ats_tmp); | 269 | GNUNET_free(ats_tmp); |
253 | } | 270 | } |
254 | GNUNET_free(ats_prop_value); | 271 | GNUNET_free(ats_prop_value); |
255 | } | 272 | } |
256 | 273 | ||
257 | fprintf (stderr, | 274 | fprintf (stderr, |
258 | _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), | 275 | _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), |
259 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, | 276 | GNUNET_i2s (&pr->address->peer), |
260 | GNUNET_ATS_print_network_type (network), | 277 | pr->address->transport_name, |
261 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__), | 278 | address, |
262 | ats_str); | 279 | GNUNET_ATS_print_network_type (network), |
280 | ntohl (pr->bandwidth_out.value__), | ||
281 | ntohl (pr->bandwidth_in.value__), | ||
282 | ats_str); | ||
263 | GNUNET_free(ats_str); | 283 | GNUNET_free(ats_str); |
264 | } | 284 | } |
265 | 285 | ||
@@ -270,10 +290,11 @@ struct AddressFindCtx | |||
270 | struct ATSAddress *res; | 290 | struct ATSAddress *res; |
271 | }; | 291 | }; |
272 | 292 | ||
293 | |||
273 | static int | 294 | static int |
274 | find_address_it (void *cls, | 295 | find_address_it (void *cls, |
275 | const struct GNUNET_PeerIdentity *key, | 296 | const struct GNUNET_PeerIdentity *key, |
276 | void *value) | 297 | void *value) |
277 | { | 298 | { |
278 | struct AddressFindCtx *actx = cls; | 299 | struct AddressFindCtx *actx = cls; |
279 | struct ATSAddress *exist = value; | 300 | struct ATSAddress *exist = value; |
@@ -287,11 +308,15 @@ find_address_it (void *cls, | |||
287 | return GNUNET_YES; | 308 | return GNUNET_YES; |
288 | } | 309 | } |
289 | 310 | ||
311 | |||
290 | static void | 312 | static void |
291 | ats_perf_mon_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | 313 | ats_perf_mon_cb(void *cls, |
292 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 314 | const struct GNUNET_HELLO_Address *address, |
293 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 315 | int active, |
294 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | 316 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
317 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
318 | const struct GNUNET_ATS_Information *ats, | ||
319 | uint32_t ats_count) | ||
295 | { | 320 | { |
296 | struct PendingResolutions *pr; | 321 | struct PendingResolutions *pr; |
297 | struct PendingResolutions *cur; | 322 | struct PendingResolutions *cur; |
@@ -364,10 +389,13 @@ ats_perf_mon_cb(void *cls, const struct GNUNET_HELLO_Address *address, int activ | |||
364 | 389 | ||
365 | 390 | ||
366 | static void | 391 | static void |
367 | ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | 392 | ats_perf_cb(void *cls, |
368 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 393 | const struct GNUNET_HELLO_Address *address, |
369 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 394 | int active, |
370 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | 395 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
396 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
397 | const struct GNUNET_ATS_Information *ats, | ||
398 | uint32_t ats_count) | ||
371 | { | 399 | { |
372 | struct PendingResolutions * pr; | 400 | struct PendingResolutions * pr; |
373 | 401 | ||
@@ -405,6 +433,7 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | |||
405 | pending++; | 433 | pending++; |
406 | } | 434 | } |
407 | 435 | ||
436 | |||
408 | static unsigned int | 437 | static unsigned int |
409 | print_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg) | 438 | print_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg) |
410 | { | 439 | { |
@@ -472,6 +501,7 @@ print_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
472 | return GNUNET_ATS_NetworkTypeCount; | 501 | return GNUNET_ATS_NetworkTypeCount; |
473 | } | 502 | } |
474 | 503 | ||
504 | |||
475 | static void | 505 | static void |
476 | testservice_ats(void *cls, int result) | 506 | testservice_ats(void *cls, int result) |
477 | { | 507 | { |
@@ -496,7 +526,9 @@ testservice_ats(void *cls, int result) | |||
496 | != GNUNET_CRYPTO_eddsa_public_key_from_string (pid_str, | 526 | != GNUNET_CRYPTO_eddsa_public_key_from_string (pid_str, |
497 | strlen (pid_str), &pid.public_key)) | 527 | strlen (pid_str), &pid.public_key)) |
498 | { | 528 | { |
499 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str); | 529 | FPRINTF (stderr, |
530 | _("Failed to parse peer identity `%s'\n"), | ||
531 | pid_str); | ||
500 | return; | 532 | return; |
501 | } | 533 | } |
502 | } | 534 | } |
@@ -521,7 +553,8 @@ testservice_ats(void *cls, int result) | |||
521 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); | 553 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); |
522 | if (NULL == ph) | 554 | if (NULL == ph) |
523 | { | 555 | { |
524 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); | 556 | fprintf (stderr, |
557 | _("Cannot connect to ATS service, exiting...\n") ); | ||
525 | return; | 558 | return; |
526 | } | 559 | } |
527 | 560 | ||
@@ -529,49 +562,58 @@ testservice_ats(void *cls, int result) | |||
529 | (NULL == pid_str) ? NULL : &pid, GNUNET_YES, ats_perf_cb, NULL ); | 562 | (NULL == pid_str) ? NULL : &pid, GNUNET_YES, ats_perf_cb, NULL ); |
530 | if (NULL == alh) | 563 | if (NULL == alh) |
531 | { | 564 | { |
532 | fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n") ); | 565 | fprintf (stderr, |
566 | _("Cannot issue request to ATS service, exiting...\n") ); | ||
533 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL ); | 567 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL ); |
534 | return; | 568 | return; |
535 | } | 569 | } |
536 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, | 570 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
537 | NULL ); | 571 | &end, |
572 | NULL); | ||
538 | } | 573 | } |
539 | else if (op_list_used) | 574 | else if (op_list_used) |
540 | { | 575 | { |
541 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); | 576 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); |
542 | if (NULL == ph) | 577 | if (NULL == ph) |
543 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); | 578 | fprintf (stderr, |
579 | _("Cannot connect to ATS service, exiting...\n") ); | ||
544 | 580 | ||
545 | alh = GNUNET_ATS_performance_list_addresses (ph, | 581 | alh = GNUNET_ATS_performance_list_addresses (ph, |
546 | (NULL == pid_str) ? NULL : &pid, GNUNET_NO, ats_perf_cb, NULL ); | 582 | (NULL == pid_str) ? NULL : &pid, GNUNET_NO, ats_perf_cb, NULL ); |
547 | if (NULL == alh) | 583 | if (NULL == alh) |
548 | { | 584 | { |
549 | fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n") ); | 585 | fprintf (stderr, |
586 | _("Cannot issue request to ATS service, exiting...\n") ); | ||
550 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL ); | 587 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL ); |
551 | return; | 588 | return; |
552 | } | 589 | } |
553 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, | 590 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
554 | NULL ); | 591 | &end, |
592 | NULL); | ||
555 | } | 593 | } |
556 | else if (op_monitor) | 594 | else if (op_monitor) |
557 | { | 595 | { |
558 | ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL ); | 596 | ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL ); |
559 | if (NULL == ph) | 597 | if (NULL == ph) |
560 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); | 598 | fprintf (stderr, |
561 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, | 599 | _("Cannot connect to ATS service, exiting...\n") ); |
562 | NULL ); | 600 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
601 | &end, | ||
602 | NULL); | ||
563 | 603 | ||
564 | } | 604 | } |
565 | else if (op_set_pref) | 605 | else if (op_set_pref) |
566 | { | 606 | { |
567 | if (NULL == type_str) | 607 | if (NULL == type_str) |
568 | { | 608 | { |
569 | fprintf (stderr, _("No preference type given!\n") ); | 609 | fprintf (stderr, |
610 | _("No preference type given!\n") ); | ||
570 | return; | 611 | return; |
571 | } | 612 | } |
572 | if (NULL == pid_str) | 613 | if (NULL == pid_str) |
573 | { | 614 | { |
574 | fprintf (stderr, _("No peer given!\n") ); | 615 | fprintf (stderr, |
616 | _("No peer given!\n") ); | ||
575 | return; | 617 | return; |
576 | } | 618 | } |
577 | 619 | ||
@@ -594,17 +636,20 @@ testservice_ats(void *cls, int result) | |||
594 | /* set */ | 636 | /* set */ |
595 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); | 637 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); |
596 | if (NULL == ph) | 638 | if (NULL == ph) |
597 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); | 639 | fprintf (stderr, |
640 | _("Cannot connect to ATS service, exiting...\n") ); | ||
598 | 641 | ||
599 | GNUNET_ATS_performance_change_preference (ph, &pid, type, (double) value, | 642 | GNUNET_ATS_performance_change_preference (ph, &pid, type, (double) value, |
600 | GNUNET_ATS_PREFERENCE_END); | 643 | GNUNET_ATS_PREFERENCE_END); |
601 | 644 | ||
602 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, | 645 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
603 | NULL ); | 646 | &end, |
647 | NULL); | ||
604 | } | 648 | } |
605 | ret = 1; | 649 | ret = 1; |
606 | } | 650 | } |
607 | 651 | ||
652 | |||
608 | /** | 653 | /** |
609 | * Main function that will be run by the scheduler. | 654 | * Main function that will be run by the scheduler. |
610 | * | 655 | * |
@@ -614,14 +659,18 @@ testservice_ats(void *cls, int result) | |||
614 | * @param my_cfg configuration | 659 | * @param my_cfg configuration |
615 | */ | 660 | */ |
616 | static void | 661 | static void |
617 | run(void *cls, char * const *args, const char *cfgfile, | 662 | run (void *cls, |
618 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) | 663 | char * const *args, |
664 | const char *cfgfile, | ||
665 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) | ||
619 | { | 666 | { |
620 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; | 667 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; |
621 | GNUNET_CLIENT_service_test ("ats", cfg, TIMEOUT, &testservice_ats, | 668 | GNUNET_CLIENT_service_test ("ats", cfg, TIMEOUT, |
622 | (void *) cfg); | 669 | &testservice_ats, |
670 | (void *) cfg); | ||
623 | } | 671 | } |
624 | 672 | ||
673 | |||
625 | /** | 674 | /** |
626 | * The main function. | 675 | * The main function. |
627 | * | 676 | * |
@@ -633,6 +682,7 @@ int | |||
633 | main(int argc, char * const *argv) | 682 | main(int argc, char * const *argv) |
634 | { | 683 | { |
635 | int res; | 684 | int res; |
685 | |||
636 | resolve_addresses_numeric = GNUNET_NO; | 686 | resolve_addresses_numeric = GNUNET_NO; |
637 | op_monitor = GNUNET_NO; | 687 | op_monitor = GNUNET_NO; |
638 | op_list_all = GNUNET_NO; | 688 | op_list_all = GNUNET_NO; |
@@ -673,7 +723,9 @@ main(int argc, char * const *argv) | |||
673 | return 2; | 723 | return 2; |
674 | 724 | ||
675 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", | 725 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", |
676 | gettext_noop ("Print information about ATS state"), options, &run, NULL ); | 726 | gettext_noop ("Print information about ATS state"), |
727 | options, | ||
728 | &run, NULL); | ||
677 | GNUNET_free_non_null(pid_str); | 729 | GNUNET_free_non_null(pid_str); |
678 | GNUNET_free_non_null(type_str); | 730 | GNUNET_free_non_null(type_str); |
679 | GNUNET_free((void * ) argv); | 731 | GNUNET_free((void * ) argv); |