GNUnet  0.11.x
Macros | Functions
testbed_api_cmd_peer.c File Reference

Command to create a peer. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "gnunet_testbed_ng_service.h"
#include "gnunet-service-testbed.h"
#include "testbed_api_peers.h"
Include dependency graph for testbed_api_cmd_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 int peer_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 
int GNUNET_TESTBED_get_trait_peer (const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_Peer **peer)
 Offer data from trait. More...
 
static void peer_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd)
 
static void do_abort (void *cls)
 abort task to run on test timed out More...
 
static void peer_started_cb (void *cls, const char *emsg)
 Functions of this signature are called when a peer has been successfully created. More...
 
static void peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
 Functions of this signature are called when a peer has been successfully created. More...
 
static void peer_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 
void peer_stopped_cb (void *cls, const char *emsg)
 
void GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps)
 Shutdown nicely. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_peer (const char *label, const char *controller_label, const char *hostname, const char *username, uint16_t port, struct GNUNET_CONFIGURATION_Handle *cfg)
 

Detailed Description

Command to create a peer.

Author
t3sserakt

Definition in file testbed_api_cmd_peer.c.

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 38 of file testbed_api_cmd_peer.c.

Referenced by do_abort(), GNUNET_TESTBED_shutdown_peer(), peer_started_cb(), and peer_stopped_cb().

Function Documentation

◆ peer_traits()

static int peer_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static
Parameters
clsclosure.
[out]retresult
traitname of the trait.
indexindex number of the object to offer.
Returns
GNUNET_OK on success.

Definition at line 52 of file testbed_api_cmd_peer.c.

References GNUNET_OK, GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, and PeerCmdState::peer.

Referenced by GNUNET_TESTBED_cmd_peer().

56 {
57  struct PeerCmdState *ps = cls;
58 
59  struct GNUNET_TESTING_Trait traits[] = {
60  {
61  .index = 0,
62  .trait_name = "peer",
63  .ptr = (const void *) ps->peer,
64  },
66  };
67 
68  return GNUNET_TESTING_get_trait (traits,
69  ret,
70  trait,
71  index);
72 
73  return GNUNET_OK;
74 }
struct GNUNET_TESTBED_Peer * peer
Peer to start.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
unsigned int index
Index number associated with the trait.
int GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_get_trait_peer()

int GNUNET_TESTBED_get_trait_peer ( const struct GNUNET_TESTING_Command cmd,
struct GNUNET_TESTBED_Peer **  peer 
)

Offer data from trait.

Parameters
cmdcommand to extract the controller from.
peerpointer GNUNET_TESTBED_PEER
Returns
GNUNET_OK on success.

Definition at line 84 of file testbed_api_cmd_peer.c.

References GNUNET_TESTING_Command::cls, and GNUNET_TESTING_Command::traits.

Referenced by tng_service_run().

87 {
88  return cmd->traits (cmd->cls,
89  (const void **) peer,
90  "peer",
91  (unsigned int) 0);
92 }
int(* traits)(void *cls, const void **ret, const char *trait, unsigned int index)
Extract information from a command that is useful for other commands.
void * cls
Closure for all commands with command-specific context information.
Here is the caller graph for this function:

◆ peer_cleanup()

static void peer_cleanup ( void *  cls,
const struct GNUNET_TESTING_Command cmd 
)
static
Parameters
clsclosure
cmdcurrent CMD being cleaned up.

Definition at line 102 of file testbed_api_cmd_peer.c.

Referenced by GNUNET_TESTBED_cmd_peer().

104 {
105  (void) cls;
106 }
Here is the caller graph for this function:

◆ do_abort()

static void do_abort ( void *  cls)
static

abort task to run on test timed out

Parameters
clsNULL
tcthe task context

Definition at line 116 of file testbed_api_cmd_peer.c.

References PeerCmdState::abort_task, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_TESTBED_shutdown_peer(), LOG, and PeerCmdState::peer_ready.

