aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-10-19 12:37:46 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-10-19 12:37:46 +0000
commitd3c4c4432ac9e6cfd29af424e752a9dfc5a6a389 (patch)
tree113b6e3ff1de90ab04e0d714ca6079431f73f07a /src
parent33b1edb5e9ee559da27d6491cddbfdbe30e6d3f4 (diff)
downloadgnunet-d3c4c4432ac9e6cfd29af424e752a9dfc5a6a389.tar.gz
gnunet-d3c4c4432ac9e6cfd29af424e752a9dfc5a6a389.zip
cleanup rocc
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-service-testbed.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 4d66df04b..a344dd87d 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -468,6 +468,24 @@ struct Peer
468 */ 468 */
469 uint32_t id; 469 uint32_t id;
470 470
471 /**
472 * References to peers are using in forwarded overlay contexts and remote
473 * overlay connect contexts. A peer can only be destroyed after all such
474 * contexts are destroyed. For this, we maintain a reference counter. When we
475 * use a peer in any such context, we increment this counter. We decrement it
476 * when we are destroying these contexts
477 */
478 uint32_t reference_cnt;
479
480 /**
481 * While destroying a peer, due to the fact that there could be references to
482 * this peer, we delay the peer destroy to a further time. We do this by using
483 * this flag to destroy the peer while destroying a context in which this peer
484 * has been used. When the flag is set to 1 and reference_cnt = 0 we destroy
485 * the peer
486 */
487 uint32_t destroy_flag;
488
471}; 489};
472 490
473 491
@@ -594,6 +612,16 @@ struct OverlayConnectContext
594struct RequestOverlayConnectContext 612struct RequestOverlayConnectContext
595{ 613{
596 /** 614 /**
615 * the next pointer for DLL
616 */
617 struct RequestOverlayConnectContext *next;
618
619 /**
620 * the prev pointer for DLL
621 */
622 struct RequestOverlayConnectContext *prev;
623
624 /**
597 * The transport handle of peer B 625 * The transport handle of peer B
598 */ 626 */
599 struct GNUNET_TRANSPORT_Handle *th; 627 struct GNUNET_TRANSPORT_Handle *th;
@@ -782,6 +810,17 @@ static struct OverlayConnectContext *occq_head;
782static struct OverlayConnectContext *occq_tail; 810static struct OverlayConnectContext *occq_tail;
783 811
784/** 812/**
813 * DLL head for RequectOverlayConnectContext DLL - to be used to clean up during
814 * shutdown
815 */
816static struct RequestOverlayConnectContext *roccq_head;
817
818/**
819 * DLL tail for RequectOverlayConnectContext DLL
820 */
821static struct RequestOverlayConnectContext *roccq_tail;
822
823/**
785 * Array of hosts 824 * Array of hosts
786 */ 825 */
787static struct GNUNET_TESTBED_Host **host_list; 826static struct GNUNET_TESTBED_Host **host_list;
@@ -3246,6 +3285,7 @@ cleanup_rocc (struct RequestOverlayConnectContext *rocc)
3246 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id); 3285 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
3247 GNUNET_TRANSPORT_disconnect (rocc->th); 3286 GNUNET_TRANSPORT_disconnect (rocc->th);
3248 GNUNET_free_non_null (rocc->hello); 3287 GNUNET_free_non_null (rocc->hello);
3288 GNUNET_CONTAINER_DLL_remove (roccq_head, roccq_tail, rocc);
3249 GNUNET_free (rocc); 3289 GNUNET_free (rocc);
3250} 3290}
3251 3291
@@ -3364,13 +3404,13 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
3364 { 3404 {
3365 struct GNUNET_MessageHeader *msg2; 3405 struct GNUNET_MessageHeader *msg2;
3366 3406
3367 msg2 = GNUNET_malloc (msize); 3407 msg2 = GNUNET_copy_message (message);
3368 (void) memcpy (msg2, message, msize);
3369 GNUNET_TESTBED_queue_message_ (peer->details.remote.slave->controller, msg2); 3408 GNUNET_TESTBED_queue_message_ (peer->details.remote.slave->controller, msg2);
3370 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3409 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3371 return; 3410 return;
3372 } 3411 }
3373 rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext)); 3412 rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext));
3413 GNUNET_CONTAINER_DLL_insert_tail (roccq_head, roccq_tail, rocc);
3374 rocc->th = GNUNET_TRANSPORT_connect (peer->details.local.cfg, NULL, rocc, 3414 rocc->th = GNUNET_TRANSPORT_connect (peer->details.local.cfg, NULL, rocc,
3375 NULL, &transport_connect_notify, NULL); 3415 NULL, &transport_connect_notify, NULL);
3376 if (NULL == rocc->th) 3416 if (NULL == rocc->th)
@@ -3522,6 +3562,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3522{ 3562{
3523 struct LCFContextQueue *lcfq; 3563 struct LCFContextQueue *lcfq;
3524 struct OverlayConnectContext *occ; 3564 struct OverlayConnectContext *occ;
3565 struct RequestOverlayConnectContext *rocc;
3525 uint32_t id; 3566 uint32_t id;
3526 3567
3527 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; 3568 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
@@ -3547,10 +3588,17 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3547 } 3588 }
3548 while (NULL != (occ = occq_head)) 3589 while (NULL != (occ = occq_head))
3549 cleanup_occ (occ); 3590 cleanup_occ (occ);
3591 while (NULL != (rocc = roccq_head))
3592 cleanup_rocc (rocc);
3550 /* Clear peer list */ 3593 /* Clear peer list */
3551 for (id = 0; id < peer_list_size; id++) 3594 for (id = 0; id < peer_list_size; id++)
3552 if (NULL != peer_list[id]) 3595 if (NULL != peer_list[id])
3553 { 3596 {
3597 /* If destroy flag is set it means that this peer should have been
3598 destroyed by a context which we destroy before */
3599 GNUNET_break (GNUNET_NO == peer_list[id]->destroy_flag);
3600 /* counter should be zero as we free all contexts before */
3601 GNUNET_break (0 == peer_list[id]->reference_cnt);
3554 if (GNUNET_NO == peer_list[id]->is_remote) 3602 if (GNUNET_NO == peer_list[id]->is_remote)
3555 { 3603 {
3556 if (GNUNET_YES == peer_list[id]->details.local.is_running) 3604 if (GNUNET_YES == peer_list[id]->details.local.is_running)