GNUnet  0.19.3
gnunet-service-testbed_barriers.c File Reference

barrier handling at the testbed controller More...

Include dependency graph for gnunet-service-testbed_barriers.c:

Go to the source code of this file.

Data Structures

struct  ClientCtx
 Context to be associated with each client. More...
 
struct  WBarrier
 Wrapper around Barrier handle. More...
 
struct  Barrier
 Barrier. More...
 

Macros

#define MESSAGE_SEND_TIMEOUT(s)    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, s)
 timeout for outgoing message transmissions in seconds More...
 
#define LOCAL_QUORUM_REACHED(barrier)    ((barrier->quorum * GST_num_local_peers) <= (barrier->nreached * 100))
 Test to see if local peers have reached the required quorum of a barrier. More...
 
#define LOG(kind, ...)    GNUNET_log_from (kind, "testbed-barriers", __VA_ARGS__)
 Logging shorthand. More...
 

Functions

static void remove_barrier (struct Barrier *barrier)
 Function to remove a barrier from the barrier map and cleanup resources occupied by a barrier. More...
 
static void cancel_wrappers (struct Barrier *barrier)
 Cancels all subcontroller barrier handles. More...
 
static void send_client_status_msg (struct GNUNET_SERVICE_Client *client, const char *name, enum GNUNET_TESTBED_BarrierStatus status, const char *emsg)
 Send a status message about a barrier to the given client. More...
 
static void send_barrier_status_msg (struct Barrier *barrier, const char *emsg)
 Sends a barrier failed message. More...
 
static int check_barrier_wait (void *cls, const struct GNUNET_TESTBED_BarrierWait *msg)
 Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT messages. More...
 
static void handle_barrier_wait (void *cls, const struct GNUNET_TESTBED_BarrierWait *msg)
 Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT messages. More...
 
static void * connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 Function called when a client connects to the testbed-barrier service. More...
 
static void disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
 Functions with this signature are called whenever a client is disconnected on the network level. More...
 
void GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg)
 Function to initialise barriers component. More...
 
static int barrier_destroy_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over hash map entries. More...
 
void GST_barriers_destroy ()
 Function to stop the barrier service. More...
 
static void wbarrier_status_cb (void *cls, const char *name, struct GNUNET_TESTBED_Barrier *b_, enum GNUNET_TESTBED_BarrierStatus status, const char *emsg)
 Functions of this type are to be given as callback argument to GNUNET_TESTBED_barrier_init(). More...
 
static void fwd_tout_barrier_init (void *cls)
 Function called upon timeout while waiting for a response from the subcontrollers to barrier init message. More...
 
int check_barrier_init (void *cls, const struct GNUNET_TESTBED_BarrierInit *msg)
 Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT messages. More...
 
void handle_barrier_init (void *cls, const struct GNUNET_TESTBED_BarrierInit *msg)
 Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT messages. More...
 
int check_barrier_cancel (void *cls, const struct GNUNET_TESTBED_BarrierCancel *msg)
 Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL messages. More...
 
void handle_barrier_cancel (void *cls, const struct GNUNET_TESTBED_BarrierCancel *msg)
 Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL messages. More...
 
