[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25065 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25065 - gnunet/src/mesh |
Date: |
Tue, 20 Nov 2012 13:01:04 +0100 |
Author: bartpolot
Date: 2012-11-20 13:01:04 +0100 (Tue, 20 Nov 2012)
New Revision: 25065
Modified:
gnunet/src/mesh/mesh_tunnel_tree.c
gnunet/src/mesh/mesh_tunnel_tree.h
Log:
- Add whole-tree iterator, for debugging / monitoring / visualization purposes.
Modified: gnunet/src/mesh/mesh_tunnel_tree.c
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.c 2012-11-20 11:59:20 UTC (rev 25064)
+++ gnunet/src/mesh/mesh_tunnel_tree.c 2012-11-20 12:01:04 UTC (rev 25065)
@@ -583,11 +583,11 @@
*
* @param tree Tree to use. Must have "me" set.
* @param cb Callback to call over each child.
- * @param cls Closure.
+ * @param cb_cls Closure for @c cb.
*/
void
tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
- void *cls)
+ void *cb_cls)
{
struct MeshTunnelTreeNode *n;
@@ -598,12 +598,78 @@
}
for (n = tree->me->children_head; NULL != n; n = n->next)
{
- cb (cls, n->peer);
+ 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);
+ }
+ }
+}
+
+
+/**
* Recusively update the info about what is the first hop to reach the node
*
* @param tree Tree this nodes belongs to.
Modified: gnunet/src/mesh/mesh_tunnel_tree.h
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.h 2012-11-20 11:59:20 UTC (rev 25064)
+++ gnunet/src/mesh/mesh_tunnel_tree.h 2012-11-20 12:01:04 UTC (rev 25065)
@@ -126,15 +126,26 @@
/******************************************************************************/
/**
- * Method called whenever a node has been marked as disconnected.
+ * Iterator over all children of a node.
*
* @param cls Closure.
- * @param peer_id short ID of peer that is no longer reachable.
+ * @param peer_id Short ID of the peer.
*/
typedef void (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id);
/**
+ * Iterator over all nodes in a tree.
+ *
+ * @param cls Closure.
+ * @param peer_id Short ID of the peer.
+ * @param peer_id Short ID of the parent of the peer.
+ */
+typedef void (*MeshWholeTreeCallback) (void *cls,
+ GNUNET_PEER_Id peer_id,
+ GNUNET_PEER_Id parent_id);
+
+/**
* Create a new tunnel tree associated to a tunnel
*
* @param peer A short peer id of the root of the tree
@@ -210,14 +221,30 @@
*
* @param tree Tree to use. Must have "me" set.
* @param cb Callback to call over each child.
- * @param cls Closure.
+ * @param cb_cls Closure for @c cb.
*/
void
-tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
- void *cls);
+tree_iterate_children (struct MeshTunnelTree *tree,
+ MeshTreeCallback cb,
+ void *cb_cls);
/**
+ * 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);
+
+
+/**
* Recusively update the info about what is the first hop to reach the node
*
* @param tree Tree this nodes belongs to.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25065 - gnunet/src/mesh,
gnunet <=