diff options
Diffstat (limited to 'src/transport/transport_api_cmd_start_peer_v3.c')
-rw-r--r-- | src/transport/transport_api_cmd_start_peer_v3.c | 617 |
1 files changed, 0 insertions, 617 deletions
diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c deleted file mode 100644 index 1a19ce60e..000000000 --- a/src/transport/transport_api_cmd_start_peer_v3.c +++ /dev/null | |||
@@ -1,617 +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 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 | |||
40 | static void | ||
41 | retrieve_hello (void *cls); | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Callback delivering the hello of this peer from peerstore. | ||
46 | * | ||
47 | */ | ||
48 | static void | ||
49 | hello_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 | */ | ||
77 | static void | ||
78 | retrieve_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 | */ | ||
96 | static int | ||
97 | start_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 | */ | ||
116 | static void | ||
117 | notify_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 | */ | ||
136 | static void * | ||
137 | notify_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 | */ | ||
176 | static void | ||
177 | start_peer_run (void *cls, | ||
178 | struct GNUNET_TESTING_Interpreter *is) | ||
179 | { | ||
180 | struct StartPeerState_v2 *sps = cls; | ||
181 | char *emsg = NULL; | ||
182 | struct GNUNET_PeerIdentity dummy; | ||
183 | const struct GNUNET_TESTING_Command *system_cmd; | ||
184 | struct GNUNET_TESTING_System *tl_system; | ||
185 | char *home; | ||
186 | char *transport_unix_path; | ||
187 | char *tcp_communicator_unix_path; | ||
188 | char *udp_communicator_unix_path; | ||
189 | char *bindto; | ||
190 | |||
191 | if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) | ||
192 | { | ||
193 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
194 | "File not found: `%s'\n", | ||
195 | sps->cfgname); | ||
196 | GNUNET_TESTING_interpreter_fail (is); | ||
197 | return; | ||
198 | } | ||
199 | |||
200 | |||
201 | sps->cfg = GNUNET_CONFIGURATION_create (); | ||
202 | GNUNET_assert (GNUNET_OK == | ||
203 | GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname)); | ||
204 | |||
205 | GNUNET_asprintf (&home, | ||
206 | "$GNUNET_TMP/test-transport/api-tcp-p%u", | ||
207 | sps->no); | ||
208 | |||
209 | GNUNET_asprintf (&transport_unix_path, | ||
210 | "$GNUNET_RUNTIME_DIR/tng-p%u.sock", | ||
211 | sps->no); | ||
212 | |||
213 | GNUNET_asprintf (&tcp_communicator_unix_path, | ||
214 | "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", | ||
215 | sps->no); | ||
216 | |||
217 | GNUNET_asprintf (&udp_communicator_unix_path, | ||
218 | "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", | ||
219 | sps->no); | ||
220 | |||
221 | GNUNET_asprintf (&bindto, | ||
222 | "%s:60002", | ||
223 | sps->node_ip); | ||
224 | |||
225 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
226 | "node_ip %s\n", | ||
227 | bindto); | ||
228 | |||
229 | GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME", | ||
230 | home); | ||
231 | GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH", | ||
232 | transport_unix_path); | ||
233 | GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", | ||
234 | "BINDTO", | ||
235 | bindto); | ||
236 | GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp", | ||
237 | "BINDTO", | ||
238 | bindto); | ||
239 | GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", | ||
240 | "UNIXPATH", | ||
241 | tcp_communicator_unix_path); | ||
242 | GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp", | ||
243 | "UNIXPATH", | ||
244 | udp_communicator_unix_path); | ||
245 | |||
246 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
247 | 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 (is); | ||
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 (is); | ||
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 (is); | ||
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 (is); | ||
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 | ¬ify_connect, | ||
319 | ¬ify_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 (is); | ||
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 (is); | ||
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 (is); | ||
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 | */ | ||
362 | static void | ||
363 | start_peer_cleanup (void *cls) | ||
364 | { | ||
365 | struct StartPeerState_v2 *sps = cls; | ||
366 | |||
367 | if (NULL != sps->handlers) | ||
368 | { | ||
369 | GNUNET_free (sps->handlers); | ||
370 | sps->handlers = NULL; | ||
371 | } | ||
372 | if (NULL != sps->cfg) | ||
373 | { | ||
374 | GNUNET_CONFIGURATION_destroy (sps->cfg); | ||
375 | sps->cfg = NULL; | ||
376 | } | ||
377 | GNUNET_free (sps->hello); | ||
378 | GNUNET_free (sps->connected_peers_map); | ||
379 | GNUNET_free (sps); | ||
380 | } | ||
381 | |||
382 | |||
383 | /** | ||
384 | * This function prepares an array with traits. | ||
385 | * | ||
386 | */ | ||
387 | static int | ||
388 | start_peer_traits (void *cls, | ||
389 | const void **ret, | ||
390 | const char *trait, | ||
391 | unsigned int index) | ||
392 | { | ||
393 | struct StartPeerState_v2 *sps = cls; | ||
394 | struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah; | ||
395 | struct GNUNET_PeerIdentity *id = &sps->id; | ||
396 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = | ||
397 | sps->connected_peers_map; | ||
398 | char *hello = sps->hello; | ||
399 | size_t hello_size = sps->hello_size; | ||
400 | |||
401 | |||
402 | struct GNUNET_TESTING_Trait traits[] = { | ||
403 | { | ||
404 | .index = 0, | ||
405 | .trait_name = "application_handle", | ||
406 | .ptr = (const void *) ah, | ||
407 | }, | ||
408 | { | ||
409 | .index = 1, | ||
410 | .trait_name = "peer_id", | ||
411 | .ptr = (const void *) id, | ||
412 | }, | ||
413 | { | ||
414 | .index = 2, | ||
415 | .trait_name = "connected_peers_map", | ||
416 | .ptr = (const void *) connected_peers_map, | ||
417 | }, | ||
418 | { | ||
419 | .index = 3, | ||
420 | .trait_name = "hello", | ||
421 | .ptr = (const void *) hello, | ||
422 | }, | ||
423 | { | ||
424 | .index = 4, | ||
425 | .trait_name = "hello_size", | ||
426 | .ptr = (const void *) hello_size, | ||
427 | }, | ||
428 | { | ||
429 | .index = 5, | ||
430 | .trait_name = "state", | ||
431 | .ptr = (const void *) sps, | ||
432 | }, | ||
433 | GNUNET_TESTING_trait_end () | ||
434 | }; | ||
435 | |||
436 | return GNUNET_TESTING_get_trait (traits, | ||
437 | ret, | ||
438 | trait, | ||
439 | index); | ||
440 | } | ||
441 | |||
442 | |||
443 | /** | ||
444 | * Function to get the trait with the struct StartPeerState_v2. | ||
445 | * | ||
446 | * @param[out] sps struct StartPeerState_v2. | ||
447 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
448 | * | ||
449 | */ | ||
450 | int | ||
451 | GNUNET_TRANSPORT_get_trait_state_v3 (const struct | ||
452 | GNUNET_TESTING_Command | ||
453 | *cmd, | ||
454 | struct StartPeerState_v2 **sps) | ||
455 | { | ||
456 | return cmd->traits (cmd->cls, | ||
457 | (const void **) sps, | ||
458 | "state", | ||
459 | (unsigned int) 5); | ||
460 | } | ||
461 | |||
462 | |||
463 | /** | ||
464 | * Function to get the trait with the size of the hello. | ||
465 | * | ||
466 | * @param[out] hello_size size of hello. | ||
467 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
468 | * | ||
469 | */ | ||
470 | int | ||
471 | GNUNET_TRANSPORT_get_trait_hello_size_v3 (const struct | ||
472 | GNUNET_TESTING_Command | ||
473 | *cmd, | ||
474 | size_t **hello_size) | ||
475 | { | ||
476 | return cmd->traits (cmd->cls, | ||
477 | (const void **) hello_size, | ||
478 | "hello_size", | ||
479 | (unsigned int) 4); | ||
480 | } | ||
481 | |||
482 | |||
483 | /** | ||
484 | * Function to get the trait with the hello. | ||
485 | * | ||
486 | * @param[out] hello The hello for the peer. | ||
487 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
488 | * | ||
489 | */ | ||
490 | int | ||
491 | GNUNET_TRANSPORT_get_trait_hello_v3 (const struct | ||
492 | GNUNET_TESTING_Command | ||
493 | *cmd, | ||
494 | char **hello) | ||
495 | { | ||
496 | return cmd->traits (cmd->cls, | ||
497 | (const void **) hello, | ||
498 | "hello", | ||
499 | (unsigned int) 3); | ||
500 | } | ||
501 | |||
502 | |||
503 | /** | ||
504 | * Function to get the trait with the map of connected peers. | ||
505 | * | ||
506 | * @param[out] connected_peers_map The map with connected peers. | ||
507 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
508 | * | ||
509 | */ | ||
510 | int | ||
511 | GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (const struct | ||
512 | GNUNET_TESTING_Command | ||
513 | *cmd, | ||
514 | struct | ||
515 | GNUNET_CONTAINER_MultiShortmap | ||
516 | * | ||
517 | * | ||
518 | connected_peers_map) | ||
519 | { | ||
520 | return cmd->traits (cmd->cls, | ||
521 | (const void **) connected_peers_map, | ||
522 | "connected_peers_map", | ||
523 | (unsigned int) 2); | ||
524 | } | ||
525 | |||
526 | |||
527 | /** | ||
528 | * Function to get the trait with the transport application handle. | ||
529 | * | ||
530 | * @param[out] ah The application handle. | ||
531 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
532 | */ | ||
533 | int | ||
534 | GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct | ||
535 | GNUNET_TESTING_Command *cmd, | ||
536 | struct | ||
537 | GNUNET_TRANSPORT_ApplicationHandle | ||
538 | **ah) | ||
539 | { | ||
540 | return cmd->traits (cmd->cls, | ||
541 | (const void **) ah, | ||
542 | "application_handle", | ||
543 | (unsigned int) 0); | ||
544 | } | ||
545 | |||
546 | |||
547 | /** | ||
548 | * Function to get the trait with the peer id. | ||
549 | * | ||
550 | * @param[out] id The peer id. | ||
551 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
552 | */ | ||
553 | int | ||
554 | GNUNET_TRANSPORT_get_trait_peer_id_v3 (const struct | ||
555 | GNUNET_TESTING_Command *cmd, | ||
556 | struct GNUNET_PeerIdentity **id) | ||
557 | { | ||
558 | return cmd->traits (cmd->cls, | ||
559 | (const void **) id, | ||
560 | "peer_id", | ||
561 | (unsigned int) 1); | ||
562 | } | ||
563 | |||
564 | |||
565 | /** | ||
566 | * Create command. | ||
567 | * | ||
568 | * @param label name for command. | ||
569 | * @param system_label Label of the cmd to setup a test environment. | ||
570 | * @param m The number of the local node of the actual network namespace. | ||
571 | * @param n The number of the actual namespace. | ||
572 | * @param local_m Number of local nodes in each namespace. | ||
573 | * @param handlers Handler for messages received by this peer. | ||
574 | * @param cfgname Configuration file name for this peer. | ||
575 | * @return command. | ||
576 | */ | ||
577 | struct GNUNET_TESTING_Command | ||
578 | GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label, | ||
579 | const char *system_label, | ||
580 | uint32_t no, | ||
581 | char *node_ip, | ||
582 | struct GNUNET_MQ_MessageHandler *handlers, | ||
583 | const char *cfgname) | ||
584 | { | ||
585 | struct StartPeerState_v2 *sps; | ||
586 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = | ||
587 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | ||
588 | unsigned int i; | ||
589 | |||
590 | sps = GNUNET_new (struct StartPeerState_v2); | ||
591 | sps->no = no; | ||
592 | sps->system_label = system_label; | ||
593 | sps->connected_peers_map = connected_peers_map; | ||
594 | sps->cfgname = cfgname; | ||
595 | sps->node_ip = node_ip; | ||
596 | |||
597 | if (NULL != handlers) | ||
598 | { | ||
599 | for (i = 0; NULL != handlers[i].cb; i++) | ||
600 | ; | ||
601 | sps->handlers = GNUNET_new_array (i + 1, | ||
602 | struct GNUNET_MQ_MessageHandler); | ||
603 | GNUNET_memcpy (sps->handlers, | ||
604 | handlers, | ||
605 | i * sizeof(struct GNUNET_MQ_MessageHandler)); | ||
606 | } | ||
607 | |||
608 | struct GNUNET_TESTING_Command cmd = { | ||
609 | .cls = sps, | ||
610 | .label = label, | ||
611 | .run = &start_peer_run, | ||
612 | .cleanup = &start_peer_cleanup, | ||
613 | .traits = &start_peer_traits | ||
614 | }; | ||
615 | |||
616 | return cmd; | ||
617 | } | ||