int check_barrier_status (void *cls, const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
 Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages. More...
 
void handle_barrier_status (void *cls, const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
 Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages. More...
 

Variables

static struct GNUNET_CONTAINER_MultiHashMapbarrier_map
 Hashtable handle for storing initialised barriers. More...
 
static struct GNUNET_SERVICE_Handlectx
 Service context. More...
 

Detailed Description

barrier handling at the testbed controller

Author
Sree Harsha Totakura sreeh.nosp@m.arsh.nosp@m.a@tot.nosp@m.akur.nosp@m.a.in

Definition in file gnunet-service-testbed_barriers.c.

Macro Definition Documentation

◆ MESSAGE_SEND_TIMEOUT

#define MESSAGE_SEND_TIMEOUT (   s)     GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, s)

timeout for outgoing message transmissions in seconds

Definition at line 36 of file gnunet-service-testbed_barriers.c.

◆ LOCAL_QUORUM_REACHED

#define LOCAL_QUORUM_REACHED (   barrier)     ((barrier->quorum * GST_num_local_peers) <= (barrier->nreached * 100))

Test to see if local peers have reached the required quorum of a barrier.

Definition at line 43 of file gnunet-service-testbed_barriers.c.

◆ LOG

#define LOG (   kind,
  ... 
)     GNUNET_log_from (kind, "testbed-barriers", __VA_ARGS__)

Logging shorthand.

Definition at line 54 of file gnunet-service-testbed_barriers.c.

Function Documentation

◆ remove_barrier()

static void remove_barrier ( struct Barrier barrier)
static

Function to remove a barrier from the barrier map and cleanup resources occupied by a barrier.

Parameters
barrierthe barrier handle

Definition at line 228 of file gnunet-service-testbed_barriers.c.

229 {
230  struct ClientCtx *ctx;
231 
234  &barrier->hash,
235  barrier));
236  while (NULL != (ctx = barrier->head))
237  {
239  barrier->tail,
240  ctx);
241  ctx->barrier = NULL;
242  }
245 }
static struct GNUNET_SERVICE_Handle * ctx
Service context.
static struct GNUNET_CONTAINER_MultiHashMap * barrier_map
Hashtable handle for storing initialised barriers.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_HashCode hash
The hashcode of the barrier name.
char * name
The name of the barrier.
struct ClientCtx * head
DLL head for the list of clients waiting for this barrier.
struct ClientCtx * tail
DLL tail for the list of clients waiting for this barrier.
Context to be associated with each client.
struct Barrier * barrier
The barrier this client is waiting for.

References ClientCtx::barrier, barrier_map, ctx, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_YES, Barrier::hash, Barrier::head, Barrier::name, and Barrier::tail.

Referenced by barrier_destroy_iterator(), fwd_tout_barrier_init(), and handle_barrier_cancel().

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

◆ cancel_wrappers()

static void cancel_wrappers ( struct Barrier barrier)
static

Cancels all subcontroller barrier handles.

Parameters
barrierthe local barrier

Definition at line 254 of file gnunet-service-testbed_barriers.c.

255 {
256  struct WBarrier *wrapper;
257 
258  while (NULL != (wrapper = barrier->whead))
259  {
262  barrier->wtail,
263  wrapper);
264  GNUNET_free (wrapper);
265  }
266 }
void GNUNET_TESTBED_barrier_cancel(struct GNUNET_TESTBED_Barrier *barrier)
Cancel a barrier.
Definition: testbed_api.c:2412
struct WBarrier * wtail
DLL tail for the list of barrier handles.
struct WBarrier * whead
DLL head for the list of barrier handles.
Wrapper around Barrier handle.
struct Barrier * barrier
The local barrier associated with the creation of this wrapper.
struct GNUNET_TESTBED_Barrier * hbarrier
The barrier handle from API.

References WBarrier::barrier, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_TESTBED_barrier_cancel(), WBarrier::hbarrier, Barrier::whead, and Barrier::wtail.

Referenced by barrier_destroy_iterator(), fwd_tout_barrier_init(), handle_barrier_cancel(), and wbarrier_status_cb().

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

◆ send_client_status_msg()

static void send_client_status_msg ( struct GNUNET_SERVICE_Client client,
const char *  name,
enum GNUNET_TESTBED_BarrierStatus  status,
const char *  emsg 
)
static

Send a status message about a barrier to the given client.

Parameters
clientthe client to send the message to
namethe barrier name
statusthe status of the barrier
emsgthe error message; should be non-NULL for status=GNUNET_TESTBED_BARRIERSTATUS_ERROR

Definition at line 279 of file gnunet-service-testbed_barriers.c.

283 {
284  struct GNUNET_MQ_Envelope *env;
286  size_t name_len;
287  size_t err_len;
288 
289  GNUNET_assert ((NULL == emsg) ||
291  name_len = strlen (name) + 1;
292  err_len = ((NULL == emsg) ? 0 : (strlen (emsg) + 1));
294  name_len + err_len,
296  msg->status = htons (status);
297  msg->name_len = htons ((uint16_t) name_len - 1);
298  GNUNET_memcpy (msg->data,
299  name,
300  name_len);
301  GNUNET_memcpy (msg->data + name_len,
302  emsg,
303  err_len);
305  env);
306 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
uint16_t status
See PRISM_STATUS_*-constants.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:62
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS
Message for signalling status of a barrier.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2443
@ GNUNET_TESTBED_BARRIERSTATUS_ERROR
Error status.
const char * name
Message for signalling status changes of a barrier.
Definition: testbed.h:822
uint16_t name_len
strlen of the barrier name
Definition: testbed.h:836

References env, GNUNET_assert, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_SERVICE_client_get_mq(), GNUNET_TESTBED_BARRIERSTATUS_ERROR, msg, name, GNUNET_TESTBED_BarrierStatusMsg::name_len, and status.

Referenced by handle_barrier_init(), and send_barrier_status_msg().

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

◆ send_barrier_status_msg()

static void send_barrier_status_msg ( struct Barrier barrier,
const char *  emsg 
)
static

Sends a barrier failed message.

Parameters
barrierthe corresponding barrier
emsgthe error message; should be non-NULL for status=GNUNET_TESTBED_BARRIERSTATUS_ERROR

Definition at line 317 of file gnunet-service-testbed_barriers.c.

319 {
320  GNUNET_assert (0 != barrier->status);
321  send_client_status_msg (barrier->mc,
322  barrier->name,
323  barrier->status,
324  emsg);
325 }
static void send_client_status_msg(struct GNUNET_SERVICE_Client *client, const char *name, enum GNUNET_TESTBED_BarrierStatus status, const char *emsg)
Send a status message about a barrier to the given client.
enum GNUNET_TESTBED_BarrierStatus status
The status of this barrier.
struct GNUNET_SERVICE_Client * mc
The client handle to the master controller.

References GNUNET_assert, Barrier::mc, Barrier::name, send_client_status_msg(), and Barrier::status.

Referenced by fwd_tout_barrier_init(), handle_barrier_init(), handle_barrier_wait(), and wbarrier_status_cb().

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

◆ check_barrier_wait()

static int check_barrier_wait ( void *  cls,
const struct GNUNET_TESTBED_BarrierWait msg 
)
static

Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT messages.

Parameters
clsidentification of the client
msgthe actual message

Definition at line 335 of file gnunet-service-testbed_barriers.c.

337 {
338  return GNUNET_OK; /* always well-formed */
339 }
@ GNUNET_OK

References GNUNET_OK.

◆ handle_barrier_wait()

static void handle_barrier_wait ( void *  cls,
const struct GNUNET_TESTBED_BarrierWait msg 
)
static

Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT messages.

This message should come from peers or a shared helper service using the testbed-barrier client API (

See also
gnunet_testbed_barrier_service.h)

This handler is queued in the main service and will handle the messages sent either from the testbed driver or from a high level controller

Parameters
clsidentification of the client
msgthe actual message

Definition at line 354 of file gnunet-service-testbed_barriers.c.

356 {
357  struct ClientCtx *client_ctx = cls;
358  struct Barrier *barrier;
359  char *name;
360  struct GNUNET_HashCode key;
361  size_t name_len;
362  uint16_t msize;
363 
364  msize = ntohs (msg->header.size);
365  if (NULL == barrier_map)
366  {
367  GNUNET_break (0);
368  GNUNET_SERVICE_client_drop (client_ctx->client);
369  return;
370  }
371  name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierWait);
372  name = GNUNET_malloc (name_len + 1);
373  name[name_len] = '\0';
375  msg->name,
376  name_len);
377  LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n",
378  name);
380  name_len,
381  &key);
382  GNUNET_free (name);
383  if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key)))
384  {
385  GNUNET_break (0);
386  GNUNET_SERVICE_client_drop (client_ctx->client);
387  return;
388  }
389  if (NULL != client_ctx->barrier)
390  {
391  GNUNET_break (0);
392  GNUNET_SERVICE_client_drop (client_ctx->client);
393  return;
394  }
395  client_ctx->barrier = barrier;
397  barrier->tail,
398  client_ctx);
399  barrier->nreached++;
400  if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) &&
401  (LOCAL_QUORUM_REACHED (barrier)))
402  {
404  send_barrier_status_msg (barrier,
405  NULL);
406  }
408 }
struct GNUNET_HashCode key
The key used in the DHT.
#define LOG_DEBUG(...)
Debug logging shorthand.
#define LOCAL_QUORUM_REACHED(barrier)
Test to see if local peers have reached the required quorum of a barrier.
static void send_barrier_status_msg(struct Barrier *barrier, const char *emsg)
Sends a barrier failed message.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_malloc(size)
Wrapper around malloc.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2330
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2249
@ GNUNET_TESTBED_BARRIERSTATUS_CROSSED
Barrier is crossed.
unsigned int num_wbarriers_reached
Number of wrapped barriers reached so far.
unsigned int num_wbarriers
Number of barriers wrapped in the above DLL.
unsigned int nreached
Number of peers which have reached this barrier.
struct GNUNET_SERVICE_Client * client
The client handle.
A 512-bit hashcode.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Message sent from peers to the testbed-barrier service to indicate that they have reached a barrier a...
Definition: testbed.h:851

References ClientCtx::barrier, barrier_map, ClientCtx::client, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_TESTBED_BARRIERSTATUS_CROSSED, Barrier::head, key, LOCAL_QUORUM_REACHED, LOG_DEBUG, msg, name, Barrier::nreached, Barrier::num_wbarriers, Barrier::num_wbarriers_reached, send_barrier_status_msg(), GNUNET_MessageHeader::size, Barrier::status, and Barrier::tail.

Here is the call graph for this function:

◆ connect_cb()

static void* connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Function called when a client connects to the testbed-barrier service.

Parameters
clsNULL
clientthe connecting client
mqqueue to talk to client
Returns
our struct ClientCtx

Definition at line 420 of file gnunet-service-testbed_barriers.c.

423 {
424  struct ClientCtx *client_ctx;
425 
426  LOG_DEBUG ("Client connected to testbed-barrier service\n");
427  client_ctx = GNUNET_new (struct ClientCtx);
428  client_ctx->client = client;
429  return client_ctx;
430 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References ClientCtx::client, GNUNET_new, and LOG_DEBUG.

Referenced by GST_barriers_init().

Here is the caller graph for this function:

◆ disconnect_cb()

static void disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  app_ctx 
)
static

Functions with this signature are called whenever a client is disconnected on the network level.

Parameters
clsclosure
clientidentification of the client; NULL for the last call when the server is destroyed

Definition at line 442 of file gnunet-service-testbed_barriers.c.

445 {
446  struct ClientCtx *client_ctx = app_ctx;
447  struct Barrier *barrier = client_ctx->barrier;
448 
449  if (NULL != barrier)
450  {
452  barrier->tail,
453  client_ctx);
454  client_ctx->barrier = NULL;
455  }
456  GNUNET_free (client_ctx);
457  LOG_DEBUG ("Client disconnected from testbed-barrier service\n");
458 }

References ClientCtx::barrier, GNUNET_CONTAINER_DLL_remove, GNUNET_free, Barrier::head, LOG_DEBUG, and Barrier::tail.

Referenced by GST_barriers_init().

Here is the caller graph for this function:

◆ GST_barriers_init()

void GST_barriers_init ( struct GNUNET_CONFIGURATION_Handle cfg)

Function to initialise barriers component.

Parameters
cfgthe configuration to use for initialisation

Definition at line 467 of file gnunet-service-testbed_barriers.c.

468 {
469  struct GNUNET_MQ_MessageHandler message_handlers[] = {
470  GNUNET_MQ_hd_var_size (barrier_wait,
473  NULL),
475  };
476 
477  LOG_DEBUG ("Launching testbed-barrier service\n");
479  GNUNET_YES);
480  ctx = GNUNET_SERVICE_start ("testbed-barrier",
481  cfg,
482  &connect_cb,
483  &disconnect_cb,
484  NULL,
485  message_handlers);
486 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static void disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Functions with this signature are called whenever a client is disconnected on the network level.
static void * connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Function called when a client connects to the testbed-barrier service.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT
Message sent by a peer when it has reached a barrier and is waiting for it to be crossed.
struct GNUNET_SERVICE_Handle * GNUNET_SERVICE_start(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SERVICE_ConnectHandler connect_cb, GNUNET_SERVICE_DisconnectHandler disconnect_cb, void *cls, const struct GNUNET_MQ_MessageHandler *handlers)
Low-level function to start a service if the scheduler is already running.
Definition: service.c:1880
Message handler for a specific message type.

References barrier_map, cfg, connect_cb(), ctx, disconnect_cb(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_SERVICE_start(), GNUNET_YES, and LOG_DEBUG.

Referenced by testbed_run().

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

◆ barrier_destroy_iterator()

static int barrier_destroy_iterator ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over hash map entries.

Parameters
clsclosure
keycurrent key code
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 500 of file gnunet-service-testbed_barriers.c.

503 {
504  struct Barrier *barrier = value;
505 
506  GNUNET_assert (NULL != barrier);
507  cancel_wrappers (barrier);
508  remove_barrier (barrier);
509  return GNUNET_YES;
510 }
static char * value
Value of the record to add/remove.
static void cancel_wrappers(struct Barrier *barrier)
Cancels all subcontroller barrier handles.
static void remove_barrier(struct Barrier *barrier)
Function to remove a barrier from the barrier map and cleanup resources occupied by a barrier.

References cancel_wrappers(), GNUNET_assert, GNUNET_YES, remove_barrier(), and value.

Referenced by GST_barriers_destroy().

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

◆ GST_barriers_destroy()

void GST_barriers_destroy ( void  )

Function to stop the barrier service.

Definition at line 517 of file gnunet-service-testbed_barriers.c.

518 {
519  GNUNET_assert (NULL != barrier_map);
522  &
524  NULL));
526  GNUNET_assert (NULL != ctx);
528 }
static int barrier_destroy_iterator(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
@ GNUNET_SYSERR
void GNUNET_SERVICE_stop(struct GNUNET_SERVICE_Handle *srv)
Stops a service that was started with GNUNET_SERVICE_start().
Definition: service.c:1913

References barrier_destroy_iterator(), barrier_map, ctx, GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_SERVICE_stop(), and GNUNET_SYSERR.

Referenced by shutdown_task().

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

◆ wbarrier_status_cb()

static void wbarrier_status_cb ( void *  cls,
const char *  name,
struct GNUNET_TESTBED_Barrier b_,
enum GNUNET_TESTBED_BarrierStatus  status,
const char *  emsg 
)
static

Functions of this type are to be given as callback argument to GNUNET_TESTBED_barrier_init().

The callback will be called when status information is available for the barrier.

Parameters
clsthe closure given to GNUNET_TESTBED_barrier_init()
namethe name of the barrier
b_the barrier handle
statusstatus of the barrier; GNUNET_OK if the barrier is crossed; GNUNET_SYSERR upon error
emsgif the status were to be GNUNET_SYSERR, this parameter has the error message

Definition at line 545 of file gnunet-service-testbed_barriers.c.

550 {
551  struct WBarrier *wrapper = cls;
552  struct Barrier *barrier = wrapper->barrier;
553 
554  GNUNET_assert (b_ == wrapper->hbarrier);
555  switch (status)
556  {
559  "Initialising barrier `%s' failed at a sub-controller: %s\n",
560  barrier->name,
561  (NULL != emsg) ? emsg : "NULL");
562  cancel_wrappers (barrier);
563  if (NULL == emsg)
564  emsg = "Initialisation failed at a sub-controller";
566  send_barrier_status_msg (barrier, emsg);
567  return;
568 
571  {
572  GNUNET_break_op (0);
573  return;
574  }
575  barrier->num_wbarriers_reached++;
576  if ((barrier->num_wbarriers_reached == barrier->num_wbarriers)
577  && (LOCAL_QUORUM_REACHED (barrier)))
578  {
580  send_barrier_status_msg (barrier, NULL);
581  }
582  return;
583 
585  if (0 != barrier->status)
586  {
587  GNUNET_break_op (0);
588  return;
589  }
590  barrier->num_wbarriers_inited++;
591  if (barrier->num_wbarriers_inited == barrier->num_wbarriers)
592  {
594  send_barrier_status_msg (barrier, NULL);
595  }
596  return;
597  }
598 }
#define LOG(kind,...)
Logging shorthand.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_TESTBED_BARRIERSTATUS_INITIALISED
Barrier initialised successfully.
unsigned int num_wbarriers_inited
Number of wrapped barrier initialised so far.

References WBarrier::barrier, cancel_wrappers(), GNUNET_assert, GNUNET_break_op, GNUNET_ERROR_TYPE_ERROR, GNUNET_TESTBED_BARRIERSTATUS_CROSSED, GNUNET_TESTBED_BARRIERSTATUS_ERROR, GNUNET_TESTBED_BARRIERSTATUS_INITIALISED, WBarrier::hbarrier, LOCAL_QUORUM_REACHED, LOG, Barrier::name, Barrier::num_wbarriers, Barrier::num_wbarriers_inited, Barrier::num_wbarriers_reached, send_barrier_status_msg(), Barrier::status, and status.

