aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c258
1 files changed, 1 insertions, 257 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 85f22a7f2..994dd0111 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -87,11 +87,6 @@ struct ValidationResolutionContext
87 struct GNUNET_TIME_Absolute next_validation; 87 struct GNUNET_TIME_Absolute next_validation;
88 88
89 /** 89 /**
90 * state of validation process
91 */
92 enum GNUNET_TRANSPORT_ValidationState state;
93
94 /**
95 * Tranport conversion handle 90 * Tranport conversion handle
96 */ 91 */
97 struct GNUNET_TRANSPORT_AddressToStringContext *asc; 92 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
@@ -296,11 +291,6 @@ static int benchmark_receive;
296static int iterate_connections; 291static int iterate_connections;
297 292
298/** 293/**
299 * Option -d.
300 */
301static int iterate_validation;
302
303/**
304 * Option -a. 294 * Option -a.
305 */ 295 */
306static int iterate_all; 296static int iterate_all;
@@ -321,11 +311,6 @@ static int monitor_connects;
321static int monitor_connections; 311static int monitor_connections;
322 312
323/** 313/**
324 * Option -f.
325 */
326static int monitor_validation;
327
328/**
329 * Option -P. 314 * Option -P.
330 */ 315 */
331static int monitor_plugins; 316static int monitor_plugins;
@@ -386,11 +371,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *monitored_plugins;
386static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic; 371static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
387 372
388/** 373/**
389 * Handle if we are monitoring transport validation activity.
390 */
391static struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic;
392
393/**
394 * Handle if we are monitoring plugin session activity. 374 * Handle if we are monitoring plugin session activity.
395 */ 375 */
396static struct GNUNET_TRANSPORT_PluginMonitor *pm; 376static struct GNUNET_TRANSPORT_PluginMonitor *pm;
@@ -507,11 +487,6 @@ shutdown_task (void *cls)
507 GNUNET_TRANSPORT_monitor_peers_cancel (pic); 487 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
508 pic = NULL; 488 pic = NULL;
509 } 489 }
510 if (NULL != vic)
511 {
512 GNUNET_TRANSPORT_monitor_validation_entries_cancel (vic);
513 vic = NULL;
514 }
515 if (NULL != pm) 490 if (NULL != pm)
516 { 491 {
517 GNUNET_TRANSPORT_monitor_plugins_cancel (pm); 492 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
@@ -729,217 +704,6 @@ result_callback (void *cls,
729} 704}
730 705
731 706
732/**
733 * Resolve address we got a validation state for to a string.
734 *
735 * @param address the address itself
736 * @param numeric #GNUNET_YES to disable DNS, #GNUNET_NO to try reverse lookup
737 * @param last_validation when was the address validated last
738 * @param valid_until until when is the address valid
739 * @param next_validation when will we try to revalidate the address next
740 * @param state where are we in the validation state machine
741 */
742static void
743resolve_validation_address (const struct GNUNET_HELLO_Address *address,
744 int numeric,
745 struct GNUNET_TIME_Absolute last_validation,
746 struct GNUNET_TIME_Absolute valid_until,
747 struct GNUNET_TIME_Absolute next_validation,
748 enum GNUNET_TRANSPORT_ValidationState state);
749
750
751/**
752 * Function to call with a textual representation of an address. This
753 * function will be called several times with different possible
754 * textual representations, and a last time with @a address being NULL
755 * to signal the end of the iteration. Note that @a address NULL
756 * always is the last call, regardless of the value in @a res.
757 *
758 * @param cls closure
759 * @param address NULL on end of iteration,
760 * otherwise 0-terminated printable UTF-8 string,
761 * in particular an empty string if @a res is #GNUNET_NO
762 * @param res result of the address to string conversion:
763 * if #GNUNET_OK: conversion successful
764 * if #GNUNET_NO: address was invalid (or not supported)
765 * if #GNUNET_SYSERR: communication error (IPC error)
766 */
767static void
768process_validation_string (void *cls,
769 const char *address,
770 int res)
771{
772 struct ValidationResolutionContext *vc = cls;
773 char *s_valid;
774 char *s_last;
775 char *s_next;
776
777 if (NULL != address)
778 {
779 if (GNUNET_SYSERR == res)
780 {
781 FPRINTF (stderr,
782 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
783 GNUNET_i2s (&vc->addrcp->peer),
784 vc->addrcp->transport_name,
785 (unsigned int) vc->addrcp->address_length);
786 }
787 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us)
788 s_valid = GNUNET_strdup ("never");
789 else
790 s_valid = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->valid_until));
791
792 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us)
793 s_last = GNUNET_strdup ("never");
794 else
795 s_last = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->last_validation));
796
797 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us)
798 s_next = GNUNET_strdup ("never");
799 else
800 s_next = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->next_validation));
801
802 FPRINTF (stdout,
803 _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"),
804 GNUNET_i2s (&vc->addrcp->peer),
805 (GNUNET_OK == res) ? address : "<invalid address>",
806 (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "",
807 "Valid until : ", s_valid,
808 "Last validation: ",s_last,
809 "Next validation: ", s_next);
810 GNUNET_free (s_valid);
811 GNUNET_free (s_last);
812 GNUNET_free (s_next);
813 vc->printed = GNUNET_YES;
814 return;
815 }
816 /* last call, we are done */
817 GNUNET_assert (address_resolutions > 0);
818 address_resolutions--;
819 if ( (GNUNET_SYSERR == res) &&
820 (GNUNET_NO == vc->printed))
821 {
822 if (numeric == GNUNET_NO)
823 {
824 /* Failed to resolve address, try numeric lookup
825 (note: this should be unnecessary, as
826 transport should fallback to numeric lookup
827 internally if DNS takes too long anyway) */
828 resolve_validation_address (vc->addrcp,
829 GNUNET_NO,
830 vc->last_validation,
831 vc->valid_until,
832 vc->next_validation,
833 vc->state);
834 }
835 else
836 {
837 FPRINTF (stdout,
838 _("Peer `%s' %s `%s' \n"),
839 GNUNET_i2s (&vc->addrcp->peer),
840 "<unable to resolve address>",
841 GNUNET_TRANSPORT_vs2s (vc->state));
842 }
843 }
844 GNUNET_free (vc->transport);
845 GNUNET_free (vc->addrcp);
846 GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, vc);
847 GNUNET_free (vc);
848 if ((0 == address_resolutions) && (iterate_validation))
849 {
850 if (NULL != op_timeout)
851 {
852 GNUNET_SCHEDULER_cancel (op_timeout);
853 op_timeout = NULL;
854 }
855 ret = 0;
856 GNUNET_SCHEDULER_shutdown ();
857 }
858}
859
860
861/**
862 * Resolve address we got a validation state for to a string.
863 *
864 * @param address the address itself
865 * @param numeric #GNUNET_YES to disable DNS, #GNUNET_NO to try reverse lookup
866 * @param last_validation when was the address validated last
867 * @param valid_until until when is the address valid
868 * @param next_validation when will we try to revalidate the address next
869 * @param state where are we in the validation state machine
870 */
871static void
872resolve_validation_address (const struct GNUNET_HELLO_Address *address,
873 int numeric,
874 struct GNUNET_TIME_Absolute last_validation,
875 struct GNUNET_TIME_Absolute valid_until,
876 struct GNUNET_TIME_Absolute next_validation,
877 enum GNUNET_TRANSPORT_ValidationState state)
878{
879 struct ValidationResolutionContext *vc;
880
881 vc = GNUNET_new (struct ValidationResolutionContext);
882 GNUNET_assert(NULL != vc);
883 GNUNET_CONTAINER_DLL_insert(vc_head, vc_tail, vc);
884 address_resolutions++;
885
886 vc->transport = GNUNET_strdup(address->transport_name);
887 vc->addrcp = GNUNET_HELLO_address_copy (address);
888 vc->printed = GNUNET_NO;
889 vc->state = state;
890 vc->last_validation = last_validation;
891 vc->valid_until = valid_until;
892 vc->next_validation = next_validation;
893
894 /* Resolve address to string */
895 vc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
896 address,
897 numeric,
898 RESOLUTION_TIMEOUT,
899 &process_validation_string, vc);
900}
901
902
903/**
904 * Resolve address we got a validation state for to a string.
905 *
906 * @param cls NULL
907 * @param address the address itself
908 * @param last_validation when was the address validated last
909 * @param valid_until until when is the address valid
910 * @param next_validation when will we try to revalidate the address next
911 * @param state where are we in the validation state machine
912 */
913static void
914process_validation_cb (void *cls,
915 const struct GNUNET_HELLO_Address *address,
916 struct GNUNET_TIME_Absolute last_validation,
917 struct GNUNET_TIME_Absolute valid_until,
918 struct GNUNET_TIME_Absolute next_validation,
919 enum GNUNET_TRANSPORT_ValidationState state)
920{
921 if (NULL == address)
922 {
923 if (monitor_validation)
924 {
925 FPRINTF (stdout,
926 "%s",
927 _("Monitor disconnected from transport service. Reconnecting.\n"));
928 return;
929 }
930 vic = NULL;
931 GNUNET_SCHEDULER_shutdown ();
932 return;
933 }
934 resolve_validation_address (address,
935 numeric,
936 last_validation,
937 valid_until,
938 next_validation,
939 state);
940}
941
942
943static void 707static void
944run_nat_test () 708run_nat_test ()
945{ 709{
@@ -1784,7 +1548,7 @@ testservice_task (void *cls,
1784 1548
1785 counter = benchmark_send + benchmark_receive + iterate_connections 1549 counter = benchmark_send + benchmark_receive + iterate_connections
1786 + monitor_connections + monitor_connects + do_disconnect + 1550 + monitor_connections + monitor_connects + do_disconnect +
1787 + iterate_validation + monitor_validation + monitor_plugins; 1551 monitor_plugins;
1788 1552
1789 if (1 < counter) 1553 if (1 < counter)
1790 { 1554 {
@@ -1901,20 +1665,6 @@ testservice_task (void *cls,
1901 &plugin_monitoring_cb, 1665 &plugin_monitoring_cb,
1902 NULL); 1666 NULL);
1903 } 1667 }
1904 else if (iterate_validation) /* -d: Print information about validations */
1905 {
1906 vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg,
1907 (NULL == cpid) ? NULL : &pid,
1908 GNUNET_YES, TIMEOUT,
1909 &process_validation_cb, (void *) cfg);
1910 }
1911 else if (monitor_validation) /* -f: Print information about validations continuously */
1912 {
1913 vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg,
1914 (NULL == cpid) ? NULL : &pid,
1915 GNUNET_NO, TIMEOUT,
1916 &process_validation_cb, (void *) cfg);
1917 }
1918 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ 1668 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1919 { 1669 {
1920 monitor_connect_counter = 0; 1670 monitor_connect_counter = 0;
@@ -1985,12 +1735,6 @@ main (int argc,
1985 { 'D', "disconnect", 1735 { 'D', "disconnect",
1986 NULL, gettext_noop ("disconnect from a peer"), 0, 1736 NULL, gettext_noop ("disconnect from a peer"), 0,
1987 &GNUNET_GETOPT_set_one, &do_disconnect }, 1737 &GNUNET_GETOPT_set_one, &do_disconnect },
1988 { 'd', "validation", NULL,
1989 gettext_noop ("print information for all pending validations "),
1990 0, &GNUNET_GETOPT_set_one, &iterate_validation },
1991 { 'f', "monitorvalidation", NULL,
1992 gettext_noop ("print information for all pending validations continuously"),
1993 0, &GNUNET_GETOPT_set_one, &monitor_validation },
1994 { 'i', "information", NULL, 1738 { 'i', "information", NULL,
1995 gettext_noop ("provide information about all current connections (once)"), 1739 gettext_noop ("provide information about all current connections (once)"),
1996 0, &GNUNET_GETOPT_set_one, &iterate_connections }, 1740 0, &GNUNET_GETOPT_set_one, &iterate_connections },