aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_cmd_connecting_peers_v2.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
committert3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
commitd64ac269856744b9bab170964e1d6f36896ecc55 (patch)
treeed5aa79b91fe3cf9388433a5611581b7ce3b846c /src/transport/transport_api_cmd_connecting_peers_v2.c
parent003910fc614cd347919707d1bf3c37a939978459 (diff)
downloadgnunet-d64ac269856744b9bab170964e1d6f36896ecc55.tar.gz
gnunet-d64ac269856744b9bab170964e1d6f36896ecc55.zip
removed versioned artefacts with v2 and v3. changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers_v2.c')
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c237
1 files changed, 0 insertions, 237 deletions
diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c
deleted file mode 100644
index 8d0f74916..000000000
--- a/src/transport/transport_api_cmd_connecting_peers_v2.c
+++ /dev/null
@@ -1,237 +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#define CONNECT_ADDRESS_TEMPLATE "tcp-192.168.15.%u:60002"
40
41/**
42 * Struct to store information needed in callbacks.
43 *
44 */
45struct ConnectPeersState
46{
47 /**
48 * Context for our asynchronous completion.
49 */
50 struct GNUNET_TESTING_AsyncContext ac;
51
52 // Label of the cmd which started the test system.
53 const char *create_label;
54
55 /**
56 * Number globally identifying the node.
57 *
58 */
59 uint32_t num;
60
61 /**
62 * Label of the cmd to start a peer.
63 *
64 */
65 const char *start_peer_label;
66
67 /**
68 * The peer identity of this peer.
69 *
70 */
71 struct GNUNET_PeerIdentity *id;
72
73 struct GNUNET_TESTING_Interpreter *is;
74};
75
76
77/**
78 * The run method of this cmd will connect to peers.
79 *
80 */
81static void
82connect_peers_run (void *cls,
83 struct GNUNET_TESTING_Interpreter *is)
84{
85 struct ConnectPeersState *cps = cls;
86 const struct GNUNET_TESTING_Command *system_cmd;
87 struct GNUNET_TESTING_System *tl_system;
88 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
89 GNUNET_CRYPTO_EddsaPrivateKey);
90 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
91 GNUNET_CRYPTO_EddsaPublicKey);
92 const struct GNUNET_TESTING_Command *peer1_cmd;
93 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
94 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
95 char *addr;
96 enum GNUNET_NetworkType nt = 0;
97 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
98 uint32_t num;
99
100 cps->is = is;
101 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
102 cps->start_peer_label);
103 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
104 &ah);
105
106 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
107 cps->create_label);
108 GNUNET_TESTING_get_trait_test_system (system_cmd,
109 &tl_system);
110
111 if (1 == cps->num)
112 {
113 num = 2;
114 // addr = "tcp-192.168.15.2:60002";
115 }
116 else
117 {
118 num = 1;
119 // addr = "tcp-192.168.15.1:60002";
120 }
121
122 GNUNET_asprintf (&addr,
123 CONNECT_ADDRESS_TEMPLATE,
124 num);
125
126 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
127 num,
128 other);
129
130 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
131 pub_key);
132
133
134 peer->public_key = *pub_key;
135
136 LOG (GNUNET_ERROR_TYPE_ERROR,
137 "num: %u pub_key %s\n",
138 num,
139 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
140
141 cps->id = peer;
142
143 GNUNET_TRANSPORT_application_validate (ah,
144 peer,
145 nt,
146 addr);
147}
148
149
150/**
151 * 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.
152 *
153 */
154static int
155connect_peers_finish (void *cls,
156 GNUNET_SCHEDULER_TaskCallback cont,
157 void *cont_cls)
158{
159 struct ConnectPeersState *cps = cls;
160 const struct GNUNET_TESTING_Command *peer1_cmd;
161 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
162 unsigned int ret;
163 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
164 struct GNUNET_HashCode hc;
165 int node_number;
166
167 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is,
168 cps->start_peer_label);
169 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
170 &connected_peers_map);
171
172 node_number = 1;
173 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
174
175 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
176 memcpy (key,
177 &hc,
178 sizeof (*key));
179 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
180 key);
181
182 if (GNUNET_YES == ret)
183 {
184 cont (cont_cls);
185 }
186
187 GNUNET_free (key);
188 return ret;
189}
190
191
192/**
193 * The cleanup function of this cmd frees resources the cmd allocated.
194 *
195 */
196static void
197connect_peers_cleanup (void *cls)
198{
199 struct ConnectPeersState *cps = cls;
200
201 GNUNET_free (cps->id);
202 GNUNET_free (cps);
203}
204
205
206/**
207 * Create command.
208 *
209 * @param label name for command.
210 * @param start_peer_label Label of the cmd to start a peer.
211 * @return command.
212 */
213struct GNUNET_TESTING_Command
214GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
215 const char *start_peer_label,
216 const char *create_label,
217 uint32_t num)
218{
219 struct ConnectPeersState *cps;
220
221 cps = GNUNET_new (struct ConnectPeersState);
222 cps->start_peer_label = start_peer_label;
223 cps->num = num;
224 cps->create_label = create_label;
225
226 {
227 struct GNUNET_TESTING_Command cmd = {
228 .cls = cps,
229 .label = label,
230 .run = &connect_peers_run,
231 .ac = &cps->ac,
232 .cleanup = &connect_peers_cleanup
233 };
234
235 return cmd;
236 }
237}