diff options
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers.c')
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers.c | 288 |
1 files changed, 0 insertions, 288 deletions
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c deleted file mode 100644 index 6bc145880..000000000 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ /dev/null | |||
@@ -1,288 +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_testing_netjail_lib.h" | ||
30 | #include "gnunet_transport_application_service.h" | ||
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "gnunet_transport_service.h" | ||
33 | #include "transport-testing-cmds.h" | ||
34 | |||
35 | /** | ||
36 | * Generic logging shortcut | ||
37 | */ | ||
38 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
39 | |||
40 | /** | ||
41 | * The run method of this cmd will connect to peers. | ||
42 | * | ||
43 | */ | ||
44 | static void | ||
45 | connect_peers_run (void *cls, | ||
46 | struct GNUNET_TESTING_Interpreter *is) | ||
47 | { | ||
48 | struct ConnectPeersState *cps = cls; | ||
49 | const struct GNUNET_TESTING_Command *system_cmd; | ||
50 | const struct GNUNET_TESTING_System *tl_system; | ||
51 | |||
52 | |||
53 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
54 | const struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
55 | struct GNUNET_PeerIdentity *peer; | ||
56 | char *addr; | ||
57 | char *addr_and_port; | ||
58 | enum GNUNET_NetworkType nt = 0; | ||
59 | uint32_t num; | ||
60 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
61 | struct GNUNET_TESTING_AddressPrefix *pos_prefix; | ||
62 | unsigned int con_num = 0; | ||
63 | const enum GNUNET_GenericReturnValue *broadcast; | ||
64 | |||
65 | cps->is = is; | ||
66 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
67 | cps->start_peer_label); | ||
68 | GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, | ||
69 | &ah); | ||
70 | GNUNET_TRANSPORT_get_trait_broadcast (peer1_cmd, | ||
71 | &broadcast); | ||
72 | |||
73 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
74 | cps->create_label); | ||
75 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
76 | &tl_system); | ||
77 | |||
78 | cps->tl_system = tl_system; | ||
79 | |||
80 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
81 | "cps->num: %u \n", | ||
82 | cps->num); | ||
83 | |||
84 | cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num, | ||
85 | cps->topology); | ||
86 | |||
87 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | ||
88 | pos_connection = pos_connection->next) | ||
89 | { | ||
90 | con_num++; | ||
91 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); | ||
92 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; | ||
93 | pos_prefix = | ||
94 | pos_prefix->next) | ||
95 | { | ||
96 | addr = GNUNET_TESTING_get_address (pos_connection, | ||
97 | pos_prefix->address_prefix); | ||
98 | if (NULL != addr) | ||
99 | { | ||
100 | char *natted_p = strstr (pos_prefix->address_prefix, "_"); | ||
101 | |||
102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
103 | "0 validating peer number %s %s %s\n", | ||
104 | natted_p, | ||
105 | pos_prefix->address_prefix, | ||
106 | addr); | ||
107 | if (0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
109 | "validating memcmp\n"); | ||
110 | if (GNUNET_YES == *broadcast) | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
112 | "validating broadcast\n"); | ||
113 | if ((0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) && | ||
114 | (GNUNET_YES == *broadcast) ) | ||
115 | GNUNET_asprintf (&addr_and_port, | ||
116 | "%s:2086", | ||
117 | addr); | ||
118 | else if (NULL == natted_p) | ||
119 | GNUNET_asprintf (&addr_and_port, | ||
120 | "%s:60002", | ||
121 | addr); | ||
122 | else if (NULL != natted_p) | ||
123 | { | ||
124 | char *prefix; | ||
125 | char *rest; | ||
126 | char *rest2; | ||
127 | char *address; | ||
128 | |||
129 | prefix = strtok (addr, "_"); | ||
130 | rest = strtok (NULL, "_"); | ||
131 | rest2 = strtok (rest, "-"); | ||
132 | address = strtok (NULL, "-"); | ||
133 | |||
134 | GNUNET_asprintf (&addr_and_port, | ||
135 | "%s-%s:0", | ||
136 | prefix, | ||
137 | address); | ||
138 | |||
139 | } | ||
140 | peer = GNUNET_TESTING_get_peer (num, tl_system); | ||
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
142 | "validating peer number %u with identity %s and address %s %u %s\n", | ||
143 | num, | ||
144 | GNUNET_i2s (peer), | ||
145 | addr_and_port, | ||
146 | *broadcast, | ||
147 | pos_prefix->address_prefix); | ||
148 | GNUNET_TRANSPORT_application_validate ((struct | ||
149 | GNUNET_TRANSPORT_ApplicationHandle | ||
150 | *) ah, | ||
151 | peer, | ||
152 | nt, | ||
153 | addr_and_port); | ||
154 | GNUNET_free (peer); | ||
155 | GNUNET_free (addr); | ||
156 | GNUNET_free (addr_and_port); | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | cps->con_num = con_num; | ||
161 | } | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Callback from start peer cmd for signaling a peer got connected. | ||
166 | * | ||
167 | */ | ||
168 | static void * | ||
169 | notify_connect (struct GNUNET_TESTING_Interpreter *is, | ||
170 | const struct GNUNET_PeerIdentity *peer) | ||
171 | { | ||
172 | const struct GNUNET_TESTING_Command *cmd; | ||
173 | struct ConnectPeersState *cps; | ||
174 | struct GNUNET_PeerIdentity *peer_connection; | ||
175 | unsigned int num; | ||
176 | unsigned int con_num; | ||
177 | void *ret = NULL; | ||
178 | |||
179 | cmd = GNUNET_TESTING_interpreter_lookup_command_all (is, | ||
180 | "connect-peers"); | ||
181 | cps = cmd->cls; // WTF? Never go directly into cls of another command! FIXME! | ||
182 | con_num = cps->con_num_notified; | ||
183 | for (struct GNUNET_TESTING_NodeConnection *pos_connection = | ||
184 | cps->node_connections_head; | ||
185 | NULL != pos_connection; | ||
186 | pos_connection = pos_connection->next) | ||
187 | { | ||
188 | num = GNUNET_TESTING_calculate_num (pos_connection, | ||
189 | cps->topology); | ||
190 | peer_connection = GNUNET_TESTING_get_peer (num, | ||
191 | cps->tl_system); | ||
192 | if (0 == GNUNET_memcmp (peer, | ||
193 | peer_connection)) | ||
194 | cps->con_num_notified++; | ||
195 | GNUNET_free (peer_connection); | ||
196 | } | ||
197 | if (cps->con_num_notified == con_num) | ||
198 | cps->additional_connects_notified++; | ||
199 | |||
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
201 | "con_num: %u add: %u num_notified: %u add_notified: %u peer: %s\n", | ||
202 | cps->con_num, | ||
203 | cps->additional_connects, | ||
204 | cps->con_num_notified, | ||
205 | cps->additional_connects_notified, | ||
206 | GNUNET_i2s (peer)); | ||
207 | if ((cps->con_num == cps->con_num_notified) && | ||
208 | (cps->additional_connects <= cps->additional_connects_notified)) | ||
209 | { | ||
210 | GNUNET_TESTING_async_finish (&cps->ac); | ||
211 | } | ||
212 | return ret; | ||
213 | } | ||
214 | |||
215 | |||
216 | /** | ||
217 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
218 | * | ||
219 | */ | ||
220 | static void | ||
221 | connect_peers_cleanup (void *cls) | ||
222 | { | ||
223 | struct ConnectPeersState *cps = cls; | ||
224 | |||
225 | GNUNET_free (cps); | ||
226 | } | ||
227 | |||
228 | |||
229 | /** | ||
230 | * This function prepares an array with traits. | ||
231 | * | ||
232 | */ | ||
233 | enum GNUNET_GenericReturnValue | ||
234 | connect_peers_traits (void *cls, | ||
235 | const void **ret, | ||
236 | const char *trait, | ||
237 | unsigned int index) | ||
238 | { | ||
239 | struct ConnectPeersState *cps = cls; | ||
240 | struct GNUNET_TESTING_Trait traits[] = { | ||
241 | GNUNET_TRANSPORT_make_trait_connect_peer_state ((const void *) cps), | ||
242 | GNUNET_TESTING_trait_end () | ||
243 | }; | ||
244 | return GNUNET_TESTING_get_trait (traits, | ||
245 | ret, | ||
246 | trait, | ||
247 | index); | ||
248 | } | ||
249 | |||
250 | |||
251 | struct GNUNET_TESTING_Command | ||
252 | GNUNET_TRANSPORT_cmd_connect_peers (const char *label, | ||
253 | const char *start_peer_label, | ||
254 | const char *create_label, | ||
255 | uint32_t num, | ||
256 | struct GNUNET_TESTING_NetjailTopology * | ||
257 | topology, | ||
258 | unsigned int additional_connects) | ||
259 | { | ||
260 | struct ConnectPeersState *cps; | ||
261 | unsigned int node_additional_connects; | ||
262 | |||
263 | node_additional_connects = GNUNET_TESTING_get_additional_connects (num, | ||
264 | topology); | ||
265 | |||
266 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
267 | "global: %u and local: %u additional_connects\n", | ||
268 | additional_connects, | ||
269 | node_additional_connects); | ||
270 | |||
271 | if (0 != node_additional_connects) | ||
272 | additional_connects = node_additional_connects; | ||
273 | |||
274 | cps = GNUNET_new (struct ConnectPeersState); | ||
275 | cps->start_peer_label = start_peer_label; | ||
276 | cps->num = num; | ||
277 | cps->create_label = create_label; | ||
278 | cps->topology = topology; | ||
279 | cps->notify_connect = notify_connect; | ||
280 | cps->additional_connects = additional_connects; | ||
281 | |||
282 | return GNUNET_TESTING_command_new (cps, | ||
283 | label, | ||
284 | &connect_peers_run, | ||
285 | &connect_peers_cleanup, | ||
286 | &connect_peers_traits, | ||
287 | &cps->ac); | ||
288 | } | ||