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

Command to create a controller. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "gnunet-service-testbed.h"
#include "testbed_api_hosts.h"
#include "gnunet_testbed_ng_service.h"
Include dependency graph for testbed_api_cmd_controller.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 do_abort (void *cls)
 abort task to run on test timed out More...
 
static void controller_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd)
 
static void controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
 Signature of the event handler function called by the respective event controller. More...
 
static void registration_comp (void *cls, const char *emsg)
 Callback which will be called to after a host registration succeeded or failed. More...
 
static void controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status)
 Callback to signal successful startup of the controller process. More...
 
static void controller_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 
static int controller_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 
int GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_Controller **controller)
 Offer data from trait. More...
 
void GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs)
 Shutdown nicely. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_controller (const char *label, const char *trusted_ip, const char *hostname, const char *username, uint16_t port, struct GNUNET_CONFIGURATION_Handle *cfg, uint64_t event_mask)
 

Detailed Description

Command to create a controller.

Author
t3sserakt

Definition in file testbed_api_cmd_controller.c.

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 37 of file testbed_api_cmd_controller.c.

Referenced by controller_cb(), do_abort(), GNUNET_TESTBED_shutdown_controller(), and registration_comp().

Function Documentation

◆ 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 48 of file testbed_api_cmd_controller.c.

References ControllerState::abort_task, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_TESTBED_shutdown_controller(), ControllerState::host_ready, and LOG.

Referenced by controller_run().

49 {
50  struct ControllerState *cs = cls;
51 
52  if (GNUNET_NO == cs->host_ready)
53  {
54  LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
55  cs->abort_task = NULL;
57  }
58 }
int host_ready
Flag indicating if host create with controller is ready.
struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
#define LOG(kind,...)
Generic logging shortcut.
void GNUNET_TESTBED_shutdown_controller(struct ControllerState *cs)
Shutdown nicely.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ controller_cleanup()

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

Definition at line 68 of file testbed_api_cmd_controller.c.

Referenced by GNUNET_TESTBED_cmd_controller().

70 {
71  (void) cls;
72 }
Here is the caller graph for this function:

◆ controller_cb()

static void controller_cb ( void *  cls,
const struct GNUNET_TESTBED_EventInformation event 
)
static

Signature of the event handler function called by the respective event controller.

Parameters
clsclosure
eventinformation about the event

Definition at line 83 of file testbed_api_cmd_controller.c.

References GNUNET_TESTBED_EventInformation::details, GNUNET_ERROR_TYPE_ERROR, GNUNET_TESTBED_operation_done(), GNUNET_TESTBED_shutdown_controller(), LOG, GNUNET_TESTBED_EventInformation::op, and GNUNET_TESTBED_EventInformation::operation_finished.

Referenced by controller_status_cb().

85 {
86  struct ControllerState *cs = cls;
87 
88  if (NULL != event->details.operation_finished.emsg)
89  {
90  LOG (GNUNET_ERROR_TYPE_ERROR, "There was an operation error: %s\n",
91  event->details.operation_finished.emsg);
93  }
94  else if (NULL == event->details.operation_finished.generic)
95  {
97  }
98 }
union GNUNET_TESTBED_EventInformation::@43 details
Details about the event.
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_EventInformation::@43::@48 operation_finished
Details about an operation finished event.
#define LOG(kind,...)
Generic logging shortcut.
void GNUNET_TESTBED_shutdown_controller(struct ControllerState *cs)
Shutdown nicely.
struct GNUNET_TESTBED_Operation * op
Handle for the corresponding operation that generated this event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ registration_comp()

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

Callback which will be called to after a host registration succeeded or failed.

Parameters
clsthe host which has been registered
emsgthe error message; NULL if host registration is successful

Definition at line 108 of file testbed_api_cmd_controller.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_TESTBED_shutdown_controller(), GNUNET_YES, ControllerState::host_ready, LOG, and ControllerState::reg_handle.

Referenced by controller_status_cb().

110 {
111  struct ControllerState *cs = cls;
112 
113  if (NULL != emsg)
114  {
116  "There was an error during host registration: %s\n",
117  emsg);
119  }
120  else
121  {
122  cs->reg_handle = NULL;
123  cs->host_ready = GNUNET_YES;
124  }
125 }
int host_ready
Flag indicating if host create with controller is ready.
struct GNUNET_TESTBED_HostRegistrationHandle * reg_handle
Handle for host registration.
#define LOG(kind,...)
Generic logging shortcut.
void GNUNET_TESTBED_shutdown_controller(struct ControllerState *cs)
Shutdown nicely.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ controller_status_cb()