Referenced by handle_barrier_init().

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

◆ fwd_tout_barrier_init()

static void fwd_tout_barrier_init ( void *  cls)
static

Function called upon timeout while waiting for a response from the subcontrollers to barrier init message.

Parameters
clsbarrier

Definition at line 608 of file gnunet-service-testbed_barriers.c.

609 {
610  struct Barrier *barrier = cls;
611 
612  cancel_wrappers (barrier);
614  send_barrier_status_msg (barrier,
615  "Timedout while propagating barrier initialisation\n");
616  remove_barrier (barrier);
617 }

References cancel_wrappers(), GNUNET_TESTBED_BARRIERSTATUS_ERROR, remove_barrier(), send_barrier_status_msg(), and Barrier::status.

Referenced by handle_barrier_init().

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

◆ check_barrier_init()

int check_barrier_init ( void *  cls,
const struct GNUNET_TESTBED_BarrierInit msg 
)

Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT messages.

Parameters
clsidentification of the client
msgthe actual message
Returns
GNUNET_OK if msg is well-formed

Definition at line 628 of file gnunet-service-testbed_barriers.c.

630 {
631  return GNUNET_OK; /* always well-formed */
632 }

References GNUNET_OK.

◆ handle_barrier_init()

void handle_barrier_init ( void *  cls,
const struct GNUNET_TESTBED_BarrierInit msg 
)

Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT messages.

This message should always come from a parent controller or the testbed API if we are the root controller.

This handler is queued in the main service and will handle the messages sent either from the testbed driver or from a high level controller

Parameters
clsidentification of the client
msgthe actual message

Definition at line 647 of file gnunet-service-testbed_barriers.c.

649 {
650  struct GNUNET_SERVICE_Client *client = cls;
651  char *name;
652  struct Barrier *barrier;
653  struct Slave *slave;
654  struct WBarrier *wrapper;
655  struct GNUNET_HashCode hash;
656  size_t name_len;
657  unsigned int cnt;
658  uint16_t msize;
659 
660  if (NULL == GST_context)
661  {
662  GNUNET_break_op (0);
664  return;
665  }
666  if (client != GST_context->client)
667  {
668  GNUNET_break_op (0);
670  return;
671  }
672  msize = ntohs (msg->header.size);
673  name_len = (size_t) msize - sizeof(struct GNUNET_TESTBED_BarrierInit);
674  name = GNUNET_malloc (name_len + 1);
675  GNUNET_memcpy (name, msg->name, name_len);
676  GNUNET_CRYPTO_hash (name, name_len, &hash);
677  LOG_DEBUG ("Received BARRIER_INIT for barrier `%s'\n",
678  name);
679  if (GNUNET_YES ==
681  &hash))
682  {
683  send_client_status_msg (client,
684  name,
686  "A barrier with the same name already exists");
687  GNUNET_free (name);
689  return;
690  }
691  barrier = GNUNET_new (struct Barrier);
692  barrier->hash = hash;
693  barrier->quorum = msg->quorum;
694  barrier->name = name;
695  barrier->mc = client;
698  &barrier->hash,
699  barrier,
702  /* Propagate barrier init to subcontrollers */
703  for (cnt = 0; cnt < GST_slave_list_size; cnt++)
704  {
705  if (NULL == (slave = GST_slave_list[cnt]))
706  continue;
707  if (NULL == slave->controller)
708  {
709  GNUNET_break (0); /* May happen when we are connecting to the controller */
710  continue;
711  }
712  wrapper = GNUNET_new (struct WBarrier);
713  wrapper->barrier = barrier;
714  wrapper->controller = slave->controller;
716  barrier->wtail,
717  wrapper);
718  barrier->num_wbarriers++;
719  wrapper->hbarrier = GNUNET_TESTBED_barrier_init_ (wrapper->controller,
720  barrier->name,
721  barrier->quorum,
723  wrapper,
724  GNUNET_NO);
725  }
726  if (NULL == barrier->whead) /* No further propagation */
727  {
729  LOG_DEBUG (
730  "Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n",
731  barrier->name);
732  send_barrier_status_msg (barrier, NULL);
733  }
734  else
736  30),
738  barrier);
739 }
struct Context * GST_context
The master context; generated with the first INIT message.
#define MESSAGE_SEND_TIMEOUT(s)
timeout for outgoing message transmissions in seconds
static void wbarrier_status_cb(void *cls, const char *name, struct GNUNET_TESTBED_Barrier *b_, enum GNUNET_TESTBED_BarrierStatus status, const char *emsg)
Functions of this type are to be given as callback argument to GNUNET_TESTBED_barrier_init().
static void fwd_tout_barrier_init(void *cls)
Function called upon timeout while waiting for a response from the subcontrollers to barrier init mes...
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_NO
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:1272
uint8_t quorum
Quorum percentage to be reached.
struct GNUNET_SCHEDULER_Task * tout_task
Identifier for the timeout task.
struct GNUNET_SERVICE_Client * client
The client handle associated with this context.
Handle to a client that is connected to a service.
Definition: service.c:252
Message to initialise a barrier.
Definition: testbed.h:783
Structure representing a connected(directly-linked) controller.
struct GNUNET_TESTBED_Controller * controller
The controller handle.
struct GNUNET_TESTBED_Controller * controller
Handle to the slave controller where this wrapper creates a barrier.
struct GNUNET_TESTBED_Barrier * GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, const char *name, unsigned int quorum, GNUNET_TESTBED_barrier_status_cb cb, void *cls, int echo)
Initialise a barrier and call the given callback when the required percentage of peers (quorum) reach...
Definition: testbed_api.c:2324

