diff options
author | t3sserakt <t3ss@posteo.de> | 2021-10-25 14:49:05 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-10-25 14:49:05 +0200 |
commit | 1609d627e509043a946f611d7589105cfae2364d (patch) | |
tree | d6022bea17730f96c7d87b0a1c8f602717edb25d /src/transport | |
parent | 513f23e74650db9408267e82ef8bcb8f770d1015 (diff) | |
download | gnunet-1609d627e509043a946f611d7589105cfae2364d.tar.gz gnunet-1609d627e509043a946f611d7589105cfae2364d.zip |
changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send.c | 10 | ||||
-rw-r--r-- | src/transport/test_transport_plugin_cmd_udp_backchannel.c | 42 | ||||
-rw-r--r-- | src/transport/transport-testing-cmds.h | 25 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_backchannel_check.c | 51 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers.c | 258 |
5 files changed, 83 insertions, 303 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index 8889f9d06..f0b47084b 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c | |||
@@ -37,6 +37,7 @@ | |||
37 | 37 | ||
38 | #define BASE_DIR "testdir" | 38 | #define BASE_DIR "testdir" |
39 | 39 | ||
40 | #define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf" | ||
40 | 41 | ||
41 | struct TestState | 42 | struct TestState |
42 | { | 43 | { |
@@ -154,8 +155,8 @@ notify_connect (void *cls, | |||
154 | { | 155 | { |
155 | struct ConnectPeersState *cps; | 156 | struct ConnectPeersState *cps; |
156 | 157 | ||
157 | GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers, | 158 | GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers, |
158 | &cps); | 159 | &cps); |
159 | void *ret = NULL; | 160 | void *ret = NULL; |
160 | 161 | ||
161 | cps->notify_connect (cps, | 162 | cps->notify_connect (cps, |
@@ -203,7 +204,7 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
203 | "start-peer", | 204 | "start-peer", |
204 | "system-create", | 205 | "system-create", |
205 | num, | 206 | num, |
206 | NULL); | 207 | topology); |
207 | 208 | ||
208 | 209 | ||
209 | 210 | ||
@@ -257,7 +258,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
257 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | 258 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", |
258 | "start-peer"), | 259 | "start-peer"), |
259 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | 260 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", |
260 | "system-create") | 261 | "system-create"), |
262 | GNUNET_TESTING_cmd_end () | ||
261 | }; | 263 | }; |
262 | 264 | ||
263 | GNUNET_TESTING_run (commands, | 265 | GNUNET_TESTING_run (commands, |
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index b0ca37447..ee6dc0274 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c | |||
@@ -62,9 +62,8 @@ struct TestState | |||
62 | 62 | ||
63 | static struct GNUNET_TESTING_Command block_send; | 63 | static struct GNUNET_TESTING_Command block_send; |
64 | 64 | ||
65 | static struct GNUNET_TESTING_Command block_receive; | ||
66 | |||
67 | static struct GNUNET_TESTING_Command connect_peers; | 65 | static struct GNUNET_TESTING_Command connect_peers; |
66 | static struct GNUNET_TESTING_Command local_prepared; | ||
68 | 67 | ||
69 | 68 | ||
70 | /** | 69 | /** |
@@ -89,14 +88,14 @@ static void | |||
89 | handle_test (void *cls, | 88 | handle_test (void *cls, |
90 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 89 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
91 | { | 90 | { |
92 | struct GNUNET_TESTING_AsyncContext *ac; | 91 | // struct GNUNET_TESTING_AsyncContext *ac; |
93 | 92 | ||
94 | GNUNET_TESTING_get_trait_async_context (&block_receive, | 93 | /*GNUNET_TESTING_get_trait_async_context (&block_receive, |
95 | &ac); | 94 | &ac); |
96 | if ((NULL == ac) || (NULL == ac->cont)) | 95 | if ((NULL == ac) || (NULL == ac->cont)) |
97 | GNUNET_TESTING_async_fail (ac); | 96 | GNUNET_TESTING_async_fail (ac); |
98 | else | 97 | else |
99 | GNUNET_TESTING_async_finish (ac); | 98 | GNUNET_TESTING_async_finish (ac);*/ |
100 | } | 99 | } |
101 | 100 | ||
102 | 101 | ||
@@ -136,8 +135,11 @@ handle_result (void *cls, | |||
136 | rv); | 135 | rv); |
137 | reply = GNUNET_TESTING_send_local_test_finished_msg (rv); | 136 | reply = GNUNET_TESTING_send_local_test_finished_msg (rv); |
138 | 137 | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
139 | "message prepared\n"); | ||
139 | ts->write_message (reply, | 140 | ts->write_message (reply, |
140 | ntohs (reply->size)); | 141 | ntohs (reply->size)); |
142 | |||
141 | GNUNET_free (ts->testdir); | 143 | GNUNET_free (ts->testdir); |
142 | GNUNET_free (ts->cfgname); | 144 | GNUNET_free (ts->cfgname); |
143 | GNUNET_free (ts); | 145 | GNUNET_free (ts); |
@@ -155,8 +157,8 @@ notify_connect (void *cls, | |||
155 | { | 157 | { |
156 | struct ConnectPeersState *cps; | 158 | struct ConnectPeersState *cps; |
157 | 159 | ||
158 | GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers, | 160 | GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers, |
159 | &cps); | 161 | &cps); |
160 | void *ret = NULL; | 162 | void *ret = NULL; |
161 | 163 | ||
162 | cps->notify_connect (cps, | 164 | cps->notify_connect (cps, |
@@ -171,7 +173,14 @@ notify_connect (void *cls, | |||
171 | static void | 173 | static void |
172 | all_local_tests_prepared () | 174 | all_local_tests_prepared () |
173 | { | 175 | { |
174 | are_all_local_tests_prepared = GNUNET_YES; | 176 | struct LocalPreparedState *lfs; |
177 | GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, | ||
178 | &lfs); | ||
179 | |||
180 | if ((NULL == &lfs->ac) || (NULL == lfs->ac.cont)) | ||
181 | GNUNET_TESTING_async_fail (&lfs->ac); | ||
182 | else | ||
183 | GNUNET_TESTING_async_finish (&lfs->ac); | ||
175 | } | 184 | } |
176 | 185 | ||
177 | /** | 186 | /** |
@@ -212,13 +221,14 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
212 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | 221 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; |
213 | 222 | ||
214 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); | 223 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); |
215 | block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
216 | "block-receive"); | ||
217 | connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", | 224 | connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", |
218 | "start-peer", | 225 | "start-peer", |
219 | "system-create", | 226 | "system-create", |
220 | num, | 227 | num, |
221 | NULL); | 228 | topology); |
229 | local_prepared = GNUNET_TESTING_cmd_local_test_prepared ( | ||
230 | "local-test-prepared", | ||
231 | write_message); | ||
222 | 232 | ||
223 | GNUNET_asprintf (&ts->cfgname, | 233 | GNUNET_asprintf (&ts->cfgname, |
224 | "test_transport_api2_tcp_node1.conf"); | 234 | "test_transport_api2_tcp_node1.conf"); |
@@ -266,16 +276,16 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
266 | m_int, | 276 | m_int, |
267 | n_int, | 277 | n_int, |
268 | topology), | 278 | topology), |
269 | GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared", | 279 | local_prepared, |
270 | write_message, | ||
271 | &are_all_local_tests_prepared), | ||
272 | block_receive, | ||
273 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | 280 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", |
274 | "start-peer"), | 281 | "start-peer"), |
275 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | 282 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", |
276 | "system-create") | 283 | "system-create"), |
284 | GNUNET_TESTING_cmd_end () | ||
277 | }; | 285 | }; |
278 | 286 | ||
287 | ts->write_message = write_message; | ||
288 | |||
279 | GNUNET_TESTING_run (commands, | 289 | GNUNET_TESTING_run (commands, |
280 | GNUNET_TIME_UNIT_FOREVER_REL, | 290 | GNUNET_TIME_UNIT_FOREVER_REL, |
281 | &handle_result, | 291 | &handle_result, |
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h index f6e34df62..d6bb46f7d 100644 --- a/src/transport/transport-testing-cmds.h +++ b/src/transport/transport-testing-cmds.h | |||
@@ -182,7 +182,7 @@ struct StartPeerState | |||
182 | * | 182 | * |
183 | */ | 183 | */ |
184 | int | 184 | int |
185 | GNUNET_TESTING_get_trait_connect_peer_state ( | 185 | GNUNET_TRANSPORT_get_trait_connect_peer_state ( |
186 | const struct GNUNET_TESTING_Command *cmd, | 186 | const struct GNUNET_TESTING_Command *cmd, |
187 | struct ConnectPeersState **cps); | 187 | struct ConnectPeersState **cps); |
188 | 188 | ||
@@ -234,6 +234,29 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label, | |||
234 | uint32_t num); | 234 | uint32_t num); |
235 | 235 | ||
236 | 236 | ||
237 | /** | ||
238 | * Create command. | ||
239 | * | ||
240 | * @param label name for command. | ||
241 | * @param start_peer_label Label of the cmd to start a peer. | ||
242 | * @param create_label Label of the cmd to create the testing system. | ||
243 | * @param num Number globally identifying the node. | ||
244 | * @param node_n The number of the node in a network namespace. | ||
245 | * @param namespace_n The number of the network namespace. | ||
246 | * @param The topology for the test setup. | ||
247 | * @return command. | ||
248 | */ | ||
249 | struct GNUNET_TESTING_Command | ||
250 | GNUNET_TRANSPORT_cmd_backchannel_check (const char *label, | ||
251 | const char *start_peer_label, | ||
252 | const char *create_label, | ||
253 | uint32_t num, | ||
254 | unsigned int node_n, | ||
255 | unsigned int namespace_n, | ||
256 | struct GNUNET_TESTING_NetjailTopology * | ||
257 | topology); | ||
258 | |||
259 | |||
237 | 260 | ||
238 | 261 | ||
239 | 262 | ||
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c index 5cc13dbfa..03b231347 100644 --- a/src/transport/transport_api_cmd_backchannel_check.c +++ b/src/transport/transport_api_cmd_backchannel_check.c | |||
@@ -51,6 +51,11 @@ | |||
51 | struct CheckState | 51 | struct CheckState |
52 | { | 52 | { |
53 | /** | 53 | /** |
54 | * Context for our asynchronous completion. | ||
55 | */ | ||
56 | struct GNUNET_TESTING_AsyncContext ac; | ||
57 | |||
58 | /** | ||
54 | * The number of the node in a network namespace. | 59 | * The number of the node in a network namespace. |
55 | */ | 60 | */ |
56 | unsigned int node_n; | 61 | unsigned int node_n; |
@@ -119,11 +124,6 @@ struct CheckState | |||
119 | * Stream to read log file lines. | 124 | * Stream to read log file lines. |
120 | */ | 125 | */ |
121 | FILE *stream; | 126 | FILE *stream; |
122 | |||
123 | /** | ||
124 | * Did we get all bachchannel messages. | ||
125 | */ | ||
126 | enum GNUNET_GenericReturnValue finished; | ||
127 | }; | 127 | }; |
128 | 128 | ||
129 | /** | 129 | /** |
@@ -195,7 +195,7 @@ read_from_log (void *cls) | |||
195 | strcmp ( | 195 | strcmp ( |
196 | "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp", | 196 | "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp", |
197 | cs->search_string[i])); | 197 | cs->search_string[i])); |
198 | cs->finished = GNUNET_YES; | 198 | GNUNET_TESTING_async_finish (&cs->ac); |
199 | fclose (cs->stream); | 199 | fclose (cs->stream); |
200 | return; | 200 | return; |
201 | } | 201 | } |
@@ -396,7 +396,6 @@ add_search_string (struct CheckState *cs, const struct | |||
396 | */ | 396 | */ |
397 | static void | 397 | static void |
398 | backchannel_check_run (void *cls, | 398 | backchannel_check_run (void *cls, |
399 | const struct GNUNET_TESTING_Command *cmd, | ||
400 | struct GNUNET_TESTING_Interpreter *is) | 399 | struct GNUNET_TESTING_Interpreter *is) |
401 | { | 400 | { |
402 | struct CheckState *cs = cls; | 401 | struct CheckState *cs = cls; |
@@ -418,12 +417,13 @@ backchannel_check_run (void *cls, | |||
418 | const struct GNUNET_TESTING_NetjailNode *node; | 417 | const struct GNUNET_TESTING_NetjailNode *node; |
419 | const struct GNUNET_TESTING_NetjailNamespace *namespace; | 418 | const struct GNUNET_TESTING_NetjailNamespace *namespace; |
420 | 419 | ||
421 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command ( | 420 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, |
422 | cs->start_peer_label); | 421 | cs->start_peer_label); |
423 | GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd, | 422 | GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, |
424 | &ah); | 423 | &ah); |
425 | 424 | ||
426 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (cs->create_label); | 425 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, |
426 | cs->create_label); | ||
427 | GNUNET_TESTING_get_trait_test_system (system_cmd, | 427 | GNUNET_TESTING_get_trait_test_system (system_cmd, |
428 | &tl_system); | 428 | &tl_system); |
429 | 429 | ||
@@ -524,28 +524,8 @@ backchannel_check_run (void *cls, | |||
524 | cs); | 524 | cs); |
525 | } | 525 | } |
526 | else | 526 | else |
527 | cs->finished = GNUNET_YES; | 527 | GNUNET_TESTING_async_finish (&cs->ac); |
528 | |||
529 | } | ||
530 | |||
531 | 528 | ||
532 | /** | ||
533 | * The finish function of this cmd will check if the peers we are trying to | ||
534 | * connect to are in the connected peers map of the start peer cmd for this peer. | ||
535 | * | ||
536 | */ | ||
537 | static int | ||
538 | backchannel_check_finish (void *cls, | ||
539 | GNUNET_SCHEDULER_TaskCallback cont, | ||
540 | void *cont_cls) | ||
541 | { | ||
542 | struct CheckState *cs = cls; | ||
543 | |||
544 | if (cs->finished) | ||
545 | { | ||
546 | cont (cont_cls); | ||
547 | } | ||
548 | return cs->finished; | ||
549 | } | 529 | } |
550 | 530 | ||
551 | 531 | ||
@@ -568,8 +548,7 @@ backchannel_check_traits (void *cls, | |||
568 | * | 548 | * |
569 | */ | 549 | */ |
570 | static void | 550 | static void |
571 | backchannel_check_cleanup (void *cls, | 551 | backchannel_check_cleanup (void *cls) |
572 | const struct GNUNET_TESTING_Command *cmd) | ||
573 | { | 552 | { |
574 | struct ConnectPeersState *cs = cls; | 553 | struct ConnectPeersState *cs = cls; |
575 | 554 | ||
@@ -613,7 +592,7 @@ GNUNET_TRANSPORT_cmd_backchannel_check (const char *label, | |||
613 | .cls = cs, | 592 | .cls = cs, |
614 | .label = label, | 593 | .label = label, |
615 | .run = &backchannel_check_run, | 594 | .run = &backchannel_check_run, |
616 | .finish = &backchannel_check_finish, | 595 | .ac = &cs->ac, |
617 | .cleanup = &backchannel_check_cleanup, | 596 | .cleanup = &backchannel_check_cleanup, |
618 | .traits = &backchannel_check_traits | 597 | .traits = &backchannel_check_traits |
619 | }; | 598 | }; |
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index 2e51363f6..017d1bca3 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c | |||
@@ -36,242 +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 | |||
56 | |||
57 | |||
58 | static struct GNUNET_PeerIdentity * | ||
59 | get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system) | ||
60 | { | ||
61 | struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); | ||
62 | struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct | ||
63 | GNUNET_CRYPTO_EddsaPublicKey); | ||
64 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct | ||
65 | GNUNET_CRYPTO_EddsaPrivateKey); | ||
66 | |||
67 | priv_key = GNUNET_TESTING_hostkey_get (tl_system, | ||
68 | num, | ||
69 | peer); | ||
70 | |||
71 | GNUNET_CRYPTO_eddsa_key_get_public (priv_key, | ||
72 | pub_key); | ||
73 | peer->public_key = *pub_key; | ||
74 | return peer; | ||
75 | } | ||
76 | |||
77 | |||
78 | static int | ||
79 | log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value) | ||
80 | { | ||
81 | struct GNUNET_TESTING_NetjailNode *node = value; | ||
82 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
83 | struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; | ||
84 | |||
85 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
86 | "plugin: %s space: %u node: %u global: %u\n", | ||
87 | node->plugin, | ||
88 | node->namespace_n, | ||
89 | node->node_n, | ||
90 | node->is_global); | ||
91 | |||
92 | for (pos_connection = node->node_connections_head; NULL != pos_connection; | ||
93 | pos_connection = pos_connection->next) | ||
94 | { | ||
95 | |||
96 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
97 | "namespace_n: %u node_n: %u node_type: %u\n", | ||
98 | pos_connection->namespace_n, | ||
99 | pos_connection->node_n, | ||
100 | pos_connection->node_type); | ||
101 | |||
102 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; | ||
103 | pos_prefix = | ||
104 | pos_prefix->next) | ||
105 | { | ||
106 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
107 | "prefix: %s\n", | ||
108 | pos_prefix->address_prefix); | ||
109 | } | ||
110 | } | ||
111 | return GNUNET_YES; | ||
112 | } | ||
113 | |||
114 | |||
115 | static int | ||
116 | log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value) | ||
117 | { | ||
118 | struct GNUNET_TESTING_NetjailNamespace *namespace = value; | ||
119 | struct GNUNET_TESTING_NetjailRouter *router = namespace->router; | ||
120 | |||
121 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
122 | "router_tcp: %u router_udp: %u spaces: %u\n", | ||
123 | router->tcp_port, | ||
124 | router->udp_port, | ||
125 | namespace->namespace_n); | ||
126 | GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL); | ||
127 | return GNUNET_YES; | ||
128 | } | ||
129 | |||
130 | |||
131 | static int | ||
132 | log_topo (struct GNUNET_TESTING_NetjailTopology *topology) | ||
133 | { | ||
134 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
135 | "plugin: %s spaces: %u nodes: %u known: %u\n", | ||
136 | topology->plugin, | ||
137 | topology->namespaces_n, | ||
138 | topology->nodes_m, | ||
139 | topology->nodes_x); | ||
140 | |||
141 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces, | ||
142 | log_namespaces, NULL); | ||
143 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes, | ||
144 | NULL); | ||
145 | return GNUNET_YES; | ||
146 | } | ||
147 | |||
148 | |||
149 | static struct GNUNET_TESTING_NodeConnection * | ||
150 | get_connections (unsigned int num, struct | ||
151 | GNUNET_TESTING_NetjailTopology *topology) | ||
152 | { | ||
153 | struct GNUNET_TESTING_NetjailNode *node; | ||
154 | struct GNUNET_ShortHashCode *hkey; | ||
155 | struct GNUNET_HashCode hc; | ||
156 | struct GNUNET_TESTING_NetjailNamespace *namespace; | ||
157 | unsigned int namespace_n, node_m; | ||
158 | |||
159 | log_topo (topology); | ||
160 | |||
161 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
162 | if (topology->nodes_x >= num) | ||
163 | { | ||
164 | |||
165 | GNUNET_CRYPTO_hash (&num, sizeof(num), &hc); | ||
166 | memcpy (hkey, | ||
167 | &hc, | ||
168 | sizeof (*hkey)); | ||
169 | node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, | ||
170 | hkey); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | namespace_n = (unsigned int) floor ((num - topology->nodes_x) | ||
175 | / topology->nodes_m); | ||
176 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
177 | "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n", | ||
178 | num, | ||
179 | topology->nodes_x, | ||
180 | topology->nodes_m, | ||
181 | namespace_n); | ||
182 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
183 | GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc); | ||
184 | memcpy (hkey, | ||
185 | &hc, | ||
186 | sizeof (*hkey)); | ||
187 | namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, | ||
188 | hkey); | ||
189 | node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1); | ||
190 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
191 | GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc); | ||
192 | memcpy (hkey, | ||
193 | &hc, | ||
194 | sizeof (*hkey)); | ||
195 | node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, | ||
196 | hkey); | ||
197 | } | ||
198 | |||
199 | |||
200 | return node->node_connections_head; | ||
201 | } | ||
202 | |||
203 | |||
204 | static unsigned int | ||
205 | calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection, | ||
206 | struct GNUNET_TESTING_NetjailTopology *topology) | ||
207 | { | ||
208 | unsigned int n, m, num; | ||
209 | |||
210 | n = node_connection->namespace_n; | ||
211 | m = node_connection->node_n; | ||
212 | |||
213 | if (0 == n) | ||
214 | num = m; | ||
215 | else | ||
216 | num = (n - 1) * topology->nodes_m + m + topology->nodes_x; | ||
217 | |||
218 | return num; | ||
219 | } | ||
220 | |||
221 | |||
222 | static char * | ||
223 | get_address (struct GNUNET_TESTING_NodeConnection *connection, | ||
224 | char *prefix) | ||
225 | { | ||
226 | struct GNUNET_TESTING_NetjailNode *node; | ||
227 | char *addr; | ||
228 | |||
229 | node = connection->node; | ||
230 | if (connection->namespace_n == node->namespace_n) | ||
231 | { | ||
232 | if (0 == strcmp (PREFIX_TCP, prefix)) | ||
233 | { | ||
234 | |||
235 | GNUNET_asprintf (&addr, | ||
236 | CONNECT_ADDRESS_TEMPLATE_TCP, | ||
237 | connection->node_n); | ||
238 | } | ||
239 | else if (0 == strcmp (PREFIX_UDP, prefix)) | ||
240 | { | ||
241 | GNUNET_asprintf (&addr, | ||
242 | CONNECT_ADDRESS_TEMPLATE_UDP, | ||
243 | connection->node_n); | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | GNUNET_break (0); | ||
248 | } | ||
249 | } | ||
250 | else | ||
251 | { | ||
252 | if (0 == strcmp (PREFIX_TCP, prefix)) | ||
253 | { | ||
254 | |||
255 | GNUNET_asprintf (&addr, | ||
256 | ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP, | ||
257 | connection->namespace_n); | ||
258 | } | ||
259 | else if (0 == strcmp (PREFIX_UDP, prefix)) | ||
260 | { | ||
261 | GNUNET_asprintf (&addr, | ||
262 | ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP, | ||
263 | connection->namespace_n); | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | GNUNET_break (0); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | return addr; | ||
272 | } | ||
273 | |||
274 | |||
275 | /** | 39 | /** |
276 | * The run method of this cmd will connect to peers. | 40 | * The run method of this cmd will connect to peers. |
277 | * | 41 | * |
@@ -292,7 +56,7 @@ connect_peers_run (void *cls, | |||
292 | enum GNUNET_NetworkType nt = 0; | 56 | enum GNUNET_NetworkType nt = 0; |
293 | uint32_t num; | 57 | uint32_t num; |
294 | struct GNUNET_TESTING_NodeConnection *pos_connection; | 58 | struct GNUNET_TESTING_NodeConnection *pos_connection; |
295 | struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; | 59 | struct GNUNET_TESTING_AddressPrefix *pos_prefix; |
296 | unsigned int con_num = 0; | 60 | unsigned int con_num = 0; |
297 | 61 | ||
298 | cps->is = is; | 62 | cps->is = is; |
@@ -308,13 +72,14 @@ connect_peers_run (void *cls, | |||
308 | 72 | ||
309 | cps->tl_system = tl_system; | 73 | cps->tl_system = tl_system; |
310 | 74 | ||
311 | cps->node_connections_head = get_connections (cps->num, cps->topology); | 75 | cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num, |
76 | cps->topology); | ||
312 | 77 | ||
313 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | 78 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; |
314 | pos_connection = pos_connection->next) | 79 | pos_connection = pos_connection->next) |
315 | { | 80 | { |
316 | con_num++; | 81 | con_num++; |
317 | num = calculate_num (pos_connection, cps->topology); | 82 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); |
318 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; | 83 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; |
319 | pos_prefix = | 84 | pos_prefix = |
320 | pos_prefix->next) | 85 | pos_prefix->next) |
@@ -324,9 +89,10 @@ connect_peers_run (void *cls, | |||
324 | "prefix: %s\n", | 89 | "prefix: %s\n", |
325 | pos_prefix->address_prefix); | 90 | pos_prefix->address_prefix); |
326 | 91 | ||
327 | addr = get_address (pos_connection, pos_prefix->address_prefix); | 92 | addr = GNUNET_TESTING_get_address (pos_connection, |
93 | pos_prefix->address_prefix); | ||
328 | 94 | ||
329 | peer = get_pub_key (num, tl_system); | 95 | peer = GNUNET_TESTING_get_pub_key (num, tl_system); |
330 | 96 | ||
331 | LOG (GNUNET_ERROR_TYPE_ERROR, | 97 | LOG (GNUNET_ERROR_TYPE_ERROR, |
332 | "num: %u pub_key %s addr: %s\n", | 98 | "num: %u pub_key %s addr: %s\n", |
@@ -365,8 +131,8 @@ notify_connect (void *cls, | |||
365 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | 131 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; |
366 | pos_connection = pos_connection->next) | 132 | pos_connection = pos_connection->next) |
367 | { | 133 | { |
368 | num = calculate_num (pos_connection, cps->topology); | 134 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); |
369 | peer_connection = get_pub_key (num, cps->tl_system); | 135 | peer_connection = GNUNET_TESTING_get_pub_key (num, cps->tl_system); |
370 | if (0 == GNUNET_memcmp (peer, | 136 | if (0 == GNUNET_memcmp (peer, |
371 | peer_connection)) | 137 | peer_connection)) |
372 | con_num++; | 138 | con_num++; |
@@ -399,7 +165,7 @@ connect_peers_cleanup (void *cls) | |||
399 | * This function prepares an array with traits. | 165 | * This function prepares an array with traits. |
400 | * | 166 | * |
401 | */ | 167 | */ |
402 | static int | 168 | enum GNUNET_GenericReturnValue |
403 | connect_peers_traits (void *cls, | 169 | connect_peers_traits (void *cls, |
404 | const void **ret, | 170 | const void **ret, |
405 | const char *trait, | 171 | const char *trait, |
@@ -428,8 +194,8 @@ connect_peers_traits (void *cls, | |||
428 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | 194 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. |
429 | * | 195 | * |
430 | */ | 196 | */ |
431 | int | 197 | enum GNUNET_GenericReturnValue |
432 | GNUNET_TESTING_get_trait_connect_peer_state ( | 198 | GNUNET_TRANSPORT_get_trait_connect_peer_state ( |
433 | const struct GNUNET_TESTING_Command *cmd, | 199 | const struct GNUNET_TESTING_Command *cmd, |
434 | struct ConnectPeersState **cps) | 200 | struct ConnectPeersState **cps) |
435 | { | 201 | { |