GNUnet 0.22.0
testing_arm_cmd_start_peer.c File Reference
Include dependency graph for testing_arm_cmd_start_peer.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TESTING_StartPeerState
 Handle for a peer controlled via ARM. More...
 

Functions

static void conn_status (void *cls, enum GNUNET_GenericReturnValue connected)
 Function called whenever we connect to or disconnect from ARM. More...
 
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. More...
 
static void start_peer_cleanup (void *cls)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
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. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_ARM_cmd_start_peer (const char *label, const char *system_label, const char *cfgname)
 Create command. More...
 

Function Documentation

◆ conn_status()

static void conn_status ( void *  cls,
enum GNUNET_GenericReturnValue  connected 
)
static

Function called whenever we connect to or disconnect from ARM.

Parameters
clsclosure
connectedGNUNET_YES if connected, GNUNET_NO if disconnected, GNUNET_SYSERR if there was an error.

Definition at line 85 of file testing_arm_cmd_start_peer.c.

88{
89 struct GNUNET_TESTING_StartPeerState *sps = cls;
90 struct GNUNET_TESTING_AsyncContext ac = sps->ac;
91
93 "We %s arm\n",
94 GNUNET_OK != connected ? "disconnected from" : "connected to");
95 if (GNUNET_NO == ac.finished && GNUNET_OK != connected)
96 {
97 GNUNET_break (0);
99 return;
100 }
101 else if (GNUNET_NO == ac.finished)
103}
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_NO
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
State each asynchronous command must have in its closure.
enum GNUNET_GenericReturnValue finished
Indication if the command finished (GNUNET_OK).
Handle for a peer controlled via ARM.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.

References GNUNET_TESTING_StartPeerState::ac, GNUNET_TESTING_AsyncContext::finished, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_TESTING_async_fail(), and GNUNET_TESTING_async_finish().

Referenced by start_peer_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_peer_run()

static void start_peer_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

The run method of this cmd will start all services of a peer to test the transport service.

Definition at line 111 of file testing_arm_cmd_start_peer.c.

113{
114 struct GNUNET_TESTING_StartPeerState *sps = cls;
115 const struct GNUNET_TESTING_Command *system_cmd;
116
117 sps->is = is;
118 if (GNUNET_NO ==
120 {
122 "File not found: `%s'\n",
123 sps->cfgname);
125 }
126 system_cmd
128 sps->system_label);
129 if (NULL == system_cmd)
131 if (GNUNET_OK !=
133 system_cmd,
134 &sps->system))
137 if (GNUNET_OK !=
139 sps->cfgname))
141 if (GNUNET_SYSERR ==
143 sps->cfg,
144 NULL,
145 NULL))
147 {
148 char *config_filename;
149 char *libexec_binary;
150 char *main_binary;
151 char *args;
152 char *prefix;
153
155 GNUNET_OK ==
157 sps->cfg,
158 "PATHS",
159 "DEFAULTCONFIG",
160 &config_filename));
161 if (GNUNET_OK !=
163 config_filename))
164 {
166 "Failed to write configuration file `%s': %s\n",
167 config_filename,
168 strerror (errno));
169 GNUNET_free (config_filename);
171 }
172
173 libexec_binary
174 = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
175
176 if (GNUNET_SYSERR ==
178 "arm",
179 "PREFIX",
180 &prefix))
181 {
182 /* No prefix */
183 main_binary = libexec_binary;
184 args = GNUNET_strdup ("");
185 }
186 else
187 {
188 main_binary = prefix;
189 args = libexec_binary;
190 }
191 sps->arm
193 NULL,
194 main_binary,
195 args,
196 "-c",
197 config_filename,
198 NULL);
199 if (NULL == sps->arm)
200 {
202 _ ("Failed to start `%s': %s\n"),
203 main_binary,
204 strerror (errno));
206 }
207 GNUNET_free (config_filename);
208 GNUNET_free (main_binary);
210 }
211
212 sps->ah = GNUNET_ARM_connect (sps->cfg,
214 sps);
215 if (NULL == sps->ah)
217}
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
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
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
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.
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:483
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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
@ 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
A command to be run by the interpreter.
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_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.
static void conn_status(void *cls, enum GNUNET_GenericReturnValue connected)
Function called whenever we connect to or disconnect from ARM.

