diff options
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers_v3.c')
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers_v3.c | 251 |
1 files changed, 12 insertions, 239 deletions
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c index e90781637..2273d9852 100644 --- a/src/transport/transport_api_cmd_connecting_peers_v3.c +++ b/src/transport/transport_api_cmd_connecting_peers_v3.c | |||
@@ -36,22 +36,6 @@ | |||
36 | */ | 36 | */ |
37 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 37 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
38 | 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 | /** | 39 | /** |
56 | * Struct to store information needed in callbacks. | 40 | * Struct to store information needed in callbacks. |
57 | * | 41 | * |
@@ -101,222 +85,6 @@ struct ConnectPeersState | |||
101 | }; | 85 | }; |
102 | 86 | ||
103 | 87 | ||
104 | static struct GNUNET_PeerIdentity * | ||
105 | get_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 | |||
124 | static int | ||
125 | log_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 | |||
161 | static int | ||
162 | log_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 | |||
177 | static int | ||
178 | log_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 | |||
195 | static struct GNUNET_TESTING_NodeConnection * | ||
196 | get_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 | |||
250 | static unsigned int | ||
251 | calculate_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 | |||
267 | static char * | ||
268 | get_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 | /** | 88 | /** |
321 | * The run method of this cmd will connect to peers. | 89 | * The run method of this cmd will connect to peers. |
322 | * | 90 | * |
@@ -338,7 +106,7 @@ connect_peers_run (void *cls, | |||
338 | enum GNUNET_NetworkType nt = 0; | 106 | enum GNUNET_NetworkType nt = 0; |
339 | uint32_t num; | 107 | uint32_t num; |
340 | struct GNUNET_TESTING_NodeConnection *pos_connection; | 108 | struct GNUNET_TESTING_NodeConnection *pos_connection; |
341 | struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; | 109 | struct GNUNET_TESTING_AddressPrefix *pos_prefix; |
342 | unsigned int con_num = 0; | 110 | unsigned int con_num = 0; |
343 | 111 | ||
344 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); | 112 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); |
@@ -351,13 +119,14 @@ connect_peers_run (void *cls, | |||
351 | 119 | ||
352 | cps->tl_system = tl_system; | 120 | cps->tl_system = tl_system; |
353 | 121 | ||
354 | cps->node_connections_head = get_connections (cps->num, cps->topology); | 122 | cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num, |
123 | cps->topology); | ||
355 | 124 | ||
356 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | 125 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; |
357 | pos_connection = pos_connection->next) | 126 | pos_connection = pos_connection->next) |
358 | { | 127 | { |
359 | con_num++; | 128 | con_num++; |
360 | num = calculate_num (pos_connection, cps->topology); | 129 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); |
361 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; | 130 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; |
362 | pos_prefix = | 131 | pos_prefix = |
363 | pos_prefix->next) | 132 | pos_prefix->next) |
@@ -367,9 +136,10 @@ connect_peers_run (void *cls, | |||
367 | "prefix: %s\n", | 136 | "prefix: %s\n", |
368 | pos_prefix->address_prefix); | 137 | pos_prefix->address_prefix); |
369 | 138 | ||
370 | addr = get_address (pos_connection, pos_prefix->address_prefix); | 139 | addr = GNUNET_TESTING_get_address (pos_connection, |
140 | pos_prefix->address_prefix); | ||
371 | 141 | ||
372 | peer = get_pub_key (num, tl_system); | 142 | peer = GNUNET_TESTING_get_pub_key (num, tl_system); |
373 | 143 | ||
374 | LOG (GNUNET_ERROR_TYPE_ERROR, | 144 | LOG (GNUNET_ERROR_TYPE_ERROR, |
375 | "num: %u pub_key %s addr: %s\n", | 145 | "num: %u pub_key %s addr: %s\n", |
@@ -417,8 +187,8 @@ connect_peers_finish (void *cls, | |||
417 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | 187 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; |
418 | pos_connection = pos_connection->next) | 188 | pos_connection = pos_connection->next) |
419 | { | 189 | { |
420 | num = calculate_num (pos_connection, cps->topology); | 190 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); |
421 | peer = get_pub_key (num, cps->tl_system); | 191 | peer = GNUNET_TESTING_get_pub_key (num, cps->tl_system); |
422 | GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc); | 192 | GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc); |
423 | memcpy (key, | 193 | memcpy (key, |
424 | &hc, | 194 | &hc, |
@@ -476,6 +246,9 @@ connect_peers_cleanup (void *cls, | |||
476 | * | 246 | * |
477 | * @param label name for command. | 247 | * @param label name for command. |
478 | * @param start_peer_label Label of the cmd to start a peer. | 248 | * @param start_peer_label Label of the cmd to start a peer. |
249 | * @param create_label Label of the cmd to create the testing system. | ||
250 | * @param num Number globally identifying the node. | ||
251 | * @param The topology for the test setup. | ||
479 | * @return command. | 252 | * @return command. |
480 | */ | 253 | */ |
481 | struct GNUNET_TESTING_Command | 254 | struct GNUNET_TESTING_Command |