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.c231
1 files changed, 0 insertions, 231 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 34b3d5925..000000000
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ /dev/null
@@ -1,231 +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 /**
46 * Label of the cmd to start a peer.
47 *
48 */
49 const char *start_peer_label;
50
51 /**
52 * The peer identity of this peer.
53 *
54 */
55 struct GNUNET_PeerIdentity *id;
56};
57
58
59/**
60 * The run method of this cmd will connect to peers.
61 *
62 */
63static void
64connect_peers_run (void *cls,
65 const struct GNUNET_TESTING_Command *cmd,
66 struct GNUNET_TESTING_Interpreter *is)
67{
68 struct ConnectPeersState *cps = cls;
69 const struct GNUNET_TESTING_Command *peer1_cmd;
70 // const struct GNUNET_TESTING_Command *peer2_cmd;
71 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
72 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
73 char *addr;
74 // struct GNUNET_TIME_Absolute t;
75 char *hello;
76 // size_t *hello_size;
77 enum GNUNET_NetworkType nt = 0;
78 char *peer_id;
79 struct GNUNET_PeerIdentity *id;
80
81 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
82 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
83 &ah);
84
85 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
86 &hello);
87
88 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
89 &id);
90
91 if (strstr (hello, "60002") != NULL)
92 {
93 addr = "tcp-192.168.15.2:60003";
94 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
95 }
96 else
97 {
98 addr = "tcp-192.168.15.1:60002";
99 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
100 }
101
102 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
103 strlen (peer_id),
104 &peer->public_key);
105
106 cps->id = peer;
107
108 // 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.
109 // ---------------------------------------------
110 /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
111 GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd,
112 &id);
113 GNUNET_TRANSPORT_get_trait_hello (peer2_cmd,
114 &hello);
115 GNUNET_TRANSPORT_get_trait_hello_size (peer2_cmd,
116 &hello_size);
117
118 addr = GNUNET_HELLO_extract_address (hello,
119 *hello_size,
120 id,
121 &nt,
122 &t);*/
123
124 // ----------------------------------------------
125
126
127 GNUNET_TRANSPORT_application_validate (ah,
128 peer,
129 nt,
130 addr);
131}
132
133
134/**
135 * 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.
136 *
137 */
138static int
139connect_peers_finish (void *cls,
140 GNUNET_SCHEDULER_TaskCallback cont,
141 void *cont_cls)
142{
143 struct ConnectPeersState *cps = cls;
144 const struct GNUNET_TESTING_Command *peer1_cmd;
145 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
146 unsigned int ret;
147 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
148 struct GNUNET_HashCode hc;
149 int node_number;
150
151 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
152 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
153 &connected_peers_map);
154
155 node_number = 1;
156 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
157
158 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
159 memcpy (key,
160 &hc,
161 sizeof (*key));
162 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
163 key);
164
165 if (GNUNET_YES == ret)
166 {
167 cont (cont_cls);
168 }
169
170 GNUNET_free (key);
171 return ret;
172}
173
174
175/**
176 * Trait function of this cmd does nothing.
177 *
178 */
179static int
180connect_peers_traits (void *cls,
181 const void **ret,
182 const char *trait,
183 unsigned int index)
184{
185 return GNUNET_OK;
186}
187
188
189/**
190 * The cleanup function of this cmd frees resources the cmd allocated.
191 *
192 */
193static void
194connect_peers_cleanup (void *cls,
195 const struct GNUNET_TESTING_Command *cmd)
196{
197 struct ConnectPeersState *cps = cls;
198
199 GNUNET_free (cps->id);
200 GNUNET_free (cps);
201}
202
203
204/**
205 * Create command.
206 *
207 * @param label name for command.
208 * @param start_peer_label Label of the cmd to start a peer.
209 * @return command.
210 */
211struct GNUNET_TESTING_Command
212GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
213 const char *start_peer_label)
214{
215 struct ConnectPeersState *cps;
216
217 cps = GNUNET_new (struct ConnectPeersState);
218 cps->start_peer_label = start_peer_label;
219
220
221 struct GNUNET_TESTING_Command cmd = {
222 .cls = cps,
223 .label = label,
224 .run = &connect_peers_run,
225 .finish = &connect_peers_finish,
226 .cleanup = &connect_peers_cleanup,
227 .traits = &connect_peers_traits
228 };
229
230 return cmd;
231}