static void controller_status_cb ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg_,
int  status 
)
static

Callback to signal successful startup of the controller process.

Parameters
clsthe closure from GNUNET_TESTBED_controller_start()
cfgthe configuration with which the controller has been started; NULL if status is not GNUNET_OK
statusGNUNET_OK if the startup is successful; GNUNET_SYSERR if not, GNUNET_TESTBED_controller_stop() shouldn't be called in this case

Definition at line 138 of file testbed_api_cmd_controller.c.

References ControllerState::controller, controller_cb(), ControllerState::cp, ControllerState::event_mask, GNUNET_OK, GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_register_host(), ControllerState::host, ControllerState::reg_handle, and registration_comp().

Referenced by controller_run().

141 {
142  struct ControllerState *cs = cls;
143 
144  if (GNUNET_OK != status)
145  {
146  cs->cp = NULL;
147  return;
148  }
149 
150  cs->controller =
152  cs);
153  cs->reg_handle =
155  cs);
156 }
static void controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Signature of the event handler function called by the respective event controller.
struct GNUNET_TESTBED_HostRegistrationHandle * reg_handle
Handle for host registration.
struct GNUNET_TESTBED_Host * host
The host to run peers and controllers on.
uint16_t status
See PRISM_STATUS_*-constants.
struct GNUNET_TESTBED_ControllerProc * cp
The controller process.
struct GNUNET_TESTBED_Controller * GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls)
Connect to a controller process.
Definition: testbed_api.c:1555
uint64_t event_mask
A bit mask with set of events to call the controller for.
struct GNUNET_TESTBED_HostRegistrationHandle * GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_HostRegistrationCompletion cc, void *cc_cls)
Register a host with the controller.
static void registration_comp(void *cls, const char *emsg)
Callback which will be called to after a host registration succeeded or failed.
struct GNUNET_TESTBED_Controller * controller
The controller handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ controller_run()

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

Definition at line 160 of file testbed_api_cmd_controller.c.

References ControllerState::abort_task, ControllerState::cfg, controller_status_cb(), ControllerState::cp, do_abort(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTBED_controller_start(), GNUNET_TESTBED_host_create(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MINUTES, ControllerState::host, ControllerState::hostname, is, ControllerState::is, ControllerState::port, ControllerState::trusted_ip, and ControllerState::username.

Referenced by GNUNET_TESTBED_cmd_controller().

163 {
164  struct ControllerState *cs = cls;
165 
166  cs->is = is;
167  cs->host = GNUNET_TESTBED_host_create (cs->hostname, cs->username, cs->cfg,
168  cs->port);
170  cs->host,
172  cs);
173  cs->abort_task =
176  &do_abort,
177  cs);
178 }
static void do_abort(void *cls)
abort task to run on test timed out
#define GNUNET_TIME_UNIT_MINUTES
One minute.
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_TESTING_Interpreter * is
Interpreter state.
static void controller_status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status)
Callback to signal successful startup of the controller process.
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
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration to use as a template while starting a controller on this host.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TESTBED_Host * host
The host to run peers and controllers on.
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 * 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_TESTBED_ControllerProc * cp
The controller process.
struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
const char * hostname
Name of the host, use "NULL" for localhost.
struct GNUNET_TESTBED_ControllerProc * GNUNET_TESTBED_controller_start(const char *trusted_ip, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_ControllerStatusCallback cb, void *cls)
Starts a controller process at the given host.
const char * trusted_ip
The ip address of the controller which will be set as TRUSTED HOST(all connections form this ip are p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ controller_traits()

static int controller_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 190 of file testbed_api_cmd_controller.c.

References ControllerState::controller, GNUNET_OK, GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), and GNUNET_TESTING_Trait::index.

Referenced by GNUNET_TESTBED_cmd_controller().

194 {
195  (void) cls;
196 
197  struct ControllerState *cs = cls;
198 
199 
200  struct GNUNET_TESTING_Trait traits[] = {
201  {
202  .index = 0,
203  .trait_name = "controller",
204  .ptr = (const void *) cs->controller,
205  },
207  };
208 
209  return GNUNET_TESTING_get_trait (traits,
210  ret,
211  trait,
212  index);
213  return GNUNET_OK;
214 }
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.
struct GNUNET_TESTBED_Controller * controller
The controller handle.
Here is the call graph for this function:
Here is the caller graph for this function: