+ cb (cb_cls, n->peer);
+ }
+}
+
+
+/**
+ * Struct to contain a list of pending nodes when iterating a tree.
+ */
+struct MeshTreePendingNode {
+
+ /**
+ * DLL next.
+ */
+ struct MeshTreePendingNode *next;
+
+ /**
+ * DLL prev.
+ */
+ struct MeshTreePendingNode *prev;
+
+ /**
+ * Pending node.
+ */
+ struct MeshTunnelTreeNode *node;
+};
+
+
+/**
+ * Iterate over all nodes in the tree.
+ *
+ * @param tree Tree to use..
+ * @param cb Callback to call over each child.
+ * @param cb_cls Closure for @c cb.
+ *
+ * TODO: recursive implementation? (s/heap/stack/g)
+ */
+void
+tree_iterate_all (struct MeshTunnelTree *tree,
+ MeshWholeTreeCallback cb,
+ void *cb_cls)
+{
+ struct MeshTunnelTreeNode *parent;
+ struct MeshTunnelTreeNode *n;
+ struct MeshTreePendingNode *head;
+ struct MeshTreePendingNode *tail;
+ struct MeshTreePendingNode *pending;
+
+ cb (cb_cls, tree->root->peer, 0);
+ pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode));
+ pending->node = tree->root;
+ head = tail = NULL;
+ GNUNET_CONTAINER_DLL_insert (head, tail, pending);
+
+ while (NULL != head)
+ {
+ pending = head;
+ parent = pending->node;
+ GNUNET_CONTAINER_DLL_remove (head, tail, pending);
+ GNUNET_free (pending);
+ for (n = parent->children_head; NULL != n; n = n->next)
+ {
+ cb (cb_cls, n->peer, parent->peer);
+ pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode));
+ pending->node = n;
+ /* Insert_tail: breadth first, Insert: depth first */
+ GNUNET_CONTAINER_DLL_insert (head, tail, pending);
+ }