aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--po/POTFILES.in3
-rw-r--r--src/include/gnunet_testing_ng_lib.h92
-rw-r--r--src/testing/gnunet-cmds-helper.c23
-rwxr-xr-xsrc/testing/netjail_start_v2.sh13
-rw-r--r--src/testing/testing.c229
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c18
-rw-r--r--src/transport/Makefile.am37
-rw-r--r--src/transport/test_transport_api2_tcp_node1.conf7
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c36
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c262
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_send.c262
-rw-r--r--src/transport/test_transport_start_with_config.c85
-rw-r--r--src/transport/transport-testing-cmds.h33
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c508
-rw-r--r--src/transport/transport_api_cmd_start_peer_v3.c619
15 files changed, 1605 insertions, 622 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 385aa00c4..ddef6ac33 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -424,6 +424,7 @@ src/testing/list-keys.c
424src/testing/testing.c 424src/testing/testing.c
425src/testing/testing_api_cmd_batch.c 425src/testing/testing_api_cmd_batch.c
426src/testing/testing_api_cmd_block_until_all_peers_started.c 426src/testing/testing_api_cmd_block_until_all_peers_started.c
427src/testing/testing_api_cmd_block_until_external_trigger.c
427src/testing/testing_api_cmd_hello_world.c 428src/testing/testing_api_cmd_hello_world.c
428src/testing/testing_api_cmd_hello_world_birth.c 429src/testing/testing_api_cmd_hello_world_birth.c
429src/testing/testing_api_cmd_local_test_finished.c 430src/testing/testing_api_cmd_local_test_finished.c
@@ -496,10 +497,12 @@ src/transport/transport_api_address_to_string.c
496src/transport/transport_api_blacklist.c 497src/transport/transport_api_blacklist.c
497src/transport/transport_api_cmd_connecting_peers.c 498src/transport/transport_api_cmd_connecting_peers.c
498src/transport/transport_api_cmd_connecting_peers_v2.c 499src/transport/transport_api_cmd_connecting_peers_v2.c
500src/transport/transport_api_cmd_connecting_peers_v3.c
499src/transport/transport_api_cmd_send_simple.c 501src/transport/transport_api_cmd_send_simple.c
500src/transport/transport_api_cmd_send_simple_v2.c 502src/transport/transport_api_cmd_send_simple_v2.c
501src/transport/transport_api_cmd_start_peer.c 503src/transport/transport_api_cmd_start_peer.c
502src/transport/transport_api_cmd_start_peer_v2.c 504src/transport/transport_api_cmd_start_peer_v2.c
505src/transport/transport_api_cmd_start_peer_v3.c
503src/transport/transport_api_cmd_stop_peer.c 506src/transport/transport_api_cmd_stop_peer.c
504src/transport/transport_api_core.c 507src/transport/transport_api_core.c
505src/transport/transport_api_hello_get.c 508src/transport/transport_api_hello_get.c
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 9ef42a3aa..31665f8f7 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -63,6 +63,88 @@ struct GNUNET_TESTING_NetjailRouter
63 unsigned int udp_port; 63 unsigned int udp_port;
64}; 64};
65 65
66/**
67 * Enum for the different types of nodes.
68 */
69enum GNUNET_TESTING_NODE_TYPE
70{
71 /**
72 * Node in a subnet.
73 */
74 GNUNET_TESTING_SUBNET_NODE,
75
76 /**
77 * Global known node.
78 */
79 GNUNET_TESTING_GLOBAL_NODE
80};
81
82struct GNUNET_TESTING_ADDRESS_PREFIX
83{
84 /**
85 * Pointer to the previous prefix in the DLL.
86 */
87 struct GNUNET_TESTING_ADDRESS_PREFIX *prev;
88
89 /**
90 * Pointer to the next prefix in the DLL.
91 */
92 struct GNUNET_TESTING_ADDRESS_PREFIX *next;
93
94 /**
95 * The address prefix.
96 */
97 char *address_prefix;
98};
99
100struct GNUNET_TESTING_NetjailNode;
101
102/**
103 * Connection to another node.
104 */
105struct GNUNET_TESTING_NodeConnection
106{
107 /**
108 * Pointer to the previous connection in the DLL.
109 */
110 struct GNUNET_TESTING_NodeConnection *prev;
111
112 /**
113 * Pointer to the next connection in the DLL.
114 */
115 struct GNUNET_TESTING_NodeConnection *next;
116
117 /**
118 * The number of the subnet of the node this connection points to. This is 0,
119 * if the node is a global known node.
120 */
121 unsigned int namespace_n;
122
123 /**
124 * The number of the node this connection points to.
125 */
126 unsigned int node_n;
127
128 /**
129 * The type of the node this connection points to.
130 */
131 enum GNUNET_TESTING_NODE_TYPE node_type;
132
133 /**
134 * The node which establish the connection
135 */
136 struct GNUNET_TESTING_NetjailNode *node;
137
138 /**
139 * Head of the DLL with the address prefixes for the protocolls this node is reachable.
140 */
141 struct GNUNET_TESTING_ADDRESS_PREFIX *address_prefixes_head;
142
143 /**
144 * Tail of the DLL with the address prefixes for the protocolls this node is reachable.
145 */
146 struct GNUNET_TESTING_ADDRESS_PREFIX *address_prefixes_tail;
147};
66 148
67/** 149/**
68 * Node in the netjail topology. 150 * Node in the netjail topology.
@@ -88,6 +170,16 @@ struct GNUNET_TESTING_NetjailNode
88 * The number of this node in the namespace. 170 * The number of this node in the namespace.
89 */ 171 */
90 unsigned int node_n; 172 unsigned int node_n;
173
174 /**
175 * Head of the DLL with the connections which shall be established to other nodes.
176 */
177 struct GNUNET_TESTING_NodeConnection *node_connections_head;
178
179 /**
180 * Tail of the DLL with the connections which shall be established to other nodes.
181 */
182 struct GNUNET_TESTING_NodeConnection *node_connections_tail;
91}; 183};
92 184
93 185
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 8f9e77709..e50db0cf6 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -57,6 +57,8 @@ testing_api_cmd_block_until_all_peers_started.c */
57 57
58#define NODE_BASE_IP "192.168.15." 58#define NODE_BASE_IP "192.168.15."
59 59
60#define KNOWN_BASE_IP "92.68.151."
61
60#define ROUTER_BASE_IP "92.68.150." 62#define ROUTER_BASE_IP "92.68.150."
61 63
62/** 64/**
@@ -343,6 +345,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
343 size_t msg_length; 345 size_t msg_length;
344 char *router_ip; 346 char *router_ip;
345 char *node_ip; 347 char *node_ip;
348 unsigned int namespace_n;
346 349
347 msize = ntohs (message->size); 350 msize = ntohs (message->size);
348 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) 351 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
@@ -378,8 +381,24 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
378 strcpy (router_ip, ROUTER_BASE_IP); 381 strcpy (router_ip, ROUTER_BASE_IP);
379 strcat (router_ip, plugin->n); 382 strcat (router_ip, plugin->n);
380 383
381 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->m) + 1); 384 sscanf (plugin->n, "%u", &namespace_n);
382 strcat (node_ip, NODE_BASE_IP); 385
386 if (0 == namespace_n)
387 {
388 LOG (GNUNET_ERROR_TYPE_ERROR,
389 "known node n: %s\n",
390 plugin->n);
391 node_ip = GNUNET_malloc (strlen (KNOWN_BASE_IP) + strlen (plugin->m) + 1);
392 strcat (node_ip, KNOWN_BASE_IP);
393 }
394 else
395 {
396 LOG (GNUNET_ERROR_TYPE_ERROR,
397 "subnet node n: %s\n",
398 plugin->n);
399 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->m) + 1);
400 strcat (node_ip, NODE_BASE_IP);
401 }
383 strcat (node_ip, plugin->m); 402 strcat (node_ip, plugin->m);
384 403
385 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, 404 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
diff --git a/src/testing/netjail_start_v2.sh b/src/testing/netjail_start_v2.sh
index cf1fe113a..dd1f2ad93 100755
--- a/src/testing/netjail_start_v2.sh
+++ b/src/testing/netjail_start_v2.sh
@@ -58,4 +58,17 @@ for N in $(seq $GLOBAL_N); do
58 for M in $(seq $LOCAL_M); do 58 for M in $(seq $LOCAL_M); do
59 netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR 59 netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR
60 done 60 done
61
62 # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports.
63
64 if [ "1" == "${R_TCP[$N]}" ]
65 then
66 ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
67 ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
68 fi
69 if [ "1" == "${R_UDP[$N]}" ]
70 then
71 ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
72 ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
73 fi
61done 74done
diff --git a/src/testing/testing.c b/src/testing/testing.c
index fcde39901..a11d404a5 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -1789,7 +1789,7 @@ get_first_value (char *line)
1789 token = strtok_r (copy, ":", &rest); 1789 token = strtok_r (copy, ":", &rest);
1790 token = strtok_r (NULL, ":", &rest); 1790 token = strtok_r (NULL, ":", &rest);
1791 sscanf (token, "%u", &ret); 1791 sscanf (token, "%u", &ret);
1792 free (copy); 1792 GNUNET_free (copy);
1793 return ret; 1793 return ret;
1794} 1794}
1795 1795
@@ -1809,7 +1809,7 @@ get_key (char *line)
1809 token = strtok_r (copy, ":", &rest); 1809 token = strtok_r (copy, ":", &rest);
1810 ret = malloc (2); 1810 ret = malloc (2);
1811 memcpy (ret, token, 2); 1811 memcpy (ret, token, 2);
1812 free (copy); 1812 GNUNET_free (copy);
1813 return ret; 1813 return ret;
1814} 1814}
1815 1815
@@ -1828,13 +1828,13 @@ get_first_string_value (char *line)
1828 memcpy (copy, line, slen); 1828 memcpy (copy, line, slen);
1829 token = strtok_r (copy, ":", &rest); 1829 token = strtok_r (copy, ":", &rest);
1830 token = strtok_r (NULL, ":", &rest); 1830 token = strtok_r (NULL, ":", &rest);
1831 LOG (GNUNET_ERROR_TYPE_DEBUG, 1831 LOG (GNUNET_ERROR_TYPE_ERROR,
1832 "first token %s\n", 1832 "first token %s\n",
1833 token); 1833 token);
1834 slen_token = strlen (token); 1834 slen_token = strlen (token);
1835 ret = malloc (slen_token + 1); 1835 ret = malloc (slen_token + 1);
1836 memcpy (ret, token, slen_token + 1); 1836 memcpy (ret, token, slen_token + 1);
1837 free (copy); 1837 GNUNET_free (copy);
1838 return ret; 1838 return ret;
1839} 1839}
1840 1840
@@ -1855,7 +1855,7 @@ get_second_value (char *line)
1855 token = strtok_r (NULL, ":", &rest); 1855 token = strtok_r (NULL, ":", &rest);
1856 token = strtok_r (NULL, ":", &rest); 1856 token = strtok_r (NULL, ":", &rest);
1857 sscanf (token, "%u", &ret); 1857 sscanf (token, "%u", &ret);
1858 free (copy); 1858 GNUNET_free (copy);
1859 return ret; 1859 return ret;
1860} 1860}
1861 1861
@@ -1883,11 +1883,129 @@ get_value (char *key, char *line)
1883 slen_token = strlen (token2); 1883 slen_token = strlen (token2);
1884 ret = malloc (slen_token + 1); 1884 ret = malloc (slen_token + 1);
1885 memcpy (ret, token2, slen_token + 1); 1885 memcpy (ret, token2, slen_token + 1);
1886 free (copy); 1886 GNUNET_free (copy);
1887 return ret; 1887 return ret;
1888} 1888}
1889 1889
1890 1890
1891static struct GNUNET_TESTING_NodeConnection *
1892get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1893{
1894 struct GNUNET_TESTING_NodeConnection *node_connection;
1895 char *copy;
1896 size_t slen;
1897 char *token;
1898 char *token2;
1899 unsigned int node_n;
1900 unsigned int namespace_n;
1901 char *rest = NULL;
1902 char *rest2 = NULL;
1903 struct GNUNET_TESTING_ADDRESS_PREFIX *prefix;
1904
1905 node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection);
1906 node_connection->node = node;
1907
1908 slen = strlen (line) + 1;
1909 copy = malloc (slen);
1910 memcpy (copy, line, slen);
1911 token = strtok_r (copy, ":", &rest);
1912 if (0 == strcmp ("{K", token))
1913 {
1914 node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE;
1915 token = strtok_r (NULL, ":", &rest);
1916 sscanf (token, "%u", &node_n);
1917 LOG (GNUNET_ERROR_TYPE_ERROR,
1918 "node_n %u\n",
1919 node_n);
1920 node_connection->node_n = node_n;
1921 node_connection->namespace_n = 0;
1922 }
1923 else if (0 == strcmp ("{P", token))
1924 {
1925 node_connection->node_type = GNUNET_TESTING_SUBNET_NODE;
1926 token = strtok_r (NULL, ":", &rest);
1927 sscanf (token, "%u", &node_n);
1928 node_connection->node_n = node_n;
1929 token = strtok_r (NULL, ":", &rest);
1930 sscanf (token, "%u", &namespace_n);
1931 node_connection->namespace_n = namespace_n;
1932 LOG (GNUNET_ERROR_TYPE_ERROR,
1933 "node_n %u namespace_n %u\n",
1934 node_n,
1935 namespace_n);
1936 }
1937 while (NULL != (token = strtok_r (NULL, ":", &rest)))
1938 {
1939 prefix = GNUNET_new (struct GNUNET_TESTING_ADDRESS_PREFIX);
1940 token2 = strtok_r (token, "}", &rest2);
1941 if (NULL != token2)
1942 {
1943 slen = strlen (token2) + 1;
1944 prefix->address_prefix = malloc (slen);
1945 memcpy (prefix->address_prefix, token2, slen);
1946 }
1947 else
1948 {
1949 slen = strlen (token) + 1;
1950 prefix->address_prefix = malloc (slen);
1951 memcpy (prefix->address_prefix, token, slen);
1952 }
1953
1954 LOG (GNUNET_ERROR_TYPE_ERROR,
1955 "address_prefix %s\n",
1956 prefix->address_prefix);
1957
1958 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head,
1959 node_connection->address_prefixes_tail,
1960 prefix);
1961 }
1962
1963 GNUNET_free (copy);
1964 LOG (GNUNET_ERROR_TYPE_ERROR,
1965 "address_prefix %s\n",
1966 prefix->address_prefix);
1967
1968 return node_connection;
1969}
1970
1971
1972static void
1973node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node)
1974{
1975 char *value, *value2;
1976 char *temp;
1977 char *copy;
1978 size_t slen;
1979 char *rest = NULL;
1980 char *rest2 = NULL;
1981 struct GNUNET_TESTING_NodeConnection *node_connection;
1982
1983
1984 temp = strstr (line, "connect");
1985 if (NULL != temp)
1986 {
1987 slen = strlen (temp) + 1;
1988 copy = malloc (slen);
1989 memcpy (copy, temp, slen);
1990 strtok_r (copy, ":", &rest);
1991 value = strtok_r (rest, "|", &rest2);
1992
1993 while (NULL != value)
1994 {
1995 node_connection = get_connect_value (value, node);
1996 GNUNET_CONTAINER_DLL_insert (node->node_connections_head,
1997 node->node_connections_tail,
1998 node_connection);
1999 value2 = strstr (value, "}}");
2000 if (NULL != value2)
2001 break;
2002 value = strtok_r (NULL, "|", &rest2);
2003
2004 }
2005 }
2006}
2007
2008
1891/** 2009/**
1892 * Getting the topology from file. 2010 * Getting the topology from file.
1893 * 2011 *
@@ -1912,6 +2030,7 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
1912 struct GNUNET_TESTING_NetjailNamespace *namespace; 2030 struct GNUNET_TESTING_NetjailNamespace *namespace;
1913 struct GNUNET_ShortHashCode *hkey; 2031 struct GNUNET_ShortHashCode *hkey;
1914 struct GNUNET_HashCode hc; 2032 struct GNUNET_HashCode hc;
2033
1915 topo->map_namespaces = 2034 topo->map_namespaces =
1916 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); 2035 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
1917 topo->map_globals = 2036 topo->map_globals =
@@ -1942,7 +2061,7 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
1942 return NULL; 2061 return NULL;
1943 } 2062 }
1944 2063
1945 LOG (GNUNET_ERROR_TYPE_DEBUG, 2064 LOG (GNUNET_ERROR_TYPE_ERROR,
1946 "data: %s\n", 2065 "data: %s\n",
1947 data); 2066 data);
1948 2067
@@ -1951,46 +2070,46 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
1951 while (NULL != token) 2070 while (NULL != token)
1952 { 2071 {
1953 key = get_key (token); 2072 key = get_key (token);
1954 LOG (GNUNET_ERROR_TYPE_DEBUG, 2073 LOG (GNUNET_ERROR_TYPE_ERROR,
1955 "In the loop with token: %s beginning with %s\n", 2074 "In the loop with token: %s beginning with %s\n",
1956 token, 2075 token,
1957 key); 2076 key);
1958 if (0 == strcmp (key, "M")) 2077 if (0 == strcmp (key, "M"))
1959 { 2078 {
1960 LOG (GNUNET_ERROR_TYPE_DEBUG, 2079 LOG (GNUNET_ERROR_TYPE_ERROR,
1961 "Get first Value for M.\n"); 2080 "Get first Value for M.\n");
1962 out = get_first_value (token); 2081 out = get_first_value (token);
1963 LOG (GNUNET_ERROR_TYPE_DEBUG, 2082 LOG (GNUNET_ERROR_TYPE_ERROR,
1964 "M: %u\n", 2083 "M: %u\n",
1965 out); 2084 out);
1966 topo->nodes_m = out; 2085 topo->nodes_m = out;
1967 } 2086 }
1968 else if (0 == strcmp (key, "N")) 2087 else if (0 == strcmp (key, "N"))
1969 { 2088 {
1970 LOG (GNUNET_ERROR_TYPE_DEBUG, 2089 LOG (GNUNET_ERROR_TYPE_ERROR,
1971 "Get first Value for N.\n"); 2090 "Get first Value for N.\n");
1972 out = get_first_value (token); 2091 out = get_first_value (token);
1973 LOG (GNUNET_ERROR_TYPE_DEBUG, 2092 LOG (GNUNET_ERROR_TYPE_ERROR,
1974 "N: %u\n", 2093 "N: %u\n",
1975 out); 2094 out);
1976 topo->namespaces_n = out; 2095 topo->namespaces_n = out;
1977 } 2096 }
1978 else if (0 == strcmp (key, "X")) 2097 else if (0 == strcmp (key, "X"))
1979 { 2098 {
1980 LOG (GNUNET_ERROR_TYPE_DEBUG, 2099 LOG (GNUNET_ERROR_TYPE_ERROR,
1981 "Get first Value for X.\n"); 2100 "Get first Value for X.\n");
1982 out = get_first_value (token); 2101 out = get_first_value (token);
1983 LOG (GNUNET_ERROR_TYPE_DEBUG, 2102 LOG (GNUNET_ERROR_TYPE_ERROR,
1984 "X: %u\n", 2103 "X: %u\n",
1985 out); 2104 out);
1986 topo->nodes_x = out; 2105 topo->nodes_x = out;
1987 } 2106 }
1988 else if (0 == strcmp (key, "T")) 2107 else if (0 == strcmp (key, "T"))
1989 { 2108 {
1990 LOG (GNUNET_ERROR_TYPE_DEBUG, 2109 LOG (GNUNET_ERROR_TYPE_ERROR,
1991 "Get first string value for T.\n"); 2110 "Get first string value for T.\n");
1992 value = get_first_string_value (token); 2111 value = get_first_string_value (token);
1993 LOG (GNUNET_ERROR_TYPE_DEBUG, 2112 LOG (GNUNET_ERROR_TYPE_ERROR,
1994 "value: %s\n", 2113 "value: %s\n",
1995 value); 2114 value);
1996 topo->plugin = value; 2115 topo->plugin = value;
@@ -2000,10 +2119,10 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2000 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 2119 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2001 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 2120 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2002 2121
2003 LOG (GNUNET_ERROR_TYPE_DEBUG, 2122 LOG (GNUNET_ERROR_TYPE_ERROR,
2004 "Get first Value for K.\n"); 2123 "Get first Value for K.\n");
2005 out = get_first_value (token); 2124 out = get_first_value (token);
2006 LOG (GNUNET_ERROR_TYPE_DEBUG, 2125 LOG (GNUNET_ERROR_TYPE_ERROR,
2007 "K: %u\n", 2126 "K: %u\n",
2008 out); 2127 out);
2009 node->node_n = out; 2128 node->node_n = out;
@@ -2012,20 +2131,24 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2012 &hc, 2131 &hc,
2013 sizeof (*hkey)); 2132 sizeof (*hkey));
2014 node->is_global = GNUNET_YES; 2133 node->is_global = GNUNET_YES;
2015 LOG (GNUNET_ERROR_TYPE_DEBUG, 2134
2016 "Get value for key value on K.\n"); 2135 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
2017 value = get_value ("plugin", token); 2136 topo->map_globals,
2018 LOG (GNUNET_ERROR_TYPE_DEBUG, 2137 hkey))
2019 "value: %s\n",
2020 value);
2021 if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_globals,
2022 hkey))
2023 GNUNET_break (0); 2138 GNUNET_break (0);
2024 else 2139 else
2025 GNUNET_CONTAINER_multishortmap_put (topo->map_globals, 2140 GNUNET_CONTAINER_multishortmap_put (topo->map_globals,
2026 hkey, 2141 hkey,
2027 node, 2142 node,
2028 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2143 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2144 LOG (GNUNET_ERROR_TYPE_ERROR,
2145 "Get value for key value on K.\n");
2146 value = get_value ("plugin", token);
2147 LOG (GNUNET_ERROR_TYPE_ERROR,
2148 "value: %s\n",
2149 value);
2150 node->plugin = value;
2151 node_connections (token, node);
2029 } 2152 }
2030 else if (0 == strcmp (key, "R")) 2153 else if (0 == strcmp (key, "R"))
2031 { 2154 {
@@ -2033,10 +2156,10 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2033 router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter); 2156 router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter);
2034 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 2157 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2035 2158
2036 LOG (GNUNET_ERROR_TYPE_DEBUG, 2159 LOG (GNUNET_ERROR_TYPE_ERROR,
2037 "Get first Value for R.\n"); 2160 "Get first Value for R.\n");
2038 out = get_first_value (token); 2161 out = get_first_value (token);
2039 LOG (GNUNET_ERROR_TYPE_DEBUG, 2162 LOG (GNUNET_ERROR_TYPE_ERROR,
2040 "R: %u\n", 2163 "R: %u\n",
2041 out); 2164 out);
2042 node->node_n = out; 2165 node->node_n = out;
@@ -2044,27 +2167,28 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2044 memcpy (hkey, 2167 memcpy (hkey,
2045 &hc, 2168 &hc,
2046 sizeof (*hkey)); 2169 sizeof (*hkey));
2047 LOG (GNUNET_ERROR_TYPE_DEBUG, 2170 LOG (GNUNET_ERROR_TYPE_ERROR,
2048 "Get value for key tcp_port on R.\n"); 2171 "Get value for key tcp_port on R.\n");
2049 value = get_value ("tcp_port", token); 2172 value = get_value ("tcp_port", token);
2050 LOG (GNUNET_ERROR_TYPE_DEBUG, 2173 LOG (GNUNET_ERROR_TYPE_ERROR,
2051 "tcp_port: %s\n", 2174 "tcp_port: %s\n",
2052 value); 2175 value);
2053 ret = sscanf (value, "%u", &(router->tcp_port)); 2176 ret = sscanf (value, "%u", &(router->tcp_port));
2054 2177
2055 GNUNET_break (0 == ret || 1 < router->tcp_port); 2178 GNUNET_break (0 != ret && 1 >= router->tcp_port);
2056 2179
2057 LOG (GNUNET_ERROR_TYPE_DEBUG, 2180 LOG (GNUNET_ERROR_TYPE_ERROR,
2058 "Get value for key udp_port on R.\n"); 2181 "Get value for key udp_port on R.\n");
2059 value = get_value ("udp_port", token); 2182 value = get_value ("udp_port", token);
2060 ret = sscanf (value, "%u", &(router->udp_port)); 2183 ret = sscanf (value, "%u", &(router->udp_port));
2061 GNUNET_break (0 == ret || 1 < router->udp_port); 2184 GNUNET_break (0 != ret && 1 >= router->udp_port);
2062 LOG (GNUNET_ERROR_TYPE_DEBUG, 2185 LOG (GNUNET_ERROR_TYPE_ERROR,
2063 "udp_port: %s\n", 2186 "udp_port: %s\n",
2064 value); 2187 value);
2065 2188
2066 if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_namespaces, 2189 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
2067 hkey)) 2190 topo->map_namespaces,
2191 hkey))
2068 { 2192 {
2069 namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces, 2193 namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2070 hkey); 2194 hkey);
@@ -2073,6 +2197,7 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2073 { 2197 {
2074 namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace); 2198 namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2075 namespace->namespace_n = out; 2199 namespace->namespace_n = out;
2200 namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2076 GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces, 2201 GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces,
2077 hkey, 2202 hkey,
2078 namespace, 2203 namespace,
@@ -2086,10 +2211,10 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2086 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 2211 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2087 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 2212 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2088 2213
2089 LOG (GNUNET_ERROR_TYPE_DEBUG, 2214 LOG (GNUNET_ERROR_TYPE_ERROR,
2090 "Get first Value for P.\n"); 2215 "Get first Value for P.\n");
2091 out = get_first_value (token); 2216 out = get_first_value (token);
2092 LOG (GNUNET_ERROR_TYPE_DEBUG, 2217 LOG (GNUNET_ERROR_TYPE_ERROR,
2093 "P: %u\n", 2218 "P: %u\n",
2094 out); 2219 out);
2095 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); 2220 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
@@ -2097,14 +2222,9 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2097 &hc, 2222 &hc,
2098 sizeof (*hkey)); 2223 sizeof (*hkey));
2099 2224
2100 LOG (GNUNET_ERROR_TYPE_DEBUG, 2225 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
2101 "Get value for key plugin on P.\n"); 2226 topo->map_namespaces,
2102 value = get_value ("plugin", token); 2227 hkey))
2103 LOG (GNUNET_ERROR_TYPE_DEBUG,
2104 "plugin: %s\n",
2105 value);
2106 if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_namespaces,
2107 hkey))
2108 { 2228 {
2109 namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces, 2229 namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2110 hkey); 2230 hkey);
@@ -2112,24 +2232,26 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2112 else 2232 else
2113 { 2233 {
2114 namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace); 2234 namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2235 namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2115 namespace->namespace_n = out; 2236 namespace->namespace_n = out;
2116 GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces, 2237 GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces,
2117 hkey, 2238 hkey,
2118 namespace, 2239 namespace,
2119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2240 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2120 } 2241 }
2121 LOG (GNUNET_ERROR_TYPE_DEBUG, 2242 LOG (GNUNET_ERROR_TYPE_ERROR,
2122 "Get second Value for P.\n"); 2243 "Get second Value for P.\n");
2123 out = get_second_value (token); 2244 out = get_second_value (token);
2124 LOG (GNUNET_ERROR_TYPE_DEBUG, 2245 LOG (GNUNET_ERROR_TYPE_ERROR,
2125 "P: %u\n", 2246 "P: %u\n",
2126 out); 2247 out);
2127 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); 2248 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2128 memcpy (hkey, 2249 memcpy (hkey,
2129 &hc, 2250 &hc,
2130 sizeof (*hkey)); 2251 sizeof (*hkey));
2131 if (0 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes, 2252 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
2132 hkey)) 2253 namespace->nodes,
2254 hkey))
2133 { 2255 {
2134 GNUNET_break (0); 2256 GNUNET_break (0);
2135 } 2257 }
@@ -2140,10 +2262,17 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2140 hkey, 2262 hkey,
2141 node, 2263 node,
2142 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2264 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2265 LOG (GNUNET_ERROR_TYPE_ERROR,
2266 "Get value for key plugin on P.\n");
2267 value = get_value ("plugin", token);
2268 LOG (GNUNET_ERROR_TYPE_ERROR,
2269 "plugin: %s\n",
2270 value);
2143 node->plugin = value; 2271 node->plugin = value;
2144 node->node_n = out; 2272 node->node_n = out;
2145 node->namespace_n = namespace->namespace_n; 2273 node->namespace_n = namespace->namespace_n;
2146 } 2274 }
2275 node_connections (token, node);
2147 } 2276 }
2148 token = strtok_r (NULL, "\n", &rest); 2277 token = strtok_r (NULL, "\n", &rest);
2149 } 2278 }
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
index 64ce549a4..ccb3f5ae8 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
@@ -62,7 +62,7 @@ struct HelperMessage
62struct NetJailState 62struct NetJailState
63{ 63{
64 /** 64 /**
65 * The complete topology infomation. 65 * The complete topology information.
66 */ 66 */
67 struct GNUNET_TESTING_NetjailTopology *topology; 67 struct GNUNET_TESTING_NetjailTopology *topology;
68 68
@@ -422,8 +422,8 @@ start_helper (struct NetJailState *ns, struct
422 struct GNUNET_TESTING_NetjailNamespace *namespace; 422 struct GNUNET_TESTING_NetjailNamespace *namespace;
423 423
424 424
425 if (0 == m) 425 if (0 == n)
426 script_num = n - 1; 426 script_num = m - 1;
427 else 427 else
428 script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known; 428 script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
429 pid = getpid (); 429 pid = getpid ();
@@ -455,8 +455,8 @@ start_helper (struct NetJailState *ns, struct
455 455
456 tbc = GNUNET_new (struct TestingSystemCount); 456 tbc = GNUNET_new (struct TestingSystemCount);
457 tbc->ns = ns; 457 tbc->ns = ns;
458 if (0 == m) 458 if (0 == n)
459 tbc->count = n; 459 tbc->count = m;
460 else 460 else
461 tbc->count = (n - 1) * ns->local_m + m + ns->known; 461 tbc->count = (n - 1) * ns->local_m + m + ns->known;
462 462
@@ -491,7 +491,7 @@ start_helper (struct NetJailState *ns, struct
491 491
492 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 492 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
493 493
494 plugin = ns->plugin_name; 494 plugin = topology->plugin;
495 495
496 if (0 == m) 496 if (0 == m)
497 { 497 {
@@ -505,7 +505,8 @@ start_helper (struct NetJailState *ns, struct
505 { 505 {
506 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, 506 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
507 hkey); 507 hkey);
508 plugin = node->plugin; 508 if (NULL != node->plugin)
509 plugin = node->plugin;
509 } 510 }
510 511
511 } 512 }
@@ -529,7 +530,8 @@ start_helper (struct NetJailState *ns, struct
529 { 530 {
530 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, 531 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
531 hkey); 532 hkey);
532 plugin = node->plugin; 533 if (NULL != node->plugin)
534 plugin = node->plugin;
533 } 535 }
534 } 536 }
535 537
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 561ac5e60..c8290628f 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -162,8 +162,10 @@ libgnunettransporttesting_la_LDFLAGS = \
162libgnunettransporttesting2_la_SOURCES = \ 162libgnunettransporttesting2_la_SOURCES = \
163 transport_api_cmd_connecting_peers.c \ 163 transport_api_cmd_connecting_peers.c \
164 transport_api_cmd_connecting_peers_v2.c \ 164 transport_api_cmd_connecting_peers_v2.c \
165 transport_api_cmd_connecting_peers_v3.c \
165 transport_api_cmd_start_peer.c \ 166 transport_api_cmd_start_peer.c \
166 transport_api_cmd_start_peer_v2.c \ 167 transport_api_cmd_start_peer_v2.c \
168 transport_api_cmd_start_peer_v3.c \
167 transport_api_cmd_stop_peer.c \ 169 transport_api_cmd_stop_peer.c \
168 transport_api_cmd_send_simple.c \ 170 transport_api_cmd_send_simple.c \
169 transport_api_cmd_send_simple_v2.c \ 171 transport_api_cmd_send_simple_v2.c \
@@ -394,7 +396,25 @@ plugin_LTLIBRARIES = \
394 $(WLAN_PLUGIN_LA) \ 396 $(WLAN_PLUGIN_LA) \
395 $(BT_PLUGIN_LA) \ 397 $(BT_PLUGIN_LA) \
396 libgnunet_test_transport_plugin_cmd_simple_send.la \ 398 libgnunet_test_transport_plugin_cmd_simple_send.la \
397 libgnunet_test_transport_plugin_cmd_simple_send_v2.la 399 libgnunet_test_transport_plugin_cmd_simple_send_v2.la \
400 libgnunet_test_transport_plugin_cmd_udp_backchannel.la
401
402libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \
403 test_transport_plugin_cmd_udp_backchannel.c
404libgnunet_test_transport_plugin_cmd_udp_backchannel_la_LIBADD = \
405 libgnunettransporttesting2.la \
406 libgnunettransportapplication.la \
407 libgnunettransportcore.la \
408 $(top_builddir)/src/testing/libgnunettesting.la \
409 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
410 $(top_builddir)/src/statistics/libgnunetstatistics.la \
411 $(top_builddir)/src/hello/libgnunethello.la \
412 $(top_builddir)/src/ats/libgnunetats.la \
413 $(top_builddir)/src/arm/libgnunetarm.la \
414 $(top_builddir)/src/util/libgnunetutil.la \
415 $(LTLIBINTL)
416libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
417 $(GN_PLUGIN_LDFLAGS)
398 418
399libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \ 419libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \
400 test_transport_plugin_cmd_simple_send.c 420 test_transport_plugin_cmd_simple_send.c
@@ -578,6 +598,7 @@ if HAVE_TESTING
578check_PROGRAMS = \ 598check_PROGRAMS = \
579 test_transport_simple_send \ 599 test_transport_simple_send \
580 test_transport_simple_send_v2 \ 600 test_transport_simple_send_v2 \
601 test_transport_start_with_config \
581 test_transport_address_switch_tcp \ 602 test_transport_address_switch_tcp \
582 test_transport_testing_startstop \ 603 test_transport_testing_startstop \
583 test_transport_testing_restart \ 604 test_transport_testing_restart \
@@ -728,6 +749,7 @@ if HAVE_EXPERIMENTAL
728TESTS += \ 749TESTS += \
729 test_transport_simple_send \ 750 test_transport_simple_send \
730 test_transport_simple_send_v2 \ 751 test_transport_simple_send_v2 \
752 test_transport_start_with_config \
731 test_transport_address_switch_udp \ 753 test_transport_address_switch_udp \
732 test_plugin_udp \ 754 test_plugin_udp \
733 test_transport_api_udp \ 755 test_transport_api_udp \
@@ -747,7 +769,18 @@ endif
747 769
748check_SCRIPTS= \ 770check_SCRIPTS= \
749 test_transport_simple_send.sh \ 771 test_transport_simple_send.sh \
750 test_transport_simple_send_v2.sh 772 test_transport_simple_send_v2.sh \
773 test_transport_udp_backchannel.sh
774
775test_transport_start_with_config_SOURCES = \
776 test_transport_start_with_config.c
777test_transport_start_with_config_LDADD = \
778 $(top_builddir)/src/testing/libgnunettesting.la \
779 $(top_builddir)/src/util/libgnunetutil.la \
780 $(top_builddir)/src/testbed/libgnunettestbed.la \
781 $(top_builddir)/src/hello/libgnunethello.la \
782 libgnunettransportcore.la \
783 libgnunettransporttesting2.la
751 784
752test_transport_simple_send_SOURCES = \ 785test_transport_simple_send_SOURCES = \
753 test_transport_simple_send.c 786 test_transport_simple_send.c
diff --git a/src/transport/test_transport_api2_tcp_node1.conf b/src/transport/test_transport_api2_tcp_node1.conf
index a867ea81a..11306fd6a 100644
--- a/src/transport/test_transport_api2_tcp_node1.conf
+++ b/src/transport/test_transport_api2_tcp_node1.conf
@@ -16,6 +16,13 @@ IMMEDIATE_START = YES
16UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p1.sock 16UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p1.sock
17#PREFIX = valgrind --log-file=/tmp/vg_cpeer1-%p 17#PREFIX = valgrind --log-file=/tmp/vg_cpeer1-%p
18 18
19[communicator-udp]
20BINARY = gnunet-communicator-udp
21BINDTO = 192.168.15.1:60002
22DISABLE_V6 = YES
23IMMEDIATE_START = YES
24UNIXPATH = $GNUNET_RUNTIME_DIR/udp-comm-p1.sock
25
19[peerstore] 26[peerstore]
20IMMEDIATE_START = YES 27IMMEDIATE_START = YES
21 28
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 35aa07ecd..07255a1a5 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -83,40 +83,11 @@ static void
83handle_test (void *cls, 83handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{ 85{
86 LOG (GNUNET_ERROR_TYPE_ERROR,
87 "message received\n");
88 message_received = GNUNET_YES; 86 message_received = GNUNET_YES;
89} 87}
90 88
91 89
92/** 90/**
93 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
94 * being received.
95 *
96 */
97static int
98check_test2 (void *cls,
99 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
100{
101 return GNUNET_OK;
102}
103
104
105/**
106 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
107 * being received.
108 *
109 */
110static void
111handle_test2 (void *cls,
112 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
113{
114 LOG (GNUNET_ERROR_TYPE_ERROR,
115 "message received\n");
116}
117
118
119/**
120 * Callback to set the flag indicating all peers started. Will be called via the plugin api. 91 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
121 * 92 *
122 */ 93 */
@@ -124,9 +95,6 @@ static void
124all_peers_started () 95all_peers_started ()
125{ 96{
126 are_all_peers_started = GNUNET_YES; 97 are_all_peers_started = GNUNET_YES;
127 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "setting are_all_peers_started: %d\n",
129 are_all_peers_started);
130} 98}
131 99
132 100
@@ -176,10 +144,6 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
176 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
177 struct GNUNET_TRANSPORT_TESTING_TestMessage, 145 struct GNUNET_TRANSPORT_TESTING_TestMessage,
178 NULL), 146 NULL),
179 GNUNET_MQ_hd_var_size (test2,
180 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
181 struct GNUNET_TRANSPORT_TESTING_TestMessage,
182 NULL),
183 GNUNET_MQ_handler_end () 147 GNUNET_MQ_handler_end ()
184 }; 148 };
185 149
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
deleted file mode 100644
index ce1245296..000000000
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41
42/**
43 * The name for a specific test environment directory.
44 *
45 */
46char *testdir;
47
48/**
49 * The name for the configuration file of the specific node.
50 *
51 */
52char *cfgname;
53
54/**
55 * Flag indicating if all peers have been started.
56 *
57 */
58unsigned int are_all_peers_started;
59
60
61/**
62 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
63 * received.
64 *
65 */
66static int
67check_test (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
69{
70 return GNUNET_OK;
71}
72
73
74/**
75 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
76 * being received.
77 *
78 */
79static void
80handle_test (void *cls,
81 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82{
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "message received\n");
85}
86
87
88/**
89 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
90 * being received.
91 *
92 */
93static int
94check_test2 (void *cls,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
96{
97 return GNUNET_OK;
98}
99
100
101/**
102 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
103 * being received.
104 *
105 */
106static void
107handle_test2 (void *cls,
108 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
109{
110 LOG (GNUNET_ERROR_TYPE_ERROR,
111 "message received\n");
112}
113
114
115/**
116 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
117 *
118 */
119static void
120all_peers_started ()
121{
122 are_all_peers_started = GNUNET_YES;
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "setting are_all_peers_started: %d\n",
125 are_all_peers_started);
126}
127
128
129/**
130 * Function to start a local test case.
131 *
132 * @param write_message Callback to send a message to the master loop.
133 * @param router_ip Global address of the network namespace.
134 * @param node_ip Local address of a node i a network namespace.
135 * @param m The number of the node in a network namespace.
136 * @param n The number of the network namespace.
137 * @param local_m The number of nodes in a network namespace.
138 */
139static void
140start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
141 char *node_ip,
142 char *m,
143 char *n,
144 char *local_m)
145{
146
147 unsigned int n_int, m_int, local_m_int, num;
148
149 struct GNUNET_TESTING_NetjailTopology *topology =
150 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
151
152 sscanf (m, "%u", &m_int);
153 sscanf (n, "%u", &n_int);
154 sscanf (local_m, "%u", &local_m_int);
155
156
157 if (0 == m_int)
158 num = n_int;
159 else
160 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
161
162 GNUNET_asprintf (&cfgname,
163 "test_transport_api2_tcp_node1.conf");
164
165 LOG (GNUNET_ERROR_TYPE_ERROR,
166 "plugin cfgname: %s\n",
167 cfgname);
168
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 "node ip: %s\n",
171 node_ip);
172
173 GNUNET_asprintf (&testdir,
174 "%s%s%s",
175 BASE_DIR,
176 m,
177 n);
178
179 struct GNUNET_MQ_MessageHandler handlers[] = {
180 GNUNET_MQ_hd_var_size (test,
181 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
182 struct GNUNET_TRANSPORT_TESTING_TestMessage,
183 NULL),
184 GNUNET_MQ_hd_var_size (test2,
185 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
186 struct GNUNET_TRANSPORT_TESTING_TestMessage,
187 NULL),
188 GNUNET_MQ_handler_end ()
189 };
190
191 struct GNUNET_TESTING_Command commands[] = {
192 GNUNET_TESTING_cmd_system_create ("system-create",
193 testdir),
194 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
195 "system-create",
196 num,
197 node_ip,
198 handlers,
199 cfgname),
200 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
201 write_message),
202 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
203 &are_all_peers_started),
204 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
205 "start-peer",
206 "system-create",
207 num),
208 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
209 "start-peer",
210 num),
211 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
212 "start-peer"),
213 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
214 "system-create"),
215 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
216 write_message)
217 };
218
219 GNUNET_TESTING_run (NULL,
220 commands,
221 GNUNET_TIME_UNIT_FOREVER_REL);
222
223}
224
225
226/**
227 * Entry point for the plugin.
228 *
229 * @param cls NULL
230 * @return the exported block API
231 */
232void *
233libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
234{
235 struct GNUNET_TESTING_PluginFunctions *api;
236
237 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
238 api->start_testcase = &start_testcase;
239 api->all_peers_started = &all_peers_started;
240 return api;
241}
242
243
244/**
245 * Exit point from the plugin.
246 *
247 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
248 * @return NULL
249 */
250void *
251libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
252{
253 struct GNUNET_TESTING_PluginFunctions *api = cls;
254
255 GNUNET_free (api);
256 GNUNET_free (testdir);
257 GNUNET_free (cfgname);
258 return NULL;
259}
260
261
262/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
deleted file mode 100644
index ce1245296..000000000
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41
42/**
43 * The name for a specific test environment directory.
44 *
45 */
46char *testdir;
47
48/**
49 * The name for the configuration file of the specific node.
50 *
51 */
52char *cfgname;
53
54/**
55 * Flag indicating if all peers have been started.
56 *
57 */
58unsigned int are_all_peers_started;
59
60
61/**
62 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
63 * received.
64 *
65 */
66static int
67check_test (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
69{
70 return GNUNET_OK;
71}
72
73
74/**
75 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
76 * being received.
77 *
78 */
79static void
80handle_test (void *cls,
81 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82{
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "message received\n");
85}
86
87
88/**
89 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
90 * being received.
91 *
92 */
93static int
94check_test2 (void *cls,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
96{
97 return GNUNET_OK;
98}
99
100
101/**
102 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
103 * being received.
104 *
105 */
106static void
107handle_test2 (void *cls,
108 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
109{
110 LOG (GNUNET_ERROR_TYPE_ERROR,
111 "message received\n");
112}
113
114
115/**
116 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
117 *
118 */
119static void
120all_peers_started ()
121{
122 are_all_peers_started = GNUNET_YES;
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "setting are_all_peers_started: %d\n",
125 are_all_peers_started);
126}
127
128
129/**
130 * Function to start a local test case.
131 *
132 * @param write_message Callback to send a message to the master loop.
133 * @param router_ip Global address of the network namespace.
134 * @param node_ip Local address of a node i a network namespace.
135 * @param m The number of the node in a network namespace.
136 * @param n The number of the network namespace.
137 * @param local_m The number of nodes in a network namespace.
138 */
139static void
140start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
141 char *node_ip,
142 char *m,
143 char *n,
144 char *local_m)
145{
146
147 unsigned int n_int, m_int, local_m_int, num;
148
149 struct GNUNET_TESTING_NetjailTopology *topology =
150 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
151
152 sscanf (m, "%u", &m_int);
153 sscanf (n, "%u", &n_int);
154 sscanf (local_m, "%u", &local_m_int);
155
156
157 if (0 == m_int)
158 num = n_int;
159 else
160 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
161
162 GNUNET_asprintf (&cfgname,
163 "test_transport_api2_tcp_node1.conf");
164
165 LOG (GNUNET_ERROR_TYPE_ERROR,
166 "plugin cfgname: %s\n",
167 cfgname);
168
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 "node ip: %s\n",
171 node_ip);
172
173 GNUNET_asprintf (&testdir,
174 "%s%s%s",
175 BASE_DIR,
176 m,
177 n);
178
179 struct GNUNET_MQ_MessageHandler handlers[] = {
180 GNUNET_MQ_hd_var_size (test,
181 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
182 struct GNUNET_TRANSPORT_TESTING_TestMessage,
183 NULL),
184 GNUNET_MQ_hd_var_size (test2,
185 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
186 struct GNUNET_TRANSPORT_TESTING_TestMessage,
187 NULL),
188 GNUNET_MQ_handler_end ()
189 };
190
191 struct GNUNET_TESTING_Command commands[] = {
192 GNUNET_TESTING_cmd_system_create ("system-create",
193 testdir),
194 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
195 "system-create",
196 num,
197 node_ip,
198 handlers,
199 cfgname),
200 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
201 write_message),
202 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
203 &are_all_peers_started),
204 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
205 "start-peer",
206 "system-create",
207 num),
208 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
209 "start-peer",
210 num),
211 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
212 "start-peer"),
213 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
214 "system-create"),
215 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
216 write_message)
217 };
218
219 GNUNET_TESTING_run (NULL,
220 commands,
221 GNUNET_TIME_UNIT_FOREVER_REL);
222
223}
224
225
226/**
227 * Entry point for the plugin.
228 *
229 * @param cls NULL
230 * @return the exported block API
231 */
232void *
233libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
234{
235 struct GNUNET_TESTING_PluginFunctions *api;
236
237 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
238 api->start_testcase = &start_testcase;
239 api->all_peers_started = &all_peers_started;
240 return api;
241}
242
243
244/**
245 * Exit point from the plugin.
246 *
247 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
248 * @return NULL
249 */
250void *
251libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
252{
253 struct GNUNET_TESTING_PluginFunctions *api = cls;
254
255 GNUNET_free (api);
256 GNUNET_free (testdir);
257 GNUNET_free (cfgname);
258 return NULL;
259}
260
261
262/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
new file mode 100644
index 000000000..795c157d7
--- /dev/null
+++ b/src/transport/test_transport_start_with_config.c
@@ -0,0 +1,85 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file transport/test_transport_start_with_config.c
23 * @brief Test case executing a script which sends a test message between two peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
31
32/**
33 * Return value of the test.
34 *
35 */
36static unsigned int rv = 0;
37
38static char *topology_config;
39
40/**
41 * Main function to run the test cases.
42 *
43 * @param cls not used.
44 *
45 */
46static void
47run (void *cls)
48{
49 struct GNUNET_TESTING_Command commands[] = {
50 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
51 topology_config),
52 GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
53 topology_config,
54 &rv),
55 GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
56 "netjail-start-testbed",
57 topology_config),
58 GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
59 topology_config),
60 GNUNET_TESTING_cmd_end ()
61 };
62
63 GNUNET_TESTING_run (NULL,
64 commands,
65 TIMEOUT);
66}
67
68
69int
70main (int argc,
71 char *const *argv)
72{
73 GNUNET_log_setup ("test-netjail",
74 "DEBUG",
75 NULL);
76
77 topology_config = argv[1];
78
79 GNUNET_SCHEDULER_run (&run,
80 NULL);
81
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 "Test finished!\n");
84 return rv;
85}
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index f9ebafade..ecdabd35f 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -211,6 +211,14 @@ GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
211 const char *cfgname); 211 const char *cfgname);
212 212
213struct GNUNET_TESTING_Command 213struct GNUNET_TESTING_Command
214GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label,
215 const char *system_label,
216 uint32_t no,
217 char *node_ip,
218 struct GNUNET_MQ_MessageHandler *handlers,
219 const char *cfgname);
220
221struct GNUNET_TESTING_Command
214GNUNET_TRANSPORT_cmd_start_peer (const char *label, 222GNUNET_TRANSPORT_cmd_start_peer (const char *label,
215 const char *system_label, 223 const char *system_label,
216 char *m, 224 char *m,
@@ -237,6 +245,14 @@ GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
237 uint32_t num); 245 uint32_t num);
238 246
239struct GNUNET_TESTING_Command 247struct GNUNET_TESTING_Command
248GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
249 const char *start_peer_label,
250 const char *create_label,
251 uint32_t num,
252 struct GNUNET_TESTING_NetjailTopology *
253 topology);
254
255struct GNUNET_TESTING_Command
240GNUNET_TRANSPORT_cmd_send_simple (const char *label, 256GNUNET_TRANSPORT_cmd_send_simple (const char *label,
241 char *m, 257 char *m,
242 char *n, 258 char *n,
@@ -281,6 +297,16 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
281 * 297 *
282 * 298 *
283 connected_peers_map); 299 connected_peers_map);
300
301int
302GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (const struct
303 GNUNET_TESTING_Command
304 *cmd,
305 struct
306 GNUNET_CONTAINER_MultiShortmap
307 *
308 *
309 connected_peers_map);
284int 310int
285GNUNET_TRANSPORT_get_trait_hello_size (const struct 311GNUNET_TRANSPORT_get_trait_hello_size (const struct
286 GNUNET_TESTING_Command 312 GNUNET_TESTING_Command
@@ -308,5 +334,12 @@ GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
308 GNUNET_TRANSPORT_ApplicationHandle 334 GNUNET_TRANSPORT_ApplicationHandle
309 **ah); 335 **ah);
310 336
337int
338GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct
339 GNUNET_TESTING_Command *cmd,
340 struct
341 GNUNET_TRANSPORT_ApplicationHandle
342 **ah);
343
311#endif 344#endif
312/* end of transport_testing.h */ 345/* end of transport_testing.h */
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
new file mode 100644
index 000000000..e90781637
--- /dev/null
+++ b/src/transport/transport_api_cmd_connecting_peers_v3.c
@@ -0,0 +1,508 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h"
31#include "gnunet_transport_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39#define CONNECT_ADDRESS_TEMPLATE_TCP "tcp-192.168.15.%u:60002"
40
41#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
42
43#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
44
45#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
46
47#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
48
49#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
50
51#define PREFIX_TCP "tcp"
52
53#define PREFIX_UDP "udp"
54
55/**
56 * Struct to store information needed in callbacks.
57 *
58 */
59struct ConnectPeersState
60{
61 /**
62 * The testing system of this node.
63 */
64 struct GNUNET_TESTING_System *tl_system;
65
66 // Label of the cmd which started the test system.
67 const char *create_label;
68
69 /**
70 * Number globally identifying the node.
71 *
72 */
73 uint32_t num;
74
75 /**
76 * Label of the cmd to start a peer.
77 *
78 */
79 const char *start_peer_label;
80
81 /**
82 * The peer identity of this peer.
83 *
84 */
85 struct GNUNET_PeerIdentity *id;
86
87 /**
88 * The topology of the test setup.
89 */
90 struct GNUNET_TESTING_NetjailTopology *topology;
91
92 /**
93 * Connections to other peers.
94 */
95 struct GNUNET_TESTING_NodeConnection *node_connections_head;
96
97 /**
98 * Number of connections.
99 */
100 unsigned int con_num;
101};
102
103
104static struct GNUNET_PeerIdentity *
105get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
106{
107 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
108 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
109 GNUNET_CRYPTO_EddsaPublicKey);
110 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
111 GNUNET_CRYPTO_EddsaPrivateKey);
112
113 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
114 num,
115 peer);
116
117 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
118 pub_key);
119 peer->public_key = *pub_key;
120 return peer;
121}
122
123
124static int
125log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
126{
127 struct GNUNET_TESTING_NetjailNode *node = value;
128 struct GNUNET_TESTING_NodeConnection *pos_connection;
129 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
130
131 LOG (GNUNET_ERROR_TYPE_ERROR,
132 "plugin: %s space: %u node: %u global: %u\n",
133 node->plugin,
134 node->namespace_n,
135 node->node_n,
136 node->is_global);
137
138 for (pos_connection = node->node_connections_head; NULL != pos_connection;
139 pos_connection = pos_connection->next)
140 {
141
142 LOG (GNUNET_ERROR_TYPE_ERROR,
143 "namespace_n: %u node_n: %u node_type: %u\n",
144 pos_connection->namespace_n,
145 pos_connection->node_n,
146 pos_connection->node_type);
147
148 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
149 pos_prefix =
150 pos_prefix->next)
151 {
152 LOG (GNUNET_ERROR_TYPE_ERROR,
153 "prefix: %s\n",
154 pos_prefix->address_prefix);
155 }
156 }
157 return GNUNET_YES;
158}
159
160
161static int
162log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
163{
164 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
165 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
166
167 LOG (GNUNET_ERROR_TYPE_ERROR,
168 "router_tcp: %u router_udp: %u spaces: %u\n",
169 router->tcp_port,
170 router->udp_port,
171 namespace->namespace_n);
172 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
173 return GNUNET_YES;
174}
175
176
177static int
178log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
179{
180 LOG (GNUNET_ERROR_TYPE_ERROR,
181 "plugin: %s spaces: %u nodes: %u known: %u\n",
182 topology->plugin,
183 topology->namespaces_n,
184 topology->nodes_m,
185 topology->nodes_x);
186
187 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
188 log_namespaces, NULL);
189 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
190 NULL);
191 return GNUNET_YES;
192}
193
194
195static struct GNUNET_TESTING_NodeConnection *
196get_connections (unsigned int num, struct
197 GNUNET_TESTING_NetjailTopology *topology)
198{
199 struct GNUNET_TESTING_NetjailNode *node;
200 struct GNUNET_ShortHashCode *hkey;
201 struct GNUNET_HashCode hc;
202 struct GNUNET_TESTING_NetjailNamespace *namespace;
203 unsigned int namespace_n, node_m;
204
205 log_topo (topology);
206
207 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
208 if (topology->nodes_x >= num)
209 {
210
211 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
212 memcpy (hkey,
213 &hc,
214 sizeof (*hkey));
215 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
216 hkey);
217 }
218 else
219 {
220 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
221 / topology->nodes_m);
222 LOG (GNUNET_ERROR_TYPE_ERROR,
223 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
224 num,
225 topology->nodes_x,
226 topology->nodes_m,
227 namespace_n);
228 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
229 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
230 memcpy (hkey,
231 &hc,
232 sizeof (*hkey));
233 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
234 hkey);
235 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
236 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
237 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
238 memcpy (hkey,
239 &hc,
240 sizeof (*hkey));
241 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
242 hkey);
243 }
244
245
246 return node->node_connections_head;
247}
248
249
250static unsigned int
251calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
252 struct GNUNET_TESTING_NetjailTopology *topology)
253{
254 unsigned int n, m, num;
255
256 n = node_connection->namespace_n;
257 m = node_connection->node_n;
258
259 if (0 == n)
260 num = m;
261 else
262 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
263
264 return num;
265}
266
267static char *
268get_address (struct GNUNET_TESTING_NodeConnection *connection,
269 char *prefix)
270{
271 struct GNUNET_TESTING_NetjailNode *node;
272 char *addr;
273
274 node = connection->node;
275 if (connection->namespace_n == node->namespace_n)
276 {
277 if (0 == strcmp (PREFIX_TCP, prefix))
278 {
279
280 GNUNET_asprintf (&addr,
281 CONNECT_ADDRESS_TEMPLATE_TCP,
282 connection->node_n);
283 }
284 else if (0 == strcmp (PREFIX_UDP, prefix))
285 {
286 GNUNET_asprintf (&addr,
287 CONNECT_ADDRESS_TEMPLATE_UDP,
288 connection->node_n);
289 }
290 else
291 {
292 GNUNET_break (0);
293 }
294 }
295 else
296 {
297 if (0 == strcmp (PREFIX_TCP, prefix))
298 {
299
300 GNUNET_asprintf (&addr,
301 ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
302 connection->namespace_n);
303 }
304 else if (0 == strcmp (PREFIX_UDP, prefix))
305 {
306 GNUNET_asprintf (&addr,
307 ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
308 connection->namespace_n);
309 }
310 else
311 {
312 GNUNET_break (0);
313 }
314 }
315
316 return addr;
317}
318
319
320/**
321 * The run method of this cmd will connect to peers.
322 *
323 */
324static void
325connect_peers_run (void *cls,
326 const struct GNUNET_TESTING_Command *cmd,
327 struct GNUNET_TESTING_Interpreter *is)
328{
329 struct ConnectPeersState *cps = cls;
330 const struct GNUNET_TESTING_Command *system_cmd;
331 struct GNUNET_TESTING_System *tl_system;
332
333
334 const struct GNUNET_TESTING_Command *peer1_cmd;
335 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
336 struct GNUNET_PeerIdentity *peer;
337 char *addr;
338 enum GNUNET_NetworkType nt = 0;
339 uint32_t num;
340 struct GNUNET_TESTING_NodeConnection *pos_connection;
341 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
342 unsigned int con_num = 0;
343
344 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
345 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
346 &ah);
347
348 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
349 GNUNET_TESTING_get_trait_test_system (system_cmd,
350 &tl_system);
351
352 cps->tl_system = tl_system;
353
354 cps->node_connections_head = get_connections (cps->num, cps->topology);
355
356 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
357 pos_connection = pos_connection->next)
358 {
359 con_num++;
360 num = calculate_num (pos_connection, cps->topology);
361 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
362 pos_prefix =
363 pos_prefix->next)
364 {
365
366 LOG (GNUNET_ERROR_TYPE_ERROR,
367 "prefix: %s\n",
368 pos_prefix->address_prefix);
369
370 addr = get_address (pos_connection, pos_prefix->address_prefix);
371
372 peer = get_pub_key (num, tl_system);
373
374 LOG (GNUNET_ERROR_TYPE_ERROR,
375 "num: %u pub_key %s addr: %s\n",
376 num,
377 GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
378 addr);
379
380 cps->id = peer;
381
382 GNUNET_TRANSPORT_application_validate (ah,
383 peer,
384 nt,
385 addr);
386 }
387 }
388 cps->con_num = con_num;
389}
390
391
392/**
393 * The finish function of this cmd will check if the peers we are trying to
394 * connect to are in the connected peers map of the start peer cmd for this peer.
395 *
396 */
397static int
398connect_peers_finish (void *cls,
399 GNUNET_SCHEDULER_TaskCallback cont,
400 void *cont_cls)
401{
402 struct ConnectPeersState *cps = cls;
403 const struct GNUNET_TESTING_Command *peer1_cmd;
404 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
405 unsigned int ret;
406 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
407 struct GNUNET_HashCode hc;
408 struct GNUNET_PeerIdentity *peer;
409 unsigned int con_num = 0;
410 struct GNUNET_TESTING_NodeConnection *pos_connection;
411 unsigned int num;
412
413 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
414 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
415 &connected_peers_map);
416
417 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
418 pos_connection = pos_connection->next)
419 {
420 num = calculate_num (pos_connection, cps->topology);
421 peer = get_pub_key (num, cps->tl_system);
422 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc);
423 memcpy (key,
424 &hc,
425 sizeof (*key));
426 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
427 connected_peers_map,
428 key))
429 con_num++;
430 }
431
432
433
434 if (cps->con_num == con_num)
435 {
436 cont (cont_cls);
437 ret = GNUNET_YES;
438 }
439
440 GNUNET_free (key);
441 return ret;
442}
443
444
445/**
446 * Trait function of this cmd does nothing.
447 *
448 */
449static int
450connect_peers_traits (void *cls,
451 const void **ret,
452 const char *trait,
453 unsigned int index)
454{
455 return GNUNET_OK;
456}
457
458
459/**
460 * The cleanup function of this cmd frees resources the cmd allocated.
461 *
462 */
463static void
464connect_peers_cleanup (void *cls,
465 const struct GNUNET_TESTING_Command *cmd)
466{
467 struct ConnectPeersState *cps = cls;
468
469 GNUNET_free (cps->id);
470 GNUNET_free (cps);
471}
472
473
474/**
475 * Create command.
476 *
477 * @param label name for command.
478 * @param start_peer_label Label of the cmd to start a peer.
479 * @return command.
480 */
481struct GNUNET_TESTING_Command
482GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
483 const char *start_peer_label,
484 const char *create_label,
485 uint32_t num,
486 struct GNUNET_TESTING_NetjailTopology *
487 topology)
488{
489 struct ConnectPeersState *cps;
490
491 cps = GNUNET_new (struct ConnectPeersState);
492 cps->start_peer_label = start_peer_label;
493 cps->num = num;
494 cps->create_label = create_label;
495 cps->topology = topology;
496
497
498 struct GNUNET_TESTING_Command cmd = {
499 .cls = cps,
500 .label = label,
501 .run = &connect_peers_run,
502 .finish = &connect_peers_finish,
503 .cleanup = &connect_peers_cleanup,
504 .traits = &connect_peers_traits
505 };
506
507 return cmd;
508}
diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c
new file mode 100644
index 000000000..b5cefecc8
--- /dev/null
+++ b/src/transport/transport_api_cmd_start_peer_v3.c
@@ -0,0 +1,619 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39
40static void
41retrieve_hello (void *cls);
42
43
44/**
45 * Callback delivering the hello of this peer from peerstore.
46 *
47 */
48static void
49hello_iter_cb (void *cb_cls,
50 const struct GNUNET_PEERSTORE_Record *record,
51 const char *emsg)
52{
53 struct StartPeerState_v2 *sps = cb_cls;
54 if (NULL == record)
55 {
56 sps->pic = NULL;
57 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
58 return;
59 }
60 // Check record type et al?
61 sps->hello_size = record->value_size;
62 sps->hello = GNUNET_malloc (sps->hello_size);
63 memcpy (sps->hello, record->value, sps->hello_size);
64 sps->hello[sps->hello_size - 1] = '\0';
65
66 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
67 sps->pic = NULL;
68 sps->finished = GNUNET_YES;
69}
70
71
72/**
73 * Function to start the retrieval task to retrieve the hello of this peer
74 * from the peerstore.
75 *
76 */
77static void
78retrieve_hello (void *cls)
79{
80 struct StartPeerState_v2 *sps = cls;
81 sps->rh_task = NULL;
82 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
83 "transport",
84 &sps->id,
85 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
86 hello_iter_cb,
87 sps);
88
89}
90
91
92/**
93 * This function checks StartPeerState_v2#finished, which is set when the hello was retrieved.
94 *
95 */
96static int
97start_peer_finish (void *cls,
98 GNUNET_SCHEDULER_TaskCallback cont,
99 void *cont_cls)
100{
101 struct StartPeerState_v2 *sps = cls;
102
103 if (GNUNET_YES == sps->finished)
104 {
105 cont (cont_cls);
106 }
107
108 return sps->finished;
109}
110
111
112/**
113 * Disconnect callback for the connection to the core service.
114 *
115 */
116static void
117notify_disconnect (void *cls,
118 const struct GNUNET_PeerIdentity *peer,
119 void *handler_cls)
120{
121 struct StartPeerState_v2 *sps = cls;
122
123 LOG (GNUNET_ERROR_TYPE_DEBUG,
124 "Peer %s disconnected from peer %u (`%s')\n",
125 GNUNET_i2s (peer),
126 sps->no,
127 GNUNET_i2s (&sps->id));
128
129}
130
131
132/**
133 * Connect callback for the connection to the core service.
134 *
135 */
136static void *
137notify_connect (void *cls,
138 const struct GNUNET_PeerIdentity *peer,
139 struct GNUNET_MQ_Handle *mq)
140{
141 struct StartPeerState_v2 *sps = cls;
142 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
143 struct GNUNET_HashCode hc;
144 struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key;
145
146 void *ret = NULL;
147
148
149 LOG (GNUNET_ERROR_TYPE_DEBUG,
150 "Peer %s connected to peer %u (`%s')\n",
151 GNUNET_i2s (peer),
152 sps->no,
153 GNUNET_i2s (&sps->id));
154
155 GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
156
157
158 memcpy (key,
159 &hc,
160 sizeof (*key));
161 GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
162 key,
163 mq,
164 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
165
166 GNUNET_free (key);
167 // TODO what does the handler function need?
168 return ret;
169}
170
171
172/**
173 * The run method of this cmd will start all services of a peer to test the transport service.
174 *
175 */
176static void
177start_peer_run (void *cls,
178 const struct GNUNET_TESTING_Command *cmd,
179 struct GNUNET_TESTING_Interpreter *is)
180{
181 struct StartPeerState_v2 *sps = cls;
182 char *emsg = NULL;
183 struct GNUNET_PeerIdentity dummy;
184 const struct GNUNET_TESTING_Command *system_cmd;
185 struct GNUNET_TESTING_System *tl_system;
186 char *home;
187 char *transport_unix_path;
188 char *tcp_communicator_unix_path;
189 char *udp_communicator_unix_path;
190 char *bindto;
191
192 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
193 {
194 LOG (GNUNET_ERROR_TYPE_ERROR,
195 "File not found: `%s'\n",
196 sps->cfgname);
197 GNUNET_TESTING_interpreter_fail ();
198 return;
199 }
200
201
202 sps->cfg = GNUNET_CONFIGURATION_create ();
203 GNUNET_assert (GNUNET_OK ==
204 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
205
206 GNUNET_asprintf (&home,
207 "$GNUNET_TMP/test-transport/api-tcp-p%u",
208 sps->no);
209
210 GNUNET_asprintf (&transport_unix_path,
211 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
212 sps->no);
213
214 GNUNET_asprintf (&tcp_communicator_unix_path,
215 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
216 sps->no);
217
218 GNUNET_asprintf (&udp_communicator_unix_path,
219 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
220 sps->no);
221
222 GNUNET_asprintf (&bindto,
223 "%s:60002",
224 sps->node_ip);
225
226 LOG (GNUNET_ERROR_TYPE_ERROR,
227 "node_ip %s\n",
228 bindto);
229
230 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
231 home);
232 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
233 transport_unix_path);
234 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
235 "BINDTO",
236 bindto);
237 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
238 "BINDTO",
239 bindto);
240 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
241 "UNIXPATH",
242 tcp_communicator_unix_path);
243 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
244 "UNIXPATH",
245 udp_communicator_unix_path);
246
247 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label);
248 GNUNET_TESTING_get_trait_test_system (system_cmd,
249 &tl_system);
250
251 sps->tl_system = tl_system;
252
253 if (GNUNET_SYSERR ==
254 GNUNET_TESTING_configuration_create (tl_system,
255 sps->cfg))
256 {
257 LOG (GNUNET_ERROR_TYPE_ERROR,
258 "Testing library failed to create unique configuration based on `%s'\n",
259 sps->cfgname);
260 GNUNET_CONFIGURATION_destroy (sps->cfg);
261 GNUNET_TESTING_interpreter_fail ();
262 return;
263 }
264
265 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
266 sps->cfg,
267 sps->no,
268 NULL,
269 &emsg);
270 if (NULL == sps->peer)
271 {
272 LOG (GNUNET_ERROR_TYPE_ERROR,
273 "Testing library failed to create unique configuration based on `%s': `%s'\n",
274 sps->cfgname,
275 emsg);
276 GNUNET_free (emsg);
277 GNUNET_TESTING_interpreter_fail ();
278 return;
279 }
280
281 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
282 {
283 LOG (GNUNET_ERROR_TYPE_ERROR,
284 "Testing library failed to create unique configuration based on `%s'\n",
285 sps->cfgname);
286 GNUNET_free (emsg);
287 GNUNET_TESTING_interpreter_fail ();
288 return;
289 }
290
291 memset (&dummy,
292 '\0',
293 sizeof(dummy));
294
295 GNUNET_TESTING_peer_get_identity (sps->peer,
296 &sps->id);
297
298 if (0 == memcmp (&dummy,
299 &sps->id,
300 sizeof(struct GNUNET_PeerIdentity)))
301 {
302 LOG (GNUNET_ERROR_TYPE_ERROR,
303 "Testing library failed to obtain peer identity for peer %u\n",
304 sps->no);
305 GNUNET_free (emsg);
306 GNUNET_TESTING_interpreter_fail ();
307 return;
308 }
309 LOG (GNUNET_ERROR_TYPE_DEBUG,
310 "Peer %u configured with identity `%s'\n",
311 sps->no,
312 GNUNET_i2s_full (&sps->id));
313
314 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
315 NULL,
316 sps->handlers,
317 sps,
318 &notify_connect,
319 &notify_disconnect);
320 if (NULL == sps->th)
321 {
322 LOG (GNUNET_ERROR_TYPE_ERROR,
323 "Failed to connect to transport service for peer `%s': `%s'\n",
324 sps->cfgname,
325 emsg);
326 GNUNET_free (emsg);
327 GNUNET_TESTING_interpreter_fail ();
328 return;
329 }
330
331 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
332 if (NULL == sps->th)
333 {
334 LOG (GNUNET_ERROR_TYPE_ERROR,
335 "Failed to connect to peerstore service for peer `%s': `%s'\n",
336 sps->cfgname,
337 emsg);
338 GNUNET_free (emsg);
339 GNUNET_TESTING_interpreter_fail ();
340 return;
341 }
342
343 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
344 if (NULL == sps->ah)
345 {
346 LOG (GNUNET_ERROR_TYPE_ERROR,
347 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
348 sps->cfgname,
349 emsg);
350 GNUNET_free (emsg);
351 GNUNET_TESTING_interpreter_fail ();
352 return;
353 }
354 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
355}
356
357
358/**
359 * The cleanup function of this cmd frees resources the cmd allocated.
360 *
361 */
362static void
363start_peer_cleanup (void *cls,
364 const struct GNUNET_TESTING_Command *cmd)
365{
366 struct StartPeerState_v2 *sps = cls;
367
368 if (NULL != sps->handlers)
369 {
370 GNUNET_free (sps->handlers);
371 sps->handlers = NULL;
372 }
373 if (NULL != sps->cfg)
374 {
375 GNUNET_CONFIGURATION_destroy (sps->cfg);
376 sps->cfg = NULL;
377 }
378 GNUNET_free (sps->hello);
379 GNUNET_free (sps->connected_peers_map);
380 GNUNET_free (sps);
381}
382
383
384/**
385 * This function prepares an array with traits.
386 *
387 */
388static int
389start_peer_traits (void *cls,
390 const void **ret,
391 const char *trait,
392 unsigned int index)
393{
394 struct StartPeerState_v2 *sps = cls;
395 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
396 struct GNUNET_PeerIdentity *id = &sps->id;
397 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
398 sps->connected_peers_map;
399 char *hello = sps->hello;
400 size_t hello_size = sps->hello_size;
401
402
403 struct GNUNET_TESTING_Trait traits[] = {
404 {
405 .index = 0,
406 .trait_name = "application_handle",
407 .ptr = (const void *) ah,
408 },
409 {
410 .index = 1,
411 .trait_name = "peer_id",
412 .ptr = (const void *) id,
413 },
414 {
415 .index = 2,
416 .trait_name = "connected_peers_map",
417 .ptr = (const void *) connected_peers_map,
418 },
419 {
420 .index = 3,
421 .trait_name = "hello",
422 .ptr = (const void *) hello,
423 },
424 {
425 .index = 4,
426 .trait_name = "hello_size",
427 .ptr = (const void *) hello_size,
428 },
429 {
430 .index = 5,
431 .trait_name = "state",
432 .ptr = (const void *) sps,
433 },
434 GNUNET_TESTING_trait_end ()
435 };
436
437 return GNUNET_TESTING_get_trait (traits,
438 ret,
439 trait,
440 index);
441}
442
443
444/**
445 * Function to get the trait with the struct StartPeerState_v2.
446 *
447 * @param[out] sps struct StartPeerState_v2.
448 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
449 *
450 */
451int
452GNUNET_TRANSPORT_get_trait_state_v3 (const struct
453 GNUNET_TESTING_Command
454 *cmd,
455 struct StartPeerState_v2 **sps)
456{
457 return cmd->traits (cmd->cls,
458 (const void **) sps,
459 "state",
460 (unsigned int) 5);
461}
462
463
464/**
465 * Function to get the trait with the size of the hello.
466 *
467 * @param[out] hello_size size of hello.
468 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
469 *
470 */
471int
472GNUNET_TRANSPORT_get_trait_hello_size_v3 (const struct
473 GNUNET_TESTING_Command
474 *cmd,
475 size_t **hello_size)
476{
477 return cmd->traits (cmd->cls,
478 (const void **) hello_size,
479 "hello_size",
480 (unsigned int) 4);
481}
482
483
484/**
485 * Function to get the trait with the hello.
486 *
487 * @param[out] hello The hello for the peer.
488 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
489 *
490 */
491int
492GNUNET_TRANSPORT_get_trait_hello_v3 (const struct
493 GNUNET_TESTING_Command
494 *cmd,
495 char **hello)
496{
497 return cmd->traits (cmd->cls,
498 (const void **) hello,
499 "hello",
500 (unsigned int) 3);
501}
502
503
504/**
505 * Function to get the trait with the map of connected peers.
506 *
507 * @param[out] connected_peers_map The map with connected peers.
508 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
509 *
510 */
511int
512GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (const struct
513 GNUNET_TESTING_Command
514 *cmd,
515 struct
516 GNUNET_CONTAINER_MultiShortmap
517 *
518 *
519 connected_peers_map)
520{
521 return cmd->traits (cmd->cls,
522 (const void **) connected_peers_map,
523 "connected_peers_map",
524 (unsigned int) 2);
525}
526
527
528/**
529 * Function to get the trait with the transport application handle.
530 *
531 * @param[out] ah The application handle.
532 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
533 */
534int
535GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct
536 GNUNET_TESTING_Command *cmd,
537 struct
538 GNUNET_TRANSPORT_ApplicationHandle
539 **ah)
540{
541 return cmd->traits (cmd->cls,
542 (const void **) ah,
543 "application_handle",
544 (unsigned int) 0);
545}
546
547
548/**
549 * Function to get the trait with the peer id.
550 *
551 * @param[out] id The peer id.
552 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
553 */
554int
555GNUNET_TRANSPORT_get_trait_peer_id_v3 (const struct
556 GNUNET_TESTING_Command *cmd,
557 struct GNUNET_PeerIdentity **id)
558{
559 return cmd->traits (cmd->cls,
560 (const void **) id,
561 "peer_id",
562 (unsigned int) 1);
563}
564
565
566/**
567 * Create command.
568 *
569 * @param label name for command.
570 * @param system_label Label of the cmd to setup a test environment.
571 * @param m The number of the local node of the actual network namespace.
572 * @param n The number of the actual namespace.
573 * @param local_m Number of local nodes in each namespace.
574 * @param handlers Handler for messages received by this peer.
575 * @param cfgname Configuration file name for this peer.
576 * @return command.
577 */
578struct GNUNET_TESTING_Command
579GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label,
580 const char *system_label,
581 uint32_t no,
582 char *node_ip,
583 struct GNUNET_MQ_MessageHandler *handlers,
584 const char *cfgname)
585{
586 struct StartPeerState_v2 *sps;
587 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
588 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
589 unsigned int i;
590
591 sps = GNUNET_new (struct StartPeerState_v2);
592 sps->no = no;
593 sps->system_label = system_label;
594 sps->connected_peers_map = connected_peers_map;
595 sps->cfgname = cfgname;
596 sps->node_ip = node_ip;
597
598 if (NULL != handlers)
599 {
600 for (i = 0; NULL != handlers[i].cb; i++)
601 ;
602 sps->handlers = GNUNET_new_array (i + 1,
603 struct GNUNET_MQ_MessageHandler);
604 GNUNET_memcpy (sps->handlers,
605 handlers,
606 i * sizeof(struct GNUNET_MQ_MessageHandler));
607 }
608
609 struct GNUNET_TESTING_Command cmd = {
610 .cls = sps,
611 .label = label,
612 .run = &start_peer_run,
613 .finish = &start_peer_finish,
614 .cleanup = &start_peer_cleanup,
615 .traits = &start_peer_traits
616 };
617
618 return cmd;
619}