References WBarrier::barrier, barrier_map, Context::client, WBarrier::controller, Slave::controller, fwd_tout_barrier_init(), GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_TESTBED_barrier_init_(), GNUNET_TESTBED_BARRIERSTATUS_ERROR, GNUNET_TESTBED_BARRIERSTATUS_INITIALISED, GNUNET_YES, GST_context, GST_slave_list, GST_slave_list_size, Barrier::hash, WBarrier::hbarrier, LOG_DEBUG, Barrier::mc, MESSAGE_SEND_TIMEOUT, msg, name, Barrier::name, Barrier::num_wbarriers, Barrier::quorum, send_barrier_status_msg(), send_client_status_msg(), GNUNET_MessageHeader::size, Barrier::status, Barrier::tout_task, wbarrier_status_cb(), Barrier::whead, and Barrier::wtail.

Here is the call graph for this function:

◆ check_barrier_cancel()

int check_barrier_cancel ( void *  cls,
const struct GNUNET_TESTBED_BarrierCancel msg 
)

Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL messages.

Parameters
clsidentification of the client
msgthe actual message
Returns
GNUNET_OK if msg is well-formed

Definition at line 750 of file gnunet-service-testbed_barriers.c.

752 {
753  return GNUNET_OK; /* all are well-formed */
754 }

References GNUNET_OK.

◆ handle_barrier_cancel()

void handle_barrier_cancel ( void *  cls,
const struct GNUNET_TESTBED_BarrierCancel msg 
)

Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL messages.

This message should always come from a parent controller or the testbed API if we are the root controller.

This handler is queued in the main service and will handle the messages sent either from the testbed driver or from a high level controller

Parameters
clsidentification of the client
msgthe actual message

Definition at line 769 of file gnunet-service-testbed_barriers.c.

771 {
772  struct GNUNET_SERVICE_Client *client = cls;
773  char *name;
774  struct Barrier *barrier;
775  struct GNUNET_HashCode hash;
776  size_t name_len;
777  uint16_t msize;
778 
779  if (NULL == GST_context)
780  {
781  GNUNET_break_op (0);
783  return;
784  }
785  if (client != GST_context->client)
786  {
787  GNUNET_break_op (0);
789  return;
790  }
791  msize = ntohs (msg->header.size);
792  name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierCancel);
793  name = GNUNET_malloc (name_len + 1);
795  msg->name,
796  name_len);
797  LOG_DEBUG ("Received BARRIER_CANCEL for barrier `%s'\n",
798  name);
800  name_len,
801  &hash);
802  if (GNUNET_NO ==
804  &hash))
805  {
806  GNUNET_break_op (0);
807  GNUNET_free (name);
809  return;
810  }
812  &hash);
813  GNUNET_assert (NULL != barrier);
814  cancel_wrappers (barrier);
815  remove_barrier (barrier);
816  GNUNET_free (name);
818 }
Message to cancel a barrier.
Definition: testbed.h:805

