aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c264
1 files changed, 258 insertions, 6 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index a11d404a5..d3acd4689 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -37,6 +37,15 @@
37 37
38#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
39 39
40#define CONNECT_ADDRESS_TEMPLATE "%s-192.168.15.%u:60002"
41
42#define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-92.68.150.%u:60002"
43
44#define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-92.68.151.%u:60002"
45
46#define PREFIX_TCP "tcp"
47
48#define PREFIX_UDP "udp"
40 49
41/** 50/**
42 * Lowest port used for GNUnet testing. Should be high enough to not 51 * Lowest port used for GNUnet testing. Should be high enough to not
@@ -1900,7 +1909,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1900 unsigned int namespace_n; 1909 unsigned int namespace_n;
1901 char *rest = NULL; 1910 char *rest = NULL;
1902 char *rest2 = NULL; 1911 char *rest2 = NULL;
1903 struct GNUNET_TESTING_ADDRESS_PREFIX *prefix; 1912 struct GNUNET_TESTING_AddressPrefix *prefix;
1904 1913
1905 node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection); 1914 node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection);
1906 node_connection->node = node; 1915 node_connection->node = node;
@@ -1936,7 +1945,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1936 } 1945 }
1937 while (NULL != (token = strtok_r (NULL, ":", &rest))) 1946 while (NULL != (token = strtok_r (NULL, ":", &rest)))
1938 { 1947 {
1939 prefix = GNUNET_new (struct GNUNET_TESTING_ADDRESS_PREFIX); 1948 prefix = GNUNET_new (struct GNUNET_TESTING_AddressPrefix);
1940 token2 = strtok_r (token, "}", &rest2); 1949 token2 = strtok_r (token, "}", &rest2);
1941 if (NULL != token2) 1950 if (NULL != token2)
1942 { 1951 {
@@ -1958,13 +1967,12 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1958 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head, 1967 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head,
1959 node_connection->address_prefixes_tail, 1968 node_connection->address_prefixes_tail,
1960 prefix); 1969 prefix);
1970 LOG (GNUNET_ERROR_TYPE_ERROR,
1971 "address_prefix %s\n",
1972 prefix->address_prefix);
1961 } 1973 }
1962 1974
1963 GNUNET_free (copy); 1975 GNUNET_free (copy);
1964 LOG (GNUNET_ERROR_TYPE_ERROR,
1965 "address_prefix %s\n",
1966 prefix->address_prefix);
1967
1968 return node_connection; 1976 return node_connection;
1969} 1977}
1970 1978
@@ -2006,6 +2014,250 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node)
2006} 2014}
2007 2015
2008 2016
2017static int
2018log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2019{
2020 struct GNUNET_TESTING_NetjailNode *node = value;
2021 struct GNUNET_TESTING_NodeConnection *pos_connection;
2022 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2023
2024 LOG (GNUNET_ERROR_TYPE_ERROR,
2025 "plugin: %s space: %u node: %u global: %u\n",
2026 node->plugin,
2027 node->namespace_n,
2028 node->node_n,
2029 node->is_global);
2030
2031 for (pos_connection = node->node_connections_head; NULL != pos_connection;
2032 pos_connection = pos_connection->next)
2033 {
2034
2035 LOG (GNUNET_ERROR_TYPE_ERROR,
2036 "namespace_n: %u node_n: %u node_type: %u\n",
2037 pos_connection->namespace_n,
2038 pos_connection->node_n,
2039 pos_connection->node_type);
2040
2041 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
2042 pos_prefix =
2043 pos_prefix->next)
2044 {
2045 LOG (GNUNET_ERROR_TYPE_ERROR,
2046 "prefix: %s\n",
2047 pos_prefix->address_prefix);
2048 }
2049 }
2050 return GNUNET_YES;
2051}
2052
2053
2054static int
2055log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2056{
2057 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2058 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
2059
2060 LOG (GNUNET_ERROR_TYPE_ERROR,
2061 "router_tcp: %u router_udp: %u spaces: %u\n",
2062 router->tcp_port,
2063 router->udp_port,
2064 namespace->namespace_n);
2065 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
2066 return GNUNET_YES;
2067}
2068
2069
2070static int
2071log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
2072{
2073 LOG (GNUNET_ERROR_TYPE_ERROR,
2074 "plugin: %s spaces: %u nodes: %u known: %u\n",
2075 topology->plugin,
2076 topology->namespaces_n,
2077 topology->nodes_m,
2078 topology->nodes_x);
2079
2080 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
2081 log_namespaces, NULL);
2082 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
2083 NULL);
2084 return GNUNET_YES;
2085}
2086
2087
2088/**
2089 * Get the connections to other nodes for a specific node.
2090 *
2091 * @param num The specific node we want the connections for.
2092 * @param topology The topology we get the connections from.
2093 * @return The connections of the node.
2094 */
2095struct GNUNET_TESTING_NodeConnection *
2096GNUNET_TESTING_get_connections (unsigned int num, struct
2097 GNUNET_TESTING_NetjailTopology *topology)
2098{
2099 struct GNUNET_TESTING_NetjailNode *node;
2100 struct GNUNET_ShortHashCode *hkey;
2101 struct GNUNET_HashCode hc;
2102 struct GNUNET_TESTING_NetjailNamespace *namespace;
2103 unsigned int namespace_n, node_m;
2104
2105 log_topo (topology);
2106
2107 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2108 if (topology->nodes_x >= num)
2109 {
2110
2111 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
2112 memcpy (hkey,
2113 &hc,
2114 sizeof (*hkey));
2115 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
2116 hkey);
2117 }
2118 else
2119 {
2120 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
2121 / topology->nodes_m);
2122 LOG (GNUNET_ERROR_TYPE_ERROR,
2123 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
2124 num,
2125 topology->nodes_x,
2126 topology->nodes_m,
2127 namespace_n);
2128 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2129 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
2130 memcpy (hkey,
2131 &hc,
2132 sizeof (*hkey));
2133 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
2134 hkey);
2135 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
2136 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2137 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
2138 memcpy (hkey,
2139 &hc,
2140 sizeof (*hkey));
2141 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2142 hkey);
2143 }
2144
2145
2146 return node->node_connections_head;
2147}
2148
2149
2150/**
2151 * Retrieve the public key from the test system with the unique node id.
2152 *
2153 * @param num The unique node id.
2154 * @param tl_system The test system.
2155 * @return The peer identity wrapping the public key.
2156 */
2157struct GNUNET_PeerIdentity *
2158GNUNET_TESTING_get_pub_key (unsigned int num, struct
2159 GNUNET_TESTING_System *tl_system)
2160{
2161 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
2162 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
2163 GNUNET_CRYPTO_EddsaPublicKey);
2164 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
2165 GNUNET_CRYPTO_EddsaPrivateKey);
2166
2167 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
2168 num,
2169 peer);
2170
2171 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
2172 pub_key);
2173 peer->public_key = *pub_key;
2174 return peer;
2175}
2176
2177
2178/**
2179 * Calculate the unique id identifying a node from a given connction.
2180 *
2181 * @param node_connection The connection we calculate the id from.
2182 * @param topology The topology we get all needed information from.
2183 * @return The unique id of the node from the connection.
2184 */
2185unsigned int
2186GNUNET_TESTING_calculate_num (struct
2187 GNUNET_TESTING_NodeConnection *node_connection,
2188 struct GNUNET_TESTING_NetjailTopology *topology)
2189{
2190 unsigned int n, m, num;
2191
2192 n = node_connection->namespace_n;
2193 m = node_connection->node_n;
2194
2195 if (0 == n)
2196 num = m;
2197 else
2198 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
2199
2200 return num;
2201}
2202
2203
2204/**
2205 * Get the address for a specific communicator from a connection.
2206 *
2207 * @param connection The connection we like to have the address from.
2208 * @param prefix The communicator protocol prefix.
2209 * @return The address of the communicator.
2210 */
2211char *
2212GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
2213 char *prefix)
2214{
2215 struct GNUNET_TESTING_NetjailNode *node;
2216 char *addr;
2217 char *template;
2218
2219 LOG (GNUNET_ERROR_TYPE_ERROR,
2220 "node_n: %u\n",
2221 connection->node_n);
2222
2223 node = connection->node;
2224 if (connection->namespace_n == node->namespace_n)
2225 {
2226 template = CONNECT_ADDRESS_TEMPLATE;
2227 }
2228 else if (0 == connection->namespace_n)
2229 {
2230 template = KNOWN_CONNECT_ADDRESS_TEMPLATE;
2231 }
2232 else
2233 {
2234 template = ROUTER_CONNECT_ADDRESS_TEMPLATE;
2235 }
2236
2237 if (0 == strcmp (PREFIX_TCP, prefix))
2238 {
2239
2240 GNUNET_asprintf (&addr,
2241 template,
2242 prefix,
2243 connection->node_n);
2244 }
2245 else if (0 == strcmp (PREFIX_UDP, prefix))
2246 {
2247 GNUNET_asprintf (&addr,
2248 template,
2249 prefix,
2250 connection->node_n);
2251 }
2252 else
2253 {
2254 GNUNET_break (0);
2255 }
2256
2257 return addr;
2258}
2259
2260
2009/** 2261/**
2010 * Getting the topology from file. 2262 * Getting the topology from file.
2011 * 2263 *