summaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_barriers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-service-testbed_barriers.c')
-rw-r--r--src/testbed/gnunet-service-testbed_barriers.c701
1 files changed, 354 insertions, 347 deletions
diff --git a/src/testbed/gnunet-service-testbed_barriers.c b/src/testbed/gnunet-service-testbed_barriers.c
index c2cb9a99c..7ea1df662 100644
--- a/src/testbed/gnunet-service-testbed_barriers.c
+++ b/src/testbed/gnunet-service-testbed_barriers.c
@@ -33,7 +33,7 @@
33 * timeout for outgoing message transmissions in seconds 33 * timeout for outgoing message transmissions in seconds
34 */ 34 */
35#define MESSAGE_SEND_TIMEOUT(s) \ 35#define MESSAGE_SEND_TIMEOUT(s) \
36 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, s) 36 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, s)
37 37
38 38
39/** 39/**
@@ -51,7 +51,7 @@
51 * Logging shorthand 51 * Logging shorthand
52 */ 52 */
53#define LOG(kind, ...) \ 53#define LOG(kind, ...) \
54 GNUNET_log_from(kind, "testbed-barriers", __VA_ARGS__) 54 GNUNET_log_from (kind, "testbed-barriers", __VA_ARGS__)
55 55
56 56
57/** 57/**
@@ -63,7 +63,8 @@ struct Barrier;
63/** 63/**
64 * Context to be associated with each client 64 * Context to be associated with each client
65 */ 65 */
66struct ClientCtx { 66struct ClientCtx
67{
67 /** 68 /**
68 * The barrier this client is waiting for 69 * The barrier this client is waiting for
69 */ 70 */
@@ -89,7 +90,8 @@ struct ClientCtx {
89/** 90/**
90 * Wrapper around Barrier handle 91 * Wrapper around Barrier handle
91 */ 92 */
92struct WBarrier { 93struct WBarrier
94{
93 /** 95 /**
94 * DLL next pointer 96 * DLL next pointer
95 */ 97 */
@@ -125,7 +127,8 @@ struct WBarrier {
125/** 127/**
126 * Barrier 128 * Barrier
127 */ 129 */
128struct Barrier { 130struct Barrier
131{
129 /** 132 /**
130 * The hashcode of the barrier name 133 * The hashcode of the barrier name
131 */ 134 */
@@ -221,23 +224,23 @@ static struct GNUNET_SERVICE_Handle *ctx;
221 * @param barrier the barrier handle 224 * @param barrier the barrier handle
222 */ 225 */
223static void 226static void
224remove_barrier(struct Barrier *barrier) 227remove_barrier (struct Barrier *barrier)
225{ 228{
226 struct ClientCtx *ctx; 229 struct ClientCtx *ctx;
227 230
228 GNUNET_assert(GNUNET_YES == 231 GNUNET_assert (GNUNET_YES ==
229 GNUNET_CONTAINER_multihashmap_remove(barrier_map, 232 GNUNET_CONTAINER_multihashmap_remove (barrier_map,
230 &barrier->hash, 233 &barrier->hash,
231 barrier)); 234 barrier));
232 while (NULL != (ctx = barrier->head)) 235 while (NULL != (ctx = barrier->head))
233 { 236 {
234 GNUNET_CONTAINER_DLL_remove(barrier->head, 237 GNUNET_CONTAINER_DLL_remove (barrier->head,
235 barrier->tail, 238 barrier->tail,
236 ctx); 239 ctx);
237 ctx->barrier = NULL; 240 ctx->barrier = NULL;
238 } 241 }
239 GNUNET_free(barrier->name); 242 GNUNET_free (barrier->name);
240 GNUNET_free(barrier); 243 GNUNET_free (barrier);
241} 244}
242 245
243 246
@@ -247,18 +250,18 @@ remove_barrier(struct Barrier *barrier)
247 * @param barrier the local barrier 250 * @param barrier the local barrier
248 */ 251 */
249static void 252static void
250cancel_wrappers(struct Barrier *barrier) 253cancel_wrappers (struct Barrier *barrier)
251{ 254{
252 struct WBarrier *wrapper; 255 struct WBarrier *wrapper;
253 256
254 while (NULL != (wrapper = barrier->whead)) 257 while (NULL != (wrapper = barrier->whead))
255 { 258 {
256 GNUNET_TESTBED_barrier_cancel(wrapper->hbarrier); 259 GNUNET_TESTBED_barrier_cancel (wrapper->hbarrier);
257 GNUNET_CONTAINER_DLL_remove(barrier->whead, 260 GNUNET_CONTAINER_DLL_remove (barrier->whead,
258 barrier->wtail, 261 barrier->wtail,
259 wrapper); 262 wrapper);
260 GNUNET_free(wrapper); 263 GNUNET_free (wrapper);
261 } 264 }
262} 265}
263 266
264 267
@@ -272,33 +275,33 @@ cancel_wrappers(struct Barrier *barrier)
272 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR 275 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR
273 */ 276 */
274static void 277static void
275send_client_status_msg(struct GNUNET_SERVICE_Client *client, 278send_client_status_msg (struct GNUNET_SERVICE_Client *client,
276 const char *name, 279 const char *name,
277 enum GNUNET_TESTBED_BarrierStatus status, 280 enum GNUNET_TESTBED_BarrierStatus status,
278 const char *emsg) 281 const char *emsg)
279{ 282{
280 struct GNUNET_MQ_Envelope *env; 283 struct GNUNET_MQ_Envelope *env;
281 struct GNUNET_TESTBED_BarrierStatusMsg *msg; 284 struct GNUNET_TESTBED_BarrierStatusMsg *msg;
282 size_t name_len; 285 size_t name_len;
283 size_t err_len; 286 size_t err_len;
284 287
285 GNUNET_assert((NULL == emsg) || 288 GNUNET_assert ((NULL == emsg) ||
286 (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)); 289 (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status));
287 name_len = strlen(name) + 1; 290 name_len = strlen (name) + 1;
288 err_len = ((NULL == emsg) ? 0 : (strlen(emsg) + 1)); 291 err_len = ((NULL == emsg) ? 0 : (strlen (emsg) + 1));
289 env = GNUNET_MQ_msg_extra(msg, 292 env = GNUNET_MQ_msg_extra (msg,
290 name_len + err_len, 293 name_len + err_len,
291 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); 294 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS);
292 msg->status = htons(status); 295 msg->status = htons (status);
293 msg->name_len = htons((uint16_t)name_len - 1); 296 msg->name_len = htons ((uint16_t) name_len - 1);
294 GNUNET_memcpy(msg->data, 297 GNUNET_memcpy (msg->data,
295 name, 298 name,
296 name_len); 299 name_len);
297 GNUNET_memcpy(msg->data + name_len, 300 GNUNET_memcpy (msg->data + name_len,
298 emsg, 301 emsg,
299 err_len); 302 err_len);
300 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 303 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
301 env); 304 env);
302} 305}
303 306
304 307
@@ -310,14 +313,14 @@ send_client_status_msg(struct GNUNET_SERVICE_Client *client,
310 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR 313 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR
311 */ 314 */
312static void 315static void
313send_barrier_status_msg(struct Barrier *barrier, 316send_barrier_status_msg (struct Barrier *barrier,
314 const char *emsg) 317 const char *emsg)
315{ 318{
316 GNUNET_assert(0 != barrier->status); 319 GNUNET_assert (0 != barrier->status);
317 send_client_status_msg(barrier->mc, 320 send_client_status_msg (barrier->mc,
318 barrier->name, 321 barrier->name,
319 barrier->status, 322 barrier->status,
320 emsg); 323 emsg);
321} 324}
322 325
323 326
@@ -328,8 +331,8 @@ send_barrier_status_msg(struct Barrier *barrier,
328 * @param message the actual message 331 * @param message the actual message
329 */ 332 */
330static int 333static int
331check_barrier_wait(void *cls, 334check_barrier_wait (void *cls,
332 const struct GNUNET_TESTBED_BarrierWait *msg) 335 const struct GNUNET_TESTBED_BarrierWait *msg)
333{ 336{
334 return GNUNET_OK; /* always well-formed */ 337 return GNUNET_OK; /* always well-formed */
335} 338}
@@ -347,8 +350,8 @@ check_barrier_wait(void *cls,
347 * @param message the actual message 350 * @param message the actual message
348 */ 351 */
349static void 352static void
350handle_barrier_wait(void *cls, 353handle_barrier_wait (void *cls,
351 const struct GNUNET_TESTBED_BarrierWait *msg) 354 const struct GNUNET_TESTBED_BarrierWait *msg)
352{ 355{
353 struct ClientCtx *client_ctx = cls; 356 struct ClientCtx *client_ctx = cls;
354 struct Barrier *barrier; 357 struct Barrier *barrier;
@@ -357,50 +360,50 @@ handle_barrier_wait(void *cls,
357 size_t name_len; 360 size_t name_len;
358 uint16_t msize; 361 uint16_t msize;
359 362
360 msize = ntohs(msg->header.size); 363 msize = ntohs (msg->header.size);
361 if (NULL == barrier_map) 364 if (NULL == barrier_map)
362 { 365 {
363 GNUNET_break(0); 366 GNUNET_break (0);
364 GNUNET_SERVICE_client_drop(client_ctx->client); 367 GNUNET_SERVICE_client_drop (client_ctx->client);
365 return; 368 return;
366 } 369 }
367 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierWait); 370 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierWait);
368 name = GNUNET_malloc(name_len + 1); 371 name = GNUNET_malloc (name_len + 1);
369 name[name_len] = '\0'; 372 name[name_len] = '\0';
370 GNUNET_memcpy(name, 373 GNUNET_memcpy (name,
371 msg->name, 374 msg->name,
372 name_len); 375 name_len);
373 LOG_DEBUG("Received BARRIER_WAIT for barrier `%s'\n", 376 LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n",
374 name); 377 name);
375 GNUNET_CRYPTO_hash(name, 378 GNUNET_CRYPTO_hash (name,
376 name_len, 379 name_len,
377 &key); 380 &key);
378 GNUNET_free(name); 381 GNUNET_free (name);
379 if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, &key))) 382 if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key)))
380 { 383 {
381 GNUNET_break(0); 384 GNUNET_break (0);
382 GNUNET_SERVICE_client_drop(client_ctx->client); 385 GNUNET_SERVICE_client_drop (client_ctx->client);
383 return; 386 return;
384 } 387 }
385 if (NULL != client_ctx->barrier) 388 if (NULL != client_ctx->barrier)
386 { 389 {
387 GNUNET_break(0); 390 GNUNET_break (0);
388 GNUNET_SERVICE_client_drop(client_ctx->client); 391 GNUNET_SERVICE_client_drop (client_ctx->client);
389 return; 392 return;
390 } 393 }
391 client_ctx->barrier = barrier; 394 client_ctx->barrier = barrier;
392 GNUNET_CONTAINER_DLL_insert_tail(barrier->head, 395 GNUNET_CONTAINER_DLL_insert_tail (barrier->head,
393 barrier->tail, 396 barrier->tail,
394 client_ctx); 397 client_ctx);
395 barrier->nreached++; 398 barrier->nreached++;
396 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) && 399 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) &&
397 (LOCAL_QUORUM_REACHED(barrier))) 400 (LOCAL_QUORUM_REACHED (barrier)))
398 { 401 {
399 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; 402 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED;
400 send_barrier_status_msg(barrier, 403 send_barrier_status_msg (barrier,
401 NULL); 404 NULL);
402 } 405 }
403 GNUNET_SERVICE_client_continue(client_ctx->client); 406 GNUNET_SERVICE_client_continue (client_ctx->client);
404} 407}
405 408
406 409
@@ -413,14 +416,14 @@ handle_barrier_wait(void *cls,
413 * @return our `struct ClientCtx` 416 * @return our `struct ClientCtx`
414 */ 417 */
415static void * 418static void *
416connect_cb(void *cls, 419connect_cb (void *cls,
417 struct GNUNET_SERVICE_Client *client, 420 struct GNUNET_SERVICE_Client *client,
418 struct GNUNET_MQ_Handle *mq) 421 struct GNUNET_MQ_Handle *mq)
419{ 422{
420 struct ClientCtx *client_ctx; 423 struct ClientCtx *client_ctx;
421 424
422 LOG_DEBUG("Client connected to testbed-barrier service\n"); 425 LOG_DEBUG ("Client connected to testbed-barrier service\n");
423 client_ctx = GNUNET_new(struct ClientCtx); 426 client_ctx = GNUNET_new (struct ClientCtx);
424 client_ctx->client = client; 427 client_ctx->client = client;
425 return client_ctx; 428 return client_ctx;
426} 429}
@@ -435,22 +438,22 @@ connect_cb(void *cls,
435 * for the last call when the server is destroyed 438 * for the last call when the server is destroyed
436 */ 439 */
437static void 440static void
438disconnect_cb(void *cls, 441disconnect_cb (void *cls,
439 struct GNUNET_SERVICE_Client *client, 442 struct GNUNET_SERVICE_Client *client,
440 void *app_ctx) 443 void *app_ctx)
441{ 444{
442 struct ClientCtx *client_ctx = app_ctx; 445 struct ClientCtx *client_ctx = app_ctx;
443 struct Barrier *barrier = client_ctx->barrier; 446 struct Barrier *barrier = client_ctx->barrier;
444 447
445 if (NULL != barrier) 448 if (NULL != barrier)
446 { 449 {
447 GNUNET_CONTAINER_DLL_remove(barrier->head, 450 GNUNET_CONTAINER_DLL_remove (barrier->head,
448 barrier->tail, 451 barrier->tail,
449 client_ctx); 452 client_ctx);
450 client_ctx->barrier = NULL; 453 client_ctx->barrier = NULL;
451 } 454 }
452 GNUNET_free(client_ctx); 455 GNUNET_free (client_ctx);
453 LOG_DEBUG("Client disconnected from testbed-barrier service\n"); 456 LOG_DEBUG ("Client disconnected from testbed-barrier service\n");
454} 457}
455 458
456 459
@@ -460,25 +463,25 @@ disconnect_cb(void *cls,
460 * @param cfg the configuration to use for initialisation 463 * @param cfg the configuration to use for initialisation
461 */ 464 */
462void 465void
463GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg) 466GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg)
464{ 467{
465 struct GNUNET_MQ_MessageHandler message_handlers[] = { 468 struct GNUNET_MQ_MessageHandler message_handlers[] = {
466 GNUNET_MQ_hd_var_size(barrier_wait, 469 GNUNET_MQ_hd_var_size (barrier_wait,
467 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT, 470 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT,
468 struct GNUNET_TESTBED_BarrierWait, 471 struct GNUNET_TESTBED_BarrierWait,
469 NULL), 472 NULL),
470 GNUNET_MQ_handler_end() 473 GNUNET_MQ_handler_end ()
471 }; 474 };
472 475
473 LOG_DEBUG("Launching testbed-barrier service\n"); 476 LOG_DEBUG ("Launching testbed-barrier service\n");
474 barrier_map = GNUNET_CONTAINER_multihashmap_create(3, 477 barrier_map = GNUNET_CONTAINER_multihashmap_create (3,
475 GNUNET_YES); 478 GNUNET_YES);
476 ctx = GNUNET_SERVICE_start("testbed-barrier", 479 ctx = GNUNET_SERVICE_start ("testbed-barrier",
477 cfg, 480 cfg,
478 &connect_cb, 481 &connect_cb,
479 &disconnect_cb, 482 &disconnect_cb,
480 NULL, 483 NULL,
481 message_handlers); 484 message_handlers);
482} 485}
483 486
484 487
@@ -493,15 +496,15 @@ GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg)
493 * #GNUNET_NO if not. 496 * #GNUNET_NO if not.
494 */ 497 */
495static int 498static int
496barrier_destroy_iterator(void *cls, 499barrier_destroy_iterator (void *cls,
497 const struct GNUNET_HashCode *key, 500 const struct GNUNET_HashCode *key,
498 void *value) 501 void *value)
499{ 502{
500 struct Barrier *barrier = value; 503 struct Barrier *barrier = value;
501 504
502 GNUNET_assert(NULL != barrier); 505 GNUNET_assert (NULL != barrier);
503 cancel_wrappers(barrier); 506 cancel_wrappers (barrier);
504 remove_barrier(barrier); 507 remove_barrier (barrier);
505 return GNUNET_YES; 508 return GNUNET_YES;
506} 509}
507 510
@@ -510,16 +513,17 @@ barrier_destroy_iterator(void *cls,
510 * Function to stop the barrier service 513 * Function to stop the barrier service
511 */ 514 */
512void 515void
513GST_barriers_destroy() 516GST_barriers_destroy ()
514{ 517{
515 GNUNET_assert(NULL != barrier_map); 518 GNUNET_assert (NULL != barrier_map);
516 GNUNET_assert(GNUNET_SYSERR != 519 GNUNET_assert (GNUNET_SYSERR !=
517 GNUNET_CONTAINER_multihashmap_iterate(barrier_map, 520 GNUNET_CONTAINER_multihashmap_iterate (barrier_map,
518 &barrier_destroy_iterator, 521 &
519 NULL)); 522 barrier_destroy_iterator,
520 GNUNET_CONTAINER_multihashmap_destroy(barrier_map); 523 NULL));
521 GNUNET_assert(NULL != ctx); 524 GNUNET_CONTAINER_multihashmap_destroy (barrier_map);
522 GNUNET_SERVICE_stop(ctx); 525 GNUNET_assert (NULL != ctx);
526 GNUNET_SERVICE_stop (ctx);
523} 527}
524 528
525 529
@@ -537,59 +541,59 @@ GST_barriers_destroy()
537 * error messsage 541 * error messsage
538 */ 542 */
539static void 543static void
540wbarrier_status_cb(void *cls, 544wbarrier_status_cb (void *cls,
541 const char *name, 545 const char *name,
542 struct GNUNET_TESTBED_Barrier *b_, 546 struct GNUNET_TESTBED_Barrier *b_,
543 enum GNUNET_TESTBED_BarrierStatus status, 547 enum GNUNET_TESTBED_BarrierStatus status,
544 const char *emsg) 548 const char *emsg)
545{ 549{
546 struct WBarrier *wrapper = cls; 550 struct WBarrier *wrapper = cls;
547 struct Barrier *barrier = wrapper->barrier; 551 struct Barrier *barrier = wrapper->barrier;
548 552
549 GNUNET_assert(b_ == wrapper->hbarrier); 553 GNUNET_assert (b_ == wrapper->hbarrier);
550 switch (status) 554 switch (status)
555 {
556 case GNUNET_TESTBED_BARRIERSTATUS_ERROR:
557 LOG (GNUNET_ERROR_TYPE_ERROR,
558 "Initialising barrier `%s' failed at a sub-controller: %s\n",
559 barrier->name,
560 (NULL != emsg) ? emsg : "NULL");
561 cancel_wrappers (barrier);
562 if (NULL == emsg)
563 emsg = "Initialisation failed at a sub-controller";
564 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR;
565 send_barrier_status_msg (barrier, emsg);
566 return;
567
568 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
569 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status)
551 { 570 {
552 case GNUNET_TESTBED_BARRIERSTATUS_ERROR: 571 GNUNET_break_op (0);
553 LOG(GNUNET_ERROR_TYPE_ERROR,
554 "Initialising barrier `%s' failed at a sub-controller: %s\n",
555 barrier->name,
556 (NULL != emsg) ? emsg : "NULL");
557 cancel_wrappers(barrier);
558 if (NULL == emsg)
559 emsg = "Initialisation failed at a sub-controller";
560 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR;
561 send_barrier_status_msg(barrier, emsg);
562 return;
563
564 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
565 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status)
566 {
567 GNUNET_break_op(0);
568 return;
569 }
570 barrier->num_wbarriers_reached++;
571 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers)
572 && (LOCAL_QUORUM_REACHED(barrier)))
573 {
574 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED;
575 send_barrier_status_msg(barrier, NULL);
576 }
577 return; 572 return;
573 }
574 barrier->num_wbarriers_reached++;
575 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers)
576 && (LOCAL_QUORUM_REACHED (barrier)))
577 {
578 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED;
579 send_barrier_status_msg (barrier, NULL);
580 }
581 return;
578 582
579 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: 583 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED:
580 if (0 != barrier->status) 584 if (0 != barrier->status)
581 { 585 {
582 GNUNET_break_op(0); 586 GNUNET_break_op (0);
583 return;
584 }
585 barrier->num_wbarriers_inited++;
586 if (barrier->num_wbarriers_inited == barrier->num_wbarriers)
587 {
588 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED;
589 send_barrier_status_msg(barrier, NULL);
590 }
591 return; 587 return;
592 } 588 }
589 barrier->num_wbarriers_inited++;
590 if (barrier->num_wbarriers_inited == barrier->num_wbarriers)
591 {
592 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED;
593 send_barrier_status_msg (barrier, NULL);
594 }
595 return;
596 }
593} 597}
594 598
595 599
@@ -600,15 +604,15 @@ wbarrier_status_cb(void *cls,
600 * @param cls barrier 604 * @param cls barrier
601 */ 605 */
602static void 606static void
603fwd_tout_barrier_init(void *cls) 607fwd_tout_barrier_init (void *cls)
604{ 608{
605 struct Barrier *barrier = cls; 609 struct Barrier *barrier = cls;
606 610
607 cancel_wrappers(barrier); 611 cancel_wrappers (barrier);
608 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; 612 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR;
609 send_barrier_status_msg(barrier, 613 send_barrier_status_msg (barrier,
610 "Timedout while propagating barrier initialisation\n"); 614 "Timedout while propagating barrier initialisation\n");
611 remove_barrier(barrier); 615 remove_barrier (barrier);
612} 616}
613 617
614 618
@@ -621,8 +625,8 @@ fwd_tout_barrier_init(void *cls)
621 * @return #GNUNET_OK if @a msg is well-formed 625 * @return #GNUNET_OK if @a msg is well-formed
622 */ 626 */
623int 627int
624check_barrier_init(void *cls, 628check_barrier_init (void *cls,
625 const struct GNUNET_TESTBED_BarrierInit *msg) 629 const struct GNUNET_TESTBED_BarrierInit *msg)
626{ 630{
627 return GNUNET_OK; /* always well-formed */ 631 return GNUNET_OK; /* always well-formed */
628} 632}
@@ -640,8 +644,8 @@ check_barrier_init(void *cls,
640 * @param msg the actual message 644 * @param msg the actual message
641 */ 645 */
642void 646void
643handle_barrier_init(void *cls, 647handle_barrier_init (void *cls,
644 const struct GNUNET_TESTBED_BarrierInit *msg) 648 const struct GNUNET_TESTBED_BarrierInit *msg)
645{ 649{
646 struct GNUNET_SERVICE_Client *client = cls; 650 struct GNUNET_SERVICE_Client *client = cls;
647 char *name; 651 char *name;
@@ -654,82 +658,84 @@ handle_barrier_init(void *cls,
654 uint16_t msize; 658 uint16_t msize;
655 659
656 if (NULL == GST_context) 660 if (NULL == GST_context)
657 { 661 {
658 GNUNET_break_op(0); 662 GNUNET_break_op (0);
659 GNUNET_SERVICE_client_drop(client); 663 GNUNET_SERVICE_client_drop (client);
660 return; 664 return;
661 } 665 }
662 if (client != GST_context->client) 666 if (client != GST_context->client)
663 { 667 {
664 GNUNET_break_op(0); 668 GNUNET_break_op (0);
665 GNUNET_SERVICE_client_drop(client); 669 GNUNET_SERVICE_client_drop (client);
666 return; 670 return;
667 } 671 }
668 msize = ntohs(msg->header.size); 672 msize = ntohs (msg->header.size);
669 name_len = (size_t)msize - sizeof(struct GNUNET_TESTBED_BarrierInit); 673 name_len = (size_t) msize - sizeof(struct GNUNET_TESTBED_BarrierInit);
670 name = GNUNET_malloc(name_len + 1); 674 name = GNUNET_malloc (name_len + 1);
671 GNUNET_memcpy(name, msg->name, name_len); 675 GNUNET_memcpy (name, msg->name, name_len);
672 GNUNET_CRYPTO_hash(name, name_len, &hash); 676 GNUNET_CRYPTO_hash (name, name_len, &hash);
673 LOG_DEBUG("Received BARRIER_INIT for barrier `%s'\n", 677 LOG_DEBUG ("Received BARRIER_INIT for barrier `%s'\n",
674 name); 678 name);
675 if (GNUNET_YES == 679 if (GNUNET_YES ==
676 GNUNET_CONTAINER_multihashmap_contains(barrier_map, 680 GNUNET_CONTAINER_multihashmap_contains (barrier_map,
677 &hash)) 681 &hash))
678 { 682 {
679 send_client_status_msg(client, 683 send_client_status_msg (client,
680 name, 684 name,
681 GNUNET_TESTBED_BARRIERSTATUS_ERROR, 685 GNUNET_TESTBED_BARRIERSTATUS_ERROR,
682 "A barrier with the same name already exists"); 686 "A barrier with the same name already exists");
683 GNUNET_free(name); 687 GNUNET_free (name);
684 GNUNET_SERVICE_client_continue(client); 688 GNUNET_SERVICE_client_continue (client);
685 return; 689 return;
686 } 690 }
687 barrier = GNUNET_new(struct Barrier); 691 barrier = GNUNET_new (struct Barrier);
688 barrier->hash = hash; 692 barrier->hash = hash;
689 barrier->quorum = msg->quorum; 693 barrier->quorum = msg->quorum;
690 barrier->name = name; 694 barrier->name = name;
691 barrier->mc = client; 695 barrier->mc = client;
692 GNUNET_assert(GNUNET_OK == 696 GNUNET_assert (GNUNET_OK ==
693 GNUNET_CONTAINER_multihashmap_put(barrier_map, 697 GNUNET_CONTAINER_multihashmap_put (barrier_map,
694 &barrier->hash, 698 &barrier->hash,
695 barrier, 699 barrier,
696 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 700 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
697 GNUNET_SERVICE_client_continue(client); 701 GNUNET_SERVICE_client_continue (client);
698 /* Propagate barrier init to subcontrollers */ 702 /* Propagate barrier init to subcontrollers */
699 for (cnt = 0; cnt < GST_slave_list_size; cnt++) 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)
700 { 708 {
701 if (NULL == (slave = GST_slave_list[cnt])) 709 GNUNET_break (0); /* May happen when we are connecting to the controller */
702 continue; 710 continue;
703 if (NULL == slave->controller)
704 {
705 GNUNET_break(0);/* May happen when we are connecting to the controller */
706 continue;
707 }
708 wrapper = GNUNET_new(struct WBarrier);
709 wrapper->barrier = barrier;
710 wrapper->controller = slave->controller;
711 GNUNET_CONTAINER_DLL_insert_tail(barrier->whead,
712 barrier->wtail,
713 wrapper);
714 barrier->num_wbarriers++;
715 wrapper->hbarrier = GNUNET_TESTBED_barrier_init_(wrapper->controller,
716 barrier->name,
717 barrier->quorum,
718 &wbarrier_status_cb,
719 wrapper,
720 GNUNET_NO);
721 } 711 }
712 wrapper = GNUNET_new (struct WBarrier);
713 wrapper->barrier = barrier;
714 wrapper->controller = slave->controller;
715 GNUNET_CONTAINER_DLL_insert_tail (barrier->whead,
716 barrier->wtail,
717 wrapper);
718 barrier->num_wbarriers++;
719 wrapper->hbarrier = GNUNET_TESTBED_barrier_init_ (wrapper->controller,
720 barrier->name,
721 barrier->quorum,
722 &wbarrier_status_cb,
723 wrapper,
724 GNUNET_NO);
725 }
722 if (NULL == barrier->whead) /* No further propagation */ 726 if (NULL == barrier->whead) /* No further propagation */
723 { 727 {
724 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; 728 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED;
725 LOG_DEBUG("Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n", 729 LOG_DEBUG (
726 barrier->name); 730 "Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n",
727 send_barrier_status_msg(barrier, NULL); 731 barrier->name);
728 } 732 send_barrier_status_msg (barrier, NULL);
733 }
729 else 734 else
730 barrier->tout_task = GNUNET_SCHEDULER_add_delayed(MESSAGE_SEND_TIMEOUT(30), 735 barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (
731 &fwd_tout_barrier_init, 736 30),
732 barrier); 737 &fwd_tout_barrier_init,
738 barrier);
733} 739}
734 740
735 741
@@ -741,8 +747,8 @@ handle_barrier_init(void *cls,
741 * @return #GNUNET_OK if @a msg is well-formed 747 * @return #GNUNET_OK if @a msg is well-formed
742 */ 748 */
743int 749int
744check_barrier_cancel(void *cls, 750check_barrier_cancel (void *cls,
745 const struct GNUNET_TESTBED_BarrierCancel *msg) 751 const struct GNUNET_TESTBED_BarrierCancel *msg)
746{ 752{
747 return GNUNET_OK; /* all are well-formed */ 753 return GNUNET_OK; /* all are well-formed */
748} 754}
@@ -760,8 +766,8 @@ check_barrier_cancel(void *cls,
760 * @param msg the actual message 766 * @param msg the actual message
761 */ 767 */
762void 768void
763handle_barrier_cancel(void *cls, 769handle_barrier_cancel (void *cls,
764 const struct GNUNET_TESTBED_BarrierCancel *msg) 770 const struct GNUNET_TESTBED_BarrierCancel *msg)
765{ 771{
766 struct GNUNET_SERVICE_Client *client = cls; 772 struct GNUNET_SERVICE_Client *client = cls;
767 char *name; 773 char *name;
@@ -771,42 +777,42 @@ handle_barrier_cancel(void *cls,
771 uint16_t msize; 777 uint16_t msize;
772 778
773 if (NULL == GST_context) 779 if (NULL == GST_context)
774 { 780 {
775 GNUNET_break_op(0); 781 GNUNET_break_op (0);
776 GNUNET_SERVICE_client_drop(client); 782 GNUNET_SERVICE_client_drop (client);
777 return; 783 return;
778 } 784 }
779 if (client != GST_context->client) 785 if (client != GST_context->client)
780 { 786 {
781 GNUNET_break_op(0); 787 GNUNET_break_op (0);
782 GNUNET_SERVICE_client_drop(client); 788 GNUNET_SERVICE_client_drop (client);
783 return; 789 return;
784 } 790 }
785 msize = ntohs(msg->header.size); 791 msize = ntohs (msg->header.size);
786 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierCancel); 792 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierCancel);
787 name = GNUNET_malloc(name_len + 1); 793 name = GNUNET_malloc (name_len + 1);
788 GNUNET_memcpy(name, 794 GNUNET_memcpy (name,
789 msg->name, 795 msg->name,
790 name_len); 796 name_len);
791 LOG_DEBUG("Received BARRIER_CANCEL for barrier `%s'\n", 797 LOG_DEBUG ("Received BARRIER_CANCEL for barrier `%s'\n",
792 name); 798 name);
793 GNUNET_CRYPTO_hash(name, 799 GNUNET_CRYPTO_hash (name,
794 name_len, 800 name_len,
795 &hash); 801 &hash);
796 if (GNUNET_NO == 802 if (GNUNET_NO ==
797 GNUNET_CONTAINER_multihashmap_contains(barrier_map, 803 GNUNET_CONTAINER_multihashmap_contains (barrier_map,
798 &hash)) 804 &hash))
799 { 805 {
800 GNUNET_break_op(0); 806 GNUNET_break_op (0);
801 GNUNET_SERVICE_client_drop(client); 807 GNUNET_SERVICE_client_drop (client);
802 return; 808 return;
803 } 809 }
804 barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, 810 barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map,
805 &hash); 811 &hash);
806 GNUNET_assert(NULL != barrier); 812 GNUNET_assert (NULL != barrier);
807 cancel_wrappers(barrier); 813 cancel_wrappers (barrier);
808 remove_barrier(barrier); 814 remove_barrier (barrier);
809 GNUNET_SERVICE_client_continue(client); 815 GNUNET_SERVICE_client_continue (client);
810} 816}
811 817
812 818
@@ -818,34 +824,34 @@ handle_barrier_cancel(void *cls,
818 * @return #GNUNET_OK if @a msg is well-formed 824 * @return #GNUNET_OK if @a msg is well-formed
819 */ 825 */
820int 826int
821check_barrier_status(void *cls, 827check_barrier_status (void *cls,
822 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 828 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
823{ 829{
824 uint16_t msize; 830 uint16_t msize;
825 uint16_t name_len; 831 uint16_t name_len;
826 const char *name; 832 const char *name;
827 enum GNUNET_TESTBED_BarrierStatus status; 833 enum GNUNET_TESTBED_BarrierStatus status;
828 834
829 msize = ntohs(msg->header.size) - sizeof(*msg); 835 msize = ntohs (msg->header.size) - sizeof(*msg);
830 status = ntohs(msg->status); 836 status = ntohs (msg->status);
831 if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED != status) 837 if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED != status)
832 { 838 {
833 GNUNET_break_op(0); /* current we only expect BARRIER_CROSSED 839 GNUNET_break_op (0); /* current we only expect BARRIER_CROSSED
834 status message this way */ 840 status message this way */
835 return GNUNET_SYSERR; 841 return GNUNET_SYSERR;
836 } 842 }
837 name = msg->data; 843 name = msg->data;
838 name_len = ntohs(msg->name_len); 844 name_len = ntohs (msg->name_len);
839 if ((name_len + 1) != msize) 845 if ((name_len + 1) != msize)
840 { 846 {
841 GNUNET_break_op(0); 847 GNUNET_break_op (0);
842 return GNUNET_SYSERR; 848 return GNUNET_SYSERR;
843 } 849 }
844 if ('\0' != name[name_len]) 850 if ('\0' != name[name_len])
845 { 851 {
846 GNUNET_break_op(0); 852 GNUNET_break_op (0);
847 return GNUNET_SYSERR; 853 return GNUNET_SYSERR;
848 } 854 }
849 return GNUNET_OK; 855 return GNUNET_OK;
850} 856}
851 857
@@ -859,8 +865,8 @@ check_barrier_status(void *cls,
859 * @param msg the actual message 865 * @param msg the actual message
860 */ 866 */
861void 867void
862handle_barrier_status(void *cls, 868handle_barrier_status (void *cls,
863 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 869 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
864{ 870{
865 struct GNUNET_SERVICE_Client *client = cls; 871 struct GNUNET_SERVICE_Client *client = cls;
866 struct Barrier *barrier; 872 struct Barrier *barrier;
@@ -872,48 +878,49 @@ handle_barrier_status(void *cls,
872 struct GNUNET_MQ_Envelope *env; 878 struct GNUNET_MQ_Envelope *env;
873 879
874 if (NULL == GST_context) 880 if (NULL == GST_context)
875 { 881 {
876 GNUNET_break_op(0); 882 GNUNET_break_op (0);
877 GNUNET_SERVICE_client_drop(client); 883 GNUNET_SERVICE_client_drop (client);
878 return; 884 return;
879 } 885 }
880 if (client != GST_context->client) 886 if (client != GST_context->client)
881 { 887 {
882 GNUNET_break_op(0); 888 GNUNET_break_op (0);
883 GNUNET_SERVICE_client_drop(client); 889 GNUNET_SERVICE_client_drop (client);
884 return; 890 return;
885 } 891 }
886 name = msg->data; 892 name = msg->data;
887 name_len = ntohs(msg->name_len); 893 name_len = ntohs (msg->name_len);
888 LOG_DEBUG("Received BARRIER_STATUS for barrier `%s'\n", 894 LOG_DEBUG ("Received BARRIER_STATUS for barrier `%s'\n",
889 name); 895 name);
890 GNUNET_CRYPTO_hash(name, 896 GNUNET_CRYPTO_hash (name,
891 name_len, 897 name_len,
892 &key); 898 &key);
893 barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, 899 barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map,
894 &key); 900 &key);
895 if (NULL == barrier) 901 if (NULL == barrier)
896 { 902 {
897 GNUNET_break_op(0); 903 GNUNET_break_op (0);
898 GNUNET_SERVICE_client_drop(client); 904 GNUNET_SERVICE_client_drop (client);
899 return; 905 return;
900 } 906 }
901 GNUNET_SERVICE_client_continue(client); 907 GNUNET_SERVICE_client_continue (client);
902 for (client_ctx = barrier->head; NULL != client_ctx; client_ctx = client_ctx->next) /* Notify peers */ 908 for (client_ctx = barrier->head; NULL != client_ctx; client_ctx =
903 { 909 client_ctx->next) /* Notify peers */
904 env = GNUNET_MQ_msg_copy(&msg->header); 910 {
905 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client_ctx->client), 911 env = GNUNET_MQ_msg_copy (&msg->header);
906 env); 912 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client_ctx->client),
907 } 913 env);
914 }
908 /** 915 /**
909 * The wrapper barriers do not echo the barrier status, so we have to do it 916 * The wrapper barriers do not echo the barrier status, so we have to do it
910 * here 917 * here
911 */ 918 */
912 for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next) 919 for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next)
913 { 920 {
914 GNUNET_TESTBED_queue_message_(wrapper->controller, 921 GNUNET_TESTBED_queue_message_ (wrapper->controller,
915 GNUNET_copy_message(&msg->header)); 922 GNUNET_copy_message (&msg->header));
916 } 923 }
917} 924}
918 925
919/* end of gnunet-service-testbed_barriers.c */ 926/* end of gnunet-service-testbed_barriers.c */