diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-11-20 12:01:04 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-11-20 12:01:04 +0000 |
commit | afd56af75f0a16ee5b8ab7777871294931ca265c (patch) | |
tree | 3822744a61f09b586bc8853570f8d20b842b2230 /src/mesh/mesh_tunnel_tree.c | |
parent | aba63e824e9867baad05307d7efbdf453e38626b (diff) | |
download | gnunet-afd56af75f0a16ee5b8ab7777871294931ca265c.tar.gz gnunet-afd56af75f0a16ee5b8ab7777871294931ca265c.zip |
- Add whole-tree iterator, for debugging / monitoring / visualization purposes.
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.c')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index b57f9410f..21b07616c 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -583,11 +583,11 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | |||
583 | * | 583 | * |
584 | * @param tree Tree to use. Must have "me" set. | 584 | * @param tree Tree to use. Must have "me" set. |
585 | * @param cb Callback to call over each child. | 585 | * @param cb Callback to call over each child. |
586 | * @param cls Closure. | 586 | * @param cb_cls Closure for @c cb. |
587 | */ | 587 | */ |
588 | void | 588 | void |
589 | tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb, | 589 | tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb, |
590 | void *cls) | 590 | void *cb_cls) |
591 | { | 591 | { |
592 | struct MeshTunnelTreeNode *n; | 592 | struct MeshTunnelTreeNode *n; |
593 | 593 | ||
@@ -598,7 +598,73 @@ tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb, | |||
598 | } | 598 | } |
599 | for (n = tree->me->children_head; NULL != n; n = n->next) | 599 | for (n = tree->me->children_head; NULL != n; n = n->next) |
600 | { | 600 | { |
601 | cb (cls, n->peer); | 601 | cb (cb_cls, n->peer); |
602 | } | ||
603 | } | ||
604 | |||
605 | |||
606 | /** | ||
607 | * Struct to contain a list of pending nodes when iterating a tree. | ||
608 | */ | ||
609 | struct MeshTreePendingNode { | ||
610 | |||
611 | /** | ||
612 | * DLL next. | ||
613 | */ | ||
614 | struct MeshTreePendingNode *next; | ||
615 | |||
616 | /** | ||
617 | * DLL prev. | ||
618 | */ | ||
619 | struct MeshTreePendingNode *prev; | ||
620 | |||
621 | /** | ||
622 | * Pending node. | ||
623 | */ | ||
624 | struct MeshTunnelTreeNode *node; | ||
625 | }; | ||
626 | |||
627 | |||
628 | /** | ||
629 | * Iterate over all nodes in the tree. | ||
630 | * | ||
631 | * @param tree Tree to use.. | ||
632 | * @param cb Callback to call over each child. | ||
633 | * @param cb_cls Closure for @c cb. | ||
634 | * | ||
635 | * TODO: recursive implementation? (s/heap/stack/g) | ||
636 | */ | ||
637 | void | ||
638 | tree_iterate_all (struct MeshTunnelTree *tree, | ||
639 | MeshWholeTreeCallback cb, | ||
640 | void *cb_cls) | ||
641 | { | ||
642 | struct MeshTunnelTreeNode *parent; | ||
643 | struct MeshTunnelTreeNode *n; | ||
644 | struct MeshTreePendingNode *head; | ||
645 | struct MeshTreePendingNode *tail; | ||
646 | struct MeshTreePendingNode *pending; | ||
647 | |||
648 | cb (cb_cls, tree->root->peer, 0); | ||
649 | pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode)); | ||
650 | pending->node = tree->root; | ||
651 | head = tail = NULL; | ||
652 | GNUNET_CONTAINER_DLL_insert (head, tail, pending); | ||
653 | |||
654 | while (NULL != head) | ||
655 | { | ||
656 | pending = head; | ||
657 | parent = pending->node; | ||
658 | GNUNET_CONTAINER_DLL_remove (head, tail, pending); | ||
659 | GNUNET_free (pending); | ||
660 | for (n = parent->children_head; NULL != n; n = n->next) | ||
661 | { | ||
662 | cb (cb_cls, n->peer, parent->peer); | ||
663 | pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode)); | ||
664 | pending->node = n; | ||
665 | /* Insert_tail: breadth first, Insert: depth first */ | ||
666 | GNUNET_CONTAINER_DLL_insert (head, tail, pending); | ||
667 | } | ||
602 | } | 668 | } |
603 | } | 669 | } |
604 | 670 | ||