Referenced by peer_run().

117 {
118  struct PeerCmdState *ps = cls;
119 
120  if (GNUNET_NO == ps->peer_ready)
121  {
122  LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
123  ps->abort_task = NULL;
125  }
126 }
struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
void GNUNET_TESTBED_shutdown_peer(struct PeerCmdState *ps)
Shutdown nicely.
int peer_ready
Flag indicating if peer is ready.
#define LOG(kind,...)
Generic logging shortcut.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_started_cb()

static void peer_started_cb ( void *  cls,
const char *  emsg 
)
static

Functions of this signature are called when a peer has been successfully created.

Parameters
clsthe closure from GNUNET_TESTBED_peer_create()
emsgMAY contain an error description, if starting peer failed.

Definition at line 137 of file testbed_api_cmd_peer.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_TESTBED_operation_done(), GNUNET_YES, LOG, PeerCmdState::operation, and PeerCmdState::peer_ready.

Referenced by peer_create_cb().

139 {
140  struct PeerCmdState *ps = cls;
141 
143  if (NULL == emsg)
144  {
145  ps->peer_ready = GNUNET_YES;
146  }
147  else
148  {
149  LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error starting a peer: %s\n",
150  emsg);
151  }
152 
153 }
struct GNUNET_TESTBED_Operation * operation
Handle to operation.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2045
int peer_ready
Flag indicating if peer is ready.
#define LOG(kind,...)
Generic logging shortcut.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_create_cb()

static void peer_create_cb ( void *  cls,
struct GNUNET_TESTBED_Peer peer,
const char *  emsg 
)
static

Functions of this signature are called when a peer has been successfully created.

Parameters
clsthe closure from GNUNET_TESTBED_peer_create()
peerthe handle for the created peer; NULL on any error during creation
emsgNULL if peer is not NULL; else MAY contain the error description

Definition at line 166 of file testbed_api_cmd_peer.c.

References GNUNET_TESTBED_operation_done(), GNUNET_TESTBED_peer_start(), PeerCmdState::operation, PeerCmdState::peer, peer, and peer_started_cb().

Referenced by peer_run().

169 {
170  struct PeerCmdState *ps = cls;
171 
172  ps->peer = peer;
175  peer,
177  ps);
178 }
struct GNUNET_TESTBED_Peer * peer
Peer to start.
static void peer_started_cb(void *cls, const char *emsg)
Functions of this signature are called when a peer has been successfully created. ...
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_start(void *op_cls, struct GNUNET_TESTBED_Peer *peer, GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls)
Start the given peer.
struct GNUNET_TESTBED_Operation * operation
Handle to operation.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2045
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_run()

static void peer_run ( void *  cls,
const struct GNUNET_TESTING_Command cmd,
struct GNUNET_TESTING_Interpreter is 
)
static

Definition at line 182 of file testbed_api_cmd_peer.c.

