GNUnet 0.21.1
testing_api_cmd_start_peer.c
Go to the documentation of this file.
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
26#include "platform.h"
27#include "gnunet_util_lib.h"
31
32
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38
43static void
44start_peer_run (void *cls,
46{
47 struct GNUNET_TESTING_StartPeerState *sps = cls;
48 char *emsg = NULL;
50 const struct GNUNET_TESTING_Command *system_cmd;
51 const struct GNUNET_TESTING_System *tl_system;
52 char *home;
53 char *transport_unix_path;
54 char *tcp_communicator_unix_path;
55 char *udp_communicator_unix_path;
56 char *bindto;
57 char *bindto_udp;
58
60 {
62 "File not found: `%s'\n",
63 sps->cfgname);
65 return;
66 }
67
68
72
73 GNUNET_asprintf (&home,
74 "$GNUNET_TMP/test-transport/api-tcp-p%u",
75 sps->no);
76
77 GNUNET_asprintf (&transport_unix_path,
78 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
79 sps->no);
80
81 GNUNET_asprintf (&tcp_communicator_unix_path,
82 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
83 sps->no);
84
85 GNUNET_asprintf (&udp_communicator_unix_path,
86 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
87 sps->no);
88
89 GNUNET_asprintf (&bindto,
90 "%s:60002",
91 sps->node_ip);
92
93 GNUNET_asprintf (&bindto_udp,
94 "2086");
95
97 "node_ip %s\n",
98 bindto);
99
101 "bind_udp %s\n",
102 GNUNET_YES == sps->broadcast ?
103 bindto_udp : bindto);
104
105 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
106 home);
107 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
108 transport_unix_path);
109 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
110 "BINDTO",
111 bindto);
112 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
113 "BINDTO",
114 GNUNET_YES == sps->broadcast ?
115 bindto_udp : bindto);
116 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
117 "UNIXPATH",
118 tcp_communicator_unix_path);
119 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
120 "UNIXPATH",
121 udp_communicator_unix_path);
122
123
125 sps->system_label);
127 &tl_system);
128
129 sps->tl_system = tl_system;
130
132 "Creating testing library with key number %u\n",
133 sps->no);
134
135 if (GNUNET_SYSERR ==
137 GNUNET_TESTING_System *) tl_system,
138 sps->cfg))
139 {
141 "Testing library failed to create unique configuration based on `%s'\n",
142 sps->cfgname);
145 return;
146 }
147
148 sps->peer = GNUNET_TESTING_peer_configure ((struct
149 GNUNET_TESTING_System *) sps->
150 tl_system,
151 sps->cfg,
152 sps->no,
153 NULL,
154 &emsg);
155 if (NULL == sps->peer)
156 {
158 "Testing library failed to create unique configuration based on `%s': `%s' with key number %u\n",
159 sps->cfgname,
160 emsg,
161 sps->no);
162 GNUNET_free (emsg);
164 return;
165 }
166
168 {
170 "Testing library failed to create unique configuration based on `%s'\n",
171 sps->cfgname);
172 GNUNET_free (emsg);
174 return;
175 }
176
177 memset (&dummy,
178 '\0',
179 sizeof(dummy));
180
182 &sps->id);
183
184 if (0 == memcmp (&dummy,
185 &sps->id,
186 sizeof(struct GNUNET_PeerIdentity)))
187 {
189 "Testing library failed to obtain peer identity for peer %u\n",
190 sps->no);
191 GNUNET_free (emsg);
193 return;
194 }
196 "Peer %u configured with identity `%s'\n",
197 sps->no,
198 GNUNET_i2s_full (&sps->id));
199
200 GNUNET_free (home);
201 GNUNET_free (transport_unix_path);
202 GNUNET_free (tcp_communicator_unix_path);
203 GNUNET_free (udp_communicator_unix_path);
204 GNUNET_free (bindto);
205 GNUNET_free (bindto_udp);
206}
207
208
213static void
215{
216 struct GNUNET_TESTING_StartPeerState *sps = cls;
217
218 //TODO Investigate why this caused problems during shutdown.
219 /*if (NULL != sps->cfg)
220 {
221 GNUNET_CONFIGURATION_destroy (sps->cfg);
222 sps->cfg = NULL;
223 }*/
224 GNUNET_free (sps->cfgname);
225 GNUNET_free (sps->node_ip);
227 GNUNET_free (sps->hello);
229 GNUNET_free (sps);
230}
231
232
237static int
239 const void **ret,
240 const char *trait,
241 unsigned int index)
242{
243 struct GNUNET_TESTING_StartPeerState *sps = cls;
245 struct GNUNET_PeerIdentity *id = &sps->id;
246 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
248 char *hello = sps->hello;
249 size_t hello_size = sps->hello_size;
250 struct GNUNET_TESTING_Trait traits[] = {
254 void *)
255 connected_peers_map),
256 GNUNET_TRANSPORT_TESTING_make_trait_hello ((const void *) hello),
257 GNUNET_TRANSPORT_TESTING_make_trait_hello_size ((const void *) hello_size),
259 GNUNET_TRANSPORT_TESTING_make_trait_broadcast ((const void *) &sps->broadcast),
261 };
262
263 return GNUNET_TESTING_get_trait (traits,
264 ret,
265 trait,
266 index);
267}
268
269
272 const char *system_label,
273 uint32_t no,
274 const char *node_ip,
275 const char *cfgname,
276 unsigned int broadcast)
277{
279 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
281
283 sps->no = no;
284 sps->system_label = GNUNET_strdup (system_label);
285 sps->connected_peers_map = connected_peers_map;
286 sps->cfgname = GNUNET_strdup (cfgname);
287 sps->node_ip = GNUNET_strdup (node_ip);
288 sps->broadcast = broadcast;
289
290 return GNUNET_TESTING_command_new (sps,
291 label,
295 NULL);
296}
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_TESTING_Interpreter * is
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_System **ret)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_TESTING_make_trait_broadcast(const enum GNUNET_GenericReturnValue *value)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_TESTING_make_trait_state(const struct GNUNET_TESTING_StartPeerState *value)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_TESTING_make_trait_hello(const char *value)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_TESTING_make_trait_application_handle(const struct GNUNET_TRANSPORT_ApplicationHandle *value)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_TESTING_make_trait_connected_peers_map(const struct GNUNET_CONTAINER_MultiShortmap *value)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_TESTING_make_trait_peer_id(const struct GNUNET_PeerIdentity *value)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_TESTING_make_trait_hello_size(const size_t *value)
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1381
struct GNUNET_TESTING_Peer * GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg)
Configure a GNUnet peer.
Definition: testing.c:1188
int GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1167
void GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id)
Obtain the peer identity from a peer handle.
Definition: testing.c:1359
Internal representation of the hash map.
The identity of the host (wraps the signing key of the peer).
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
Global state of the interpreter, used by a command to access information about other commands.
struct GNUNET_PeerIdentity id
Peer identity.
const struct GNUNET_TESTING_System * tl_system
Test setup for this peer.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer's configuration.
char * system_label
The label of the command which was started by calling GNUNET_TESTING_cmd_system_create.
unsigned int no
An unique number to identify the peer.
struct GNUNET_CONTAINER_MultiShortmap * connected_peers_map
A map with struct GNUNET_MQ_Handle values for each peer this peer is connected to.
struct GNUNET_TESTING_Peer * peer
struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure.
enum GNUNET_GenericReturnValue broadcast
Flag indicating, if udp broadcast should be switched on.
char * cfgname
GNUnet configuration file used to start a peer.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:122
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
Handle to the TRANSPORT subsystem for application management.
static void start_peer_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_start_peer(const char *label, const char *system_label, uint32_t no, const char *node_ip, const char *cfgname, unsigned int broadcast)
Create command.
static int start_peer_traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
#define LOG(kind,...)
Generic logging shortcut.
static void start_peer_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will start all services of a peer to test the transport service.