GNUnet  0.11.x
Data Structures | Enumerations | Functions
testbed_api_services.c File Reference

convenience functions for accessing services More...

#include "platform.h"
#include "testbed_api.h"
#include "testbed_api_peers.h"
#include "testbed_api_operations.h"
Include dependency graph for testbed_api_services.c:

Go to the source code of this file.

Data Structures

struct  ServiceConnectData
 Data accessed during service connections. More...
 

Enumerations

enum  State {
  STATE_INIT = 0, STATE_SLAVES_STARTING, STATE_PEERS_CREATING, STATE_PEERS_STARTING,
  STATE_PEERS_LINKING, STATE_SEARCH_REGEX, STATE_PEERS_DESTROYING, INIT,
  CFG_REQUEST_QUEUED, SERVICE_CONNECTED, RC_INIT = 0, RC_LINKED,
  RC_PEERS_CREATED, RC_READY, RC_PEERS_SHUTDOWN
}
 States for Service connect operations. More...
 

Functions

static void configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
 Type of a function to call when we receive a message from the service. More...
 
static void opstart_service_connect (void *cls)
 Function called when a service connect operation is ready. More...
 
static void oprelease_service_connect (void *cls)
 Callback which will be called when service connect type operation is released. More...
 
struct GNUNET_TESTBED_OperationGNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
 Connect to a service offered by the given peer. More...
 

Detailed Description

convenience functions for accessing services

Author
Christian Grothoff

Definition in file testbed_api_services.c.

Enumeration Type Documentation

◆ State

enum State

States for Service connect operations.

Enumerator
STATE_INIT 

Initial state.

STATE_SLAVES_STARTING 

Starting slaves.

STATE_PEERS_CREATING 

Creating peers.

STATE_PEERS_STARTING 

Starting peers.

STATE_PEERS_LINKING 

Linking peers.

STATE_SEARCH_REGEX 

Matching strings against announced regexes.

STATE_PEERS_DESTROYING 

Destroying peers; we can do this as the controller takes care of stopping a peer if it is running.

INIT 

Initial state.

CFG_REQUEST_QUEUED 

The configuration request has been sent.

SERVICE_CONNECTED 

connected to service

RC_INIT 

Initial state.

RC_LINKED 

Controllers on given hosts started and linked.

RC_PEERS_CREATED 

Peers are created.

RC_READY 

The testbed run is ready and the master callback can be called now.

At this time the peers are all started and if a topology is provided in the configuration the topology would have been attempted

RC_PEERS_SHUTDOWN 

All peers shutdown (stopped and destroyed)

Definition at line 35 of file testbed_api_services.c.

36 {
40  INIT,
41 
46 
51 };
connected to service
Initial state.
The configuration request has been sent.

Function Documentation

◆ configuration_receiver()

static void configuration_receiver ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Type of a function to call when we receive a message from the service.

Parameters
clsServiceConnectData
msgmessage received, NULL on timeout or fatal error

Definition at line 134 of file testbed_api_services.c.

References ServiceConnectData::ca, ServiceConnectData::cada_cls, ServiceConnectData::cb, ServiceConnectData::cb_cls, GNUNET_TESTBED_Controller::cc, GNUNET_TESTBED_Controller::cc_cls, ServiceConnectData::cfg, GNUNET_TESTBED_Peer::controller, data, GNUNET_TESTBED_EventInformation::details, GNUNET_TESTBED_EventInformation::emsg, GNUNET_TESTBED_Controller::event_mask, GNUNET_assert, GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT, GNUNET_TESTBED_ET_OPERATION_FINISHED, GNUNET_TESTBED_extract_config_(), GNUNET_TESTBED_parse_error_string_(), GNUNET_TESTBED_EventInformation::op, ServiceConnectData::op_cls, GNUNET_TESTBED_EventInformation::op_cls, ServiceConnectData::op_result, ServiceConnectData::operation, GNUNET_TESTBED_EventInformation::operation_finished, ServiceConnectData::peer, SERVICE_CONNECTED, ServiceConnectData::state, GNUNET_MessageHeader::type, and GNUNET_TESTBED_EventInformation::type.

