aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_barriers.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-09-02 21:50:06 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-09-02 21:50:06 +0000
commit185a7fb990f6d5cc92d24ad9a7a5b9d7e2d4eef6 (patch)
tree9e58fbe314f528cdcb0ce107a525e6aee997be00 /src/testbed/gnunet-service-testbed_barriers.c
parenteee4dba55bb2ce508f087cef09536a4ce2f2a42f (diff)
downloadgnunet-185a7fb990f6d5cc92d24ad9a7a5b9d7e2d4eef6.tar.gz
gnunet-185a7fb990f6d5cc92d24ad9a7a5b9d7e2d4eef6.zip
- propagate barrier cancel message
Diffstat (limited to 'src/testbed/gnunet-service-testbed_barriers.c')
-rw-r--r--src/testbed/gnunet-service-testbed_barriers.c83
1 files changed, 75 insertions, 8 deletions
diff --git a/src/testbed/gnunet-service-testbed_barriers.c b/src/testbed/gnunet-service-testbed_barriers.c
index 0a4c84808..c16882032 100644
--- a/src/testbed/gnunet-service-testbed_barriers.c
+++ b/src/testbed/gnunet-service-testbed_barriers.c
@@ -310,6 +310,29 @@ queue_message (struct ClientCtx *ctx, struct GNUNET_MessageHeader *msg)
310 310
311 311
312/** 312/**
313 * Function to cleanup client context data structure
314 *
315 * @param ctx the client context data structure
316 */
317static void
318cleanup_clientctx (struct ClientCtx *ctx)
319{
320 struct MessageQueue *mq;
321
322 GNUNET_SERVER_client_drop (ctx->client);
323 if (NULL != ctx->tx)
324 GNUNET_SERVER_notify_transmit_ready_cancel (ctx->tx);
325 if (NULL != (mq = ctx->mq_head))
326 {
327 GNUNET_CONTAINER_DLL_remove (ctx->mq_head, ctx->mq_tail, mq);
328 GNUNET_free (mq->msg);
329 GNUNET_free (mq);
330 }
331 GNUNET_free (ctx);
332}
333
334
335/**
313 * Function to remove a barrier from the barrier map and cleanup resources 336 * Function to remove a barrier from the barrier map and cleanup resources
314 * occupied by a barrier 337 * occupied by a barrier
315 * 338 *
@@ -318,9 +341,16 @@ queue_message (struct ClientCtx *ctx, struct GNUNET_MessageHeader *msg)
318static void 341static void
319remove_barrier (struct Barrier *barrier) 342remove_barrier (struct Barrier *barrier)
320{ 343{
344 struct ClientCtx *ctx;
345
321 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (barrier_map, 346 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (barrier_map,
322 &barrier->hash, 347 &barrier->hash,
323 barrier)); 348 barrier));
349 while (NULL != (ctx = barrier->head))
350 {
351 GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, ctx);
352 cleanup_clientctx (ctx);
353 }
324 GNUNET_free (barrier->name); 354 GNUNET_free (barrier->name);
325 GNUNET_SERVER_client_drop (barrier->client); 355 GNUNET_SERVER_client_drop (barrier->client);
326 GNUNET_free (barrier); 356 GNUNET_free (barrier);
@@ -511,15 +541,12 @@ static void
511disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) 541disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
512{ 542{
513 struct ClientCtx *client_ctx; 543 struct ClientCtx *client_ctx;
514 struct Barrier *barrier;
515 544
516 client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx); 545 client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx);
517 if (NULL == client_ctx) 546 if (NULL == client_ctx)
518 return; 547 return; /* We only set user context for locally
519 barrier = client_ctx->barrier; 548 connected clients */
520 GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, client_ctx); 549 cleanup_clientctx (client_ctx);
521 if (NULL != client_ctx->tx)
522 GNUNET_SERVER_notify_transmit_ready_cancel (client_ctx->tx);
523} 550}
524 551
525 552
@@ -702,7 +729,6 @@ GST_handle_barrier_init (void *cls, struct GNUNET_SERVER_Client *client,
702 name_len = (size_t) msize - sizeof (struct GNUNET_TESTBED_BarrierInit); 729 name_len = (size_t) msize - sizeof (struct GNUNET_TESTBED_BarrierInit);
703 name = GNUNET_malloc (name_len + 1); 730 name = GNUNET_malloc (name_len + 1);
704 (void) memcpy (name, msg->name, name_len); 731 (void) memcpy (name, msg->name, name_len);
705 name[name_len] = '\0';
706 GNUNET_CRYPTO_hash (name, name_len, &hash); 732 GNUNET_CRYPTO_hash (name, name_len, &hash);
707 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (barrier_map, &hash)) 733 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (barrier_map, &hash))
708 { 734 {
@@ -771,7 +797,48 @@ void
771GST_handle_barrier_cancel (void *cls, struct GNUNET_SERVER_Client *client, 797GST_handle_barrier_cancel (void *cls, struct GNUNET_SERVER_Client *client,
772 const struct GNUNET_MessageHeader *message) 798 const struct GNUNET_MessageHeader *message)
773{ 799{
774 GNUNET_break (0); 800 const struct GNUNET_TESTBED_BarrierCancel *msg;
801 char *name;
802 struct Barrier *barrier;
803 struct GNUNET_HashCode hash;
804 size_t name_len;
805 uint16_t msize;
806
807 if (NULL == GST_context)
808 {
809 GNUNET_break_op (0);
810 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
811 return;
812 }
813 if (client != GST_context->client)
814 {
815 GNUNET_break_op (0);
816 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
817 return;
818 }
819 msize = ntohs (message->size);
820 if (msize <= sizeof (struct GNUNET_TESTBED_BarrierCancel))
821 {
822 GNUNET_break_op (0);
823 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
824 return;
825 }
826 msg = (const struct GNUNET_TESTBED_BarrierCancel *) message;
827 name_len = msize - sizeof (struct GNUNET_TESTBED_BarrierCancel);
828 name = GNUNET_malloc (name_len + 1);
829 (void) memcpy (name, msg->name, name_len);
830 GNUNET_CRYPTO_hash (name, name_len, &hash);
831 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (barrier_map, &hash))
832 {
833 GNUNET_break_op (0);
834 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
835 return;
836 }
837 barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &hash);
838 GNUNET_assert (NULL != barrier);
839 cancel_wrappers (barrier);
840 remove_barrier (barrier);
841 GNUNET_SERVER_receive_done (client, GNUNET_OK);
775} 842}
776 843
777/* end of gnunet-service-testbed_barriers.c */ 844/* end of gnunet-service-testbed_barriers.c */