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