Referenced by opstart_service_connect().

135 {
136  struct ServiceConnectData *data = cls;
137  struct GNUNET_TESTBED_Controller *c;
138  const char *emsg;
140  uint16_t mtype;
141 
142  c = data->peer->controller;
143  mtype = ntohs (msg->type);
144  emsg = NULL;
146  info.op = data->operation;
147  info.op_cls = data->op_cls;
149  {
150  emsg =
153  *) msg);
154  if (NULL == emsg)
155  emsg = "Unknown error";
156  info.details.operation_finished.emsg = emsg;
157  info.details.operation_finished.generic = NULL;
158  goto call_cb;
159  }
160  data->cfg = GNUNET_TESTBED_extract_config_ (msg);
161  GNUNET_assert (NULL == data->op_result);
162  data->op_result = data->ca (data->cada_cls, data->cfg);
163  info.details.operation_finished.emsg = NULL;
164  info.details.operation_finished.generic = data->op_result;
165  data->state = SERVICE_CONNECTED;
166 
167 call_cb:
169  (NULL != c->cc))
170  c->cc (c->cc_cls, &info);
171  if (NULL != data->cb)
172  data->cb (data->cb_cls, data->operation, data->op_result, emsg);
173 }
struct GNUNET_TESTBED_Operation * operation
The operation which created this structure.
Handle to interact with a GNUnet testbed controller.
Definition: testbed_api.h:193
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONFIGURATION_Handle * cfg
The acquired configuration of the peer.
Argument to GNUNET_TESTBED_ControllerCallback with details about the event.
GNUNET_TESTBED_ConnectAdapter ca
helper function callback to establish the connection
const char * emsg
Error message for the operation, NULL on success.
Event notification from a controller to a client.
Definition: testbed.h:508
struct GNUNET_CONFIGURATION_Handle * GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg)
Generates configuration by uncompressing configuration in given message.
Definition: testbed_api.c:2066
void * op_cls
Closure for operation event.
#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT
Message for operation events.
uint64_t event_mask
The controller event mask.
Definition: testbed_api.h:265
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
void * cb_cls
The closure for operation completion callback.
connected to service
enum State state
State information.
A requested testbed operation has been completed.
struct GNUNET_TESTBED_Controller * controller
Our controller context (not necessarily the controller that is responsible for starting/running the p...
struct GNUNET_TESTBED_Peer * peer
The peer handle.
GNUNET_TESTBED_ServiceConnectCompletionCallback cb
The operation completion callback.
void * cada_cls
Closure to the above callbacks.
void * cc_cls
The closure for controller callback.
Definition: testbed_api.h:208
void * op_result
The op_result pointer from ConnectAdapter.
Data accessed during service connections.
uint32_t data
The data value.
const char * GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
Checks the integrity of the OperationFailureEventMessage and if good returns the error message it con...
Definition: testbed_api.c:2180
GNUNET_TESTBED_ControllerCallback cc
The controller callback.
Definition: testbed_api.h:203
Here is the call graph for this function:
Here is the caller graph for this function:

◆ opstart_service_connect()

static void opstart_service_connect ( void *  cls)
static

Function called when a service connect operation is ready.

Parameters
clsthe closure from GNUNET_TESTBED_operation_create_()

Definition at line 182 of file testbed_api_services.c.

References CFG_REQUEST_QUEUED, configuration_receiver(), GNUNET_TESTBED_Peer::controller, data, GNUNET_assert, GNUNET_free, GNUNET_TESTBED_forward_operation_msg_(), GNUNET_TESTBED_generate_peergetconfig_msg_(), GNUNET_TESTBED_get_next_op_id(), GNUNET_TESTBED_PeerGetConfigurationMessage::header, msg, ServiceConnectData::opc, ServiceConnectData::peer, ServiceConnectData::state, and GNUNET_TESTBED_Peer::unique_id.

Referenced by GNUNET_TESTBED_service_connect().

183 {
184  struct ServiceConnectData *data = cls;
186  struct GNUNET_TESTBED_Controller *c;
187  uint64_t op_id;
188 
189  GNUNET_assert (NULL != data);
190  GNUNET_assert (NULL != data->peer);
191  c = data->peer->controller;
192  op_id = GNUNET_TESTBED_get_next_op_id (c);
193  msg =
195  data->opc =
197  &configuration_receiver, data);
198  GNUNET_free (msg);
199  data->state = CFG_REQUEST_QUEUED;
200 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Handle to interact with a GNUnet testbed controller.
Definition: testbed_api.h:193
Message sent from client to testing service to obtain the configuration of a peer.
Definition: testbed.h:581
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller)
Function to return the operation id for a controller.
Definition: testbed_api.c:2208
struct GNUNET_TESTBED_PeerGetConfigurationMessage * GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, uint64_t operation_id)
Generate PeerGetConfigurationMessage.
enum State state
State information.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION.
Definition: testbed.h:586
struct GNUNET_TESTBED_Controller * controller
Our controller context (not necessarily the controller that is responsible for starting/running the p...
struct OperationContext * opc
The operation context from GNUNET_TESTBED_forward_operation_msg_()
struct GNUNET_TESTBED_Peer * peer
The peer handle.
struct OperationContext * GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controller, uint64_t operation_id, const struct GNUNET_MessageHeader *msg, GNUNET_MQ_MessageCallback cc, void *cc_cls)
Sends the given message as an operation.
Definition: testbed_api.c:1369
uint32_t unique_id
Globally unique ID of the peer.
Data accessed during service connections.
uint32_t data
The data value.
static void configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg)
Type of a function to call when we receive a message from the service.
#define GNUNET_free(ptr)
Wrapper around free.
The configuration request has been sent.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oprelease_service_connect()

