diff options
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers.c')
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers.c | 258 |
1 files changed, 12 insertions, 246 deletions
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 | { |