diff options
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers.c')
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers.c | 265 |
1 files changed, 0 insertions, 265 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 8aba290c3..000000000 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ /dev/null | |||
@@ -1,265 +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 | char *port; | ||
65 | |||
66 | cps->is = is; | ||
67 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
68 | cps->start_peer_label); | ||
69 | GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, | ||
70 | &ah); | ||
71 | GNUNET_TRANSPORT_get_trait_broadcast (peer1_cmd, | ||
72 | &broadcast); | ||
73 | |||
74 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
75 | cps->create_label); | ||
76 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
77 | &tl_system); | ||
78 | |||
79 | cps->tl_system = tl_system; | ||
80 | |||
81 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
82 | "cps->num: %u \n", | ||
83 | cps->num); | ||
84 | |||
85 | cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num, | ||
86 | cps->topology); | ||
87 | |||
88 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | ||
89 | pos_connection = pos_connection->next) | ||
90 | { | ||
91 | con_num++; | ||
92 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); | ||
93 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; | ||
94 | pos_prefix = | ||
95 | pos_prefix->next) | ||
96 | { | ||
97 | addr = GNUNET_TESTING_get_address (pos_connection, | ||
98 | pos_prefix->address_prefix); | ||
99 | if (NULL != addr) | ||
100 | { | ||
101 | if (0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) | ||
102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
103 | "validating memcmp\n"); | ||
104 | if (GNUNET_YES == *broadcast) | ||
105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
106 | "validating broadcast\n"); | ||
107 | if ((0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) && | ||
108 | (GNUNET_YES == *broadcast) ) | ||
109 | GNUNET_asprintf (&addr_and_port, | ||
110 | "%s:2086", | ||
111 | addr); | ||
112 | else | ||
113 | GNUNET_asprintf (&addr_and_port, | ||
114 | "%s:60002", | ||
115 | addr); | ||
116 | peer = GNUNET_TESTING_get_pub_key (num, tl_system); | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
118 | "validating peer number %u with identity %s and address %s %u %s\n", | ||
119 | num, | ||
120 | GNUNET_i2s (peer), | ||
121 | addr_and_port, | ||
122 | *broadcast, | ||
123 | pos_prefix->address_prefix); | ||
124 | GNUNET_TRANSPORT_application_validate ((struct | ||
125 | GNUNET_TRANSPORT_ApplicationHandle | ||
126 | *) ah, | ||
127 | peer, | ||
128 | nt, | ||
129 | addr_and_port); | ||
130 | GNUNET_free (peer); | ||
131 | GNUNET_free (addr); | ||
132 | GNUNET_free (addr_and_port); | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | cps->con_num = con_num; | ||
137 | } | ||
138 | |||
139 | |||
140 | /** | ||
141 | * Callback from start peer cmd for signaling a peer got connected. | ||
142 | * | ||
143 | */ | ||
144 | static void * | ||
145 | notify_connect (struct GNUNET_TESTING_Interpreter *is, | ||
146 | const struct GNUNET_PeerIdentity *peer) | ||
147 | { | ||
148 | const struct GNUNET_TESTING_Command *cmd; | ||
149 | struct ConnectPeersState *cps; | ||
150 | struct GNUNET_PeerIdentity *peer_connection; | ||
151 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
152 | unsigned int num; | ||
153 | unsigned int con_num; | ||
154 | void *ret = NULL; | ||
155 | |||
156 | cmd = GNUNET_TESTING_interpreter_lookup_command_all (is, | ||
157 | "connect-peers"); | ||
158 | cps = cmd->cls; | ||
159 | con_num = cps->con_num_notified; | ||
160 | for (pos_connection = cps->node_connections_head; NULL != pos_connection; | ||
161 | pos_connection = pos_connection->next) | ||
162 | { | ||
163 | num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology); | ||
164 | peer_connection = GNUNET_TESTING_get_pub_key (num, cps->tl_system); | ||
165 | if (0 == GNUNET_memcmp (peer, | ||
166 | peer_connection)) | ||
167 | cps->con_num_notified++; | ||
168 | GNUNET_free (peer_connection); | ||
169 | } | ||
170 | if (cps->con_num == con_num) | ||
171 | cps->additional_connects_notified++; | ||
172 | |||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
174 | "con_num: %u add: %u num_notified: %u add_notified: %u\n", | ||
175 | cps->con_num, | ||
176 | cps->additional_connects, | ||
177 | cps->con_num_notified, | ||
178 | cps->additional_connects_notified); | ||
179 | if (cps->con_num + cps->additional_connects == cps->con_num_notified | ||
180 | + cps->additional_connects_notified) | ||
181 | { | ||
182 | GNUNET_TESTING_async_finish (&cps->ac); | ||
183 | } | ||
184 | return ret; | ||
185 | } | ||
186 | |||
187 | |||
188 | /** | ||
189 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
190 | * | ||
191 | */ | ||
192 | static void | ||
193 | connect_peers_cleanup (void *cls) | ||
194 | { | ||
195 | struct ConnectPeersState *cps = cls; | ||
196 | |||
197 | GNUNET_free (cps); | ||
198 | } | ||
199 | |||
200 | |||
201 | /** | ||
202 | * This function prepares an array with traits. | ||
203 | * | ||
204 | */ | ||
205 | enum GNUNET_GenericReturnValue | ||
206 | connect_peers_traits (void *cls, | ||
207 | const void **ret, | ||
208 | const char *trait, | ||
209 | unsigned int index) | ||
210 | { | ||
211 | struct ConnectPeersState *cps = cls; | ||
212 | struct GNUNET_TESTING_Trait traits[] = { | ||
213 | GNUNET_TRANSPORT_make_trait_connect_peer_state ((const void *) cps), | ||
214 | GNUNET_TESTING_trait_end () | ||
215 | }; | ||
216 | return GNUNET_TESTING_get_trait (traits, | ||
217 | ret, | ||
218 | trait, | ||
219 | index); | ||
220 | } | ||
221 | |||
222 | |||
223 | /** | ||
224 | * Create command | ||
225 | * | ||
226 | * @param label name for command | ||
227 | * @param start_peer_label Label of the cmd to start a peer. | ||
228 | * @param create_peer_label Label of the cmd which started the test system. | ||
229 | * @param num Number globally identifying the node. | ||
230 | * @param The topology for the test setup. | ||
231 | * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd. | ||
232 | * @return command. | ||
233 | */ | ||
234 | struct GNUNET_TESTING_Command | ||
235 | GNUNET_TRANSPORT_cmd_connect_peers (const char *label, | ||
236 | const char *start_peer_label, | ||
237 | const char *create_label, | ||
238 | uint32_t num, | ||
239 | struct GNUNET_TESTING_NetjailTopology * | ||
240 | topology, | ||
241 | unsigned int additional_connects) | ||
242 | { | ||
243 | struct ConnectPeersState *cps; | ||
244 | |||
245 | cps = GNUNET_new (struct ConnectPeersState); | ||
246 | cps->start_peer_label = start_peer_label; | ||
247 | cps->num = num; | ||
248 | cps->create_label = create_label; | ||
249 | cps->topology = topology; | ||
250 | cps->notify_connect = notify_connect; | ||
251 | cps->additional_connects = additional_connects; | ||
252 | |||
253 | { | ||
254 | struct GNUNET_TESTING_Command cmd = { | ||
255 | .cls = cps, | ||
256 | .label = label, | ||
257 | .run = &connect_peers_run, | ||
258 | .ac = &cps->ac, | ||
259 | .cleanup = &connect_peers_cleanup, | ||
260 | .traits = &connect_peers_traits | ||
261 | }; | ||
262 | |||
263 | return cmd; | ||
264 | } | ||
265 | } | ||