diff options
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers_v3.c')
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers_v3.c | 281 |
1 files changed, 0 insertions, 281 deletions
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c deleted file mode 100644 index 2273d9852..000000000 --- a/src/transport/transport_api_cmd_connecting_peers_v3.c +++ /dev/null | |||
@@ -1,281 +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_transport_application_service.h" | ||
30 | #include "gnunet_hello_lib.h" | ||
31 | #include "gnunet_transport_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 | * Struct to store information needed in callbacks. | ||
41 | * | ||
42 | */ | ||
43 | struct ConnectPeersState | ||
44 | { | ||
45 | /** | ||
46 | * The testing system of this node. | ||
47 | */ | ||
48 | struct GNUNET_TESTING_System *tl_system; | ||
49 | |||
50 | // Label of the cmd which started the test system. | ||
51 | const char *create_label; | ||
52 | |||
53 | /** | ||
54 | * Number globally identifying the node. | ||
55 | * | ||
56 | */ | ||
57 | uint32_t num; | ||
58 | |||
59 | /** | ||
60 | * Label of the cmd to start a peer. | ||
61 | * | ||
62 | */ | ||
63 | const char *start_peer_label; | ||
64 | |||
65 | /** | ||
66 | * The peer identity of this peer. | ||
67 | * | ||
68 | */ | ||
69 | struct GNUNET_PeerIdentity *id; | ||
70 | |||
71 | /** | ||
72 | * The topology of the test setup. | ||
73 | */ | ||
74 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
75 | |||
76 | /** | ||
77 | * Connections to other peers. | ||
78 | */ | ||
79 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
80 | |||
81 | /** | ||
82 | * Number of connections. | ||
83 | */ | ||
84 | unsigned int con_num; | ||
85 | }; | ||
86 | |||
87 | |||
88 | /** | ||
89 | * The run method of this cmd will connect to peers. | ||
90 | * | ||
91 | */ | ||
92 | static void | ||
93 | connect_peers_run (void *cls, | ||
94 | const struct GNUNET_TESTING_Command *cmd, | ||
95 | struct GNUNET_TESTING_Interpreter *is) | ||
96 | { | ||
97 | struct ConnectPeersState *cps = cls; | ||
98 | const struct GNUNET_TESTING_Command *system_cmd; | ||
99 | struct GNUNET_TESTING_System *tl_system; | ||
100 | |||
101 | |||
102 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
103 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
104 | struct GNUNET_PeerIdentity *peer; | ||
105 | char *addr; | ||
106 | enum GNUNET_NetworkType nt = 0; | ||
107 | uint32_t num; | ||
108 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
109 | struct GNUNET_TESTING_AddressPrefix *pos_prefix; | ||
110 | unsigned int con_num = 0; | ||
111 | |||
112 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); | ||
113 | GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd, | ||
114 | &ah); | ||
115 | |||
116 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label); | ||
117 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
118 | &tl_system); | ||
119 | |||
120 | cps->tl_system = tl_system; | ||
121 | |||
122 | cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num, | ||
123 | cps->topology); | ||
124 | |||
125 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | ||
126 | pos_connection = pos_connection->next) | ||
127 | { | ||
128 | con_num++; | ||
129 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); | ||
130 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; | ||
131 | pos_prefix = | ||
132 | pos_prefix->next) | ||
133 | { | ||
134 | |||
135 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
136 | "prefix: %s\n", | ||
137 | pos_prefix->address_prefix); | ||
138 | |||
139 | addr = GNUNET_TESTING_get_address (pos_connection, | ||
140 | pos_prefix->address_prefix); | ||
141 | |||
142 | peer = GNUNET_TESTING_get_pub_key (num, tl_system); | ||
143 | |||
144 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
145 | "num: %u pub_key %s addr: %s\n", | ||
146 | num, | ||
147 | GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)), | ||
148 | addr); | ||
149 | |||
150 | cps->id = peer; | ||
151 | |||
152 | GNUNET_TRANSPORT_application_validate (ah, | ||
153 | peer, | ||
154 | nt, | ||
155 | addr); | ||
156 | } | ||
157 | } | ||
158 | cps->con_num = con_num; | ||
159 | } | ||
160 | |||
161 | |||
162 | /** | ||
163 | * The finish function of this cmd will check if the peers we are trying to | ||
164 | * connect to are in the connected peers map of the start peer cmd for this peer. | ||
165 | * | ||
166 | */ | ||
167 | static int | ||
168 | connect_peers_finish (void *cls, | ||
169 | GNUNET_SCHEDULER_TaskCallback cont, | ||
170 | void *cont_cls) | ||
171 | { | ||
172 | struct ConnectPeersState *cps = cls; | ||
173 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
174 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
175 | unsigned int ret; | ||
176 | struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); | ||
177 | struct GNUNET_HashCode hc; | ||
178 | struct GNUNET_PeerIdentity *peer; | ||
179 | unsigned int con_num = 0; | ||
180 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
181 | unsigned int num; | ||
182 | |||
183 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); | ||
184 | GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd, | ||
185 | &connected_peers_map); | ||
186 | |||
187 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | ||
188 | pos_connection = pos_connection->next) | ||
189 | { | ||
190 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); | ||
191 | peer = GNUNET_TESTING_get_pub_key (num, cps->tl_system); | ||
192 | GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc); | ||
193 | memcpy (key, | ||
194 | &hc, | ||
195 | sizeof (*key)); | ||
196 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( | ||
197 | connected_peers_map, | ||
198 | key)) | ||
199 | con_num++; | ||
200 | } | ||
201 | |||
202 | |||
203 | |||
204 | if (cps->con_num == con_num) | ||
205 | { | ||
206 | cont (cont_cls); | ||
207 | ret = GNUNET_YES; | ||
208 | } | ||
209 | |||
210 | GNUNET_free (key); | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | |||
215 | /** | ||
216 | * Trait function of this cmd does nothing. | ||
217 | * | ||
218 | */ | ||
219 | static int | ||
220 | connect_peers_traits (void *cls, | ||
221 | const void **ret, | ||
222 | const char *trait, | ||
223 | unsigned int index) | ||
224 | { | ||
225 | return GNUNET_OK; | ||
226 | } | ||
227 | |||
228 | |||
229 | /** | ||
230 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
231 | * | ||
232 | */ | ||
233 | static void | ||
234 | connect_peers_cleanup (void *cls, | ||
235 | const struct GNUNET_TESTING_Command *cmd) | ||
236 | { | ||
237 | struct ConnectPeersState *cps = cls; | ||
238 | |||
239 | GNUNET_free (cps->id); | ||
240 | GNUNET_free (cps); | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Create command. | ||
246 | * | ||
247 | * @param label name for command. | ||
248 | * @param start_peer_label Label of the cmd to start a peer. | ||
249 | * @param create_label Label of the cmd to create the testing system. | ||
250 | * @param num Number globally identifying the node. | ||
251 | * @param The topology for the test setup. | ||
252 | * @return command. | ||
253 | */ | ||
254 | struct GNUNET_TESTING_Command | ||
255 | GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, | ||
256 | const char *start_peer_label, | ||
257 | const char *create_label, | ||
258 | uint32_t num, | ||
259 | struct GNUNET_TESTING_NetjailTopology * | ||
260 | topology) | ||
261 | { | ||
262 | struct ConnectPeersState *cps; | ||
263 | |||
264 | cps = GNUNET_new (struct ConnectPeersState); | ||
265 | cps->start_peer_label = start_peer_label; | ||
266 | cps->num = num; | ||
267 | cps->create_label = create_label; | ||
268 | cps->topology = topology; | ||
269 | |||
270 | |||
271 | struct GNUNET_TESTING_Command cmd = { | ||
272 | .cls = cps, | ||
273 | .label = label, | ||
274 | .run = &connect_peers_run, | ||
275 | .finish = &connect_peers_finish, | ||
276 | .cleanup = &connect_peers_cleanup, | ||
277 | .traits = &connect_peers_traits | ||
278 | }; | ||
279 | |||
280 | return cmd; | ||
281 | } | ||