aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-16 09:14:05 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-16 09:14:05 +0000
commit23a5ebdcbcffd87533bccd48efb99942eb60cdd7 (patch)
treebd1a5538f70fa818f6e54ddffae767038a591475 /src/transport/gnunet-transport.c
parent202940f94609fe47c450455b98f3d410d7e2422d (diff)
downloadgnunet-23a5ebdcbcffd87533bccd48efb99942eb60cdd7.tar.gz
gnunet-23a5ebdcbcffd87533bccd48efb99942eb60cdd7.zip
printing validation information with cli
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c197
1 files changed, 179 insertions, 18 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index c8408b757..8311c1d72 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -316,13 +316,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
316 } 316 }
317} 317}
318 318
319static struct ResolutionContext *rc_head; 319static struct PeerResolutionContext *rc_head;
320static struct ResolutionContext *rc_tail; 320static struct PeerResolutionContext *rc_tail;
321 321
322struct ResolutionContext 322struct PeerResolutionContext
323{ 323{
324 struct ResolutionContext *next; 324 struct PeerResolutionContext *next;
325 struct ResolutionContext *prev; 325 struct PeerResolutionContext *prev;
326 struct GNUNET_PeerIdentity id; 326 struct GNUNET_PeerIdentity id;
327 struct GNUNET_HELLO_Address *addrcp; 327 struct GNUNET_HELLO_Address *addrcp;
328 struct GNUNET_TRANSPORT_AddressToStringContext *asc; 328 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
@@ -332,11 +332,32 @@ struct ResolutionContext
332 int printed; 332 int printed;
333}; 333};
334 334
335static struct ValidationResolutionContext *vc_head;
336static struct ValidationResolutionContext *vc_tail;
337
338struct ValidationResolutionContext
339{
340 struct ValidationResolutionContext *next;
341 struct ValidationResolutionContext *prev;
342
343 struct GNUNET_PeerIdentity id;
344 struct GNUNET_HELLO_Address *addrcp;
345 struct GNUNET_TIME_Absolute last_validation;
346 struct GNUNET_TIME_Absolute valid_until;
347 struct GNUNET_TIME_Absolute next_validation;
348 enum GNUNET_TRANSPORT_ValidationState state;
349
350 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
351
352 char *transport;
353 int printed;
354};
355
335static void 356static void
336operation_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 357operation_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
337{ 358{
338 struct ResolutionContext *cur; 359 struct PeerResolutionContext *cur;
339 struct ResolutionContext *next; 360 struct PeerResolutionContext *next;
340 op_timeout = GNUNET_SCHEDULER_NO_TASK; 361 op_timeout = GNUNET_SCHEDULER_NO_TASK;
341 if ((try_connect) || (benchmark_send) || (benchmark_receive)) 362 if ((try_connect) || (benchmark_send) || (benchmark_receive))
342 { 363 {
@@ -442,6 +463,126 @@ fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
442 display_test_result (tstc, GNUNET_NO); 463 display_test_result (tstc, GNUNET_NO);
443} 464}
444 465
466
467static void
468resolve_validation_address (const struct GNUNET_PeerIdentity *id,
469 const struct GNUNET_HELLO_Address *address, int numeric,
470 struct GNUNET_TIME_Absolute last_validation,
471 struct GNUNET_TIME_Absolute valid_until,
472 struct GNUNET_TIME_Absolute next_validation,
473 enum GNUNET_TRANSPORT_ValidationState state);
474
475static void
476process_validation_string (void *cls, const char *address)
477{
478 struct ValidationResolutionContext *vc = cls;
479 char *s_valid;
480 char *s_last;
481 char *s_next;
482
483 if (address != NULL )
484 {
485 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us)
486 s_valid = GNUNET_strdup("never");
487 else
488 s_valid = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->valid_until));
489
490 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us)
491 s_last = GNUNET_strdup("never");
492 else
493 s_last = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->last_validation));
494
495 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us)
496 s_next = GNUNET_strdup("never");
497 else
498 s_next = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->next_validation));
499
500 FPRINTF (stdout,
501 _("Peer `%s' %s `%s'\n\t%s%s\n\t%s%s\n\t%s%s\n"),
502 GNUNET_i2s (&vc->id), address, GNUNET_TRANSPORT_vs2s (vc->state),
503 "Valid until : ", s_valid,
504 "Last validation: ",s_last,
505 "Next validation: ", s_next);
506 GNUNET_free (s_valid);
507 GNUNET_free (s_last);
508 GNUNET_free (s_next);
509 vc->printed = GNUNET_YES;
510 }
511 else
512 {
513 /* done */
514 GNUNET_assert(address_resolutions > 0);
515 address_resolutions--;
516 if (GNUNET_NO == vc->printed)
517 {
518 if (numeric == GNUNET_NO)
519 {
520 /* Failed to resolve address, try numeric lookup */
521 resolve_validation_address (&vc->id, vc->addrcp, GNUNET_NO,
522 vc->last_validation, vc->valid_until, vc->next_validation,
523 vc->state);
524 }
525 else
526 {
527 FPRINTF (stdout, _("Peer `%s' %s `%s' \n"),
528 GNUNET_i2s (&vc->id), "<unable to resolve address>",
529 GNUNET_TRANSPORT_vs2s (vc->state));
530 }
531 }
532 GNUNET_free (vc->transport);
533 GNUNET_free (vc->addrcp);
534 GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, vc);
535 GNUNET_free(vc);
536 if ((0 == address_resolutions) && (iterate_validation))
537 {
538 if (GNUNET_SCHEDULER_NO_TASK != end)
539 {
540 GNUNET_SCHEDULER_cancel (end);
541 end = GNUNET_SCHEDULER_NO_TASK;
542 }
543 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
544 {
545 GNUNET_SCHEDULER_cancel (op_timeout);
546 op_timeout = GNUNET_SCHEDULER_NO_TASK;
547 }
548 ret = 0;
549 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
550 }
551 }
552}
553
554
555
556static void
557resolve_validation_address (const struct GNUNET_PeerIdentity *id,
558 const struct GNUNET_HELLO_Address *address, int numeric,
559 struct GNUNET_TIME_Absolute last_validation,
560 struct GNUNET_TIME_Absolute valid_until,
561 struct GNUNET_TIME_Absolute next_validation,
562 enum GNUNET_TRANSPORT_ValidationState state)
563{
564 struct ValidationResolutionContext *vc;
565
566 vc = GNUNET_new (struct ValidationResolutionContext);
567 GNUNET_assert(NULL != vc);
568 GNUNET_CONTAINER_DLL_insert(vc_head, vc_tail, vc);
569 address_resolutions++;
570
571 vc->id = (*id);
572 vc->transport = GNUNET_strdup(address->transport_name);
573 vc->addrcp = GNUNET_HELLO_address_copy (address);
574 vc->printed = GNUNET_NO;
575 vc->state = state;
576 vc->last_validation = last_validation;
577 vc->valid_until = valid_until;
578 vc->next_validation = next_validation;
579
580 /* Resolve address to string */
581 vc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
582 RESOLUTION_TIMEOUT, &process_validation_string, vc);
583}
584
585
445void process_validation_cb (void *cls, 586void process_validation_cb (void *cls,
446 const struct GNUNET_PeerIdentity *peer, 587 const struct GNUNET_PeerIdentity *peer,
447 const struct GNUNET_HELLO_Address *address, 588 const struct GNUNET_HELLO_Address *address,
@@ -450,7 +591,27 @@ void process_validation_cb (void *cls,
450 struct GNUNET_TIME_Absolute next_validation, 591 struct GNUNET_TIME_Absolute next_validation,
451 enum GNUNET_TRANSPORT_ValidationState state) 592 enum GNUNET_TRANSPORT_ValidationState state)
452{ 593{
453 GNUNET_break (0); 594 if ((NULL == peer) && (NULL == address))
595 {
596 /* done */
597 vic = NULL;
598 if (GNUNET_SCHEDULER_NO_TASK != end)
599 GNUNET_SCHEDULER_cancel (end);
600 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
601 return;
602 }
603 if ((NULL == peer) || (NULL == address))
604 {
605 /* invalid response */
606 vic = NULL;
607 if (GNUNET_SCHEDULER_NO_TASK != end)
608 GNUNET_SCHEDULER_cancel (end);
609 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
610 return;
611 }
612 resolve_validation_address (peer, address,
613 numeric, last_validation,
614 valid_until, next_validation, state);
454} 615}
455 616
456/** 617/**
@@ -701,7 +862,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
701} 862}
702 863
703static void 864static void
704resolve_address (const struct GNUNET_PeerIdentity *id, 865resolve_peer_address (const struct GNUNET_PeerIdentity *id,
705 const struct GNUNET_HELLO_Address *address, int numeric, 866 const struct GNUNET_HELLO_Address *address, int numeric,
706 enum GNUNET_TRANSPORT_PeerState state, 867 enum GNUNET_TRANSPORT_PeerState state,
707 struct GNUNET_TIME_Absolute state_timeout); 868 struct GNUNET_TIME_Absolute state_timeout);
@@ -729,9 +890,9 @@ print_info (const struct GNUNET_PeerIdentity *id, const char *transport,
729} 890}
730 891
731static void 892static void
732process_string (void *cls, const char *address) 893process_peer_string (void *cls, const char *address)
733{ 894{
734 struct ResolutionContext *rc = cls; 895 struct PeerResolutionContext *rc = cls;
735 896
736 if (address != NULL ) 897 if (address != NULL )
737 { 898 {
@@ -748,7 +909,7 @@ process_string (void *cls, const char *address)
748 if (numeric == GNUNET_NO) 909 if (numeric == GNUNET_NO)
749 { 910 {
750 /* Failed to resolve address, try numeric lookup */ 911 /* Failed to resolve address, try numeric lookup */
751 resolve_address (&rc->id, rc->addrcp, GNUNET_YES, 912 resolve_peer_address (&rc->id, rc->addrcp, GNUNET_YES,
752 rc->state, rc->state_timeout); 913 rc->state, rc->state_timeout);
753 } 914 }
754 else 915 else
@@ -780,14 +941,14 @@ process_string (void *cls, const char *address)
780} 941}
781 942
782static void 943static void
783resolve_address (const struct GNUNET_PeerIdentity *id, 944resolve_peer_address (const struct GNUNET_PeerIdentity *id,
784 const struct GNUNET_HELLO_Address *address, int numeric, 945 const struct GNUNET_HELLO_Address *address, int numeric,
785 enum GNUNET_TRANSPORT_PeerState state, 946 enum GNUNET_TRANSPORT_PeerState state,
786 struct GNUNET_TIME_Absolute state_timeout) 947 struct GNUNET_TIME_Absolute state_timeout)
787{ 948{
788 struct ResolutionContext *rc; 949 struct PeerResolutionContext *rc;
789 950
790 rc = GNUNET_new (struct ResolutionContext); 951 rc = GNUNET_new (struct PeerResolutionContext);
791 GNUNET_assert(NULL != rc); 952 GNUNET_assert(NULL != rc);
792 GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc); 953 GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc);
793 address_resolutions++; 954 address_resolutions++;
@@ -800,7 +961,7 @@ resolve_address (const struct GNUNET_PeerIdentity *id,
800 rc->state_timeout = state_timeout; 961 rc->state_timeout = state_timeout;
801 /* Resolve address to string */ 962 /* Resolve address to string */
802 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, 963 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
803 RESOLUTION_TIMEOUT, &process_string, rc); 964 RESOLUTION_TIMEOUT, &process_peer_string, rc);
804} 965}
805 966
806/** 967/**
@@ -843,7 +1004,7 @@ process_peer_iteration_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
843 GNUNET_i2s (peer), address->transport_name); 1004 GNUNET_i2s (peer), address->transport_name);
844 1005
845 if (NULL != address) 1006 if (NULL != address)
846 resolve_address (peer, address, numeric, state, state_timeout); 1007 resolve_peer_address (peer, address, numeric, state, state_timeout);
847 else 1008 else
848 print_info (peer, NULL, NULL, state, state_timeout); 1009 print_info (peer, NULL, NULL, state, state_timeout);
849} 1010}
@@ -915,7 +1076,7 @@ process_peer_monitoring_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
915 m->state_timeout = state_timeout; 1076 m->state_timeout = state_timeout;
916 1077
917 if (NULL != address) 1078 if (NULL != address)
918 resolve_address (peer, m->address, numeric, m->state, m->state_timeout); 1079 resolve_peer_address (peer, m->address, numeric, m->state, m->state_timeout);
919 else 1080 else
920 print_info (peer, NULL, NULL, m->state, m->state_timeout); 1081 print_info (peer, NULL, NULL, m->state, m->state_timeout);
921} 1082}