GNUnet 0.21.1
testing_api_cmd_start_peer.c File Reference

cmd to start a peer. More...

Include dependency graph for testing_api_cmd_start_peer.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

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 int 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_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. More...
 

Detailed Description

cmd to start a peer.

Author
t3sserakt

Definition in file testing_api_cmd_start_peer.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 36 of file testing_api_cmd_start_peer.c.

Function Documentation

◆ 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 44 of file testing_api_cmd_start_peer.c.

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}
struct GNUNET_TESTING_Interpreter * is
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
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)
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
@ 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_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
The identity of the host (wraps the signing key of the peer).
A command to be run by the interpreter.
struct GNUNET_PeerIdentity id
Peer identity.
const struct GNUNET_TESTING_System * tl_system
Test setup for this peer.
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_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
#define LOG(kind,...)
Generic logging shortcut.

References GNUNET_TESTING_StartPeerState::broadcast, GNUNET_TESTING_StartPeerState::cfg, GNUNET_TESTING_StartPeerState::cfgname, dummy, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s_full(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_configuration_create(), GNUNET_TESTING_get_trait_test_system(), GNUNET_TESTING_interpreter_fail(), GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_peer_configure(), GNUNET_TESTING_peer_get_identity(), GNUNET_TESTING_peer_start(), GNUNET_YES, GNUNET_TESTING_StartPeerState::id, is, LOG, GNUNET_TESTING_StartPeerState::no, GNUNET_TESTING_StartPeerState::node_ip, GNUNET_TESTING_StartPeerState::peer, GNUNET_TESTING_StartPeerState::system_label, and GNUNET_TESTING_StartPeerState::tl_system.

Referenced by GNUNET_TESTING_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 214 of file testing_api_cmd_start_peer.c.

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}
struct GNUNET_CONTAINER_MultiShortmap * connected_peers_map
A map with struct GNUNET_MQ_Handle values for each peer this peer is connected to.

References GNUNET_TESTING_StartPeerState::cfgname, GNUNET_TESTING_StartPeerState::connected_peers_map, GNUNET_free, GNUNET_TESTING_StartPeerState::hello, GNUNET_TESTING_StartPeerState::node_ip, and GNUNET_TESTING_StartPeerState::system_label.

Referenced by GNUNET_TESTING_cmd_start_peer().

Here is the caller graph for this function:

◆ start_peer_traits()

static int 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 238 of file testing_api_cmd_start_peer.c.

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),
261 };
262
263 return GNUNET_TESTING_get_trait (traits,
264 ret,
265 trait,
266 index);
267}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
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.
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)
Internal representation of the hash map.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
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.

References ah, GNUNET_TESTING_StartPeerState::ah, GNUNET_TESTING_StartPeerState::connected_peers_map, GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TRANSPORT_TESTING_make_trait_application_handle(), GNUNET_TRANSPORT_TESTING_make_trait_broadcast(), GNUNET_TRANSPORT_TESTING_make_trait_connected_peers_map(), GNUNET_TRANSPORT_TESTING_make_trait_hello(), GNUNET_TRANSPORT_TESTING_make_trait_hello_size(), GNUNET_TRANSPORT_TESTING_make_trait_peer_id(), GNUNET_TRANSPORT_TESTING_make_trait_state(), GNUNET_TESTING_StartPeerState::hello, GNUNET_TESTING_StartPeerState::hello_size, GNUNET_TESTING_StartPeerState::id, GNUNET_TESTING_Trait::index, and ret.

Referenced by GNUNET_TESTING_cmd_start_peer().

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

◆ GNUNET_TESTING_cmd_start_peer()

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.

Parameters
labelname for command.
system_labelLabel of the cmd to setup a test environment.
noDecimal number representing the last byte of the IP address of this peer.
node_ipThe IP address of this node.
cfgnameConfiguration file name for this peer.
broadcastFlag indicating, if broadcast should be switched on.
Returns
command.

Definition at line 271 of file testing_api_cmd_start_peer.c.

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}
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_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).
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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 int 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::broadcast, GNUNET_TESTING_StartPeerState::cfgname, GNUNET_TESTING_StartPeerState::connected_peers_map, GNUNET_CONTAINER_multishortmap_create(), GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_TESTING_command_new(), GNUNET_TESTING_StartPeerState::no, GNUNET_TESTING_StartPeerState::node_ip, start_peer_cleanup(), start_peer_run(), start_peer_traits(), and GNUNET_TESTING_StartPeerState::system_label.

Here is the call graph for this function: