GNUnet  0.11.x
Macros | Functions
testbed_api_cmd_tng_service.c File Reference
#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_tng_service.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 tng_service_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd)
 
static int tng_service_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 
static void * notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 
static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
 
static void * connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Adapter function called to establish a connection to a service. More...
 
static void disconnect_adapter (void *cls, void *op_result)
 Adapter function called to destroy a connection to a service. More...
 
static void service_connect_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
 Callback to be called when a service connect operation is completed. More...
 
static void pi_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg)
 Callback to be called when the requested peer information is available. More...
 
static void tng_service_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 
void GNUNET_TESTBED_shutdown_service (struct TngState *cs)
 Shutdown nicely. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_tng_service (const char *label, const char *peer_label, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_TRANSPORT_NotifyConnect nc, void *cb_cls)
 

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 36 of file testbed_api_cmd_tng_service.c.

Referenced by do_abort(), GNUNET_TESTBED_shutdown_service(), notify_connect(), and service_connect_comp_cb().

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 47 of file testbed_api_cmd_tng_service.c.

References TngState::abort_task, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_TESTBED_shutdown_service(), LOG, and TngState::service_ready.

48 {
49  struct TngState *ts = cls;
50 
51  if (GNUNET_NO == ts->service_ready)
52  {
53  LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
54  ts->abort_task = NULL;
56  }
57 }
int service_ready
Flag indicating if service is ready.
void GNUNET_TESTBED_shutdown_service(struct TngState *cs)
Shutdown nicely.
struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
#define LOG(kind,...)
Generic logging shortcut.
Here is the call graph for this function:

◆ tng_service_cleanup()

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

Definition at line 66 of file testbed_api_cmd_tng_service.c.

68 {
69  (void) cls;
70 }

◆ tng_service_traits()

static int tng_service_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 82 of file testbed_api_cmd_tng_service.c.

References GNUNET_OK.

Referenced by GNUNET_TESTBED_cmd_tng_service().

86 {
87  (void) cls;
88  return GNUNET_OK;
89 }
Here is the caller graph for this function:

◆ notify_connect()

static void* notify_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Definition at line 93 of file testbed_api_cmd_tng_service.c.

References TngState::cb_cls, GNUNET_ERROR_TYPE_ERROR, LOG, and TngState::nc.

Referenced by connect_adapter().

96 {
97  struct TngState *ts = cls;
98 
99  if (NULL != emsg)
100  {
102  "There was an error starting the transport subsystem: %s\n",
103  emsg);
104  }
105  GNUNET_TESTING_interpreter_next (ps->is);
106  return ts->nc (ts->cb_cls);
107 
108 }
void * cb_cls
Closure for the nc callback.
GNUNET_TRANSPORT_NotifyConnect nc
Notify connect callback.
#define LOG(kind,...)
Generic logging shortcut.
Here is the caller graph for this function:

◆ notify_disconnect()

static void notify_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  handler_cls 
)
static

Definition at line 112 of file testbed_api_cmd_tng_service.c.

Referenced by connect_adapter().

115 {
116 }
Here is the caller graph for this function:

◆ connect_adapter()

static void* connect_adapter ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Adapter function called to establish a connection to a service.

Parameters
clsclosure
cfgconfiguration of the peer to connect to; will be available until GNUNET_TESTBED_operation_done() is called on the operation returned from GNUNET_TESTBED_service_connect()
Returns
service handle to return in 'op_result', NULL on error

Definition at line 132 of file testbed_api_cmd_tng_service.c.

References GNUNET_TRANSPORT_core_connect(), TngState::handlers, notify_connect(), notify_disconnect(), and TngState::peer_identity.

Referenced by pi_cb().

134 {
135  struct TngState *ts = cls;
136 
137  service_handle = GNUNET_TRANSPORT_core_connect (cfg,
138  ts->peer_identity,
139  ts->handlers,
140  ts,
143  return service_handle;
144 }
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
struct GNUNET_PeerIdentity * peer_identity
Peer identity of the system.
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
const struct GNUNET_MQ_MessageHandler * handlers
Message handler for transport service.
static void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect_adapter()

static void disconnect_adapter ( void *  cls,
void *  op_result 
)
static

Adapter function called to destroy a connection to a service.

Parameters
clsclosure
op_resultservice handle returned from the connect adapter

Definition at line 155 of file testbed_api_cmd_tng_service.c.

Referenced by pi_cb().

157 {
158 }
Here is the caller graph for this function:

◆ service_connect_comp_cb()

static void service_connect_comp_cb ( void *  cls,
struct GNUNET_TESTBED_Operation op,
void *  ca_result,
const char *  emsg 
)
static

Callback to be called when a service connect operation is completed.

Parameters
clsthe callback closure from functions generating an operation
opthe operation that has been finished
ca_resultthe service handle returned from GNUNET_TESTBED_ConnectAdapter()
emsgerror message in case the operation has failed; will be NULL if operation has executed successfully.

Definition at line 170 of file testbed_api_cmd_tng_service.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_TESTBED_operation_done(), LOG, and TngState::operation.

Referenced by pi_cb().

174 {
175  struct TngState *ts = cls;
176 
177  if (NULL != emsg)
178  {
180  "An error occurred connecting to service %s\n",
181  emsg);
183  }
184 }
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
#define LOG(kind,...)
Generic logging shortcut.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pi_cb()

static void pi_cb ( void *  cls,
struct GNUNET_TESTBED_Operation op,
const struct GNUNET_TESTBED_PeerInformation pinfo,
const char *  emsg 
)
static

Callback to be called when the requested peer information is available.

Parameters
clsthe closure from GNUNET_TESTBED_peer_getinformation()
opthe operation this callback corresponds to
pinfothe result; will be NULL if the operation has failed
emsgerror message if the operation has failed; NULL if the operation is successful

Definition at line 197 of file testbed_api_cmd_tng_service.c.

References connect_adapter(), disconnect_adapter(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_PeerInformation::id, TngState::operation, peer, TngState::peer_identity, and service_connect_comp_cb().

Referenced by tng_service_run().

201 {
202  struct TngState *ts = cls;
203 
204  ts->peer_identity = pinfo->id;
205  ts->operation =
210  ts);
211 }
static void disconnect_adapter(void *cls, void *op_result)
Adapter function called to destroy a connection to a service.
struct GNUNET_TESTBED_Operation * operation
Handle to operation.
static void service_connect_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Callback to be called when a service connect operation is completed.
struct GNUNET_PeerIdentity * id
The identity of the peer.
struct GNUNET_TESTBED_Operation * GNUNET_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.
struct GNUNET_PeerIdentity * peer_identity
Peer identity of the system.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void * connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to a service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tng_service_run()

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

Definition at line 215 of file testbed_api_cmd_tng_service.c.

References GNUNET_TESTBED_get_trait_peer(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_PIT_IDENTITY, GNUNET_TESTING_interpreter_lookup_command(), is, TngState::operation, peer, TngState::peer_label, and pi_cb().

Referenced by GNUNET_TESTBED_cmd_tng_service().

218 {
219  struct TngState *ts = cls;
220  struct GNUNET_TESTBED_Peer *peer;
221  const struct GNUNET_TESTING_Command *peer_cmd;
222 
223  ts->is = is;
225  ts->peer_label);
227  &peer);
228 
231  &pi_cb,
232  ts);
233 }
static void pi_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg)
Callback to be called when the requested peer information is available.
struct GNUNET_TESTBED_Operation * operation
Handle to operation.
A command to be run by the interpreter.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer, enum GNUNET_TESTBED_PeerInformationType pit, GNUNET_TESTBED_PeerInfoCallback cb, void *cb_cls)
Request information about a peer.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int GNUNET_TESTBED_get_trait_peer(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_Peer **peer)
Offer data from trait.
What is the identity of the peer? Returns a 'const struct GNUNET_PeerIdentity *'. ...
A peer controlled by the testing framework.
const char * peer_label
Label of peer command.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_cmd_tng_service()

struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_tng_service ( const char *  label,
const char *  peer_label,
const struct GNUNET_MQ_MessageHandler handlers,
GNUNET_TRANSPORT_NotifyConnect  nc,
void *  cb_cls 
)

Definition at line 249 of file testbed_api_cmd_tng_service.c.

References TngState::cb_cls, GNUNET_TESTING_Command::cls, GNUNET_new, TngState::handlers, handlers, GNUNET_TESTING_Command::label, nc, TngState::nc, TngState::peer_label, TngState::servicename, tng_service_run(), and tng_service_traits().

255 {
256  struct TngState *ts;
257 
258  ts = GNUNET_new (struct TngState);
259  ts->servicename = servicename;
260  ts->peer_label = peer_label;
261  ts->handlers = handlers;
262  ts->nc = nc;
263  ts->nd = nd;
264  ts->cb_cls;
265 
266 
267  struct GNUNET_TESTING_Command cmd = {
268  .cls = ts,
269  .label = label,
270  .run = &tng_service_run,
271  .cleanup = &tmg_service_cleanup,
272  .traits = &tng_service_traits
273  };
274 
275  return cmd;
276 }
static int tng_service_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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const char * servicename
Name of service to start.
static void tng_service_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
void * cb_cls
Closure for the nc callback.
GNUNET_TRANSPORT_NotifyConnect nc
Notify connect callback.
void * cls
Closure for all commands with command-specific context information.
const char * peer_label
Label of peer command.
const struct GNUNET_MQ_MessageHandler * handlers
Message handler for transport service.
Here is the call graph for this function: