diff options
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 72 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.h | 37 |
2 files changed, 101 insertions, 8 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 | ||
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index 84fd0acb2..b1d89d6ff 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h | |||
@@ -126,15 +126,26 @@ path_destroy (struct MeshPeerPath *p); | |||
126 | /******************************************************************************/ | 126 | /******************************************************************************/ |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Method called whenever a node has been marked as disconnected. | 129 | * Iterator over all children of a node. |
130 | * | 130 | * |
131 | * @param cls Closure. | 131 | * @param cls Closure. |
132 | * @param peer_id short ID of peer that is no longer reachable. | 132 | * @param peer_id Short ID of the peer. |
133 | */ | 133 | */ |
134 | typedef void (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id); | 134 | typedef void (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id); |
135 | 135 | ||
136 | 136 | ||
137 | /** | 137 | /** |
138 | * Iterator over all nodes in a tree. | ||
139 | * | ||
140 | * @param cls Closure. | ||
141 | * @param peer_id Short ID of the peer. | ||
142 | * @param peer_id Short ID of the parent of the peer. | ||
143 | */ | ||
144 | typedef void (*MeshWholeTreeCallback) (void *cls, | ||
145 | GNUNET_PEER_Id peer_id, | ||
146 | GNUNET_PEER_Id parent_id); | ||
147 | |||
148 | /** | ||
138 | * Create a new tunnel tree associated to a tunnel | 149 | * Create a new tunnel tree associated to a tunnel |
139 | * | 150 | * |
140 | * @param peer A short peer id of the root of the tree | 151 | * @param peer A short peer id of the root of the tree |
@@ -210,11 +221,27 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id); | |||
210 | * | 221 | * |
211 | * @param tree Tree to use. Must have "me" set. | 222 | * @param tree Tree to use. Must have "me" set. |
212 | * @param cb Callback to call over each child. | 223 | * @param cb Callback to call over each child. |
213 | * @param cls Closure. | 224 | * @param cb_cls Closure for @c cb. |
225 | */ | ||
226 | void | ||
227 | tree_iterate_children (struct MeshTunnelTree *tree, | ||
228 | MeshTreeCallback cb, | ||
229 | void *cb_cls); | ||
230 | |||
231 | |||
232 | /** | ||
233 | * Iterate over all nodes in the tree. | ||
234 | * | ||
235 | * @param tree Tree to use.. | ||
236 | * @param cb Callback to call over each child. | ||
237 | * @param cb_cls Closure for @c cb. | ||
238 | * | ||
239 | * TODO: recursive implementation? (s/heap/stack/g) | ||
214 | */ | 240 | */ |
215 | void | 241 | void |
216 | tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb, | 242 | tree_iterate_all (struct MeshTunnelTree *tree, |
217 | void *cls); | 243 | MeshWholeTreeCallback cb, |
244 | void *cb_cls); | ||
218 | 245 | ||
219 | 246 | ||
220 | /** | 247 | /** |