aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-17 14:56:18 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-17 14:56:18 +0000
commit81121a773937eff5908179855adf61232ebc1ce1 (patch)
treee2eb7eafd491475ad4ff58932475faf6666c8df9
parentc5989d817871492bde9ee6df59db98901d4cf317 (diff)
downloadgnunet-81121a773937eff5908179855adf61232ebc1ce1.tar.gz
gnunet-81121a773937eff5908179855adf61232ebc1ce1.zip
- use hashmap instead of DLL
-rw-r--r--src/testbed/testbed_api.c8
-rw-r--r--src/testbed/testbed_api_testbed.c223
2 files changed, 143 insertions, 88 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index c691826f9..e9a70abb3 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -329,10 +329,10 @@ GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c,
329{ 329{
330 if (NULL == c->opc_map) 330 if (NULL == c->opc_map)
331 c->opc_map = GNUNET_CONTAINER_multihashmap32_create (256); 331 c->opc_map = GNUNET_CONTAINER_multihashmap32_create (256);
332 GNUNET_assert (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_contains_value 332 GNUNET_assert (GNUNET_OK ==
333 (c->opc_map, (uint32_t) opc->id, opc)); 333 GNUNET_CONTAINER_multihashmap32_put (c->opc_map,
334 GNUNET_CONTAINER_multihashmap32_put (c->opc_map, (uint32_t) opc->id, opc, 334 (uint32_t) opc->id, opc,
335 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 335 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
336} 336}
337 337
338 338
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index a7134d24e..767d91cb9 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -50,9 +50,9 @@
50#define DEFAULT_SETUP_TIMEOUT 300 50#define DEFAULT_SETUP_TIMEOUT 300
51 51
52/** 52/**
53 * DLL of operations 53 * Context information for the operation we start
54 */ 54 */
55struct DLLOperation 55struct RunContextOperation
56{ 56{
57 /** 57 /**
58 * The testbed operation handle 58 * The testbed operation handle
@@ -69,15 +69,6 @@ struct DLLOperation
69 */ 69 */
70 void *cls; 70 void *cls;
71 71
72 /**
73 * The next pointer for DLL
74 */
75 struct DLLOperation *next;
76
77 /**
78 * The prev pointer for DLL
79 */
80 struct DLLOperation *prev;
81}; 72};
82 73
83 74
@@ -178,14 +169,9 @@ struct RunContext
178 void *test_master_cls; 169 void *test_master_cls;
179 170
180 /** 171 /**
181 * The head element of DLL operations 172 * A hashmap for operations started by us
182 */ 173 */
183 struct DLLOperation *dll_op_head; 174 struct GNUNET_CONTAINER_MultiHashMap32 *rcop_map;
184
185 /**
186 * The tail element of DLL operations
187 */
188 struct DLLOperation *dll_op_tail;
189 175
190 /** 176 /**
191 * An array of hosts loaded from the hostkeys file 177 * An array of hosts loaded from the hostkeys file
@@ -307,6 +293,72 @@ struct RunContext
307 293
308}; 294};
309 295
296static uint32_t
297rcop_key (void *rcop)
298{
299 return * ((uint32_t *) &rcop);
300}
301
302
303struct SearchContext
304{
305 struct GNUNET_TESTBED_Operation *query;
306
307 struct RunContextOperation *result;
308};
309
310static int
311search_iterator (void *cls, uint32_t key, void *value)
312{
313 struct RunContextOperation *rcop = value;
314 struct SearchContext *sc = cls;
315
316 GNUNET_assert (NULL != rcop);
317 if (sc->query == rcop->op)
318 {
319 GNUNET_assert (NULL == sc->result);
320 sc->result = rcop;
321 return GNUNET_NO;
322 }
323 return GNUNET_YES;
324}
325
326static struct RunContextOperation *
327search_rcop (struct RunContext *rc, struct GNUNET_TESTBED_Operation *op)
328{
329 struct SearchContext sc;
330
331 sc.query = op;
332 sc.result = NULL;
333 if (GNUNET_SYSERR ==
334 GNUNET_CONTAINER_multihashmap32_get_multiple (rc->rcop_map,
335 rcop_key (op),
336 &search_iterator,
337 &sc))
338 {
339 GNUNET_assert (NULL != sc.result);
340 return sc.result;
341 }
342 return NULL;
343}
344
345static void
346insert_rcop (struct RunContext *rc, struct RunContextOperation *rcop)
347{
348 GNUNET_assert (GNUNET_OK ==
349 GNUNET_CONTAINER_multihashmap32_put (rc->rcop_map,
350 rcop_key (rcop->op), rcop,
351 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
352}
353
354static void
355remove_rcop (struct RunContext *rc, struct RunContextOperation *rcop)
356{
357 GNUNET_assert (GNUNET_YES ==
358 GNUNET_CONTAINER_multihashmap32_remove (rc->rcop_map,
359 rcop_key (rcop->op),
360 rcop));
361}
310 362
311/** 363/**
312 * Assuming all peers have been destroyed cleanup run handle 364 * Assuming all peers have been destroyed cleanup run handle
@@ -325,7 +377,8 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
325 GNUNET_assert (NULL == rc->peers); 377 GNUNET_assert (NULL == rc->peers);
326 GNUNET_assert (NULL == rc->hc_handles); 378 GNUNET_assert (NULL == rc->hc_handles);
327 GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state); 379 GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state);
328 GNUNET_assert (NULL == rc->dll_op_head); 380 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map));
381 GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map);
329 if (NULL != rc->c) 382 if (NULL != rc->c)
330 GNUNET_TESTBED_controller_disconnect (rc->c); 383 GNUNET_TESTBED_controller_disconnect (rc->c);
331 if (NULL != rc->cproc) 384 if (NULL != rc->cproc)
@@ -342,10 +395,22 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
342 GNUNET_free (rc); 395 GNUNET_free (rc);
343} 396}
344 397
398static int
399rcop_cleanup_iterator (void *cls, uint32_t key, void *value)
400{
401 struct RunContext *rc = cls;
402 struct RunContextOperation *rcop = value;
403
404 GNUNET_assert (rc == rcop->rc);
405 remove_rcop (rc, rcop);
406 GNUNET_TESTBED_operation_done (rcop->op);
407 GNUNET_free (rcop);
408 return GNUNET_YES;
409}
410
345static void 411static void
346cleanup (struct RunContext *rc) 412cleanup (struct RunContext *rc)
347{ 413{
348 struct DLLOperation *dll_op;
349 unsigned int nhost; 414 unsigned int nhost;
350 415
351 if (NULL != rc->hc_handles) 416 if (NULL != rc->hc_handles)
@@ -383,12 +448,10 @@ cleanup (struct RunContext *rc)
383 rc->topology_operation = NULL; 448 rc->topology_operation = NULL;
384 } 449 }
385 /* cancel any exiting operations */ 450 /* cancel any exiting operations */
386 while (NULL != (dll_op = rc->dll_op_head)) 451 GNUNET_assert (GNUNET_SYSERR !=
387 { 452 GNUNET_CONTAINER_multihashmap32_iterate (rc->rcop_map,
388 GNUNET_TESTBED_operation_done (dll_op->op); 453 &rcop_cleanup_iterator,
389 GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); 454 rc));
390 GNUNET_free (dll_op);
391 }
392} 455}
393 456
394 457
@@ -402,7 +465,7 @@ static void
402shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 465shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
403{ 466{
404 struct RunContext *rc = cls; 467 struct RunContext *rc = cls;
405 struct DLLOperation *dll_op; 468 struct RunContextOperation *rcop;
406 469
407 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rc->shutdown_run_task); 470 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rc->shutdown_run_task);
408 rc->shutdown_run_task = GNUNET_SCHEDULER_NO_TASK; 471 rc->shutdown_run_task = GNUNET_SCHEDULER_NO_TASK;
@@ -413,13 +476,13 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
413 { 476 {
414 if (NULL != rc->peers) 477 if (NULL != rc->peers)
415 { 478 {
416 dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); 479 rcop = GNUNET_malloc (sizeof (struct RunContextOperation));
417 dll_op->op = GNUNET_TESTBED_shutdown_peers (rc->c, dll_op, NULL, NULL); 480 rcop->rc = rc;
418 GNUNET_assert (NULL != dll_op->op); 481 rcop->op = GNUNET_TESTBED_shutdown_peers (rc->c, rcop, NULL, NULL);
482 GNUNET_assert (NULL != rcop->op);
419 DEBUG ("Shutting down peers\n"); 483 DEBUG ("Shutting down peers\n");
420 rc->pstart_time = GNUNET_TIME_absolute_get (); 484 rc->pstart_time = GNUNET_TIME_absolute_get ();
421 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, 485 insert_rcop (rc, rcop);
422 dll_op);
423 return; 486 return;
424 } 487 }
425 } 488 }
@@ -483,18 +546,19 @@ static void
483start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 546start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
484{ 547{
485 struct RunContext *rc = cls; 548 struct RunContext *rc = cls;
486 struct DLLOperation *dll_op; 549 struct RunContextOperation *rcop;
487 unsigned int peer; 550 unsigned int peer;
488 551
489 DEBUG ("Starting Peers\n"); 552 DEBUG ("Starting Peers\n");
490 rc->pstart_time = GNUNET_TIME_absolute_get (); 553 rc->pstart_time = GNUNET_TIME_absolute_get ();
491 for (peer = 0; peer < rc->num_peers; peer++) 554 for (peer = 0; peer < rc->num_peers; peer++)
492 { 555 {
493 dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); 556 rcop = GNUNET_malloc (sizeof (struct RunContextOperation));
494 dll_op->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL); 557 rcop->rc = rc;
495 GNUNET_assert (NULL != dll_op->op); 558 rcop->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL);
496 dll_op->cls = rc->peers[peer]; 559 GNUNET_assert (NULL != rcop->op);
497 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op); 560 rcop->cls = rc->peers[peer];
561 insert_rcop (rc, rcop);
498 } 562 }
499 rc->peer_count = 0; 563 rc->peer_count = 0;
500} 564}
@@ -512,15 +576,14 @@ start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
512static void 576static void
513peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 577peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
514{ 578{
515 struct DLLOperation *dll_op = cls; 579 struct RunContextOperation *rcop = cls;
516 struct RunContext *rc; 580 struct RunContext *rc;
517 581
518 GNUNET_assert (NULL != dll_op); 582 GNUNET_assert (NULL != rcop);
519 rc = dll_op->rc; 583 GNUNET_assert (NULL != (rc = rcop->rc));
520 GNUNET_assert (NULL != rc); 584 remove_rcop (rc, rcop);
521 GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); 585 GNUNET_TESTBED_operation_done (rcop->op);
522 GNUNET_TESTBED_operation_done (dll_op->op); 586 GNUNET_free (rcop);
523 GNUNET_free (dll_op);
524 if (NULL == peer) 587 if (NULL == peer)
525 { 588 {
526 if (NULL != emsg) 589 if (NULL != emsg)
@@ -588,7 +651,7 @@ topology_completion_callback (void *cls, unsigned int nsuccess,
588static void 651static void
589create_peers (struct RunContext *rc) 652create_peers (struct RunContext *rc)
590{ 653{
591 struct DLLOperation *dll_op; 654 struct RunContextOperation *rcop;
592 unsigned int peer; 655 unsigned int peer;
593 656
594 DEBUG ("Creating peers\n"); 657 DEBUG ("Creating peers\n");
@@ -599,16 +662,16 @@ create_peers (struct RunContext *rc)
599 rc->peer_count = 0; 662 rc->peer_count = 0;
600 for (peer = 0; peer < rc->num_peers; peer++) 663 for (peer = 0; peer < rc->num_peers; peer++)
601 { 664 {
602 dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); 665 rcop = GNUNET_malloc (sizeof (struct RunContextOperation));
603 dll_op->rc = rc; 666 rcop->rc = rc;
604 dll_op->op = 667 rcop->op =
605 GNUNET_TESTBED_peer_create (rc->c, 668 GNUNET_TESTBED_peer_create (rc->c,
606 (0 == 669 (0 ==
607 rc->num_hosts) ? rc->h : rc->hosts[peer % 670 rc->num_hosts) ? rc->h : rc->hosts[peer %
608 rc->num_hosts], 671 rc->num_hosts],
609 rc->cfg, peer_create_cb, dll_op); 672 rc->cfg, &peer_create_cb, rcop);
610 GNUNET_assert (NULL != dll_op->op); 673 GNUNET_assert (NULL != rcop->op);
611 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op); 674 insert_rcop (rc, rcop);
612 } 675 }
613} 676}
614 677
@@ -624,14 +687,14 @@ static void
624event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) 687event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
625{ 688{
626 struct RunContext *rc = cls; 689 struct RunContext *rc = cls;
627 struct DLLOperation *dll_op; 690 struct RunContextOperation *rcop;
628 691
629 if (RC_INIT == rc->state) 692 if (RC_INIT == rc->state)
630 { 693 {
631 switch (event->type) 694 switch (event->type)
632 { 695 {
633 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 696 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
634 dll_op = event->op_cls; 697 rcop = event->op_cls;
635 if (NULL != event->details.operation_finished.emsg) 698 if (NULL != event->details.operation_finished.emsg)
636 { 699 {
637 LOG (GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting")); 700 LOG (GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting"));
@@ -639,10 +702,10 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
639 } 702 }
640 else 703 else
641 rc->reg_hosts++; 704 rc->reg_hosts++;
642 GNUNET_assert (event->op == dll_op->op); 705 GNUNET_assert (event->op == rcop->op);
643 GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); 706 remove_rcop (rc, rcop);
644 GNUNET_TESTBED_operation_done (dll_op->op); 707 GNUNET_TESTBED_operation_done (rcop->op);
645 GNUNET_free (dll_op); 708 GNUNET_free (rcop);
646 if (rc->reg_hosts == rc->num_hosts) 709 if (rc->reg_hosts == rc->num_hosts)
647 { 710 {
648 rc->state = RC_LINKED; 711 rc->state = RC_LINKED;
@@ -655,17 +718,13 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
655 return; 718 return;
656 } 719 }
657 } 720 }
658 for (dll_op = rc->dll_op_head; NULL != dll_op; dll_op = dll_op->next) 721 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
659 { 722 goto call_cc;
660 if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && 723 if (NULL == (rcop = search_rcop (rc, event->op)))
661 (event->op == dll_op->op))
662 break;
663 }
664 if (NULL == dll_op)
665 goto call_cc; 724 goto call_cc;
666 GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); 725 remove_rcop (rc, rcop);
667 GNUNET_TESTBED_operation_done (dll_op->op); 726 GNUNET_TESTBED_operation_done (rcop->op);
668 GNUNET_free (dll_op); 727 GNUNET_free (rcop);
669 if ( (GNUNET_NO == rc->shutdown) 728 if ( (GNUNET_NO == rc->shutdown)
670 && (NULL != event->details.operation_finished.emsg) ) 729 && (NULL != event->details.operation_finished.emsg) )
671 { 730 {
@@ -696,15 +755,11 @@ call_cc:
696 rc->cc (rc->cc_cls, event); 755 rc->cc (rc->cc_cls, event);
697 if (GNUNET_TESTBED_ET_PEER_START != event->type) 756 if (GNUNET_TESTBED_ET_PEER_START != event->type)
698 return; 757 return;
699 for (dll_op = rc->dll_op_head; NULL != dll_op; dll_op = dll_op->next) 758 if (NULL == (rcop = search_rcop (rc, event->op))) /* Not our operation */
700 if ((NULL != dll_op->cls) &&
701 (event->details.peer_start.peer == dll_op->cls))
702 break;
703 if (NULL == dll_op) /* Not our operation */
704 return; 759 return;
705 GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); 760 remove_rcop (rc, rcop);
706 GNUNET_TESTBED_operation_done (dll_op->op); 761 GNUNET_TESTBED_operation_done (rcop->op);
707 GNUNET_free (dll_op); 762 GNUNET_free (rcop);
708 rc->peer_count++; 763 rc->peer_count++;
709 if (rc->peer_count < rc->num_peers) 764 if (rc->peer_count < rc->num_peers)
710 return; 765 return;
@@ -802,7 +857,7 @@ static void
802register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 857register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
803{ 858{
804 struct RunContext *rc = cls; 859 struct RunContext *rc = cls;
805 struct DLLOperation *dll_op; 860 struct RunContextOperation *rcop;
806 unsigned int slave; 861 unsigned int slave;
807 862
808 rc->register_hosts_task = GNUNET_SCHEDULER_NO_TASK; 863 rc->register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
@@ -812,14 +867,13 @@ register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
812 /* Start slaves */ 867 /* Start slaves */
813 for (slave = 0; slave < rc->num_hosts; slave++) 868 for (slave = 0; slave < rc->num_hosts; slave++)
814 { 869 {
815 dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); 870 rcop = GNUNET_malloc (sizeof (struct RunContextOperation));
816 dll_op->rc = rc; 871 rcop->rc = rc;
817 dll_op->op = 872 rcop->op =
818 GNUNET_TESTBED_controller_link (dll_op, rc->c, rc->hosts[slave], 873 GNUNET_TESTBED_controller_link (rcop, rc->c, rc->hosts[slave],
819 rc->h, rc->cfg, GNUNET_YES); 874 rc->h, rc->cfg, GNUNET_YES);
820 GNUNET_assert (NULL != dll_op->op); 875 GNUNET_assert (NULL != rcop->op);
821 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, 876 insert_rcop (rc, rcop);
822 dll_op);
823 } 877 }
824 rc->reg_hosts = 0; 878 rc->reg_hosts = 0;
825 return; 879 return;
@@ -1184,6 +1238,7 @@ GNUNET_TESTBED_run (const char *host_filename,
1184 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1238 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1185 DEFAULT_SETUP_TIMEOUT); 1239 DEFAULT_SETUP_TIMEOUT);
1186 } 1240 }
1241 rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256);
1187 rc->timeout_task = 1242 rc->timeout_task =
1188 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc); 1243 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
1189 rc->interrupt_task = 1244 rc->interrupt_task =