diff options
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/Makefile.am | 29 | ||||
-rw-r--r-- | src/transport/plugin_cmd_simple_send.c | 122 | ||||
-rw-r--r-- | src/transport/test_transport_api_cmd_simple_send.c | 80 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers.c | 178 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_send_simple.c | 136 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_start_peer.c | 558 |
6 files changed, 1102 insertions, 1 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index bc3004a70..9f680ad3b 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -167,6 +167,9 @@ libgnunettransporttesting_la_LDFLAGS = \ | |||
167 | $(GN_LIB_LDFLAGS) | 167 | $(GN_LIB_LDFLAGS) |
168 | 168 | ||
169 | libgnunettransporttesting2_la_SOURCES = \ | 169 | libgnunettransporttesting2_la_SOURCES = \ |
170 | transport_api_cmd_connecting_peers.c \ | ||
171 | transport_api_cmd_start_peer.c \ | ||
172 | transport_api_cmd_send_simple.c \ | ||
170 | transport-testing2.c transport-testing2.h \ | 173 | transport-testing2.c transport-testing2.h \ |
171 | transport-testing-filenames2.c \ | 174 | transport-testing-filenames2.c \ |
172 | transport-testing-loggers2.c \ | 175 | transport-testing-loggers2.c \ |
@@ -394,7 +397,19 @@ plugin_LTLIBRARIES = \ | |||
394 | $(HTTP_SERVER_PLUGIN_LA) \ | 397 | $(HTTP_SERVER_PLUGIN_LA) \ |
395 | $(HTTPS_SERVER_PLUGIN_LA) \ | 398 | $(HTTPS_SERVER_PLUGIN_LA) \ |
396 | $(WLAN_PLUGIN_LA) \ | 399 | $(WLAN_PLUGIN_LA) \ |
397 | $(BT_PLUGIN_LA) | 400 | $(BT_PLUGIN_LA) |
401 | # libgnunet_plugin_simple_send.la | ||
402 | |||
403 | # libgnunet_plugin_cmd_simple_send_la_SOURCES = \ | ||
404 | # plugin_cmd_simple_send.c | ||
405 | # libgnunet_plugin_cmd_simple_send_la_LIBADD = \ | ||
406 | # $(top_builddir)/src/util/libgnunetutil.la \ | ||
407 | # $(top_builddir)/src/testing/libgnunettesting.la \ | ||
408 | # $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
409 | # $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
410 | # $(LTLIBINTL) | ||
411 | # libgnunet_plugin_cmd_simple_send_la_LDFLAGS = \ | ||
412 | # $(GN_PLUGIN_LDFLAGS) | ||
398 | 413 | ||
399 | if HAVE_EXPERIMENTAL | 414 | if HAVE_EXPERIMENTAL |
400 | plugin_LTLIBRARIES += libgnunet_plugin_transport_udp.la | 415 | plugin_LTLIBRARIES += libgnunet_plugin_transport_udp.la |
@@ -541,6 +556,7 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \ | |||
541 | 556 | ||
542 | if HAVE_TESTING | 557 | if HAVE_TESTING |
543 | check_PROGRAMS = \ | 558 | check_PROGRAMS = \ |
559 | test_transport_api_cmd_simple_send \ | ||
544 | test_transport_address_switch_tcp \ | 560 | test_transport_address_switch_tcp \ |
545 | test_transport_testing_startstop \ | 561 | test_transport_testing_startstop \ |
546 | test_transport_testing_restart \ | 562 | test_transport_testing_restart \ |
@@ -629,6 +645,7 @@ endif | |||
629 | if ENABLE_TEST_RUN | 645 | if ENABLE_TEST_RUN |
630 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 646 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
631 | TESTS = \ | 647 | TESTS = \ |
648 | test_transport_api_cmd_simple_send \ | ||
632 | test_transport_address_switch_tcp \ | 649 | test_transport_address_switch_tcp \ |
633 | $(HTTP_SWITCH) \ | 650 | $(HTTP_SWITCH) \ |
634 | $(HTTPS_SWITCH) \ | 651 | $(HTTPS_SWITCH) \ |
@@ -705,6 +722,16 @@ TESTS += \ | |||
705 | endif | 722 | endif |
706 | endif | 723 | endif |
707 | 724 | ||
725 | test_transport_api_cmd_simple_send_SOURCES = \ | ||
726 | test_transport_api_cmd_simple_send.c | ||
727 | test_transport_api_cmd_simple_send_LDADD = \ | ||
728 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
729 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
730 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
731 | libgnunettransport.la \ | ||
732 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
733 | libgnunettransporttesting.la | ||
734 | |||
708 | test_transport_testing_startstop_SOURCES = \ | 735 | test_transport_testing_startstop_SOURCES = \ |
709 | test_transport_testing_startstop.c | 736 | test_transport_testing_startstop.c |
710 | test_transport_testing_startstop_LDADD = \ | 737 | test_transport_testing_startstop_LDADD = \ |
diff --git a/src/transport/plugin_cmd_simple_send.c b/src/transport/plugin_cmd_simple_send.c new file mode 100644 index 000000000..ed3481c00 --- /dev/null +++ b/src/transport/plugin_cmd_simple_send.c | |||
@@ -0,0 +1,122 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2013, 2014 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 testbed/plugin_testcmd.c | ||
23 | * @brief a plugin to provide the API for running test cases. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testbed_ng_service.h" | ||
30 | |||
31 | /** | ||
32 | * Generic logging shortcut | ||
33 | */ | ||
34 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
35 | |||
36 | #define BASE_DIR "testdir" | ||
37 | |||
38 | |||
39 | static void | ||
40 | start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip, | ||
41 | char *node_ip, | ||
42 | char *m, | ||
43 | char *n) | ||
44 | { | ||
45 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | ||
46 | char *testdir; | ||
47 | |||
48 | testdir = GNUNET_malloc (strlen (basedir) + strlen (m) + strlen (n) | ||
49 | + 1); | ||
50 | |||
51 | strcpy (testdir, BASE_DIR); | ||
52 | strcat (testdir, m); | ||
53 | strcat (testdir, n); | ||
54 | |||
55 | struct GNUNET_TESTING_Command commands[] = { | ||
56 | GNUNET_TESTING_cmd_system_create ("system-create-1", | ||
57 | testdir), | ||
58 | GNUNET_TESTING_cmd_start_peer ("start-peer-1", | ||
59 | "system-create-1", | ||
60 | m, | ||
61 | n, | ||
62 | struct GNUNET_MQ_MessageHandler *handlers, | ||
63 | const char *cfgname), | ||
64 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1", | ||
65 | write_message), | ||
66 | GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1", | ||
67 | &are_all_peers_started), | ||
68 | GNUNET_TESTING_cmd_connect_peers ("connect-peers-1", | ||
69 | "start-peer-1", | ||
70 | "this is useless"), | ||
71 | /*GNUNET_TESTING_cmd_send_simple ("send-simple-1", | ||
72 | char *m, | ||
73 | char *n, | ||
74 | uint32_t num, | ||
75 | const char *peer1_label, | ||
76 | const char *peer2_label),*/ | ||
77 | GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1", | ||
78 | write_message) | ||
79 | }; | ||
80 | |||
81 | GNUNET_TESTING_run (NULL, | ||
82 | commands, | ||
83 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
84 | |||
85 | } | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Entry point for the plugin. | ||
90 | * | ||
91 | * @param cls NULL | ||
92 | * @return the exported block API | ||
93 | */ | ||
94 | void * | ||
95 | libgnunet_plugin_testcmd_init (void *cls) | ||
96 | { | ||
97 | struct GNUNET_TESTING_PluginFunctions *api; | ||
98 | |||
99 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | ||
100 | api->start_testcase = &start_testcase; | ||
101 | api->all_peers_started = &all_peers_started; | ||
102 | return api; | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Exit point from the plugin. | ||
108 | * | ||
109 | * @param cls the return value from #libgnunet_plugin_block_test_init | ||
110 | * @return NULL | ||
111 | */ | ||
112 | void * | ||
113 | libgnunet_plugin_testcmd_done (void *cls) | ||
114 | { | ||
115 | struct GNUNET_TESTING_PluginFunctions *api = cls; | ||
116 | |||
117 | GNUNET_free (api); | ||
118 | return NULL; | ||
119 | } | ||
120 | |||
121 | |||
122 | /* end of plugin_testcmd.c */ | ||
diff --git a/src/transport/test_transport_api_cmd_simple_send.c b/src/transport/test_transport_api_cmd_simple_send.c new file mode 100644 index 000000000..36c7d23b2 --- /dev/null +++ b/src/transport/test_transport_api_cmd_simple_send.c | |||
@@ -0,0 +1,80 @@ | |||
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 transport/test_transport_api_cmd_simple_send.c | ||
23 | * @brief Test case executing a script which sends a test message between two peers. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_testbed_ng_service.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Main function to run the test cases. | ||
34 | * | ||
35 | * @param cls not used. | ||
36 | * | ||
37 | */ | ||
38 | static void | ||
39 | run (void *cls) | ||
40 | { | ||
41 | struct GNUNET_TESTING_Command commands[] = { | ||
42 | GNUNET_TESTBED_cmd_netjail_start ("netjail-start-1", | ||
43 | "2", | ||
44 | "2"), | ||
45 | GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1", | ||
46 | "2", | ||
47 | "2", | ||
48 | "libgnunet_plugin_cmd_simple_send"), | ||
49 | GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed", | ||
50 | "netjail-start-testbed-1", | ||
51 | "2", | ||
52 | "2"), | ||
53 | GNUNET_TESTBED_cmd_netjail_stop ("netjail-stop-1", | ||
54 | "2", | ||
55 | "2"), | ||
56 | GNUNET_TESTING_cmd_end () | ||
57 | }; | ||
58 | |||
59 | GNUNET_TESTING_run (NULL, | ||
60 | commands, | ||
61 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
62 | } | ||
63 | |||
64 | |||
65 | int | ||
66 | main (int argc, | ||
67 | char *const *argv) | ||
68 | { | ||
69 | int rv = 0; | ||
70 | |||
71 | GNUNET_log_setup ("test-netjail", | ||
72 | "DEBUG", | ||
73 | NULL); | ||
74 | GNUNET_SCHEDULER_run (&run, | ||
75 | NULL); | ||
76 | |||
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
78 | "Test finished!\n"); | ||
79 | return rv; | ||
80 | } | ||
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c new file mode 100644 index 000000000..297b90864 --- /dev/null +++ b/src/transport/transport_api_cmd_connecting_peers.c | |||
@@ -0,0 +1,178 @@ | |||
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_transport_application_service.h" | ||
30 | #include "gnunet_hello_lib.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
36 | |||
37 | struct ConnectPeersState | ||
38 | { | ||
39 | const char *peer1_label; | ||
40 | |||
41 | const char *peer2_label; | ||
42 | }; | ||
43 | |||
44 | |||
45 | static void | ||
46 | connect_peers_run (void *cls, | ||
47 | const struct GNUNET_TESTING_Command *cmd, | ||
48 | struct GNUNET_TESTING_Interpreter *is) | ||
49 | { | ||
50 | struct ConnectPeersState *cps = cls; | ||
51 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
52 | const struct GNUNET_TESTING_Command *peer2_cmd; | ||
53 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
54 | struct GNUNET_PeerIdentity *id; | ||
55 | char *addr; | ||
56 | struct GNUNET_TIME_Absolute t; | ||
57 | char *hello; | ||
58 | size_t *hello_size; | ||
59 | enum GNUNET_NetworkType nt = 0; | ||
60 | |||
61 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); | ||
62 | GNUNET_TESTING_get_trait_application_handle (peer1_cmd, | ||
63 | &ah); | ||
64 | |||
65 | GNUNET_TESTING_get_trait_hello (peer1_cmd, | ||
66 | &hello); | ||
67 | |||
68 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
69 | "hello: %s\n", | ||
70 | hello); | ||
71 | |||
72 | // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers. | ||
73 | // --------------------------------------------- | ||
74 | /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label); | ||
75 | GNUNET_TESTING_get_trait_peer_id (peer2_cmd, | ||
76 | &id); | ||
77 | GNUNET_TESTING_get_trait_hello (peer2_cmd, | ||
78 | &hello); | ||
79 | GNUNET_TESTING_get_trait_hello_size (peer2_cmd, | ||
80 | &hello_size); | ||
81 | |||
82 | addr = GNUNET_HELLO_extract_address (hello, | ||
83 | *hello_size, | ||
84 | id, | ||
85 | &nt, | ||
86 | &t); | ||
87 | |||
88 | //---------------------------------------------- | ||
89 | |||
90 | GNUNET_TRANSPORT_application_validate (ah, | ||
91 | id, | ||
92 | nt, | ||
93 | addr);*/ | ||
94 | } | ||
95 | |||
96 | |||
97 | static int | ||
98 | connect_peers_finish (void *cls, | ||
99 | GNUNET_SCHEDULER_TaskCallback cont, | ||
100 | void *cont_cls) | ||
101 | { | ||
102 | /*struct ConnectPeersState *cps = cls; | ||
103 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
104 | const struct GNUNET_TESTING_Command *peer2_cmd; | ||
105 | struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map; | ||
106 | unsigned int ret; | ||
107 | struct GNUNET_PeerIdentity *id; | ||
108 | |||
109 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); | ||
110 | GNUNET_TESTING_get_trait_peer_id (peer1_cmd, | ||
111 | &id); | ||
112 | |||
113 | peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label); | ||
114 | GNUNET_TESTING_get_trait_connected_peers_map (peer2_cmd, | ||
115 | &connected_peers_map); | ||
116 | |||
117 | ret = GNUNET_CONTAINER_multipeermap_contains (connected_peers_map, | ||
118 | id); | ||
119 | |||
120 | if (GNUNET_YES == ret) | ||
121 | { | ||
122 | cont (cont_cls); | ||
123 | } | ||
124 | |||
125 | return ret;*/ | ||
126 | return GNUNET_OK; | ||
127 | } | ||
128 | |||
129 | |||
130 | static int | ||
131 | connect_peers_traits (void *cls, | ||
132 | const void **ret, | ||
133 | const char *trait, | ||
134 | unsigned int index) | ||
135 | { | ||
136 | return GNUNET_OK; | ||
137 | } | ||
138 | |||
139 | |||
140 | static void | ||
141 | connect_peers_cleanup (void *cls, | ||
142 | const struct GNUNET_TESTING_Command *cmd) | ||
143 | { | ||
144 | struct ConnectPeersState *cps = cls; | ||
145 | |||
146 | GNUNET_free (cps); | ||
147 | } | ||
148 | |||
149 | |||
150 | /** | ||
151 | * Create command. | ||
152 | * | ||
153 | * @param label name for command. | ||
154 | * @return command. | ||
155 | */ | ||
156 | struct GNUNET_TESTING_Command | ||
157 | GNUNET_TESTING_cmd_connect_peers (const char *label, | ||
158 | const char *peer1_label, | ||
159 | const char *peer2_label) | ||
160 | { | ||
161 | struct ConnectPeersState *cps; | ||
162 | |||
163 | cps = GNUNET_new (struct ConnectPeersState); | ||
164 | cps->peer1_label = peer1_label; | ||
165 | cps->peer2_label = peer2_label; | ||
166 | |||
167 | |||
168 | struct GNUNET_TESTING_Command cmd = { | ||
169 | .cls = cps, | ||
170 | .label = label, | ||
171 | .run = &connect_peers_run, | ||
172 | .finish = &connect_peers_finish, | ||
173 | .cleanup = &connect_peers_cleanup, | ||
174 | .traits = &connect_peers_traits | ||
175 | }; | ||
176 | |||
177 | return cmd; | ||
178 | } | ||
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c new file mode 100644 index 000000000..e4ac199d1 --- /dev/null +++ b/src/transport/transport_api_cmd_send_simple.c | |||
@@ -0,0 +1,136 @@ | |||
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 "transport-testing.h" | ||
30 | |||
31 | struct SendSimpleState | ||
32 | { | ||
33 | char *m; | ||
34 | |||
35 | char *n; | ||
36 | |||
37 | uint32_t num; | ||
38 | |||
39 | const char *peer1_label; | ||
40 | |||
41 | const char *peer2_label; | ||
42 | }; | ||
43 | |||
44 | static int | ||
45 | send_simple_traits (void *cls, | ||
46 | const void **ret, | ||
47 | const char *trait, | ||
48 | unsigned int index) | ||
49 | { | ||
50 | return GNUNET_OK; | ||
51 | } | ||
52 | |||
53 | |||
54 | static void | ||
55 | send_simple_cleanup (void *cls, | ||
56 | const struct GNUNET_TESTING_Command *cmd) | ||
57 | { | ||
58 | struct SendSimpleState *sss = cls; | ||
59 | |||
60 | GNUNET_free (sss); | ||
61 | } | ||
62 | |||
63 | |||
64 | static void | ||
65 | send_simple_run (void *cls, | ||
66 | const struct GNUNET_TESTING_Command *cmd, | ||
67 | struct GNUNET_TESTING_Interpreter *is) | ||
68 | { | ||
69 | struct SendSimpleState *sss = cls; | ||
70 | struct GNUNET_MQ_Envelope *env; | ||
71 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | ||
72 | struct GNUNET_MQ_Handle *mq; | ||
73 | struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map; | ||
74 | struct GNUNET_PeerIdentity *id; | ||
75 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
76 | const struct GNUNET_TESTING_Command *peer2_cmd; | ||
77 | |||
78 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label); | ||
79 | GNUNET_TESTING_get_trait_connected_peers_map (peer1_cmd, | ||
80 | &connected_peers_map); | ||
81 | |||
82 | peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer2_label); | ||
83 | GNUNET_TESTING_get_trait_peer_id (peer2_cmd, | ||
84 | &id); | ||
85 | |||
86 | mq = GNUNET_CONTAINER_multipeermap_get (connected_peers_map, | ||
87 | id); | ||
88 | |||
89 | env = GNUNET_MQ_msg_extra (test, | ||
90 | 2600 - sizeof(*test), | ||
91 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); | ||
92 | test->num = htonl (sss->num); | ||
93 | memset (&test[1], | ||
94 | sss->num, | ||
95 | 2600 - sizeof(*test)); | ||
96 | /*GNUNET_MQ_notify_sent (env, | ||
97 | cont, | ||
98 | cont_cls);*/ | ||
99 | GNUNET_MQ_send (mq, | ||
100 | env); | ||
101 | |||
102 | |||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Create command. | ||
108 | * | ||
109 | * @param label name for command. | ||
110 | * @return command. | ||
111 | */ | ||
112 | struct GNUNET_TESTING_Command | ||
113 | GNUNET_TESTING_cmd_send_simple (const char *label, | ||
114 | char *m, | ||
115 | char *n, | ||
116 | uint32_t num, | ||
117 | const char *peer1_label, | ||
118 | const char *peer2_label) | ||
119 | { | ||
120 | struct SendSimpleState *sss; | ||
121 | |||
122 | sss = GNUNET_new (struct SendSimpleState); | ||
123 | sss->m = m; | ||
124 | sss->n = n; | ||
125 | sss->num = num; | ||
126 | |||
127 | struct GNUNET_TESTING_Command cmd = { | ||
128 | .cls = sss, | ||
129 | .label = label, | ||
130 | .run = &send_simple_run, | ||
131 | .cleanup = &send_simple_cleanup, | ||
132 | .traits = &send_simple_traits | ||
133 | }; | ||
134 | |||
135 | return cmd; | ||
136 | } | ||
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c new file mode 100644 index 000000000..4077b7561 --- /dev/null +++ b/src/transport/transport_api_cmd_start_peer.c | |||
@@ -0,0 +1,558 @@ | |||
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 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
36 | |||
37 | struct StartPeerState | ||
38 | { | ||
39 | /** | ||
40 | * Receive callback | ||
41 | */ | ||
42 | struct GNUNET_MQ_MessageHandler *handlers; | ||
43 | |||
44 | const char *cfgname; | ||
45 | |||
46 | /** | ||
47 | * Peer's configuration | ||
48 | */ | ||
49 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
50 | |||
51 | struct GNUNET_TESTING_Peer *peer; | ||
52 | |||
53 | /** | ||
54 | * Peer identity | ||
55 | */ | ||
56 | struct GNUNET_PeerIdentity *id; | ||
57 | |||
58 | /** | ||
59 | * Peer's transport service handle | ||
60 | */ | ||
61 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
62 | |||
63 | /** | ||
64 | * Application handle | ||
65 | */ | ||
66 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
67 | |||
68 | /** | ||
69 | * Peer's PEERSTORE Handle | ||
70 | */ | ||
71 | struct GNUNET_PEERSTORE_Handle *ph; | ||
72 | |||
73 | /** | ||
74 | * Hello get task | ||
75 | */ | ||
76 | struct GNUNET_SCHEDULER_Task *rh_task; | ||
77 | |||
78 | /** | ||
79 | * Peer's transport get hello handle to retrieve peer's HELLO message | ||
80 | */ | ||
81 | struct GNUNET_PEERSTORE_IterateContext *pic; | ||
82 | |||
83 | /** | ||
84 | * Hello | ||
85 | */ | ||
86 | char *hello; | ||
87 | |||
88 | /** | ||
89 | * Hello size | ||
90 | */ | ||
91 | size_t hello_size; | ||
92 | |||
93 | char *m; | ||
94 | |||
95 | char *n; | ||
96 | |||
97 | unsigned int finished; | ||
98 | |||
99 | const char *system_label; | ||
100 | |||
101 | /** | ||
102 | * An unique number to identify the peer | ||
103 | */ | ||
104 | unsigned int no; | ||
105 | |||
106 | struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map; | ||
107 | |||
108 | struct GNUNET_TESTING_System *tl_system; | ||
109 | |||
110 | }; | ||
111 | |||
112 | |||
113 | static void | ||
114 | retrieve_hello (void *cls); | ||
115 | |||
116 | static void | ||
117 | hello_iter_cb (void *cb_cls, | ||
118 | const struct GNUNET_PEERSTORE_Record *record, | ||
119 | const char *emsg) | ||
120 | { | ||
121 | struct StartPeerState *sps = cb_cls; | ||
122 | if (NULL == record) | ||
123 | { | ||
124 | sps->pic = NULL; | ||
125 | sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); | ||
126 | return; | ||
127 | } | ||
128 | // Check record type et al? | ||
129 | sps->hello_size = record->value_size; | ||
130 | sps->hello = GNUNET_malloc (sps->hello_size); | ||
131 | memcpy (sps->hello, record->value, sps->hello_size); | ||
132 | sps->hello[sps->hello_size - 1] = '\0'; | ||
133 | |||
134 | GNUNET_PEERSTORE_iterate_cancel (sps->pic); | ||
135 | sps->pic = NULL; | ||
136 | sps->finished = GNUNET_YES; | ||
137 | } | ||
138 | |||
139 | |||
140 | static void | ||
141 | retrieve_hello (void *cls) | ||
142 | { | ||
143 | struct StartPeerState *sps = cls; | ||
144 | sps->rh_task = NULL; | ||
145 | sps->pic = GNUNET_PEERSTORE_iterate (sps->ph, | ||
146 | "transport", | ||
147 | sps->id, | ||
148 | GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, | ||
149 | hello_iter_cb, | ||
150 | sps); | ||
151 | |||
152 | } | ||
153 | |||
154 | static int | ||
155 | start_peer_finish (void *cls, | ||
156 | GNUNET_SCHEDULER_TaskCallback cont, | ||
157 | void *cont_cls) | ||
158 | { | ||
159 | struct StartPeerState *sps = cls; | ||
160 | |||
161 | if (GNUNET_YES == sps->finished) | ||
162 | { | ||
163 | cont (cont_cls); | ||
164 | } | ||
165 | |||
166 | return sps->finished; | ||
167 | } | ||
168 | |||
169 | |||
170 | static void | ||
171 | notify_disconnect (void *cls, | ||
172 | const struct GNUNET_PeerIdentity *peer, | ||
173 | void *handler_cls) | ||
174 | { | ||
175 | struct StartPeerState *sps = cls; | ||
176 | |||
177 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
178 | "Peer %s disconnected from peer %u (`%s')\n", | ||
179 | GNUNET_i2s (peer), | ||
180 | sps->no, | ||
181 | GNUNET_i2s (sps->id)); | ||
182 | |||
183 | } | ||
184 | |||
185 | |||
186 | static void * | ||
187 | notify_connect (void *cls, | ||
188 | const struct GNUNET_PeerIdentity *peer, | ||
189 | struct GNUNET_MQ_Handle *mq) | ||
190 | { | ||
191 | struct StartPeerState *sps = cls; | ||
192 | |||
193 | |||
194 | void *ret; | ||
195 | |||
196 | |||
197 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
198 | "Peer %s connected to peer %u (`%s')\n", | ||
199 | GNUNET_i2s (peer), | ||
200 | sps->no, | ||
201 | GNUNET_i2s (sps->id)); | ||
202 | |||
203 | GNUNET_CONTAINER_multipeermap_put (sps->connected_peers_map, | ||
204 | peer, | ||
205 | mq, | ||
206 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
207 | |||
208 | // TODO what does the handler function need? | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | |||
213 | static void | ||
214 | start_peer_run (void *cls, | ||
215 | const struct GNUNET_TESTING_Command *cmd, | ||
216 | struct GNUNET_TESTING_Interpreter *is) | ||
217 | { | ||
218 | struct StartPeerState *sps = cls; | ||
219 | char *emsg = NULL; | ||
220 | struct GNUNET_PeerIdentity dummy; | ||
221 | const struct GNUNET_TESTING_Command *system_cmd; | ||
222 | struct GNUNET_TESTING_System *tl_system; | ||
223 | |||
224 | if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) | ||
225 | { | ||
226 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
227 | "File not found: `%s'\n", | ||
228 | sps->cfgname); | ||
229 | GNUNET_TESTING_interpreter_fail (); | ||
230 | return; | ||
231 | } | ||
232 | |||
233 | |||
234 | sps->cfg = GNUNET_CONFIGURATION_create (); | ||
235 | GNUNET_assert (GNUNET_OK == | ||
236 | GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname)); | ||
237 | |||
238 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label); | ||
239 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
240 | &tl_system); | ||
241 | |||
242 | sps->tl_system = tl_system; | ||
243 | |||
244 | if (GNUNET_SYSERR == | ||
245 | GNUNET_TESTING_configuration_create (tl_system, | ||
246 | sps->cfg)) | ||
247 | { | ||
248 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
249 | "Testing library failed to create unique configuration based on `%s'\n", | ||
250 | sps->cfgname); | ||
251 | GNUNET_CONFIGURATION_destroy (sps->cfg); | ||
252 | GNUNET_TESTING_interpreter_fail (); | ||
253 | } | ||
254 | |||
255 | sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, | ||
256 | sps->cfg, | ||
257 | sps->no, | ||
258 | NULL, | ||
259 | &emsg); | ||
260 | if (NULL == sps->peer) | ||
261 | { | ||
262 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
263 | "Testing library failed to create unique configuration based on `%s': `%s'\n", | ||
264 | sps->cfgname, | ||
265 | emsg); | ||
266 | GNUNET_free (emsg); | ||
267 | GNUNET_TESTING_interpreter_fail (); | ||
268 | } | ||
269 | |||
270 | if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer)) | ||
271 | { | ||
272 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
273 | "Testing library failed to create unique configuration based on `%s'\n", | ||
274 | sps->cfgname); | ||
275 | GNUNET_free (emsg); | ||
276 | GNUNET_TESTING_interpreter_fail (); | ||
277 | } | ||
278 | |||
279 | memset (&dummy, | ||
280 | '\0', | ||
281 | sizeof(dummy)); | ||
282 | GNUNET_TESTING_peer_get_identity (sps->peer, | ||
283 | sps->id); | ||
284 | if (0 == memcmp (&dummy, | ||
285 | &sps->id, | ||
286 | sizeof(struct GNUNET_PeerIdentity))) | ||
287 | { | ||
288 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
289 | "Testing library failed to obtain peer identity for peer %u\n", | ||
290 | sps->no); | ||
291 | GNUNET_free (emsg); | ||
292 | GNUNET_TESTING_interpreter_fail (); | ||
293 | } | ||
294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
295 | "Peer %u configured with identity `%s'\n", | ||
296 | sps->no, | ||
297 | GNUNET_i2s_full (sps->id)); | ||
298 | sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg, | ||
299 | NULL, | ||
300 | sps->handlers, | ||
301 | sps, | ||
302 | ¬ify_connect, | ||
303 | ¬ify_disconnect); | ||
304 | if (NULL == sps->th) | ||
305 | { | ||
306 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
307 | "Failed to connect to transport service for peer `%s': `%s'\n", | ||
308 | sps->cfgname, | ||
309 | emsg); | ||
310 | GNUNET_free (emsg); | ||
311 | GNUNET_TESTING_interpreter_fail (); | ||
312 | } | ||
313 | sps->ph = GNUNET_PEERSTORE_connect (sps->cfg); | ||
314 | if (NULL == sps->th) | ||
315 | { | ||
316 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
317 | "Failed to connect to peerstore service for peer `%s': `%s'\n", | ||
318 | sps->cfgname, | ||
319 | emsg); | ||
320 | GNUNET_free (emsg); | ||
321 | GNUNET_TESTING_interpreter_fail (); | ||
322 | } | ||
323 | sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg); | ||
324 | if (NULL == sps->ah) | ||
325 | { | ||
326 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
327 | "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n", | ||
328 | sps->cfgname, | ||
329 | emsg); | ||
330 | GNUNET_free (emsg); | ||
331 | GNUNET_TESTING_interpreter_fail (); | ||
332 | } | ||
333 | sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); | ||
334 | } | ||
335 | |||
336 | |||
337 | static void | ||
338 | start_peer_cleanup (void *cls, | ||
339 | const struct GNUNET_TESTING_Command *cmd) | ||
340 | { | ||
341 | struct StartPeerState *sps = cls; | ||
342 | |||
343 | if (NULL != sps->rh_task) | ||
344 | GNUNET_SCHEDULER_cancel (sps->rh_task); | ||
345 | sps->rh_task = NULL; | ||
346 | if (NULL != sps->ah) | ||
347 | { | ||
348 | GNUNET_TRANSPORT_application_done (sps->ah); | ||
349 | sps->ah = NULL; | ||
350 | } | ||
351 | if (NULL != sps->ph) | ||
352 | { | ||
353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
354 | "Disconnecting from PEERSTORE service\n"); | ||
355 | GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO); | ||
356 | sps->ph = NULL; | ||
357 | } | ||
358 | if (NULL != sps->handlers) | ||
359 | { | ||
360 | GNUNET_free (sps->handlers); | ||
361 | sps->handlers = NULL; | ||
362 | } | ||
363 | if (NULL != sps->cfg) | ||
364 | { | ||
365 | GNUNET_CONFIGURATION_destroy (sps->cfg); | ||
366 | sps->cfg = NULL; | ||
367 | } | ||
368 | if (NULL != sps->peer) | ||
369 | { | ||
370 | if (GNUNET_OK != | ||
371 | GNUNET_TESTING_peer_stop (sps->peer)) | ||
372 | { | ||
373 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
374 | "Testing lib failed to stop peer %u (`%s')\n", | ||
375 | sps->no, | ||
376 | GNUNET_i2s (sps->id)); | ||
377 | } | ||
378 | GNUNET_TESTING_peer_destroy (sps->peer); | ||
379 | sps->peer = NULL; | ||
380 | } | ||
381 | if (NULL != sps->th) | ||
382 | { | ||
383 | GNUNET_TRANSPORT_core_disconnect (sps->th); | ||
384 | sps->th = NULL; | ||
385 | } | ||
386 | if (NULL != sps->tl_system) | ||
387 | { | ||
388 | GNUNET_free (sps->tl_system); | ||
389 | } | ||
390 | GNUNET_free (sps->hello); | ||
391 | GNUNET_free (sps->connected_peers_map); | ||
392 | GNUNET_free (sps); | ||
393 | } | ||
394 | |||
395 | |||
396 | static int | ||
397 | start_peer_traits (void *cls, | ||
398 | const void **ret, | ||
399 | const char *trait, | ||
400 | unsigned int index) | ||
401 | { | ||
402 | struct StartPeerState *sps = cls; | ||
403 | struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah; | ||
404 | struct GNUNET_PeerIdentity *id = sps->id; | ||
405 | struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map = | ||
406 | sps->connected_peers_map; | ||
407 | char *hello = sps->hello; | ||
408 | size_t hello_size = sps->hello_size; | ||
409 | |||
410 | |||
411 | struct GNUNET_TESTING_Trait traits[] = { | ||
412 | { | ||
413 | .index = 0, | ||
414 | .trait_name = "application_handle", | ||
415 | .ptr = (const void *) ah, | ||
416 | }, | ||
417 | { | ||
418 | .index = 1, | ||
419 | .trait_name = "peer_id", | ||
420 | .ptr = (const void *) id, | ||
421 | }, | ||
422 | { | ||
423 | .index = 2, | ||
424 | .trait_name = "connected_peers_map", | ||
425 | .ptr = (const void *) connected_peers_map, | ||
426 | }, | ||
427 | { | ||
428 | .index = 3, | ||
429 | .trait_name = "hello", | ||
430 | .ptr = (const void *) hello, | ||
431 | }, | ||
432 | { | ||
433 | .index = 4, | ||
434 | .trait_name = "hello_size", | ||
435 | .ptr = (const void *) hello_size, | ||
436 | }, | ||
437 | GNUNET_TESTING_trait_end () | ||
438 | }; | ||
439 | |||
440 | return GNUNET_TESTING_get_trait (traits, | ||
441 | ret, | ||
442 | trait, | ||
443 | index); | ||
444 | } | ||
445 | |||
446 | int | ||
447 | GNUNET_TESTING_get_trait_hello_size (const struct | ||
448 | GNUNET_TESTING_Command | ||
449 | *cmd, | ||
450 | size_t **hello_size) | ||
451 | { | ||
452 | return cmd->traits (cmd->cls, | ||
453 | (const void **) hello_size, | ||
454 | "hello_size", | ||
455 | (unsigned int) 4); | ||
456 | } | ||
457 | |||
458 | int | ||
459 | GNUNET_TESTING_get_trait_hello (const struct | ||
460 | GNUNET_TESTING_Command | ||
461 | *cmd, | ||
462 | char **hello) | ||
463 | { | ||
464 | return cmd->traits (cmd->cls, | ||
465 | (const void **) hello, | ||
466 | "hello", | ||
467 | (unsigned int) 3); | ||
468 | } | ||
469 | |||
470 | int | ||
471 | GNUNET_TESTING_get_trait_connected_peers_map (const struct | ||
472 | GNUNET_TESTING_Command | ||
473 | *cmd, | ||
474 | struct | ||
475 | GNUNET_CONTAINER_MultiPeerMap ** | ||
476 | connected_peers_map) | ||
477 | { | ||
478 | return cmd->traits (cmd->cls, | ||
479 | (const void **) connected_peers_map, | ||
480 | "connected_peers_map", | ||
481 | (unsigned int) 2); | ||
482 | } | ||
483 | |||
484 | |||
485 | int | ||
486 | GNUNET_TESTING_get_trait_application_handle (const struct | ||
487 | GNUNET_TESTING_Command *cmd, | ||
488 | struct | ||
489 | GNUNET_TRANSPORT_ApplicationHandle | ||
490 | **ah) | ||
491 | { | ||
492 | return cmd->traits (cmd->cls, | ||
493 | (const void **) ah, | ||
494 | "application_handle", | ||
495 | (unsigned int) 0); | ||
496 | } | ||
497 | |||
498 | |||
499 | int | ||
500 | GNUNET_TESTING_get_trait_peer_id (const struct | ||
501 | GNUNET_TESTING_Command *cmd, | ||
502 | struct GNUNET_PeerIdentity **id) | ||
503 | { | ||
504 | return cmd->traits (cmd->cls, | ||
505 | (const void **) id, | ||
506 | "peer_id", | ||
507 | (unsigned int) 1); | ||
508 | } | ||
509 | |||
510 | |||
511 | /** | ||
512 | * Create command. | ||
513 | * | ||
514 | * @param label name for command. | ||
515 | * @return command. | ||
516 | */ | ||
517 | struct GNUNET_TESTING_Command | ||
518 | GNUNET_TESTING_cmd_start_peer (const char *label, | ||
519 | const char *system_label, | ||
520 | char *m, | ||
521 | char *n, | ||
522 | struct GNUNET_MQ_MessageHandler *handlers, | ||
523 | const char *cfgname) | ||
524 | { | ||
525 | struct StartPeerState *sps; | ||
526 | struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map = | ||
527 | GNUNET_CONTAINER_multipeermap_create (1,GNUNET_NO); | ||
528 | unsigned int i; | ||
529 | |||
530 | sps = GNUNET_new (struct StartPeerState); | ||
531 | sps->m = m; | ||
532 | sps->n = n; | ||
533 | sps->system_label = system_label; | ||
534 | sps->connected_peers_map = connected_peers_map; | ||
535 | sps->cfgname = cfgname; | ||
536 | |||
537 | if (NULL != handlers) | ||
538 | { | ||
539 | for (i = 0; NULL != handlers[i].cb; i++) | ||
540 | ; | ||
541 | sps->handlers = GNUNET_new_array (i + 1, | ||
542 | struct GNUNET_MQ_MessageHandler); | ||
543 | GNUNET_memcpy (sps->handlers, | ||
544 | handlers, | ||
545 | i * sizeof(struct GNUNET_MQ_MessageHandler)); | ||
546 | } | ||
547 | |||
548 | struct GNUNET_TESTING_Command cmd = { | ||
549 | .cls = sps, | ||
550 | .label = label, | ||
551 | .run = &start_peer_run, | ||
552 | .finish = &start_peer_finish, | ||
553 | .cleanup = &start_peer_cleanup, | ||
554 | .traits = &start_peer_traits | ||
555 | }; | ||
556 | |||
557 | return cmd; | ||
558 | } | ||