aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/gnunet-transport.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c1202
1 files changed, 603 insertions, 599 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 6cc342d06..f0d9d30c3 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -34,18 +34,19 @@
34 * Timeout for a name resolution 34 * Timeout for a name resolution
35 */ 35 */
36#define RESOLUTION_TIMEOUT \ 36#define RESOLUTION_TIMEOUT \
37 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 37 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 38
39/** 39/**
40 * Timeout for an operation 40 * Timeout for an operation
41 */ 41 */
42#define OP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 42#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
43 43
44 44
45/** 45/**
46 * Context to store name resolutions for valiation 46 * Context to store name resolutions for valiation
47 */ 47 */
48struct ValidationResolutionContext { 48struct ValidationResolutionContext
49{
49 /** 50 /**
50 * Next in DLL 51 * Next in DLL
51 */ 52 */
@@ -95,7 +96,8 @@ struct ValidationResolutionContext {
95/** 96/**
96 * Struct to store information about peers in monitor mode 97 * Struct to store information about peers in monitor mode
97 */ 98 */
98struct MonitoredPeer { 99struct MonitoredPeer
100{
99 /** 101 /**
100 * State of the peer 102 * State of the peer
101 */ 103 */
@@ -115,7 +117,8 @@ struct MonitoredPeer {
115/** 117/**
116 * Context to store name resolutions for valiation 118 * Context to store name resolutions for valiation
117 */ 119 */
118struct PeerResolutionContext { 120struct PeerResolutionContext
121{
119 /** 122 /**
120 * Next in DLL 123 * Next in DLL
121 */ 124 */
@@ -329,15 +332,15 @@ static struct PeerResolutionContext *rc_tail;
329 * @return #GNUNET_OK (continue to iterate) 332 * @return #GNUNET_OK (continue to iterate)
330 */ 333 */
331static int 334static int
332destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 335destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
333{ 336{
334 struct MonitoredPeer *m = value; 337 struct MonitoredPeer *m = value;
335 338
336 GNUNET_assert( 339 GNUNET_assert (
337 GNUNET_OK == 340 GNUNET_OK ==
338 GNUNET_CONTAINER_multipeermap_remove(monitored_peers, key, value)); 341 GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value));
339 GNUNET_free_non_null(m->address); 342 GNUNET_free_non_null (m->address);
340 GNUNET_free(value); 343 GNUNET_free (value);
341 return GNUNET_OK; 344 return GNUNET_OK;
342} 345}
343 346
@@ -349,7 +352,7 @@ destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
349 * @param cls NULL 352 * @param cls NULL
350 */ 353 */
351static void 354static void
352shutdown_task(void *cls) 355shutdown_task (void *cls)
353{ 356{
354 struct GNUNET_TIME_Relative duration; 357 struct GNUNET_TIME_Relative duration;
355 struct ValidationResolutionContext *cur; 358 struct ValidationResolutionContext *cur;
@@ -357,82 +360,82 @@ shutdown_task(void *cls)
357 struct PeerResolutionContext *rc; 360 struct PeerResolutionContext *rc;
358 361
359 if (NULL != op_timeout) 362 if (NULL != op_timeout)
360 { 363 {
361 GNUNET_SCHEDULER_cancel(op_timeout); 364 GNUNET_SCHEDULER_cancel (op_timeout);
362 op_timeout = NULL; 365 op_timeout = NULL;
363 } 366 }
364 if (NULL != pic) 367 if (NULL != pic)
365 { 368 {
366 GNUNET_TRANSPORT_monitor_peers_cancel(pic); 369 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
367 pic = NULL; 370 pic = NULL;
368 } 371 }
369 if (NULL != pm) 372 if (NULL != pm)
370 { 373 {
371 GNUNET_TRANSPORT_monitor_plugins_cancel(pm); 374 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
372 pm = NULL; 375 pm = NULL;
373 } 376 }
374 377
375 next = vc_head; 378 next = vc_head;
376 for (cur = next; NULL != cur; cur = next) 379 for (cur = next; NULL != cur; cur = next)
377 { 380 {
378 next = cur->next; 381 next = cur->next;
379 382
380 GNUNET_TRANSPORT_address_to_string_cancel(cur->asc); 383 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
381 GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, cur); 384 GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur);
382 GNUNET_free(cur->transport); 385 GNUNET_free (cur->transport);
383 GNUNET_HELLO_address_free(cur->addrcp); 386 GNUNET_HELLO_address_free (cur->addrcp);
384 GNUNET_free(cur); 387 GNUNET_free (cur);
385 } 388 }
386 while (NULL != (rc = rc_head)) 389 while (NULL != (rc = rc_head))
387 { 390 {
388 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc); 391 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
389 GNUNET_TRANSPORT_address_to_string_cancel(rc->asc); 392 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
390 GNUNET_free(rc->transport); 393 GNUNET_free (rc->transport);
391 GNUNET_free(rc->addrcp); 394 GNUNET_free (rc->addrcp);
392 GNUNET_free(rc); 395 GNUNET_free (rc);
393 } 396 }
394 if (NULL != handle) 397 if (NULL != handle)
395 { 398 {
396 GNUNET_TRANSPORT_core_disconnect(handle); 399 GNUNET_TRANSPORT_core_disconnect (handle);
397 handle = NULL; 400 handle = NULL;
398 } 401 }
399 if (benchmark_send) 402 if (benchmark_send)
400 { 403 {
401 duration = GNUNET_TIME_absolute_get_duration(start_time); 404 duration = GNUNET_TIME_absolute_get_duration (start_time);
402 fprintf(stdout, 405 fprintf (stdout,
403 _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), 406 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
404 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), 407 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
405 traffic_sent, 408 traffic_sent,
406 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); 409 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
407 } 410 }
408 if (benchmark_receive) 411 if (benchmark_receive)
409 { 412 {
410 duration = GNUNET_TIME_absolute_get_duration(start_time); 413 duration = GNUNET_TIME_absolute_get_duration (start_time);
411 fprintf(stdout, 414 fprintf (stdout,
412 _("Received %llu bytes/s (%llu bytes in %s)\n"), 415 _ ("Received %llu bytes/s (%llu bytes in %s)\n"),
413 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 416 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
414 traffic_received, 417 traffic_received,
415 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); 418 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
416 } 419 }
417 420
418 if (NULL != monitored_peers) 421 if (NULL != monitored_peers)
419 { 422 {
420 GNUNET_CONTAINER_multipeermap_iterate(monitored_peers, &destroy_it, NULL); 423 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL);
421 GNUNET_CONTAINER_multipeermap_destroy(monitored_peers); 424 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
422 monitored_peers = NULL; 425 monitored_peers = NULL;
423 } 426 }
424 if (NULL != monitored_plugins) 427 if (NULL != monitored_plugins)
425 { 428 {
426 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(monitored_plugins)); 429 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
427 GNUNET_CONTAINER_multipeermap_destroy(monitored_plugins); 430 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
428 monitored_plugins = NULL; 431 monitored_plugins = NULL;
429 } 432 }
430 if (NULL != blacklist) 433 if (NULL != blacklist)
431 { 434 {
432 GNUNET_TRANSPORT_blacklist_cancel(blacklist); 435 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
433 blacklist = NULL; 436 blacklist = NULL;
434 ret = 0; 437 ret = 0;
435 } 438 }
436} 439}
437 440
438 441
@@ -440,42 +443,42 @@ shutdown_task(void *cls)
440 * We are done, shut down. 443 * We are done, shut down.
441 */ 444 */
442static void 445static void
443operation_timeout(void *cls) 446operation_timeout (void *cls)
444{ 447{
445 struct PeerResolutionContext *cur; 448 struct PeerResolutionContext *cur;
446 struct PeerResolutionContext *next; 449 struct PeerResolutionContext *next;
447 450
448 op_timeout = NULL; 451 op_timeout = NULL;
449 if ((benchmark_send) || (benchmark_receive)) 452 if ((benchmark_send) || (benchmark_receive))
450 { 453 {
451 fprintf(stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full(&pid)); 454 fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
452 GNUNET_SCHEDULER_shutdown(); 455 GNUNET_SCHEDULER_shutdown ();
453 ret = 1; 456 ret = 1;
454 return; 457 return;
455 } 458 }
456 if (iterate_connections) 459 if (iterate_connections)
460 {
461 next = rc_head;
462 while (NULL != (cur = next))
457 { 463 {
458 next = rc_head; 464 next = cur->next;
459 while (NULL != (cur = next)) 465 fprintf (stdout,
460 { 466 _ ("Failed to resolve address for peer `%s'\n"),
461 next = cur->next; 467 GNUNET_i2s (&cur->addrcp->peer));
462 fprintf(stdout, 468
463 _("Failed to resolve address for peer `%s'\n"), 469 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur);
464 GNUNET_i2s(&cur->addrcp->peer)); 470 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
465 471 GNUNET_free (cur->transport);
466 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur); 472 GNUNET_free (cur->addrcp);
467 GNUNET_TRANSPORT_address_to_string_cancel(cur->asc); 473 GNUNET_free (cur);
468 GNUNET_free(cur->transport);
469 GNUNET_free(cur->addrcp);
470 GNUNET_free(cur);
471 }
472 fprintf(stdout,
473 "%s",
474 _("Failed to list connections, timeout occurred\n"));
475 GNUNET_SCHEDULER_shutdown();
476 ret = 1;
477 return;
478 } 474 }
475 fprintf (stdout,
476 "%s",
477 _ ("Failed to list connections, timeout occurred\n"));
478 GNUNET_SCHEDULER_shutdown ();
479 ret = 1;
480 return;
481 }
479} 482}
480 483
481 484
@@ -486,21 +489,21 @@ operation_timeout(void *cls)
486 * @param cls closure with the message queue 489 * @param cls closure with the message queue
487 */ 490 */
488static void 491static void
489do_send(void *cls) 492do_send (void *cls)
490{ 493{
491 struct GNUNET_MQ_Handle *mq = cls; 494 struct GNUNET_MQ_Handle *mq = cls;
492 struct GNUNET_MessageHeader *m; 495 struct GNUNET_MessageHeader *m;
493 struct GNUNET_MQ_Envelope *env; 496 struct GNUNET_MQ_Envelope *env;
494 497
495 env = GNUNET_MQ_msg_extra(m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY); 498 env = GNUNET_MQ_msg_extra (m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY);
496 memset(&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader)); 499 memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
497 traffic_sent += BLOCKSIZE * 1024; 500 traffic_sent += BLOCKSIZE * 1024;
498 GNUNET_MQ_notify_sent(env, &do_send, mq); 501 GNUNET_MQ_notify_sent (env, &do_send, mq);
499 if (verbosity > 0) 502 if (verbosity > 0)
500 fprintf(stdout, 503 fprintf (stdout,
501 _("Transmitting %u bytes\n"), 504 _ ("Transmitting %u bytes\n"),
502 (unsigned int)BLOCKSIZE * 1024); 505 (unsigned int) BLOCKSIZE * 1024);
503 GNUNET_MQ_send(mq, env); 506 GNUNET_MQ_send (mq, env);
504} 507}
505 508
506 509
@@ -513,29 +516,29 @@ do_send(void *cls)
513 * @param mq message queue for sending to @a peer 516 * @param mq message queue for sending to @a peer
514 */ 517 */
515static void * 518static void *
516notify_connect(void *cls, 519notify_connect (void *cls,
517 const struct GNUNET_PeerIdentity *peer, 520 const struct GNUNET_PeerIdentity *peer,
518 struct GNUNET_MQ_Handle *mq) 521 struct GNUNET_MQ_Handle *mq)
519{ 522{
520 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 523 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
521 return NULL; 524 return NULL;
522 ret = 0; 525 ret = 0;
523 if (!benchmark_send) 526 if (! benchmark_send)
524 return NULL; 527 return NULL;
525 if (NULL != op_timeout) 528 if (NULL != op_timeout)
526 { 529 {
527 GNUNET_SCHEDULER_cancel(op_timeout); 530 GNUNET_SCHEDULER_cancel (op_timeout);
528 op_timeout = NULL; 531 op_timeout = NULL;
529 } 532 }
530 if (verbosity > 0) 533 if (verbosity > 0)
531 fprintf( 534 fprintf (
532 stdout, 535 stdout,
533 _( 536 _ (
534 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), 537 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
535 GNUNET_i2s(peer), 538 GNUNET_i2s (peer),
536 BLOCKSIZE); 539 BLOCKSIZE);
537 start_time = GNUNET_TIME_absolute_get(); 540 start_time = GNUNET_TIME_absolute_get ();
538 do_send(mq); 541 do_send (mq);
539 return mq; 542 return mq;
540} 543}
541 544
@@ -549,19 +552,19 @@ notify_connect(void *cls,
549 * @param internal_cls what we returned from #notify_connect() 552 * @param internal_cls what we returned from #notify_connect()
550 */ 553 */
551static void 554static void
552notify_disconnect(void *cls, 555notify_disconnect (void *cls,
553 const struct GNUNET_PeerIdentity *peer, 556 const struct GNUNET_PeerIdentity *peer,
554 void *internal_cls) 557 void *internal_cls)
555{ 558{
556 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 559 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
557 return; 560 return;
558 if (NULL == internal_cls) 561 if (NULL == internal_cls)
559 return; /* not about target peer */ 562 return; /* not about target peer */
560 if (!benchmark_send) 563 if (! benchmark_send)
561 return; /* not transmitting */ 564 return; /* not transmitting */
562 fprintf(stdout, 565 fprintf (stdout,
563 _("Disconnected from peer `%s' while benchmarking\n"), 566 _ ("Disconnected from peer `%s' while benchmarking\n"),
564 GNUNET_i2s(&pid)); 567 GNUNET_i2s (&pid));
565} 568}
566 569
567 570
@@ -575,20 +578,20 @@ notify_disconnect(void *cls,
575 * @return NULL 578 * @return NULL
576 */ 579 */
577static void * 580static void *
578monitor_notify_connect(void *cls, 581monitor_notify_connect (void *cls,
579 const struct GNUNET_PeerIdentity *peer, 582 const struct GNUNET_PeerIdentity *peer,
580 struct GNUNET_MQ_Handle *mq) 583 struct GNUNET_MQ_Handle *mq)
581{ 584{
582 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 585 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
583 const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now); 586 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
584 587
585 monitor_connect_counter++; 588 monitor_connect_counter++;
586 fprintf(stdout, 589 fprintf (stdout,
587 _("%24s: %-17s %4s (%u connections in total)\n"), 590 _ ("%24s: %-17s %4s (%u connections in total)\n"),
588 now_str, 591 now_str,
589 _("Connected to"), 592 _ ("Connected to"),
590 GNUNET_i2s(peer), 593 GNUNET_i2s (peer),
591 monitor_connect_counter); 594 monitor_connect_counter);
592 return NULL; 595 return NULL;
593} 596}
594 597
@@ -602,22 +605,22 @@ monitor_notify_connect(void *cls,
602 * @param internal_cls what we returned from #monitor_notify_connect() 605 * @param internal_cls what we returned from #monitor_notify_connect()
603 */ 606 */
604static void 607static void
605monitor_notify_disconnect(void *cls, 608monitor_notify_disconnect (void *cls,
606 const struct GNUNET_PeerIdentity *peer, 609 const struct GNUNET_PeerIdentity *peer,
607 void *internal_cls) 610 void *internal_cls)
608{ 611{
609 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 612 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
610 const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now); 613 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
611 614
612 GNUNET_assert(monitor_connect_counter > 0); 615 GNUNET_assert (monitor_connect_counter > 0);
613 monitor_connect_counter--; 616 monitor_connect_counter--;
614 617
615 fprintf(stdout, 618 fprintf (stdout,
616 _("%24s: %-17s %4s (%u connections in total)\n"), 619 _ ("%24s: %-17s %4s (%u connections in total)\n"),
617 now_str, 620 now_str,
618 _("Disconnected from"), 621 _ ("Disconnected from"),
619 GNUNET_i2s(peer), 622 GNUNET_i2s (peer),
620 monitor_connect_counter); 623 monitor_connect_counter);
621} 624}
622 625
623 626
@@ -629,7 +632,7 @@ monitor_notify_disconnect(void *cls,
629 * @return #GNUNET_OK 632 * @return #GNUNET_OK
630 */ 633 */
631static int 634static int
632check_dummy(void *cls, const struct GNUNET_MessageHeader *message) 635check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
633{ 636{
634 return GNUNET_OK; /* all messages are fine */ 637 return GNUNET_OK; /* all messages are fine */
635} 638}
@@ -642,17 +645,17 @@ check_dummy(void *cls, const struct GNUNET_MessageHeader *message)
642 * @param message the message 645 * @param message the message
643 */ 646 */
644static void 647static void
645handle_dummy(void *cls, const struct GNUNET_MessageHeader *message) 648handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
646{ 649{
647 if (!benchmark_receive) 650 if (! benchmark_receive)
648 return; 651 return;
649 if (verbosity > 0) 652 if (verbosity > 0)
650 fprintf(stdout, 653 fprintf (stdout,
651 _("Received %u bytes\n"), 654 _ ("Received %u bytes\n"),
652 (unsigned int)ntohs(message->size)); 655 (unsigned int) ntohs (message->size));
653 if (0 == traffic_received) 656 if (0 == traffic_received)
654 start_time = GNUNET_TIME_absolute_get(); 657 start_time = GNUNET_TIME_absolute_get ();
655 traffic_received += ntohs(message->size); 658 traffic_received += ntohs (message->size);
656} 659}
657 660
658 661
@@ -666,40 +669,40 @@ handle_dummy(void *cls, const struct GNUNET_MessageHeader *message)
666 * @param state_timeout when will the peer's state expire 669 * @param state_timeout when will the peer's state expire
667 */ 670 */
668static void 671static void
669resolve_peer_address(const struct GNUNET_HELLO_Address *address, 672resolve_peer_address (const struct GNUNET_HELLO_Address *address,
670 int numeric, 673 int numeric,
671 enum GNUNET_TRANSPORT_PeerState state, 674 enum GNUNET_TRANSPORT_PeerState state,
672 struct GNUNET_TIME_Absolute state_timeout); 675 struct GNUNET_TIME_Absolute state_timeout);
673 676
674 677
675static void 678static void
676print_info(const struct GNUNET_PeerIdentity *id, 679print_info (const struct GNUNET_PeerIdentity *id,
677 const char *transport, 680 const char *transport,
678 const char *addr, 681 const char *addr,
679 enum GNUNET_TRANSPORT_PeerState state, 682 enum GNUNET_TRANSPORT_PeerState state,
680 struct GNUNET_TIME_Absolute state_timeout) 683 struct GNUNET_TIME_Absolute state_timeout)
681{ 684{
682 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || 685 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
683 (GNUNET_YES == monitor_connections)) 686 (GNUNET_YES == monitor_connections))
684 { 687 {
685 fprintf(stdout, 688 fprintf (stdout,
686 _("Peer `%s': %s %s in state `%s' until %s\n"), 689 _ ("Peer `%s': %s %s in state `%s' until %s\n"),
687 GNUNET_i2s(id), 690 GNUNET_i2s (id),
688 (NULL == transport) ? "<none>" : transport, 691 (NULL == transport) ? "<none>" : transport,
689 (NULL == transport) ? "<none>" : addr, 692 (NULL == transport) ? "<none>" : addr,
690 GNUNET_TRANSPORT_ps2s(state), 693 GNUNET_TRANSPORT_ps2s (state),
691 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 694 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
692 } 695 }
693 else if ((GNUNET_YES == iterate_connections) && 696 else if ((GNUNET_YES == iterate_connections) &&
694 (GNUNET_TRANSPORT_is_connected(state))) 697 (GNUNET_TRANSPORT_is_connected (state)))
695 { 698 {
696 /* Only connected peers, skip state */ 699 /* Only connected peers, skip state */
697 fprintf(stdout, 700 fprintf (stdout,
698 _("Peer `%s': %s %s\n"), 701 _ ("Peer `%s': %s %s\n"),
699 GNUNET_i2s(id), 702 GNUNET_i2s (id),
700 transport, 703 transport,
701 addr); 704 addr);
702 } 705 }
703} 706}
704 707
705 708
@@ -720,82 +723,82 @@ print_info(const struct GNUNET_PeerIdentity *id,
720 * if #GNUNET_SYSERR: communication error (IPC error) 723 * if #GNUNET_SYSERR: communication error (IPC error)
721 */ 724 */
722static void 725static void
723process_peer_string(void *cls, const char *address, int res) 726process_peer_string (void *cls, const char *address, int res)
724{ 727{
725 struct PeerResolutionContext *rc = cls; 728 struct PeerResolutionContext *rc = cls;
726 729
727 if (NULL != address) 730 if (NULL != address)
731 {
732 if (GNUNET_SYSERR == res)
728 { 733 {
729 if (GNUNET_SYSERR == res) 734 fprintf (
730 { 735 stderr,
731 fprintf( 736 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
732 stderr, 737 GNUNET_i2s (&rc->addrcp->peer),
733 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", 738 rc->addrcp->transport_name,
734 GNUNET_i2s(&rc->addrcp->peer), 739 (unsigned int) rc->addrcp->address_length);
735 rc->addrcp->transport_name, 740 print_info (&rc->addrcp->peer,
736 (unsigned int)rc->addrcp->address_length); 741 rc->transport,
737 print_info(&rc->addrcp->peer, 742 NULL,
738 rc->transport, 743 rc->state,
739 NULL, 744 rc->state_timeout);
740 rc->state, 745 rc->printed = GNUNET_YES;
741 rc->state_timeout);
742 rc->printed = GNUNET_YES;
743 return;
744 }
745 if (GNUNET_OK == res)
746 {
747 print_info(&rc->addrcp->peer,
748 rc->transport,
749 address,
750 rc->state,
751 rc->state_timeout);
752 rc->printed = GNUNET_YES;
753 return; /* Wait for done call */
754 }
755 /* GNUNET_NO == res: ignore, was simply not supported */
756 return; 746 return;
757 } 747 }
748 if (GNUNET_OK == res)
749 {
750 print_info (&rc->addrcp->peer,
751 rc->transport,
752 address,
753 rc->state,
754 rc->state_timeout);
755 rc->printed = GNUNET_YES;
756 return; /* Wait for done call */
757 }
758 /* GNUNET_NO == res: ignore, was simply not supported */
759 return;
760 }
758 /* NULL == address, last call, we are done */ 761 /* NULL == address, last call, we are done */
759 762
760 rc->asc = NULL; 763 rc->asc = NULL;
761 GNUNET_assert(address_resolutions > 0); 764 GNUNET_assert (address_resolutions > 0);
762 address_resolutions--; 765 address_resolutions--;
763 if (GNUNET_NO == rc->printed) 766 if (GNUNET_NO == rc->printed)
767 {
768 if (numeric == GNUNET_NO)
764 { 769 {
765 if (numeric == GNUNET_NO) 770 /* Failed to resolve address, try numeric lookup
766 { 771 (note: this should not be needed, as transport
767 /* Failed to resolve address, try numeric lookup 772 should fallback to numeric conversion if DNS takes
768 (note: this should not be needed, as transport 773 too long) */
769 should fallback to numeric conversion if DNS takes 774 resolve_peer_address (rc->addrcp,
770 too long) */ 775 GNUNET_YES,
771 resolve_peer_address(rc->addrcp, 776 rc->state,
772 GNUNET_YES, 777 rc->state_timeout);
773 rc->state,
774 rc->state_timeout);
775 }
776 else
777 {
778 print_info(&rc->addrcp->peer,
779 rc->transport,
780 NULL,
781 rc->state,
782 rc->state_timeout);
783 }
784 } 778 }
785 GNUNET_free(rc->transport); 779 else
786 GNUNET_free(rc->addrcp); 780 {
787 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc); 781 print_info (&rc->addrcp->peer,
788 GNUNET_free(rc); 782 rc->transport,
783 NULL,
784 rc->state,
785 rc->state_timeout);
786 }
787 }
788 GNUNET_free (rc->transport);
789 GNUNET_free (rc->addrcp);
790 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
791 GNUNET_free (rc);
789 if ((0 == address_resolutions) && (iterate_connections)) 792 if ((0 == address_resolutions) && (iterate_connections))
793 {
794 if (NULL != op_timeout)
790 { 795 {
791 if (NULL != op_timeout) 796 GNUNET_SCHEDULER_cancel (op_timeout);
792 { 797 op_timeout = NULL;
793 GNUNET_SCHEDULER_cancel(op_timeout);
794 op_timeout = NULL;
795 }
796 ret = 0;
797 GNUNET_SCHEDULER_shutdown();
798 } 798 }
799 ret = 0;
800 GNUNET_SCHEDULER_shutdown ();
801 }
799} 802}
800 803
801 804
@@ -810,28 +813,28 @@ process_peer_string(void *cls, const char *address, int res)
810 * @param state_timeout when will the peer's state expire 813 * @param state_timeout when will the peer's state expire
811 */ 814 */
812static void 815static void
813resolve_peer_address(const struct GNUNET_HELLO_Address *address, 816resolve_peer_address (const struct GNUNET_HELLO_Address *address,
814 int numeric, 817 int numeric,
815 enum GNUNET_TRANSPORT_PeerState state, 818 enum GNUNET_TRANSPORT_PeerState state,
816 struct GNUNET_TIME_Absolute state_timeout) 819 struct GNUNET_TIME_Absolute state_timeout)
817{ 820{
818 struct PeerResolutionContext *rc; 821 struct PeerResolutionContext *rc;
819 822
820 rc = GNUNET_new(struct PeerResolutionContext); 823 rc = GNUNET_new (struct PeerResolutionContext);
821 GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc); 824 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc);
822 address_resolutions++; 825 address_resolutions++;
823 rc->transport = GNUNET_strdup(address->transport_name); 826 rc->transport = GNUNET_strdup (address->transport_name);
824 rc->addrcp = GNUNET_HELLO_address_copy(address); 827 rc->addrcp = GNUNET_HELLO_address_copy (address);
825 rc->printed = GNUNET_NO; 828 rc->printed = GNUNET_NO;
826 rc->state = state; 829 rc->state = state;
827 rc->state_timeout = state_timeout; 830 rc->state_timeout = state_timeout;
828 /* Resolve address to string */ 831 /* Resolve address to string */
829 rc->asc = GNUNET_TRANSPORT_address_to_string(cfg, 832 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
830 address, 833 address,
831 numeric, 834 numeric,
832 RESOLUTION_TIMEOUT, 835 RESOLUTION_TIMEOUT,
833 &process_peer_string, 836 &process_peer_string,
834 rc); 837 rc);
835} 838}
836 839
837 840
@@ -846,44 +849,45 @@ resolve_peer_address(const struct GNUNET_HELLO_Address *address,
846 * @param state_timeout time out for the current state 849 * @param state_timeout time out for the current state
847 */ 850 */
848static void 851static void
849process_peer_iteration_cb(void *cls, 852process_peer_iteration_cb (void *cls,
850 const struct GNUNET_PeerIdentity *peer, 853 const struct GNUNET_PeerIdentity *peer,
851 const struct GNUNET_HELLO_Address *address, 854 const struct GNUNET_HELLO_Address *address,
852 enum GNUNET_TRANSPORT_PeerState state, 855 enum GNUNET_TRANSPORT_PeerState state,
853 struct GNUNET_TIME_Absolute state_timeout) 856 struct GNUNET_TIME_Absolute state_timeout)
854{ 857{
855 if (NULL == peer) 858 if (NULL == peer)
856 { 859 {
857 /* done */ 860 /* done */
858 pic = NULL; 861 pic = NULL;
859 return; 862 return;
860 } 863 }
861 864
862 if ((GNUNET_NO == iterate_all) && 865 if ((GNUNET_NO == iterate_all) &&
863 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state))) 866 (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state)))
864 return; /* Display only connected peers */ 867 return; /* Display only connected peers */
865 868
866 if (NULL != op_timeout) 869 if (NULL != op_timeout)
867 GNUNET_SCHEDULER_cancel(op_timeout); 870 GNUNET_SCHEDULER_cancel (op_timeout);
868 op_timeout = 871 op_timeout =
869 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); 872 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
870 873
871 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
872 "Received address for peer `%s': %s\n", 875 "Received address for peer `%s': %s\n",
873 GNUNET_i2s(peer), 876 GNUNET_i2s (peer),
874 address ? address->transport_name : ""); 877 address ? address->transport_name : "");
875 878
876 if (NULL != address) 879 if (NULL != address)
877 resolve_peer_address(address, numeric, state, state_timeout); 880 resolve_peer_address (address, numeric, state, state_timeout);
878 else 881 else
879 print_info(peer, NULL, NULL, state, state_timeout); 882 print_info (peer, NULL, NULL, state, state_timeout);
880} 883}
881 884
882 885
883/** 886/**
884 * Context for address resolution by #plugin_monitoring_cb(). 887 * Context for address resolution by #plugin_monitoring_cb().
885 */ 888 */
886struct PluginMonitorAddress { 889struct PluginMonitorAddress
890{
887 /** 891 /**
888 * Ongoing resolution request. 892 * Ongoing resolution request.
889 */ 893 */
@@ -909,57 +913,57 @@ struct PluginMonitorAddress {
909 * @param info the monitoring information 913 * @param info the monitoring information
910 */ 914 */
911static void 915static void
912print_plugin_event_info(struct PluginMonitorAddress *addr, 916print_plugin_event_info (struct PluginMonitorAddress *addr,
913 const struct GNUNET_TRANSPORT_SessionInfo *info) 917 const struct GNUNET_TRANSPORT_SessionInfo *info)
914{ 918{
915 const char *state; 919 const char *state;
916 920
917 switch (info->state) 921 switch (info->state)
918 { 922 {
919 case GNUNET_TRANSPORT_SS_INIT: 923 case GNUNET_TRANSPORT_SS_INIT:
920 state = "INIT"; 924 state = "INIT";
921 break; 925 break;
922 926
923 case GNUNET_TRANSPORT_SS_HANDSHAKE: 927 case GNUNET_TRANSPORT_SS_HANDSHAKE:
924 state = "HANDSHAKE"; 928 state = "HANDSHAKE";
925 break; 929 break;
926 930
927 case GNUNET_TRANSPORT_SS_UP: 931 case GNUNET_TRANSPORT_SS_UP:
928 state = "UP"; 932 state = "UP";
929 break; 933 break;
930 934
931 case GNUNET_TRANSPORT_SS_UPDATE: 935 case GNUNET_TRANSPORT_SS_UPDATE:
932 state = "UPDATE"; 936 state = "UPDATE";
933 break; 937 break;
934 938
935 case GNUNET_TRANSPORT_SS_DONE: 939 case GNUNET_TRANSPORT_SS_DONE:
936 state = "DONE"; 940 state = "DONE";
937 break; 941 break;
938 942
939 default: 943 default:
940 state = "UNKNOWN"; 944 state = "UNKNOWN";
941 break; 945 break;
942 } 946 }
943 fprintf(stdout, 947 fprintf (stdout,
944 "%s: state %s timeout in %s @ %s%s\n", 948 "%s: state %s timeout in %s @ %s%s\n",
945 GNUNET_i2s(&info->address->peer), 949 GNUNET_i2s (&info->address->peer),
946 state, 950 state,
947 GNUNET_STRINGS_relative_time_to_string( 951 GNUNET_STRINGS_relative_time_to_string (
948 GNUNET_TIME_absolute_get_remaining(info->session_timeout), 952 GNUNET_TIME_absolute_get_remaining (info->session_timeout),
949 GNUNET_YES), 953 GNUNET_YES),
950 addr->str, 954 addr->str,
951 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : ""); 955 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
952 fprintf(stdout, 956 fprintf (stdout,
953 "%s: queue has %3u messages and %6u bytes\n", 957 "%s: queue has %3u messages and %6u bytes\n",
954 GNUNET_i2s(&info->address->peer), 958 GNUNET_i2s (&info->address->peer),
955 info->num_msg_pending, 959 info->num_msg_pending,
956 info->num_bytes_pending); 960 info->num_bytes_pending);
957 if (0 != 961 if (0 !=
958 GNUNET_TIME_absolute_get_remaining(info->receive_delay).rel_value_us) 962 GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us)
959 fprintf(stdout, 963 fprintf (stdout,
960 "%s: receiving blocked until %s\n", 964 "%s: receiving blocked until %s\n",
961 GNUNET_i2s(&info->address->peer), 965 GNUNET_i2s (&info->address->peer),
962 GNUNET_STRINGS_absolute_time_to_string(info->receive_delay)); 966 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay));
963} 967}
964 968
965 969
@@ -980,19 +984,19 @@ print_plugin_event_info(struct PluginMonitorAddress *addr,
980 * if #GNUNET_SYSERR: communication error (IPC error) 984 * if #GNUNET_SYSERR: communication error (IPC error)
981 */ 985 */
982static void 986static void
983address_cb(void *cls, const char *address, int res) 987address_cb (void *cls, const char *address, int res)
984{ 988{
985 struct PluginMonitorAddress *addr = cls; 989 struct PluginMonitorAddress *addr = cls;
986 990
987 if (NULL == address) 991 if (NULL == address)
988 { 992 {
989 addr->asc = NULL; 993 addr->asc = NULL;
990 return; 994 return;
991 } 995 }
992 if (NULL != addr->str) 996 if (NULL != addr->str)
993 return; 997 return;
994 addr->str = GNUNET_strdup(address); 998 addr->str = GNUNET_strdup (address);
995 print_plugin_event_info(addr, &addr->si); 999 print_plugin_event_info (addr, &addr->si);
996} 1000}
997 1001
998 1002
@@ -1014,10 +1018,10 @@ address_cb(void *cls, const char *address, int res)
1014 * was being cancelled while sessions were active 1018 * was being cancelled while sessions were active
1015 */ 1019 */
1016static void 1020static void
1017plugin_monitoring_cb(void *cls, 1021plugin_monitoring_cb (void *cls,
1018 struct GNUNET_TRANSPORT_PluginSession *session, 1022 struct GNUNET_TRANSPORT_PluginSession *session,
1019 void **session_ctx, 1023 void **session_ctx,
1020 const struct GNUNET_TRANSPORT_SessionInfo *info) 1024 const struct GNUNET_TRANSPORT_SessionInfo *info)
1021{ 1025{
1022 struct PluginMonitorAddress *addr; 1026 struct PluginMonitorAddress *addr;
1023 1027
@@ -1025,50 +1029,50 @@ plugin_monitoring_cb(void *cls,
1025 return; /* in sync with transport service */ 1029 return; /* in sync with transport service */
1026 addr = *session_ctx; 1030 addr = *session_ctx;
1027 if (NULL == info) 1031 if (NULL == info)
1032 {
1033 if (NULL != addr)
1028 { 1034 {
1029 if (NULL != addr) 1035 if (NULL != addr->asc)
1030 { 1036 {
1031 if (NULL != addr->asc) 1037 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1032 { 1038 addr->asc = NULL;
1033 GNUNET_TRANSPORT_address_to_string_cancel(addr->asc); 1039 }
1034 addr->asc = NULL; 1040 GNUNET_free_non_null (addr->str);
1035 } 1041 GNUNET_free (addr);
1036 GNUNET_free_non_null(addr->str); 1042 *session_ctx = NULL;
1037 GNUNET_free(addr);
1038 *session_ctx = NULL;
1039 }
1040 return; /* shutdown */
1041 } 1043 }
1044 return; /* shutdown */
1045 }
1042 if (0 != 1046 if (0 !=
1043 memcmp(&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity))) 1047 memcmp (&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity)))
1044 return; /* filtered */ 1048 return; /* filtered */
1045 if (NULL == addr) 1049 if (NULL == addr)
1046 { 1050 {
1047 addr = GNUNET_new(struct PluginMonitorAddress); 1051 addr = GNUNET_new (struct PluginMonitorAddress);
1048 addr->asc = 1052 addr->asc =
1049 GNUNET_TRANSPORT_address_to_string(cfg, 1053 GNUNET_TRANSPORT_address_to_string (cfg,
1050 info->address, 1054 info->address,
1051 numeric, 1055 numeric,
1052 GNUNET_TIME_UNIT_FOREVER_REL, 1056 GNUNET_TIME_UNIT_FOREVER_REL,
1053 &address_cb, 1057 &address_cb,
1054 addr); 1058 addr);
1055 *session_ctx = addr; 1059 *session_ctx = addr;
1056 } 1060 }
1057 if (NULL == addr->str) 1061 if (NULL == addr->str)
1058 addr->si = *info; 1062 addr->si = *info;
1059 else 1063 else
1060 print_plugin_event_info(addr, info); 1064 print_plugin_event_info (addr, info);
1061 if (GNUNET_TRANSPORT_SS_DONE == info->state) 1065 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1066 {
1067 if (NULL != addr->asc)
1062 { 1068 {
1063 if (NULL != addr->asc) 1069 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1064 { 1070 addr->asc = NULL;
1065 GNUNET_TRANSPORT_address_to_string_cancel(addr->asc);
1066 addr->asc = NULL;
1067 }
1068 GNUNET_free_non_null(addr->str);
1069 GNUNET_free(addr);
1070 *session_ctx = NULL;
1071 } 1071 }
1072 GNUNET_free_non_null (addr->str);
1073 GNUNET_free (addr);
1074 *session_ctx = NULL;
1075 }
1072} 1076}
1073 1077
1074 1078
@@ -1083,64 +1087,64 @@ plugin_monitoring_cb(void *cls,
1083 * @param state_timeout time out for the current state 1087 * @param state_timeout time out for the current state
1084 */ 1088 */
1085static void 1089static void
1086process_peer_monitoring_cb(void *cls, 1090process_peer_monitoring_cb (void *cls,
1087 const struct GNUNET_PeerIdentity *peer, 1091 const struct GNUNET_PeerIdentity *peer,
1088 const struct GNUNET_HELLO_Address *address, 1092 const struct GNUNET_HELLO_Address *address,
1089 enum GNUNET_TRANSPORT_PeerState state, 1093 enum GNUNET_TRANSPORT_PeerState state,
1090 struct GNUNET_TIME_Absolute state_timeout) 1094 struct GNUNET_TIME_Absolute state_timeout)
1091{ 1095{
1092 struct MonitoredPeer *m; 1096 struct MonitoredPeer *m;
1093 1097
1094 if (NULL == peer) 1098 if (NULL == peer)
1095 { 1099 {
1096 fprintf(stdout, 1100 fprintf (stdout,
1097 "%s", 1101 "%s",
1098 _( 1102 _ (
1099 "Monitor disconnected from transport service. Reconnecting.\n")); 1103 "Monitor disconnected from transport service. Reconnecting.\n"));
1100 return; 1104 return;
1101 } 1105 }
1102 1106
1103 if (NULL != op_timeout) 1107 if (NULL != op_timeout)
1104 GNUNET_SCHEDULER_cancel(op_timeout); 1108 GNUNET_SCHEDULER_cancel (op_timeout);
1105 op_timeout = 1109 op_timeout =
1106 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); 1110 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1107 1111
1108 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get(monitored_peers, peer))) 1112 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1109 { 1113 {
1110 m = GNUNET_new(struct MonitoredPeer); 1114 m = GNUNET_new (struct MonitoredPeer);
1111 GNUNET_CONTAINER_multipeermap_put( 1115 GNUNET_CONTAINER_multipeermap_put (
1112 monitored_peers, 1116 monitored_peers,
1113 peer, 1117 peer,
1114 m, 1118 m,
1115 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1116 } 1120 }
1117 else 1121 else
1122 {
1123 if ((m->state == state) &&
1124 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1125 (NULL == address) && (NULL == m->address))
1118 { 1126 {
1119 if ((m->state == state) && 1127 return; /* No real change */
1120 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1121 (NULL == address) && (NULL == m->address))
1122 {
1123 return; /* No real change */
1124 }
1125 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1126 (0 == GNUNET_HELLO_address_cmp(m->address, address)))
1127 return; /* No real change */
1128 } 1128 }
1129 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1130 (0 == GNUNET_HELLO_address_cmp (m->address, address)))
1131 return; /* No real change */
1132 }
1129 1133
1130 if (NULL != m->address) 1134 if (NULL != m->address)
1131 { 1135 {
1132 GNUNET_free(m->address); 1136 GNUNET_free (m->address);
1133 m->address = NULL; 1137 m->address = NULL;
1134 } 1138 }
1135 if (NULL != address) 1139 if (NULL != address)
1136 m->address = GNUNET_HELLO_address_copy(address); 1140 m->address = GNUNET_HELLO_address_copy (address);
1137 m->state = state; 1141 m->state = state;
1138 m->state_timeout = state_timeout; 1142 m->state_timeout = state_timeout;
1139 1143
1140 if (NULL != address) 1144 if (NULL != address)
1141 resolve_peer_address(m->address, numeric, m->state, m->state_timeout); 1145 resolve_peer_address (m->address, numeric, m->state, m->state_timeout);
1142 else 1146 else
1143 print_info(peer, NULL, NULL, m->state, m->state_timeout); 1147 print_info (peer, NULL, NULL, m->state, m->state_timeout);
1144} 1148}
1145 1149
1146 1150
@@ -1154,9 +1158,9 @@ process_peer_monitoring_cb(void *cls,
1154 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not 1158 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1155 */ 1159 */
1156static int 1160static int
1157blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid) 1161blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid)
1158{ 1162{
1159 if (0 == memcmp(cpid, &pid, sizeof(struct GNUNET_PeerIdentity))) 1163 if (0 == memcmp (cpid, &pid, sizeof(struct GNUNET_PeerIdentity)))
1160 return GNUNET_SYSERR; 1164 return GNUNET_SYSERR;
1161 return GNUNET_OK; 1165 return GNUNET_OK;
1162} 1166}
@@ -1171,259 +1175,259 @@ blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid)
1171 * @param mycfg configuration 1175 * @param mycfg configuration
1172 */ 1176 */
1173static void 1177static void
1174run(void *cls, 1178run (void *cls,
1175 char *const *args, 1179 char *const *args,
1176 const char *cfgfile, 1180 const char *cfgfile,
1177 const struct GNUNET_CONFIGURATION_Handle *mycfg) 1181 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1178{ 1182{
1179 static struct GNUNET_PeerIdentity zero_pid; 1183 static struct GNUNET_PeerIdentity zero_pid;
1180 int counter = 0; 1184 int counter = 0;
1181 1185
1182 ret = 1; 1186 ret = 1;
1183 1187
1184 cfg = (struct GNUNET_CONFIGURATION_Handle *)mycfg; 1188 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1185 1189
1186 counter = benchmark_send + benchmark_receive + iterate_connections + 1190 counter = benchmark_send + benchmark_receive + iterate_connections
1187 monitor_connections + monitor_connects + do_disconnect + 1191 + monitor_connections + monitor_connects + do_disconnect
1188 monitor_plugins; 1192 + monitor_plugins;
1189 1193
1190 if (1 < counter) 1194 if (1 < counter)
1195 {
1196 fprintf (
1197 stderr,
1198 _ (
1199 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1200 "disconnect",
1201 "benchmark send",
1202 "benchmark receive",
1203 "information",
1204 "monitor",
1205 "events",
1206 "plugins");
1207 return;
1208 }
1209 if (0 == counter)
1210 {
1211 fprintf (
1212 stderr,
1213 _ (
1214 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1215 "disconnect",
1216 "benchmark send",
1217 "benchmark receive",
1218 "information",
1219 "monitor",
1220 "events",
1221 "plugins");
1222 return;
1223 }
1224
1225 if (do_disconnect) /* -D: Disconnect from peer */
1226 {
1227 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1191 { 1228 {
1192 fprintf( 1229 fprintf (stderr,
1193 stderr, 1230 _ ("Option `%s' makes no sense without option `%s'.\n"),
1194 _( 1231 "-D",
1195 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), 1232 "-p");
1196 "disconnect", 1233 ret = 1;
1197 "benchmark send",
1198 "benchmark receive",
1199 "information",
1200 "monitor",
1201 "events",
1202 "plugins");
1203 return; 1234 return;
1204 } 1235 }
1205 if (0 == counter) 1236 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
1237 if (NULL == blacklist)
1206 { 1238 {
1207 fprintf( 1239 fprintf (stderr,
1208 stderr, 1240 "%s",
1209 _( 1241 _ (
1210 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), 1242 "Failed to connect to transport service for disconnection\n"));
1211 "disconnect", 1243 ret = 1;
1212 "benchmark send",
1213 "benchmark receive",
1214 "information",
1215 "monitor",
1216 "events",
1217 "plugins");
1218 return; 1244 return;
1219 } 1245 }
1220 1246 fprintf (stdout,
1221 if (do_disconnect) /* -D: Disconnect from peer */ 1247 "%s",
1248 _ ("Blacklisting request in place, stop with CTRL-C\n"));
1249 }
1250 else if (benchmark_send) /* -s: Benchmark sending */
1251 {
1252 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1222 { 1253 {
1223 if (0 == memcmp(&zero_pid, &pid, sizeof(pid))) 1254 fprintf (stderr,
1224 { 1255 _ ("Option `%s' makes no sense without option `%s'.\n"),
1225 fprintf(stderr, 1256 "-s",
1226 _("Option `%s' makes no sense without option `%s'.\n"), 1257 "-p");
1227 "-D", 1258 ret = 1;
1228 "-p"); 1259 return;
1229 ret = 1;
1230 return;
1231 }
1232 blacklist = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_cb, NULL);
1233 if (NULL == blacklist)
1234 {
1235 fprintf(stderr,
1236 "%s",
1237 _(
1238 "Failed to connect to transport service for disconnection\n"));
1239 ret = 1;
1240 return;
1241 }
1242 fprintf(stdout,
1243 "%s",
1244 _("Blacklisting request in place, stop with CTRL-C\n"));
1245 } 1260 }
1246 else if (benchmark_send) /* -s: Benchmark sending */ 1261 handle = GNUNET_TRANSPORT_core_connect (cfg,
1262 NULL,
1263 NULL,
1264 NULL,
1265 &notify_connect,
1266 &notify_disconnect,
1267 NULL);
1268 if (NULL == handle)
1247 { 1269 {
1248 if (0 == memcmp(&zero_pid, &pid, sizeof(pid))) 1270 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1249 { 1271 ret = 1;
1250 fprintf(stderr, 1272 return;
1251 _("Option `%s' makes no sense without option `%s'.\n"),
1252 "-s",
1253 "-p");
1254 ret = 1;
1255 return;
1256 }
1257 handle = GNUNET_TRANSPORT_core_connect(cfg,
1258 NULL,
1259 NULL,
1260 NULL,
1261 &notify_connect,
1262 &notify_disconnect,
1263 NULL);
1264 if (NULL == handle)
1265 {
1266 fprintf(stderr, "%s", _("Failed to connect to transport service\n"));
1267 ret = 1;
1268 return;
1269 }
1270 start_time = GNUNET_TIME_absolute_get();
1271 op_timeout =
1272 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL);
1273 } 1273 }
1274 start_time = GNUNET_TIME_absolute_get ();
1275 op_timeout =
1276 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1277 }
1274 else if (benchmark_receive) /* -b: Benchmark receiving */ 1278 else if (benchmark_receive) /* -b: Benchmark receiving */
1279 {
1280 struct GNUNET_MQ_MessageHandler handlers[] =
1281 { GNUNET_MQ_hd_var_size (dummy,
1282 GNUNET_MESSAGE_TYPE_DUMMY,
1283 struct GNUNET_MessageHeader,
1284 NULL),
1285 GNUNET_MQ_handler_end () };
1286
1287 handle = GNUNET_TRANSPORT_core_connect (cfg,
1288 NULL,
1289 handlers,
1290 NULL,
1291 NULL,
1292 NULL,
1293 NULL);
1294 if (NULL == handle)
1275 { 1295 {
1276 struct GNUNET_MQ_MessageHandler handlers[] = 1296 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1277 { GNUNET_MQ_hd_var_size(dummy, 1297 ret = 1;
1278 GNUNET_MESSAGE_TYPE_DUMMY, 1298 return;
1279 struct GNUNET_MessageHeader,
1280 NULL),
1281 GNUNET_MQ_handler_end() };
1282
1283 handle = GNUNET_TRANSPORT_core_connect(cfg,
1284 NULL,
1285 handlers,
1286 NULL,
1287 NULL,
1288 NULL,
1289 NULL);
1290 if (NULL == handle)
1291 {
1292 fprintf(stderr, "%s", _("Failed to connect to transport service\n"));
1293 ret = 1;
1294 return;
1295 }
1296 if (verbosity > 0)
1297 fprintf(stdout, "%s", _("Starting to receive benchmark data\n"));
1298 start_time = GNUNET_TIME_absolute_get();
1299 } 1299 }
1300 if (verbosity > 0)
1301 fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1302 start_time = GNUNET_TIME_absolute_get ();
1303 }
1300 else if (iterate_connections) /* -i: List information about peers once */ 1304 else if (iterate_connections) /* -i: List information about peers once */
1301 { 1305 {
1302 pic = GNUNET_TRANSPORT_monitor_peers(cfg, 1306 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1303 &pid, 1307 &pid,
1304 GNUNET_YES, 1308 GNUNET_YES,
1305 &process_peer_iteration_cb, 1309 &process_peer_iteration_cb,
1306 (void *)cfg); 1310 (void *) cfg);
1307 op_timeout = 1311 op_timeout =
1308 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); 1312 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1309 } 1313 }
1310 else if (monitor_connections) /* -m: List information about peers continuously 1314 else if (monitor_connections) /* -m: List information about peers continuously
1311 */ 1315 */
1312 { 1316 {
1313 monitored_peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 1317 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1314 pic = GNUNET_TRANSPORT_monitor_peers(cfg, 1318 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1315 &pid, 1319 &pid,
1316 GNUNET_NO, 1320 GNUNET_NO,
1317 &process_peer_monitoring_cb, 1321 &process_peer_monitoring_cb,
1318 NULL); 1322 NULL);
1319 } 1323 }
1320 else if (monitor_plugins) /* -P: List information about plugins continuously 1324 else if (monitor_plugins) /* -P: List information about plugins continuously
1321 */ 1325 */
1322 { 1326 {
1323 monitored_plugins = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 1327 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1324 pm = GNUNET_TRANSPORT_monitor_plugins(cfg, &plugin_monitoring_cb, NULL); 1328 pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL);
1325 } 1329 }
1326 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ 1330 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1331 {
1332 monitor_connect_counter = 0;
1333 handle = GNUNET_TRANSPORT_core_connect (cfg,
1334 NULL,
1335 NULL,
1336 NULL,
1337 &monitor_notify_connect,
1338 &monitor_notify_disconnect,
1339 NULL);
1340 if (NULL == handle)
1327 { 1341 {
1328 monitor_connect_counter = 0; 1342 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1329 handle = GNUNET_TRANSPORT_core_connect(cfg, 1343 ret = 1;
1330 NULL,
1331 NULL,
1332 NULL,
1333 &monitor_notify_connect,
1334 &monitor_notify_disconnect,
1335 NULL);
1336 if (NULL == handle)
1337 {
1338 fprintf(stderr, "%s", _("Failed to connect to transport service\n"));
1339 ret = 1;
1340 return;
1341 }
1342 ret = 0;
1343 }
1344 else
1345 {
1346 GNUNET_break(0);
1347 return; 1344 return;
1348 } 1345 }
1346 ret = 0;
1347 }
1348 else
1349 {
1350 GNUNET_break (0);
1351 return;
1352 }
1349 1353
1350 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 1354 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1351} 1355}
1352 1356
1353 1357
1354int 1358int
1355main(int argc, char *const *argv) 1359main (int argc, char *const *argv)
1356{ 1360{
1357 int res; 1361 int res;
1358 struct GNUNET_GETOPT_CommandLineOption options[] = 1362 struct GNUNET_GETOPT_CommandLineOption options[] =
1359 { GNUNET_GETOPT_option_flag( 1363 { GNUNET_GETOPT_option_flag (
1360 'a', 1364 'a',
1361 "all", 1365 "all",
1362 gettext_noop( 1366 gettext_noop (
1363 "print information for all peers (instead of only connected peers)"), 1367 "print information for all peers (instead of only connected peers)"),
1364 &iterate_all), 1368 &iterate_all),
1365 GNUNET_GETOPT_option_flag( 1369 GNUNET_GETOPT_option_flag (
1366 'b', 1370 'b',
1367 "benchmark", 1371 "benchmark",
1368 gettext_noop( 1372 gettext_noop (
1369 "measure how fast we are receiving data from all peers (until CTRL-C)"), 1373 "measure how fast we are receiving data from all peers (until CTRL-C)"),
1370 &benchmark_receive), 1374 &benchmark_receive),
1371 GNUNET_GETOPT_option_flag('D', 1375 GNUNET_GETOPT_option_flag ('D',
1372 "disconnect", 1376 "disconnect",
1373 gettext_noop("disconnect from a peer"), 1377 gettext_noop ("disconnect from a peer"),
1374 &do_disconnect), 1378 &do_disconnect),
1375 GNUNET_GETOPT_option_flag( 1379 GNUNET_GETOPT_option_flag (
1376 'i', 1380 'i',
1377 "information", 1381 "information",
1378 gettext_noop( 1382 gettext_noop (
1379 "provide information about all current connections (once)"), 1383 "provide information about all current connections (once)"),
1380 &iterate_connections), 1384 &iterate_connections),
1381 GNUNET_GETOPT_option_flag( 1385 GNUNET_GETOPT_option_flag (
1382 'm', 1386 'm',
1383 "monitor", 1387 "monitor",
1384 gettext_noop( 1388 gettext_noop (
1385 "provide information about all current connections (continuously)"), 1389 "provide information about all current connections (continuously)"),
1386 &monitor_connections), 1390 &monitor_connections),
1387 GNUNET_GETOPT_option_flag( 1391 GNUNET_GETOPT_option_flag (
1388 'e', 1392 'e',
1389 "events", 1393 "events",
1390 gettext_noop( 1394 gettext_noop (
1391 "provide information about all connects and disconnect events (continuously)"), 1395 "provide information about all connects and disconnect events (continuously)"),
1392 &monitor_connects), 1396 &monitor_connects),
1393 GNUNET_GETOPT_option_flag('n', 1397 GNUNET_GETOPT_option_flag ('n',
1394 "numeric", 1398 "numeric",
1395 gettext_noop("do not resolve hostnames"), 1399 gettext_noop ("do not resolve hostnames"),
1396 &numeric), 1400 &numeric),
1397 GNUNET_GETOPT_option_base32_auto('p', 1401 GNUNET_GETOPT_option_base32_auto ('p',
1398 "peer", 1402 "peer",
1399 "PEER", 1403 "PEER",
1400 gettext_noop("peer identity"), 1404 gettext_noop ("peer identity"),
1401 &pid), 1405 &pid),
1402 GNUNET_GETOPT_option_flag('P', 1406 GNUNET_GETOPT_option_flag ('P',
1403 "plugins", 1407 "plugins",
1404 gettext_noop("monitor plugin sessions"), 1408 gettext_noop ("monitor plugin sessions"),
1405 &monitor_plugins), 1409 &monitor_plugins),
1406 GNUNET_GETOPT_option_flag( 1410 GNUNET_GETOPT_option_flag (
1407 's', 1411 's',
1408 "send", 1412 "send",
1409 gettext_noop( 1413 gettext_noop (
1410 "send data for benchmarking to the other peer (until CTRL-C)"), 1414 "send data for benchmarking to the other peer (until CTRL-C)"),
1411 &benchmark_send), 1415 &benchmark_send),
1412 GNUNET_GETOPT_option_verbose(&verbosity), 1416 GNUNET_GETOPT_option_verbose (&verbosity),
1413 GNUNET_GETOPT_OPTION_END }; 1417 GNUNET_GETOPT_OPTION_END };
1414 1418
1415 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 1419 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1416 return 2; 1420 return 2;
1417 1421
1418 res = 1422 res =
1419 GNUNET_PROGRAM_run(argc, 1423 GNUNET_PROGRAM_run (argc,
1420 argv, 1424 argv,
1421 "gnunet-transport", 1425 "gnunet-transport",
1422 gettext_noop("Direct access to transport service."), 1426 gettext_noop ("Direct access to transport service."),
1423 options, 1427 options,
1424 &run, 1428 &run,
1425 NULL); 1429 NULL);
1426 GNUNET_free((void *)argv); 1430 GNUNET_free ((void *) argv);
1427 if (GNUNET_OK == res) 1431 if (GNUNET_OK == res)
1428 return ret; 1432 return ret;
1429 return 1; 1433 return 1;