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.c943
1 files changed, 471 insertions, 472 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c
index 519f77af8..1628610cc 100644
--- a/src/ats-tool/gnunet-ats.c
+++ b/src/ats-tool/gnunet-ats.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009--2015 GNUnet e.V. 3 Copyright (C) 2009--2015 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -81,7 +81,7 @@ static char *opt_pid_str;
81static char *opt_type_str; 81static char *opt_type_str;
82 82
83/** 83/**
84 * CLI Option: preference value to set 84 * CLI Option: preference value to set
85 */ 85 */
86static unsigned int opt_pref_value; 86static unsigned int opt_pref_value;
87 87
@@ -151,8 +151,7 @@ static struct GNUNET_CONTAINER_MultiPeerMap *addresses;
151 * We keep address information in here while we talk to transport 151 * We keep address information in here while we talk to transport
152 * to map the address to a string. 152 * to map the address to a string.
153 */ 153 */
154struct PendingResolutions 154struct PendingResolutions {
155{
156 /** 155 /**
157 * Kept in a DLL. 156 * Kept in a DLL.
158 */ 157 */
@@ -200,8 +199,7 @@ struct PendingResolutions
200 * Information we keep for an address. Used to avoid 199 * Information we keep for an address. Used to avoid
201 * printing the same data multiple times. 200 * printing the same data multiple times.
202 */ 201 */
203struct ATSAddress 202struct ATSAddress {
204{
205 /** 203 /**
206 * Address information. 204 * Address information.
207 */ 205 */
@@ -244,14 +242,14 @@ static struct PendingResolutions *tail;
244 * @return #GNUNET_YES (always) 242 * @return #GNUNET_YES (always)
245 */ 243 */
246static int 244static int
247free_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 245free_addr_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
248{ 246{
249 struct ATSAddress *a = value; 247 struct ATSAddress *a = value;
250 248
251 GNUNET_assert (GNUNET_OK == 249 GNUNET_assert(GNUNET_OK ==
252 GNUNET_CONTAINER_multipeermap_remove (addresses, key, value)); 250 GNUNET_CONTAINER_multipeermap_remove(addresses, key, value));
253 GNUNET_HELLO_address_free (a->address); 251 GNUNET_HELLO_address_free(a->address);
254 GNUNET_free (a); 252 GNUNET_free(a);
255 return GNUNET_OK; 253 return GNUNET_OK;
256} 254}
257 255
@@ -262,56 +260,56 @@ free_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
262 * @param cls NULL 260 * @param cls NULL
263 */ 261 */
264static void 262static void
265end (void *cls) 263end(void *cls)
266{ 264{
267 struct PendingResolutions *pr; 265 struct PendingResolutions *pr;
268 struct PendingResolutions *next; 266 struct PendingResolutions *next;
269 unsigned int pending; 267 unsigned int pending;
270 268
271 if (NULL != alh) 269 if (NULL != alh)
272 { 270 {
273 GNUNET_ATS_performance_list_addresses_cancel (alh); 271 GNUNET_ATS_performance_list_addresses_cancel(alh);
274 alh = NULL; 272 alh = NULL;
275 } 273 }
276 274
277 if (NULL != ph) 275 if (NULL != ph)
278 { 276 {
279 GNUNET_ATS_performance_done (ph); 277 GNUNET_ATS_performance_done(ph);
280 ph = NULL; 278 ph = NULL;
281 } 279 }
282 280
283 pending = 0; 281 pending = 0;
284 next = head; 282 next = head;
285 while (NULL != (pr = next)) 283 while (NULL != (pr = next))
286 { 284 {
287 next = pr->next; 285 next = pr->next;
288 GNUNET_CONTAINER_DLL_remove (head, tail, pr); 286 GNUNET_CONTAINER_DLL_remove(head, tail, pr);
289 GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); 287 GNUNET_TRANSPORT_address_to_string_cancel(pr->tats_ctx);
290 GNUNET_free (pr->address); 288 GNUNET_free(pr->address);
291 GNUNET_free (pr); 289 GNUNET_free(pr);
292 pending++; 290 pending++;
293 } 291 }
294 GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL); 292 GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL);
295 GNUNET_CONTAINER_multipeermap_destroy (addresses); 293 GNUNET_CONTAINER_multipeermap_destroy(addresses);
296 addresses = NULL; 294 addresses = NULL;
297 295
298 if (0 < pending) 296 if (0 < pending)
299 fprintf (stdout, _ ("%u address resolutions had a timeout\n"), pending); 297 fprintf(stdout, _("%u address resolutions had a timeout\n"), pending);
300 if (opt_list_used || opt_list_all) 298 if (opt_list_used || opt_list_all)
301 fprintf (stdout, 299 fprintf(stdout,
302 _ ("ATS returned stat_results for %u addresses\n"), 300 _("ATS returned stat_results for %u addresses\n"),
303 stat_results); 301 stat_results);
304 302
305 if (NULL != ats_sh) 303 if (NULL != ats_sh)
306 { 304 {
307 GNUNET_ATS_connectivity_suggest_cancel (ats_sh); 305 GNUNET_ATS_connectivity_suggest_cancel(ats_sh);
308 ats_sh = NULL; 306 ats_sh = NULL;
309 } 307 }
310 if (NULL != ats_ch) 308 if (NULL != ats_ch)
311 { 309 {
312 GNUNET_ATS_connectivity_done (ats_ch); 310 GNUNET_ATS_connectivity_done(ats_ch);
313 ats_ch = NULL; 311 ats_ch = NULL;
314 } 312 }
315 ret = 0; 313 ret = 0;
316} 314}
317 315
@@ -333,72 +331,74 @@ end (void *cls)
333 * if #GNUNET_SYSERR: communication error (IPC error) 331 * if #GNUNET_SYSERR: communication error (IPC error)
334 */ 332 */
335static void 333static void
336transport_addr_to_str_cb (void *cls, const char *address, int res) 334transport_addr_to_str_cb(void *cls, const char *address, int res)
337{ 335{
338 struct PendingResolutions *pr = cls; 336 struct PendingResolutions *pr = cls;
339 337
340 if (NULL == address) 338 if (NULL == address)
341 {
342 /* We're done */
343 GNUNET_CONTAINER_DLL_remove (head, tail, pr);
344 GNUNET_free (pr->address);
345 GNUNET_free (pr);
346 stat_pending--;
347
348 if ((GNUNET_YES == stat_receive_done) && (0 == stat_pending))
349 { 339 {
350 /* All messages received and no resolutions pending*/ 340 /* We're done */
351 if (shutdown_task != NULL) 341 GNUNET_CONTAINER_DLL_remove(head, tail, pr);
352 GNUNET_SCHEDULER_cancel (shutdown_task); 342 GNUNET_free(pr->address);
353 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 343 GNUNET_free(pr);
344 stat_pending--;
345
346 if ((GNUNET_YES == stat_receive_done) && (0 == stat_pending))
347 {
348 /* All messages received and no resolutions pending*/
349 if (shutdown_task != NULL)
350 GNUNET_SCHEDULER_cancel(shutdown_task);
351 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
352 }
353 return;
354 } 354 }
355 return;
356 }
357 switch (res) 355 switch (res)
358 { 356 {
359 case GNUNET_SYSERR: 357 case GNUNET_SYSERR:
360 fprintf ( 358 fprintf(
361 stderr, 359 stderr,
362 "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n", 360 "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n",
363 GNUNET_i2s (&pr->address->peer), 361 GNUNET_i2s(&pr->address->peer),
364 pr->address->transport_name, 362 pr->address->transport_name,
365 (unsigned int) pr->address->address_length); 363 (unsigned int)pr->address->address_length);
366 return; 364 return;
367 case GNUNET_NO: 365
368 fprintf ( 366 case GNUNET_NO:
369 stderr, 367 fprintf(
370 "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n", 368 stderr,
371 GNUNET_i2s (&pr->address->peer), 369 "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n",
372 pr->address->transport_name, 370 GNUNET_i2s(&pr->address->peer),
373 (unsigned int) pr->address->address_length); 371 pr->address->transport_name,
374 return; 372 (unsigned int)pr->address->address_length);
375 case GNUNET_OK: 373 return;
376 /* continues below */ 374
377 break; 375 case GNUNET_OK:
378 default: 376 /* continues below */
379 GNUNET_break (0); 377 break;
380 return; 378
381 } 379 default:
382 380 GNUNET_break(0);
383 fprintf ( 381 return;
382 }
383
384 fprintf(
384 stdout, 385 stdout,
385 _ ( 386 _(
386 "Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), 387 "Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
387 GNUNET_i2s (&pr->address->peer), 388 GNUNET_i2s(&pr->address->peer),
388 pr->address->transport_name, 389 pr->address->transport_name,
389 address, 390 address,
390 GNUNET_NT_to_string (pr->properties.scope), 391 GNUNET_NT_to_string(pr->properties.scope),
391 ntohl (pr->bandwidth_out.value__), 392 ntohl(pr->bandwidth_out.value__),
392 ntohl (pr->bandwidth_in.value__), 393 ntohl(pr->bandwidth_in.value__),
393 pr->active ? _ ("active ") : _ ("inactive ")); 394 pr->active ? _("active ") : _("inactive "));
394} 395}
395 396
396 397
397/** 398/**
398 * Closure for #find_address_it(). 399 * Closure for #find_address_it().
399 */ 400 */
400struct AddressFindCtx 401struct AddressFindCtx {
401{
402 /** 402 /**
403 * Address we are looking for. 403 * Address we are looking for.
404 */ 404 */
@@ -420,16 +420,16 @@ struct AddressFindCtx
420 * @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
421 */ 421 */
422static int 422static int
423find_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 423find_address_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
424{ 424{
425 struct AddressFindCtx *actx = cls; 425 struct AddressFindCtx *actx = cls;
426 struct ATSAddress *exist = value; 426 struct ATSAddress *exist = value;
427 427
428 if (0 == GNUNET_HELLO_address_cmp (actx->src, exist->address)) 428 if (0 == GNUNET_HELLO_address_cmp(actx->src, exist->address))
429 { 429 {
430 actx->res = exist; 430 actx->res = exist;
431 return GNUNET_NO; 431 return GNUNET_NO;
432 } 432 }
433 return GNUNET_YES; 433 return GNUNET_YES;
434} 434}
435 435
@@ -448,115 +448,115 @@ find_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
448 * @param prop performance data for the address (as far as known) 448 * @param prop performance data for the address (as far as known)
449 */ 449 */
450static void 450static void
451ats_perf_mon_cb (void *cls, 451ats_perf_mon_cb(void *cls,
452 const struct GNUNET_HELLO_Address *address, 452 const struct GNUNET_HELLO_Address *address,
453 int active, 453 int active,
454 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 454 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
455 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 455 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
456 const struct GNUNET_ATS_Properties *prop) 456 const struct GNUNET_ATS_Properties *prop)
457{ 457{
458 struct PendingResolutions *pr; 458 struct PendingResolutions *pr;
459 struct PendingResolutions *cur; 459 struct PendingResolutions *cur;
460 struct PendingResolutions *next; 460 struct PendingResolutions *next;
461 461
462 if (NULL == address) 462 if (NULL == address)
463 {
464 /* ATS service temporarily disconnected, remove current state */
465 next = head;
466 for (cur = next; NULL != cur; cur = next)
467 { 463 {
468 next = cur->next; 464 /* ATS service temporarily disconnected, remove current state */
469 GNUNET_CONTAINER_DLL_remove (head, tail, cur); 465 next = head;
470 GNUNET_TRANSPORT_address_to_string_cancel (cur->tats_ctx); 466 for (cur = next; NULL != cur; cur = next)
471 GNUNET_HELLO_address_free (cur->address); 467 {
472 GNUNET_free (cur); 468 next = cur->next;
469 GNUNET_CONTAINER_DLL_remove(head, tail, cur);
470 GNUNET_TRANSPORT_address_to_string_cancel(cur->tats_ctx);
471 GNUNET_HELLO_address_free(cur->address);
472 GNUNET_free(cur);
473 }
474 GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL);
475 return;
473 } 476 }
474 GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL);
475 return;
476 }
477 if (GNUNET_SYSERR == active) 477 if (GNUNET_SYSERR == active)
478 {
479 /* remove address */
480 struct AddressFindCtx actx;
481
482 actx.src = address;
483 actx.res = NULL;
484 GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
485 &address->peer,
486 &find_address_it,
487 &actx);
488 if (NULL == actx.res)
489 { 478 {
490 GNUNET_break (0); 479 /* remove address */
491 return; 480 struct AddressFindCtx actx;
492 } 481
493 GNUNET_break (GNUNET_OK == 482 actx.src = address;
494 GNUNET_CONTAINER_multipeermap_remove (addresses, 483 actx.res = NULL;
484 GNUNET_CONTAINER_multipeermap_get_multiple(addresses,
485 &address->peer,
486 &find_address_it,
487 &actx);
488 if (NULL == actx.res)
489 {
490 GNUNET_break(0);
491 return;
492 }
493 GNUNET_break(GNUNET_OK ==
494 GNUNET_CONTAINER_multipeermap_remove(addresses,
495 &address->peer, 495 &address->peer,
496 actx.res)); 496 actx.res));
497 fprintf (stdout, 497 fprintf(stdout,
498 _ ("Removed address of peer `%s' with plugin `%s'\n"), 498 _("Removed address of peer `%s' with plugin `%s'\n"),
499 GNUNET_i2s (&address->peer), 499 GNUNET_i2s(&address->peer),
500 actx.res->address->transport_name); 500 actx.res->address->transport_name);
501 GNUNET_HELLO_address_free (actx.res); 501 GNUNET_HELLO_address_free(actx.res);
502 return; 502 return;
503 } 503 }
504 504
505 if (GNUNET_NO == opt_verbose) 505 if (GNUNET_NO == opt_verbose)
506 {
507 struct AddressFindCtx actx;
508 struct ATSAddress *a;
509
510 actx.src = address;
511 actx.res = NULL;
512 GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
513 &address->peer,
514 &find_address_it,
515 &actx);
516 if ((NULL != actx.res))
517 { 506 {
518 if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) && 507 struct AddressFindCtx actx;
519 (bandwidth_out.value__ == actx.res->bandwidth_out.value__) && 508 struct ATSAddress *a;
520 (active == actx.res->active)) 509
521 { 510 actx.src = address;
522 return; /* Nothing to do here */ 511 actx.res = NULL;
523 } 512 GNUNET_CONTAINER_multipeermap_get_multiple(addresses,
513 &address->peer,
514 &find_address_it,
515 &actx);
516 if ((NULL != actx.res))
517 {
518 if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) &&
519 (bandwidth_out.value__ == actx.res->bandwidth_out.value__) &&
520 (active == actx.res->active))
521 {
522 return; /* Nothing to do here */
523 }
524 else
525 {
526 actx.res->bandwidth_in = bandwidth_in;
527 actx.res->bandwidth_out = bandwidth_out;
528 }
529 }
524 else 530 else
525 { 531 {
526 actx.res->bandwidth_in = bandwidth_in; 532 a = GNUNET_new(struct ATSAddress);
527 actx.res->bandwidth_out = bandwidth_out; 533
528 } 534 a->address = GNUNET_HELLO_address_copy(address);
529 } 535 a->bandwidth_in = bandwidth_in;
530 else 536 a->bandwidth_out = bandwidth_out;
531 { 537 a->active = active;
532 a = GNUNET_new (struct ATSAddress); 538 GNUNET_CONTAINER_multipeermap_put(
533 539 addresses,
534 a->address = GNUNET_HELLO_address_copy (address); 540 &address->peer,
535 a->bandwidth_in = bandwidth_in; 541 a,
536 a->bandwidth_out = bandwidth_out; 542 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
537 a->active = active; 543 }
538 GNUNET_CONTAINER_multipeermap_put (
539 addresses,
540 &address->peer,
541 a,
542 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
543 } 544 }
544 }
545 545
546 pr = GNUNET_new (struct PendingResolutions); 546 pr = GNUNET_new(struct PendingResolutions);
547 pr->properties = *prop; 547 pr->properties = *prop;
548 pr->address = GNUNET_HELLO_address_copy (address); 548 pr->address = GNUNET_HELLO_address_copy(address);
549 pr->bandwidth_in = bandwidth_in; 549 pr->bandwidth_in = bandwidth_in;
550 pr->bandwidth_out = bandwidth_out; 550 pr->bandwidth_out = bandwidth_out;
551 pr->active = active; 551 pr->active = active;
552 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string ( 552 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string(
553 cfg, 553 cfg,
554 address, 554 address,
555 opt_resolve_addresses_numeric, 555 opt_resolve_addresses_numeric,
556 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 556 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
557 &transport_addr_to_str_cb, 557 &transport_addr_to_str_cb,
558 pr); 558 pr);
559 GNUNET_CONTAINER_DLL_insert (head, tail, pr); 559 GNUNET_CONTAINER_DLL_insert(head, tail, pr);
560 stat_results++; 560 stat_results++;
561 stat_pending++; 561 stat_pending++;
562} 562}
@@ -574,44 +574,44 @@ ats_perf_mon_cb (void *cls,
574 * @param prop performance data for the address (as far as known) 574 * @param prop performance data for the address (as far as known)
575 */ 575 */
576static void 576static void
577ats_perf_cb (void *cls, 577ats_perf_cb(void *cls,
578 const struct GNUNET_HELLO_Address *address, 578 const struct GNUNET_HELLO_Address *address,
579 int active, 579 int active,
580 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 580 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
581 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 581 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
582 const struct GNUNET_ATS_Properties *prop) 582 const struct GNUNET_ATS_Properties *prop)
583{ 583{
584 struct PendingResolutions *pr; 584 struct PendingResolutions *pr;
585 585
586 if (NULL == address) 586 if (NULL == address)
587 {
588 /* All messages received */
589 stat_receive_done = GNUNET_YES;
590 alh = NULL;
591 if (0 == stat_pending)
592 { 587 {
593 /* All messages received and no resolutions pending*/ 588 /* All messages received */
594 if (shutdown_task != NULL) 589 stat_receive_done = GNUNET_YES;
595 GNUNET_SCHEDULER_cancel (shutdown_task); 590 alh = NULL;
596 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 591 if (0 == stat_pending)
592 {
593 /* All messages received and no resolutions pending*/
594 if (shutdown_task != NULL)
595 GNUNET_SCHEDULER_cancel(shutdown_task);
596 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
597 }
598 return;
597 } 599 }
598 return;
599 }
600 600
601 pr = GNUNET_new (struct PendingResolutions); 601 pr = GNUNET_new(struct PendingResolutions);
602 pr->properties = *prop; 602 pr->properties = *prop;
603 pr->address = GNUNET_HELLO_address_copy (address); 603 pr->address = GNUNET_HELLO_address_copy(address);
604 pr->bandwidth_in = bandwidth_in; 604 pr->bandwidth_in = bandwidth_in;
605 pr->bandwidth_out = bandwidth_out; 605 pr->bandwidth_out = bandwidth_out;
606 pr->active = active; 606 pr->active = active;
607 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string ( 607 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string(
608 cfg, 608 cfg,
609 address, 609 address,
610 opt_resolve_addresses_numeric, 610 opt_resolve_addresses_numeric,
611 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 611 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
612 &transport_addr_to_str_cb, 612 &transport_addr_to_str_cb,
613 pr); 613 pr);
614 GNUNET_CONTAINER_DLL_insert (head, tail, pr); 614 GNUNET_CONTAINER_DLL_insert(head, tail, pr);
615 stat_results++; 615 stat_results++;
616 stat_pending++; 616 stat_pending++;
617} 617}
@@ -625,7 +625,7 @@ ats_perf_cb (void *cls,
625 * @return total number of ATS network types known 625 * @return total number of ATS network types known
626 */ 626 */
627static unsigned int 627static unsigned int
628print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) 628print_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg)
629{ 629{
630 char *entry_in = NULL; 630 char *entry_in = NULL;
631 char *entry_out = NULL; 631 char *entry_out = NULL;
@@ -636,64 +636,63 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
636 int c; 636 int c;
637 637
638 for (c = 0; (c < GNUNET_NT_COUNT); c++) 638 for (c = 0; (c < GNUNET_NT_COUNT); c++)
639 {
640
641 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", GNUNET_NT_to_string (c));
642 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", GNUNET_NT_to_string (c));
643
644 /* quota out */
645 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
646 "ats",
647 entry_out,
648 &quota_out_str))
649 {
650 if (0 == strcmp (quota_out_str, UNLIMITED_STRING) ||
651 (GNUNET_SYSERR ==
652 GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &quota_out)))
653 quota_out = UINT32_MAX;
654
655 GNUNET_free (quota_out_str);
656 GNUNET_asprintf (&quota_out_str, "%llu", quota_out);
657 }
658 else
659 {
660 fprintf (stderr,
661 "Outbound quota for network `%11s' not configured!\n",
662 GNUNET_NT_to_string (c));
663 GNUNET_asprintf (&quota_out_str, "-");
664 }
665 GNUNET_free (entry_out);
666
667 /* quota in */
668 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
669 "ats",
670 entry_in,
671 &quota_in_str))
672 {
673 if (0 == strcmp (quota_in_str, UNLIMITED_STRING) ||
674 (GNUNET_SYSERR ==
675 GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in)))
676 quota_in = UINT32_MAX;
677 GNUNET_free (quota_in_str);
678 GNUNET_asprintf (&quota_in_str, "%llu", quota_in);
679 }
680 else
681 { 639 {
682 fprintf (stderr, 640 GNUNET_asprintf(&entry_out, "%s_QUOTA_OUT", GNUNET_NT_to_string(c));
683 "Inbound quota for network `%11s' not configured!\n", 641 GNUNET_asprintf(&entry_in, "%s_QUOTA_IN", GNUNET_NT_to_string(c));
684 GNUNET_NT_to_string (c)); 642
685 GNUNET_asprintf (&quota_in_str, "-"); 643 /* quota out */
644 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg,
645 "ats",
646 entry_out,
647 &quota_out_str))
648 {
649 if (0 == strcmp(quota_out_str, UNLIMITED_STRING) ||
650 (GNUNET_SYSERR ==
651 GNUNET_STRINGS_fancy_size_to_bytes(quota_out_str, &quota_out)))
652 quota_out = UINT32_MAX;
653
654 GNUNET_free(quota_out_str);
655 GNUNET_asprintf(&quota_out_str, "%llu", quota_out);
656 }
657 else
658 {
659 fprintf(stderr,
660 "Outbound quota for network `%11s' not configured!\n",
661 GNUNET_NT_to_string(c));
662 GNUNET_asprintf(&quota_out_str, "-");
663 }
664 GNUNET_free(entry_out);
665
666 /* quota in */
667 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg,
668 "ats",
669 entry_in,
670 &quota_in_str))
671 {
672 if (0 == strcmp(quota_in_str, UNLIMITED_STRING) ||
673 (GNUNET_SYSERR ==
674 GNUNET_STRINGS_fancy_size_to_bytes(quota_in_str, &quota_in)))
675 quota_in = UINT32_MAX;
676 GNUNET_free(quota_in_str);
677 GNUNET_asprintf(&quota_in_str, "%llu", quota_in);
678 }
679 else
680 {
681 fprintf(stderr,
682 "Inbound quota for network `%11s' not configured!\n",
683 GNUNET_NT_to_string(c));
684 GNUNET_asprintf(&quota_in_str, "-");
685 }
686 GNUNET_free(entry_in);
687
688 fprintf(stdout,
689 _("Quota for network `%11s' (in/out): %10s / %10s\n"),
690 GNUNET_NT_to_string(c),
691 quota_in_str,
692 quota_out_str);
693 GNUNET_free(quota_out_str);
694 GNUNET_free(quota_in_str);
686 } 695 }
687 GNUNET_free (entry_in);
688
689 fprintf (stdout,
690 _ ("Quota for network `%11s' (in/out): %10s / %10s\n"),
691 GNUNET_NT_to_string (c),
692 quota_in_str,
693 quota_out_str);
694 GNUNET_free (quota_out_str);
695 GNUNET_free (quota_in_str);
696 }
697 return GNUNET_NT_COUNT; 696 return GNUNET_NT_COUNT;
698} 697}
699 698
@@ -707,176 +706,176 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
707 * @param my_cfg configuration 706 * @param my_cfg configuration
708 */ 707 */
709static void 708static void
710run (void *cls, 709run(void *cls,
711 char *const *args, 710 char *const *args,
712 const char *cfgfile, 711 const char *cfgfile,
713 const struct GNUNET_CONFIGURATION_Handle *my_cfg) 712 const struct GNUNET_CONFIGURATION_Handle *my_cfg)
714{ 713{
715 struct GNUNET_PeerIdentity pid; 714 struct GNUNET_PeerIdentity pid;
716 struct GNUNET_PeerIdentity cpid; 715 struct GNUNET_PeerIdentity cpid;
717 unsigned int c; 716 unsigned int c;
718 unsigned int type; 717 unsigned int type;
719 718
720 cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; 719 cfg = (struct GNUNET_CONFIGURATION_Handle *)my_cfg;
721 addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 720 addresses = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
722 stat_results = 0; 721 stat_results = 0;
723 722
724 c = 0; 723 c = 0;
725 if (NULL != opt_pid_str) 724 if (NULL != opt_pid_str)
726 {
727 if (GNUNET_OK !=
728 GNUNET_CRYPTO_eddsa_public_key_from_string (opt_pid_str,
729 strlen (opt_pid_str),
730 &pid.public_key))
731 { 725 {
732 fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), opt_pid_str); 726 if (GNUNET_OK !=
733 return; 727 GNUNET_CRYPTO_eddsa_public_key_from_string(opt_pid_str,
728 strlen(opt_pid_str),
729 &pid.public_key))
730 {
731 fprintf(stderr, _("Failed to parse peer identity `%s'\n"), opt_pid_str);
732 return;
733 }
734 } 734 }
735 }
736 if (NULL != cpid_str) 735 if (NULL != cpid_str)
737 {
738 if (GNUNET_OK !=
739 GNUNET_CRYPTO_eddsa_public_key_from_string (cpid_str,
740 strlen (cpid_str),
741 &cpid.public_key))
742 { 736 {
743 fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), cpid_str); 737 if (GNUNET_OK !=
744 return; 738 GNUNET_CRYPTO_eddsa_public_key_from_string(cpid_str,
739 strlen(cpid_str),
740 &cpid.public_key))
741 {
742 fprintf(stderr, _("Failed to parse peer identity `%s'\n"), cpid_str);
743 return;
744 }
745 c++;
745 } 746 }
746 c++;
747 }
748 747
749 c += opt_list_all + opt_list_used + opt_monitor + opt_set_pref; 748 c += opt_list_all + opt_list_used + opt_monitor + opt_set_pref;
750 749
751 if (1 < c) 750 if (1 < c)
752 { 751 {
753 fprintf (stderr, 752 fprintf(stderr,
754 _ ("Please select one operation: %s or %s or %s or %s or %s\n"), 753 _("Please select one operation: %s or %s or %s or %s or %s\n"),
755 "--used", 754 "--used",
756 "--all", 755 "--all",
757 "--monitor", 756 "--monitor",
758 "--preference", 757 "--preference",
759 "--quotas"); 758 "--quotas");
760 return; 759 return;
761 } 760 }
762 if (0 == c) 761 if (0 == c)
763 opt_list_used = GNUNET_YES; /* set default */ 762 opt_list_used = GNUNET_YES; /* set default */
764 if (opt_print_quotas) 763 if (opt_print_quotas)
765 {
766 ret = print_quotas (cfg);
767 return;
768 }
769 if (opt_list_all)
770 {
771 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
772 if (NULL == ph)
773 { 764 {
774 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n")); 765 ret = print_quotas(cfg);
775 return; 766 return;
776 } 767 }
777 alh = GNUNET_ATS_performance_list_addresses (ph, 768 if (opt_list_all)
778 (NULL == opt_pid_str) ? NULL
779 : &pid,
780 GNUNET_YES,
781 &ats_perf_cb,
782 NULL);
783 if (NULL == alh)
784 { 769 {
785 fprintf (stderr, 770 ph = GNUNET_ATS_performance_init(cfg, NULL, NULL);
786 "%s", 771 if (NULL == ph)
787 _ ("Cannot issue request to ATS service, exiting...\n")); 772 {
788 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 773 fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
774 return;
775 }
776 alh = GNUNET_ATS_performance_list_addresses(ph,
777 (NULL == opt_pid_str) ? NULL
778 : &pid,
779 GNUNET_YES,
780 &ats_perf_cb,
781 NULL);
782 if (NULL == alh)
783 {
784 fprintf(stderr,
785 "%s",
786 _("Cannot issue request to ATS service, exiting...\n"));
787 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
788 return;
789 }
790 shutdown_task = GNUNET_SCHEDULER_add_shutdown(&end, NULL);
789 return; 791 return;
790 } 792 }
791 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
792 return;
793 }
794 if (opt_list_used) 793 if (opt_list_used)
795 {
796 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
797 if (NULL == ph)
798 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
799
800 alh = GNUNET_ATS_performance_list_addresses (ph,
801 (NULL == opt_pid_str) ? NULL
802 : &pid,
803 GNUNET_NO,
804 &ats_perf_cb,
805 NULL);
806 if (NULL == alh)
807 { 794 {
808 fprintf (stderr, 795 ph = GNUNET_ATS_performance_init(cfg, NULL, NULL);
809 "%s", 796 if (NULL == ph)
810 _ ("Cannot issue request to ATS service, exiting...\n")); 797 fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
811 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 798
799 alh = GNUNET_ATS_performance_list_addresses(ph,
800 (NULL == opt_pid_str) ? NULL
801 : &pid,
802 GNUNET_NO,
803 &ats_perf_cb,
804 NULL);
805 if (NULL == alh)
806 {
807 fprintf(stderr,
808 "%s",
809 _("Cannot issue request to ATS service, exiting...\n"));
810 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
811 return;
812 }
813 shutdown_task = GNUNET_SCHEDULER_add_shutdown(&end, NULL);
812 return; 814 return;
813 } 815 }
814 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
815 return;
816 }
817 if (opt_monitor) 816 if (opt_monitor)
818 {
819 ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL);
820 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
821 if (NULL == ph)
822 { 817 {
823 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n")); 818 ph = GNUNET_ATS_performance_init(cfg, &ats_perf_mon_cb, NULL);
824 GNUNET_SCHEDULER_shutdown (); 819 shutdown_task = GNUNET_SCHEDULER_add_shutdown(&end, NULL);
825 } 820 if (NULL == ph)
826 return; 821 {
827 } 822 fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
828 if (opt_set_pref) 823 GNUNET_SCHEDULER_shutdown();
829 { 824 }
830 if (NULL == opt_type_str)
831 {
832 fprintf (stderr, "%s", _ ("No preference type given!\n"));
833 return; 825 return;
834 } 826 }
835 if (NULL == opt_pid_str) 827 if (opt_set_pref)
836 { 828 {
837 fprintf (stderr, "%s", _ ("No peer given!\n")); 829 if (NULL == opt_type_str)
830 {
831 fprintf(stderr, "%s", _("No preference type given!\n"));
832 return;
833 }
834 if (NULL == opt_pid_str)
835 {
836 fprintf(stderr, "%s", _("No peer given!\n"));
837 return;
838 }
839
840 for (c = 0; c < strlen(opt_type_str); c++)
841 {
842 if (isupper((unsigned char)opt_type_str[c]))
843 opt_type_str[c] = tolower((unsigned char)opt_type_str[c]);
844 }
845
846 if (0 == strcasecmp("latency", opt_type_str))
847 type = GNUNET_ATS_PREFERENCE_LATENCY;
848 else if (0 == strcasecmp("bandwidth", opt_type_str))
849 type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
850 else
851 {
852 fprintf(stderr, "%s", _("Valid type required\n"));
853 return;
854 }
855
856 /* set */
857 ph = GNUNET_ATS_performance_init(cfg, NULL, NULL);
858 if (NULL == ph)
859 fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
860
861 GNUNET_ATS_performance_change_preference(ph,
862 &pid,
863 type,
864 (double)opt_pref_value,
865 GNUNET_ATS_PREFERENCE_END);
866
867 shutdown_task =
868 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &end, NULL);
838 return; 869 return;
839 } 870 }
840 871 if (NULL != cpid_str)
841 for (c = 0; c < strlen (opt_type_str); c++)
842 {
843 if (isupper ((unsigned char) opt_type_str[c]))
844 opt_type_str[c] = tolower ((unsigned char) opt_type_str[c]);
845 }
846
847 if (0 == strcasecmp ("latency", opt_type_str))
848 type = GNUNET_ATS_PREFERENCE_LATENCY;
849 else if (0 == strcasecmp ("bandwidth", opt_type_str))
850 type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
851 else
852 { 872 {
853 fprintf (stderr, "%s", _ ("Valid type required\n")); 873 ats_ch = GNUNET_ATS_connectivity_init(cfg);
874 ats_sh = GNUNET_ATS_connectivity_suggest(ats_ch, &cpid, 1000);
875 shutdown_task =
876 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &end, NULL);
854 return; 877 return;
855 } 878 }
856
857 /* set */
858 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
859 if (NULL == ph)
860 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
861
862 GNUNET_ATS_performance_change_preference (ph,
863 &pid,
864 type,
865 (double) opt_pref_value,
866 GNUNET_ATS_PREFERENCE_END);
867
868 shutdown_task =
869 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
870 return;
871 }
872 if (NULL != cpid_str)
873 {
874 ats_ch = GNUNET_ATS_connectivity_init (cfg);
875 ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch, &cpid, 1000);
876 shutdown_task =
877 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
878 return;
879 }
880 ret = 1; 879 ret = 1;
881} 880}
882 881
@@ -889,7 +888,7 @@ run (void *cls,
889 * @return 0 ok, 1 on error 888 * @return 0 ok, 1 on error
890 */ 889 */
891int 890int
892main (int argc, char *const *argv) 891main(int argc, char *const *argv)
893{ 892{
894 int res; 893 int res;
895 894
@@ -903,82 +902,82 @@ main (int argc, char *const *argv)
903 opt_type_str = NULL; 902 opt_type_str = NULL;
904 903
905 struct GNUNET_GETOPT_CommandLineOption options[] = 904 struct GNUNET_GETOPT_CommandLineOption options[] =
906 {GNUNET_GETOPT_option_flag ('u', 905 { GNUNET_GETOPT_option_flag('u',
907 "used", 906 "used",
908 gettext_noop ( 907 gettext_noop(
909 "get list of active addresses currently used"), 908 "get list of active addresses currently used"),
910 &opt_list_used), 909 &opt_list_used),
911 GNUNET_GETOPT_option_flag ('a', 910 GNUNET_GETOPT_option_flag('a',
912 "all", 911 "all",
913 gettext_noop ( 912 gettext_noop(
914 "get list of all active addresses"), 913 "get list of all active addresses"),
915 &opt_list_all), 914 &opt_list_all),
916 915
917 GNUNET_GETOPT_option_string ('C', 916 GNUNET_GETOPT_option_string('C',
918 "connect", 917 "connect",
919 NULL, 918 NULL,
920 gettext_noop ("connect to PEER"), 919 gettext_noop("connect to PEER"),
921 &cpid_str), 920 &cpid_str),
922 GNUNET_GETOPT_option_flag ('n', 921 GNUNET_GETOPT_option_flag('n',
923 "numeric", 922 "numeric",
924 gettext_noop ( 923 gettext_noop(
925 "do not resolve IP addresses to hostnames"), 924 "do not resolve IP addresses to hostnames"),
926 &opt_resolve_addresses_numeric), 925 &opt_resolve_addresses_numeric),
927 926
928 GNUNET_GETOPT_option_flag ('m', 927 GNUNET_GETOPT_option_flag('m',
929 "monitor", 928 "monitor",
930 gettext_noop ("monitor mode"), 929 gettext_noop("monitor mode"),
931 &opt_monitor), 930 &opt_monitor),
932 931
933 GNUNET_GETOPT_option_flag ('p', 932 GNUNET_GETOPT_option_flag('p',
934 "preference", 933 "preference",
935 gettext_noop ( 934 gettext_noop(
936 "set preference for the given peer"), 935 "set preference for the given peer"),
937 &opt_set_pref), 936 &opt_set_pref),
938 937
939 GNUNET_GETOPT_option_flag ('q', 938 GNUNET_GETOPT_option_flag('q',
940 "quotas", 939 "quotas",
941 gettext_noop ("print all configured quotas"), 940 gettext_noop("print all configured quotas"),
942 &opt_print_quotas), 941 &opt_print_quotas),
943 GNUNET_GETOPT_option_string ('i', 942 GNUNET_GETOPT_option_string('i',
944 "id", 943 "id",
945 "TYPE", 944 "TYPE",
946 gettext_noop ("peer id"), 945 gettext_noop("peer id"),
947 &opt_pid_str), 946 &opt_pid_str),
948 947
949 GNUNET_GETOPT_option_string ('t', 948 GNUNET_GETOPT_option_string('t',
950 "type", 949 "type",
951 "TYPE", 950 "TYPE",
952 gettext_noop ( 951 gettext_noop(
953 "preference type to set: latency | bandwidth"), 952 "preference type to set: latency | bandwidth"),
954 &opt_type_str), 953 &opt_type_str),
955 954
956 GNUNET_GETOPT_option_uint ('k', 955 GNUNET_GETOPT_option_uint('k',
957 "value", 956 "value",
958 "VALUE", 957 "VALUE",
959 gettext_noop ("preference value"), 958 gettext_noop("preference value"),
960 &opt_pref_value), 959 &opt_pref_value),
961 960
962 GNUNET_GETOPT_option_flag ( 961 GNUNET_GETOPT_option_flag(
963 'V', 962 'V',
964 "verbose", 963 "verbose",
965 gettext_noop ("verbose output (include ATS address properties)"), 964 gettext_noop("verbose output (include ATS address properties)"),
966 &opt_verbose), 965 &opt_verbose),
967 GNUNET_GETOPT_OPTION_END}; 966 GNUNET_GETOPT_OPTION_END };
968 967
969 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 968 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
970 return 2; 969 return 2;
971 970
972 res = GNUNET_PROGRAM_run (argc, 971 res = GNUNET_PROGRAM_run(argc,
973 argv, 972 argv,
974 "gnunet-ats", 973 "gnunet-ats",
975 gettext_noop ("Print information about ATS state"), 974 gettext_noop("Print information about ATS state"),
976 options, 975 options,
977 &run, 976 &run,
978 NULL); 977 NULL);
979 GNUNET_free_non_null (opt_pid_str); 978 GNUNET_free_non_null(opt_pid_str);
980 GNUNET_free_non_null (opt_type_str); 979 GNUNET_free_non_null(opt_type_str);
981 GNUNET_free ((void *) argv); 980 GNUNET_free((void *)argv);
982 981
983 if (GNUNET_OK == res) 982 if (GNUNET_OK == res)
984 return ret; 983 return ret;