References barrier_map, cancel_wrappers(), Context::client, GNUNET_assert, GNUNET_break_op, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GST_context, LOG_DEBUG, msg, name, remove_barrier(), and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ check_barrier_status()

int check_barrier_status ( void *  cls,
const struct GNUNET_TESTBED_BarrierStatusMsg msg 
)

Check GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages.

Parameters
clsidentification of the client
msgthe actual message
Returns
GNUNET_OK if msg is well-formed

Definition at line 829 of file gnunet-service-testbed_barriers.c.

831 {
832  uint16_t msize;
833  uint16_t name_len;
834  const char *name;
836 
837  msize = ntohs (msg->header.size) - sizeof(*msg);
838  status = ntohs (msg->status);
840  {
841  GNUNET_break_op (0); /* current we only expect BARRIER_CROSSED
842  status message this way */
843  return GNUNET_SYSERR;
844  }
845  name = msg->data;
846  name_len = ntohs (msg->name_len);
847  if ((name_len + 1) != msize)
848  {
849  GNUNET_break_op (0);
850  return GNUNET_SYSERR;
851  }
852  if ('\0' != name[name_len])
853  {
854  GNUNET_break_op (0);
855  return GNUNET_SYSERR;
856  }
857  return GNUNET_OK;
858 }
GNUNET_TESTBED_BarrierStatus
Status of a barrier.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTBED_BARRIERSTATUS_CROSSED, msg, name, GNUNET_MessageHeader::size, and status.

◆ handle_barrier_status()

void handle_barrier_status ( void *  cls,
const struct GNUNET_TESTBED_BarrierStatusMsg msg 
)

Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages.

This handler is queued in the main service and will handle the messages sent either from the testbed driver or from a high level controller

Parameters
clsidentification of the client
msgthe actual message

The wrapper barriers do not echo the barrier status, so we have to do it here

Definition at line 870 of file gnunet-service-testbed_barriers.c.

872 {
873  struct GNUNET_SERVICE_Client *client = cls;
874  struct Barrier *barrier;
875  struct ClientCtx *client_ctx;
876  struct WBarrier *wrapper;
877  const char *name;
878  struct GNUNET_HashCode key;
879  uint16_t name_len;
880  struct GNUNET_MQ_Envelope *env;
881 
882  if (NULL == GST_context)
883  {
884  GNUNET_break_op (0);
886  return;
887  }
888  if (client != GST_context->client)
889  {
890  GNUNET_break_op (0);
892  return;
893  }
894  name = msg->data;
895  name_len = ntohs (msg->name_len);
896  LOG_DEBUG ("Received BARRIER_STATUS for barrier `%s'\n",
897  name);
899  name_len,
900  &key);
902  &key);
903  if (NULL == barrier)
904  {
905  GNUNET_break_op (0);
907  return;
908  }
910  for (client_ctx = barrier->head; NULL != client_ctx; client_ctx =
911  client_ctx->next) /* Notify peers */
912  {
913  env = GNUNET_MQ_msg_copy (&msg->header);
915  env);
916  }
921  for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next)
922  {
924  GNUNET_copy_message (&msg->header));
925  }
926 }
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:533
struct ClientCtx * next
DLL next ptr.
struct WBarrier * next
DLL next pointer.
void GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, struct GNUNET_MessageHeader *msg)
Queues a message in send queue for sending to the service.
Definition: testbed_api.c:1336

References barrier_map, Context::client, ClientCtx::client, WBarrier::controller, env, GNUNET_break_op, GNUNET_CONTAINER_multihashmap_get(), GNUNET_copy_message(), GNUNET_CRYPTO_hash(), GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_SERVICE_client_get_mq(), GNUNET_TESTBED_queue_message_(), GST_context, Barrier::head, key, LOG_DEBUG, msg, name, ClientCtx::next, WBarrier::next, and Barrier::whead.

Here is the call graph for this function:

Variable Documentation

◆ barrier_map

struct GNUNET_CONTAINER_MultiHashMap* barrier_map
static

◆ ctx

struct GNUNET_SERVICE_Handle* ctx
static

Service context.

Definition at line 218 of file gnunet-service-testbed_barriers.c.

Referenced by GST_barriers_destroy(), GST_barriers_init(), and remove_barrier().