static void oprelease_service_connect ( void *  cls)
static

Callback which will be called when service connect type operation is released.

Parameters
clsthe closure from GNUNET_TESTBED_operation_create_()

Definition at line 210 of file testbed_api_services.c.

References ServiceConnectData::cada_cls, ServiceConnectData::cfg, CFG_REQUEST_QUEUED, ServiceConnectData::da, data, GNUNET_assert, GNUNET_CONFIGURATION_destroy(), GNUNET_free, GNUNET_TESTBED_forward_operation_msg_cancel_(), INIT, ServiceConnectData::op_result, ServiceConnectData::opc, SERVICE_CONNECTED, and ServiceConnectData::state.

Referenced by GNUNET_TESTBED_service_connect().

211 {
212  struct ServiceConnectData *data = cls;
213 
214  switch (data->state)
215  {
216  case INIT:
217  break;
218 
219  case CFG_REQUEST_QUEUED:
220  GNUNET_assert (NULL != data->opc);
222  break;
223 
224  case SERVICE_CONNECTED:
225  GNUNET_assert (NULL != data->cfg);
227  if (NULL != data->da)
228  data->da (data->cada_cls, data->op_result);
229  break;
230  }
231  GNUNET_free (data);
232 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONFIGURATION_Handle * cfg
The acquired configuration of the peer.
connected to service
enum State state
State information.
void GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc)
Function to cancel an operation created by simply forwarding an operation message.
Definition: testbed_api.c:1406
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
GNUNET_TESTBED_DisconnectAdapter da
helper function callback to close the connection
struct OperationContext * opc
The operation context from GNUNET_TESTBED_forward_operation_msg_()
void * cada_cls
Closure to the above callbacks.
void * op_result
The op_result pointer from ConnectAdapter.
Data accessed during service connections.
Initial state.
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
The configuration request has been sent.
Here is the call graph for this function:
Here is the caller graph for this function: