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