References _, GNUNET_TESTING_StartPeerState::ah, consensus-simulation::args, GNUNET_TESTING_StartPeerState::arm, GNUNET_TESTING_StartPeerState::cfg, GNUNET_TESTING_StartPeerState::cfgname, conn_status(), GNUNET_ARM_connect(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_OS_start_process_s(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_TESTBED_configuration_create(), GNUNET_TESTING_FAIL, GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_TESTBED_get_trait_test_system(), is, GNUNET_TESTING_StartPeerState::is, prefix, GNUNET_TESTING_StartPeerState::system, and GNUNET_TESTING_StartPeerState::system_label.

Referenced by GNUNET_TESTING_ARM_cmd_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_peer_cleanup()

static void start_peer_cleanup ( void *  cls)
static

The cleanup function of this cmd frees resources the cmd allocated.

Definition at line 225 of file testing_arm_cmd_start_peer.c.

226{
227 struct GNUNET_TESTING_StartPeerState *sps = cls;
228
229 if (NULL != sps->ah)
230 {
232 sps->ah = NULL;
233 }
234 if (NULL != sps->arm)
235 {
236 GNUNET_break (0 ==
238 SIGTERM));
242 sps->ah = NULL;
243 }
244
245 if (NULL != sps->cfg)
246 {
248 sps->cfg = NULL;
249 }
250 GNUNET_free (sps);
251}
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service and destroy the handle.
Definition: arm_api.c:603
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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

References GNUNET_TESTING_StartPeerState::ah, GNUNET_TESTING_StartPeerState::arm, GNUNET_TESTING_StartPeerState::cfg, GNUNET_ARM_disconnect(), GNUNET_break, GNUNET_CONFIGURATION_destroy(), GNUNET_free, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), and GNUNET_OS_process_wait().

Referenced by GNUNET_TESTING_ARM_cmd_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_peer_traits()

static enum GNUNET_GenericReturnValue start_peer_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

This function prepares an array with traits.

Definition at line 259 of file testing_arm_cmd_start_peer.c.

263{
264 struct GNUNET_TESTING_StartPeerState *sps = cls;
265 struct GNUNET_TESTING_Trait traits[] = {
267 &sps->arm),
268 // FIXME: expose sps->cfg as trait...
269 GNUNET_TESTING_ARM_make_trait_arm_handle (
270 sps->ah),
272 };
273
275 ret,
276 trait,
277 index);
278}
static int ret
Final status code.
Definition: gnunet-arm.c:93
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process(struct GNUNET_OS_Process **value)
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.
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.

References GNUNET_TESTING_StartPeerState::ah, GNUNET_TESTING_StartPeerState::arm, GNUNET_TESTING_get_trait(), GNUNET_TESTING_make_trait_process(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ret, and traits().

Referenced by GNUNET_TESTING_ARM_cmd_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_ARM_cmd_start_peer()

struct GNUNET_TESTING_Command GNUNET_TESTING_ARM_cmd_start_peer ( const char *  label,
const char *  system_label,
const char *  cfgname 
)

Create command.

Parameters
labelname for command.
system_labelLabel of the cmd to setup a test environment.
cfgnameConfiguration file name for this peer.
Returns
command.

Definition at line 282 of file testing_arm_cmd_start_peer.c.

286{
288
291 sps->cfgname = cfgname;
293 label,
297 &sps->ac);
298}
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
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.

References GNUNET_TESTING_StartPeerState::ac, GNUNET_TESTING_StartPeerState::cfgname, GNUNET_new, GNUNET_strdup, GNUNET_TESTING_command_new_ac(), start_peer_cleanup(), start_peer_run(), start_peer_traits(), and GNUNET_TESTING_StartPeerState::system_label.

Here is the call graph for this function: