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.c281
1 files changed, 0 insertions, 281 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 09ca9e54c..000000000
--- a/src/transport/transport_api_cmd_connecting_peers.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 */
43struct ConnectPeersState
44{
45 // Label of the cmd which started the test system.
46 const char *create_label;
47
48 /**
49 * Number globally identifying the node.
50 *
51 */
52 uint32_t num;
53
54 /**
55 * Label of the cmd to start a peer.
56 *
57 */
58 const char *start_peer_label;
59
60 /**
61 * The peer identity of this peer.
62 *
63 */
64 struct GNUNET_PeerIdentity *id;
65};
66
67
68/**
69 * The run method of this cmd will connect to peers.
70 *
71 */
72static void
73connect_peers_run (void *cls,
74 const struct GNUNET_TESTING_Command *cmd,
75 struct GNUNET_TESTING_Interpreter *is)
76{
77 struct ConnectPeersState *cps = cls;
78 const struct GNUNET_TESTING_Command *system_cmd;
79 struct GNUNET_TESTING_System *tl_system;
80 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
81 GNUNET_CRYPTO_EddsaPrivateKey);
82 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
83 GNUNET_CRYPTO_EddsaPublicKey);
84 ;
85 const struct GNUNET_TESTING_Command *peer1_cmd;
86 // const struct GNUNET_TESTING_Command *peer2_cmd;
87 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
88 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
89 char *addr;
90 // struct GNUNET_TIME_Absolute t;
91 char *hello;
92 // size_t *hello_size;
93 enum GNUNET_NetworkType nt = 0;
94 char *peer_id;
95 struct GNUNET_PeerIdentity *id;
96 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
97 uint32_t num;
98
99 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
100 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
101 &ah);
102
103 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
104 &hello);
105
106 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
107 &id);
108
109 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
110 GNUNET_TESTING_get_trait_test_system (system_cmd,
111 &tl_system);
112
113 if (2 == cps->num)
114 num = 1;
115 else
116 num = 2;
117
118
119
120
121 // if (strstr (hello, "60002") != NULL)
122 if (2 == num)
123 {
124 addr = "tcp-192.168.15.2:60002";
125 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
126 }
127 else
128 {
129 addr = "tcp-192.168.15.1:60002";
130 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
131 }
132
133 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
134 num,
135 other);
136
137 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
138 pub_key);
139
140 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
141 strlen (peer_id),
142 &peer->public_key);
143
144 peer->public_key = *pub_key;
145
146 LOG (GNUNET_ERROR_TYPE_ERROR,
147 "\nnum: %u\n peer_id: %s\n pub_key %s\n",
148 num,
149 peer_id,
150 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
151
152 cps->id = peer;
153
154 // 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.
155 // ---------------------------------------------
156 /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
157 GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd,
158 &id);
159 GNUNET_TRANSPORT_get_trait_hello (peer2_cmd,
160 &hello);
161 GNUNET_TRANSPORT_get_trait_hello_size (peer2_cmd,
162 &hello_size);
163
164 addr = GNUNET_HELLO_extract_address (hello,
165 *hello_size,
166 id,
167 &nt,
168 &t);*/
169
170 // ----------------------------------------------
171
172
173 GNUNET_TRANSPORT_application_validate (ah,
174 peer,
175 nt,
176 addr);
177}
178
179
180/**
181 * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer.
182 *
183 */
184static int
185connect_peers_finish (void *cls,
186 GNUNET_SCHEDULER_TaskCallback cont,
187 void *cont_cls)
188{
189 struct ConnectPeersState *cps = cls;
190 const struct GNUNET_TESTING_Command *peer1_cmd;
191 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
192 unsigned int ret;
193 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
194 struct GNUNET_HashCode hc;
195 int node_number;
196
197 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
198 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
199 &connected_peers_map);
200
201 node_number = 1;
202 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
203
204 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
205 memcpy (key,
206 &hc,
207 sizeof (*key));
208 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
209 key);
210
211 if (GNUNET_YES == ret)
212 {
213 cont (cont_cls);
214 }
215
216 GNUNET_free (key);
217 return ret;
218}
219
220
221/**
222 * Trait function of this cmd does nothing.
223 *
224 */
225static int
226connect_peers_traits (void *cls,
227 const void **ret,
228 const char *trait,
229 unsigned int index)
230{
231 return GNUNET_OK;
232}
233
234
235/**
236 * The cleanup function of this cmd frees resources the cmd allocated.
237 *
238 */
239static void
240connect_peers_cleanup (void *cls,
241 const struct GNUNET_TESTING_Command *cmd)
242{
243 struct ConnectPeersState *cps = cls;
244
245 GNUNET_free (cps->id);
246 GNUNET_free (cps);
247}
248
249
250/**
251 * Create command.
252 *
253 * @param label name for command.
254 * @param start_peer_label Label of the cmd to start a peer.
255 * @return command.
256 */
257struct GNUNET_TESTING_Command
258GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
259 const char *start_peer_label,
260 const char *create_label,
261 uint32_t num)
262{
263 struct ConnectPeersState *cps;
264
265 cps = GNUNET_new (struct ConnectPeersState);
266 cps->start_peer_label = start_peer_label;
267 cps->num = num;
268 cps->create_label = create_label;
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}