References PeerCmdState::abort_task, PeerCmdState::cfg, PeerCmdState::controller_label, do_abort(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTBED_get_trait_controller(), GNUNET_TESTBED_host_create(), GNUNET_TESTBED_peer_create(), GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MINUTES, PeerCmdState::host, PeerCmdState::hostname, is, PeerCmdState::is, PeerCmdState::operation, peer_create_cb(), PeerCmdState::port, and PeerCmdState::username.

Referenced by GNUNET_TESTBED_cmd_peer().

185 {
186  struct PeerCmdState *ps = cls;
187  const struct GNUNET_TESTING_Command *controller_cmd;
188  struct GNUNET_TESTBED_Controller *controller;
189 
190  ps->is = is;
192  ps->controller_label);
193  GNUNET_TESTBED_get_trait_controller (controller_cmd,
194  &controller);
195  ps->host = GNUNET_TESTBED_host_create (ps->hostname, ps->username, ps->cfg,
196  ps->port);
197  ps->operation =
198  GNUNET_TESTBED_peer_create (controller,
199  ps->host,
200  ps->cfg,
202  ps);
203 
204  ps->abort_task =
207  &do_abort,
208  ps);
209 }
struct GNUNET_TESTING_Interpreter * is
Interpreter state.
Handle to interact with a GNUnet testbed controller.
Definition: testbed_api.h:197
int GNUNET_TESTBED_get_trait_controller(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_Controller **controller)
Offer data from trait.
static void do_abort(void *cls)
abort task to run on test timed out
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
A command to be run by the interpreter.
const char * username
Username to use for the login; may be NULL.
uint16_t port
Port number to use for ssh; use 0 to let ssh decide.
struct GNUNET_TESTBED_Operation * operation
Handle to operation.
static void peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
Functions of this signature are called when a peer has been successfully created. ...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
const char * controller_label
The label of a controller command.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311
struct GNUNET_TESTBED_Host * host
The host to run peers and controllers on.
struct GNUNET_TESTBED_Host * GNUNET_TESTBED_host_create(const char *hostname, const char *username, const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t port)
Create a host to run peers and controllers on.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration to use as a template while starting a controller on this host.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_create(struct GNUNET_TESTBED_Controller *controller, struct GNUNET_TESTBED_Host *host, const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TESTBED_PeerCreateCallback cb, void *cls)
Create the given peer at the specified host using the given controller.
const char * hostname
Name of the host, use "NULL" for localhost.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_stopped_cb()

void peer_stopped_cb ( void *  cls,
const char *  emsg 
)

Definition at line 213 of file testbed_api_cmd_peer.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_TESTBED_operation_done(), GNUNET_TESTBED_peer_destroy(), LOG, PeerCmdState::operation, and PeerCmdState::peer.

Referenced by GNUNET_TESTBED_shutdown_peer().

215 {
216  struct PeerCmdState *ps = cls;
217 
218  if (NULL != emsg)
219  {
220  LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error stopping a peer: %s\n",
221  emsg);
222  }
225 }
struct GNUNET_TESTBED_Peer * peer
Peer to start.
struct GNUNET_TESTBED_Operation * operation
Handle to operation.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2045
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_destroy(struct GNUNET_TESTBED_Peer *peer)
Destroy the given peer; the peer should have been stopped first (if it was started).
#define LOG(kind,...)
Generic logging shortcut.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_cmd_peer()

struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_peer ( const char *  label,
const char *  controller_label,
const char *  hostname,
const char *  username,
uint16_t  port,
struct GNUNET_CONFIGURATION_Handle cfg 
)

Definition at line 256 of file testbed_api_cmd_peer.c.

References cfg, PeerCmdState::cfg, GNUNET_TESTING_Command::cls, PeerCmdState::controller_label, GNUNET_new, PeerCmdState::hostname, hostname, GNUNET_TESTING_Command::label, peer_cleanup(), peer_run(), peer_traits(), PeerCmdState::port, port, and PeerCmdState::username.

262 {
263  struct PeerCmdState *ps;
264 
265  ps = GNUNET_new (struct PeerCmdState);
266  ps->hostname = hostname;
267  ps->username = username;
268  ps->port = port;
269  ps->cfg = cfg;
271 
272  struct GNUNET_TESTING_Command cmd = {
273  .cls = ps,
274  .label = label,
275  .run = &peer_run,
276  .cleanup = &peer_cleanup,
277  .traits = &peer_traits
278  };
279 
280  return cmd;
281 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int peer_traits(void *cls, const void **ret, const char *trait, unsigned int index)
const char * label
Label for the command.
A command to be run by the interpreter.
const char * username
Username to use for the login; may be NULL.
uint16_t port
Port number to use for ssh; use 0 to let ssh decide.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void peer_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
const char * controller_label
The label of a controller command.
static void peer_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration to use as a template while starting a controller on this host.
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
void * cls
Closure for all commands with command-specific context information.
const char * hostname
Name of the host, use "NULL" for localhost.
Here is the call graph for this function: