GNUnet 0.21.2
testing_arm_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"
28#include "gnunet_testing_lib.h"
29#include "gnunet_testbed_lib.h"
32
33
38{
39
40 const char *system_label;
41
42 const char *cfgname;
43
48
53
58
63
68
73
74};
75
76
84static void
86 void *cls,
87 enum GNUNET_GenericReturnValue connected)
88{
89 struct GNUNET_TESTING_StartPeerState *sps = cls;
90
91 if (GNUNET_OK != connected)
92 {
93 GNUNET_break (0);
95 return;
96 }
98}
99
100
105static void
106start_peer_run (void *cls,
108{
109 struct GNUNET_TESTING_StartPeerState *sps = cls;
110 const struct GNUNET_TESTING_Command *system_cmd;
111
112 sps->is = is;
113 if (GNUNET_NO ==
115 {
117 "File not found: `%s'\n",
118 sps->cfgname);
120 }
121 system_cmd
123 sps->system_label);
124 if (NULL == system_cmd)
126 if (GNUNET_OK !=
128 system_cmd,
129 &sps->system))
132 if (GNUNET_OK !=
134 sps->cfgname))
136 if (GNUNET_SYSERR ==
138 sps->cfg,
139 NULL,
140 NULL))
142 {
143 char *config_filename;
144 char *libexec_binary;
145 char *main_binary;
146 char *args;
147 char *prefix;
148
150 GNUNET_OK ==
152 sps->cfg,
153 "PATHS",
154 "DEFAULTCONFIG",
155 &config_filename));
156 if (GNUNET_OK !=
158 config_filename))
159 {
161 "Failed to write configuration file `%s': %s\n",
162 config_filename,
163 strerror (errno));
164 GNUNET_free (config_filename);
166 }
167
168 libexec_binary
169 = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
170
171 if (GNUNET_SYSERR ==
173 "arm",
174 "PREFIX",
175 &prefix))
176 {
177 /* No prefix */
178 main_binary = libexec_binary;
179 args = GNUNET_strdup ("");
180 }
181 else
182 {
183 main_binary = prefix;
184 args = libexec_binary;
185 }
186 sps->arm
188 NULL,
189 main_binary,
190 args,
191 "-c",
192 config_filename,
193 NULL);
194 if (NULL == sps->arm)
195 {
197 _ ("Failed to start `%s': %s\n"),
198 main_binary,
199 strerror (errno));
201 }
202 GNUNET_free (config_filename);
203 GNUNET_free (main_binary);
205 }
206
207 sps->ah = GNUNET_ARM_connect (sps->cfg,
209 sps);
210 if (NULL == sps->ah)
212}
213
214
219static void
221{
222 struct GNUNET_TESTING_StartPeerState *sps = cls;
223
224 if (NULL != sps->ah)
225 {
227 sps->ah = NULL;
228 }
229 if (NULL != sps->arm)
230 {
231 GNUNET_break (0 ==
233 SIGTERM));
237 sps->ah = NULL;
238 }
239
240 if (NULL != sps->cfg)
241 {
243 sps->cfg = NULL;
244 }
245 GNUNET_free (sps);
246}
247
248
255 const void **ret,
256 const char *trait,
257 unsigned int index)
258{
259 struct GNUNET_TESTING_StartPeerState *sps = cls;
260 struct GNUNET_TESTING_Trait traits[] = {
262 &sps->arm),
263 // FIXME: expose sps->cfg as trait...
264 GNUNET_TESTING_ARM_make_trait_arm_handle (
265 sps->ah),
267 };
268
270 ret,
271 trait,
272 index);
273}
274
275
278 const char *label,
279 const char *system_label,
280 const char *cfgname)
281{
283
286 sps->cfgname = cfgname;
288 label,
292 &sps->ac);
293}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_TESTING_Interpreter * is
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:66
enum GNUNET_GenericReturnValue GNUNET_TESTBED_configuration_create(struct GNUNET_TESTBED_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t **ports, unsigned int *nports)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testbed.c:532
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(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 that may be asynchronous.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process(struct GNUNET_OS_Process **value)
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
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_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.
enum GNUNET_GenericReturnValue GNUNET_TESTING_TESTBED_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_System **ret)
struct GNUNET_ARM_Handle * GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ARM_ConnectionStatusCallback conn_status, void *conn_status_cls)
Set up a context for communicating with ARM, then start connecting to the ARM service using that cont...
Definition: arm_api.c:577
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service and destroy the handle.
Definition: arm_api.c:603
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
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_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
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
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#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.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:665
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:877
@ GNUNET_OS_INHERIT_STD_OUT_AND_ERR
When these flags are set, the child process will inherit stdout and stderr of the parent.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle for interacting with ARM.
Definition: arm_api.c:103
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testbed.c:54
State each asynchronous command must have in its closure.
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Handle for a peer controlled via ARM.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
char * system_label
The label of the command which was started by calling GNUNET_TESTING_cmd_system_create.
struct GNUNET_TESTING_Interpreter * is
Our interpreter.
struct GNUNET_OS_Process * arm
Handle to the ARM process information.
struct GNUNET_ARM_Handle * ah
The handle to the peer's ARM service.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer's configuration.
struct GNUNET_TESTBED_System * system
The TESTBED system associated with this peer.
char * cfgname
GNUnet configuration file used to start a peer.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
static void conn_status(void *cls, enum GNUNET_GenericReturnValue connected)
Function called whenever we connect to or disconnect from ARM.
static void start_peer_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static enum GNUNET_GenericReturnValue start_peer_traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
struct GNUNET_TESTING_Command GNUNET_TESTING_ARM_cmd_start_peer(const char *label, const char *system_label, const char *cfgname)
Create command.
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.