diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-09 12:22:31 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-09 12:22:31 +0000 |
commit | de547f838e21de9f847c0b357c41cbfa6ecbe967 (patch) | |
tree | 35da1aed63ed018249ec58941447bacd758adfff /src/testbed/gnunet-service-testbed_barriers.c | |
parent | a3efd7521e99175689c589a128240f2c84c55c45 (diff) | |
download | gnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.tar.gz gnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.zip |
- barriers test case; more fixes
Diffstat (limited to 'src/testbed/gnunet-service-testbed_barriers.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_barriers.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/testbed/gnunet-service-testbed_barriers.c b/src/testbed/gnunet-service-testbed_barriers.c index 894bf1056..693396ef6 100644 --- a/src/testbed/gnunet-service-testbed_barriers.c +++ b/src/testbed/gnunet-service-testbed_barriers.c | |||
@@ -42,6 +42,17 @@ | |||
42 | ((barrier->quorum * GST_num_local_peers) <= (barrier->nreached * 100)) | 42 | ((barrier->quorum * GST_num_local_peers) <= (barrier->nreached * 100)) |
43 | 43 | ||
44 | 44 | ||
45 | #ifdef LOG | ||
46 | #undef LOG | ||
47 | #endif | ||
48 | |||
49 | /** | ||
50 | * Logging shorthand | ||
51 | */ | ||
52 | #define LOG(kind,...) \ | ||
53 | GNUNET_log_from (kind, "testbed-barriers", __VA_ARGS__) | ||
54 | |||
55 | |||
45 | /** | 56 | /** |
46 | * Barrier | 57 | * Barrier |
47 | */ | 58 | */ |
@@ -392,16 +403,18 @@ send_client_status_msg (struct GNUNET_SERVER_Client *client, | |||
392 | uint16_t msize; | 403 | uint16_t msize; |
393 | 404 | ||
394 | GNUNET_assert ((NULL == emsg) || (BARRIER_STATUS_ERROR == status)); | 405 | GNUNET_assert ((NULL == emsg) || (BARRIER_STATUS_ERROR == status)); |
395 | name_len = strlen (name) + 1; | 406 | name_len = strlen (name); |
396 | msize = sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) | 407 | msize = sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) |
397 | + name_len | 408 | + (name_len + 1) |
398 | + (NULL == emsg) ? 0 : strlen (emsg) + 1; | 409 | + ((NULL == emsg) ? 0 : (strlen (emsg) + 1)); |
399 | msg = GNUNET_malloc (msize); | 410 | msg = GNUNET_malloc (msize); |
411 | msg->header.size = htons (msize); | ||
412 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); | ||
400 | msg->status = htons (status); | 413 | msg->status = htons (status); |
401 | msg->name_len = htons ((uint16_t) name_len); | 414 | msg->name_len = htons ((uint16_t) name_len); |
402 | (void) memcpy (msg->data, name, name_len); | 415 | (void) memcpy (msg->data, name, name_len); |
403 | if (NULL != emsg) | 416 | if (NULL != emsg) |
404 | (void) memcpy (msg->data + name_len, emsg, strlen (emsg) + 1); | 417 | (void) memcpy (msg->data + name_len + 1, emsg, strlen (emsg)); |
405 | GST_queue_message (client, &msg->header); | 418 | GST_queue_message (client, &msg->header); |
406 | } | 419 | } |
407 | 420 | ||
@@ -444,7 +457,7 @@ notify_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
444 | msg = GNUNET_malloc (msize); | 457 | msg = GNUNET_malloc (msize); |
445 | msg->header.size = htons (msize); | 458 | msg->header.size = htons (msize); |
446 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); | 459 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); |
447 | msg->status = 0; | 460 | msg->status = htons (BARRIER_STATUS_CROSSED); |
448 | msg->name_len = htons (name_len); | 461 | msg->name_len = htons (name_len); |
449 | (void) memcpy (msg->data, barrier->name, name_len); | 462 | (void) memcpy (msg->data, barrier->name, name_len); |
450 | msg->data[name_len] = '\0'; | 463 | msg->data[name_len] = '\0'; |
@@ -453,8 +466,6 @@ notify_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
453 | dup_msg = GNUNET_copy_message (&msg->header); | 466 | dup_msg = GNUNET_copy_message (&msg->header); |
454 | queue_message (client_ctx, dup_msg); | 467 | queue_message (client_ctx, dup_msg); |
455 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, client_ctx); | 468 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, client_ctx); |
456 | GNUNET_SERVER_client_set_user_context_ (client_ctx->client, NULL, 0); | ||
457 | GNUNET_free (client_ctx); | ||
458 | } | 469 | } |
459 | } | 470 | } |
460 | 471 | ||
@@ -501,7 +512,8 @@ handle_barrier_wait (void *cls, struct GNUNET_SERVER_Client *client, | |||
501 | name = GNUNET_malloc (name_len + 1); | 512 | name = GNUNET_malloc (name_len + 1); |
502 | name[name_len] = '\0'; | 513 | name[name_len] = '\0'; |
503 | (void) memcpy (name, msg->name, name_len); | 514 | (void) memcpy (name, msg->name, name_len); |
504 | GNUNET_CRYPTO_hash (name, name_len - 1, &key); | 515 | LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n", name); |
516 | GNUNET_CRYPTO_hash (name, name_len, &key); | ||
505 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) | 517 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) |
506 | { | 518 | { |
507 | GNUNET_break (0); | 519 | GNUNET_break (0); |
@@ -517,9 +529,14 @@ handle_barrier_wait (void *cls, struct GNUNET_SERVER_Client *client, | |||
517 | GNUNET_SERVER_client_keep (client); | 529 | GNUNET_SERVER_client_keep (client); |
518 | client_ctx->barrier = barrier; | 530 | client_ctx->barrier = barrier; |
519 | GNUNET_CONTAINER_DLL_insert_tail (barrier->head, barrier->tail, client_ctx); | 531 | GNUNET_CONTAINER_DLL_insert_tail (barrier->head, barrier->tail, client_ctx); |
520 | barrier->nreached++; | 532 | } |
521 | if (LOCAL_QUORUM_REACHED (barrier)) | 533 | barrier->nreached++; |
522 | notify_task_cb (barrier, NULL); | 534 | if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) |
535 | && (LOCAL_QUORUM_REACHED (barrier))) | ||
536 | { | ||
537 | barrier->status = BARRIER_STATUS_CROSSED; | ||
538 | send_barrier_status_msg (barrier, NULL); | ||
539 | notify_task_cb (barrier, NULL); | ||
523 | } | 540 | } |
524 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 541 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
525 | } | 542 | } |
@@ -538,6 +555,8 @@ disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
538 | { | 555 | { |
539 | struct ClientCtx *client_ctx; | 556 | struct ClientCtx *client_ctx; |
540 | 557 | ||
558 | if (NULL == client) | ||
559 | return; | ||
541 | client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx); | 560 | client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx); |
542 | if (NULL == client_ctx) | 561 | if (NULL == client_ctx) |
543 | return; /* We only set user context for locally | 562 | return; /* We only set user context for locally |
@@ -548,6 +567,8 @@ disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
548 | 567 | ||
549 | /** | 568 | /** |
550 | * Function to initialise barrriers component | 569 | * Function to initialise barrriers component |
570 | * | ||
571 | * @param cfg the configuration to use for initialisation | ||
551 | */ | 572 | */ |
552 | void | 573 | void |
553 | GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) | 574 | GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -571,7 +592,7 @@ GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
571 | * Function to stop the barrier service | 592 | * Function to stop the barrier service |
572 | */ | 593 | */ |
573 | void | 594 | void |
574 | GST_barriers_stop () | 595 | GST_barriers_destroy () |
575 | { | 596 | { |
576 | GNUNET_assert (NULL != barrier_map); | 597 | GNUNET_assert (NULL != barrier_map); |
577 | GNUNET_CONTAINER_multihashmap_destroy (barrier_map); | 598 | GNUNET_CONTAINER_multihashmap_destroy (barrier_map); |
@@ -719,9 +740,10 @@ GST_handle_barrier_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
719 | name = GNUNET_malloc (name_len + 1); | 740 | name = GNUNET_malloc (name_len + 1); |
720 | (void) memcpy (name, msg->name, name_len); | 741 | (void) memcpy (name, msg->name, name_len); |
721 | GNUNET_CRYPTO_hash (name, name_len, &hash); | 742 | GNUNET_CRYPTO_hash (name, name_len, &hash); |
743 | LOG_DEBUG ("Received BARRIER_INIT for barrier `%s'\n", name); | ||
722 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (barrier_map, &hash)) | 744 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (barrier_map, &hash)) |
723 | { | 745 | { |
724 | 746 | ||
725 | send_client_status_msg (client, name, BARRIER_STATUS_ERROR, | 747 | send_client_status_msg (client, name, BARRIER_STATUS_ERROR, |
726 | "A barrier with the same name already exists"); | 748 | "A barrier with the same name already exists"); |
727 | GNUNET_free (name); | 749 | GNUNET_free (name); |
@@ -762,6 +784,8 @@ GST_handle_barrier_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
762 | if (NULL == barrier->whead) /* No further propagation */ | 784 | if (NULL == barrier->whead) /* No further propagation */ |
763 | { | 785 | { |
764 | barrier->status = BARRIER_STATUS_INITIALISED; | 786 | barrier->status = BARRIER_STATUS_INITIALISED; |
787 | LOG_DEBUG ("Sending BARRIER_STATUS_INITIALISED for barrier `%s'\n", | ||
788 | barrier->name); | ||
765 | send_barrier_status_msg (barrier, NULL); | 789 | send_barrier_status_msg (barrier, NULL); |
766 | }else | 790 | }else |
767 | barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (30), | 791 | barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (30), |