summaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-27 20:28:29 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-27 20:28:29 +0000
commit83a2993fd05ff8bff76b7aaf36a61a86983713db (patch)
tree549d6a8f81d49c4df3a2f2f64f7171b142d31ba4 /src/mesh
parentf8acae3eb63f3cd32650f31a2da4b9fdf903f756 (diff)
Fixed testcase and small bugs in tree
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_tunnel_tree.c34
-rw-r--r--src/mesh/test_mesh_path_api.c10
2 files changed, 32 insertions, 12 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index a80cbb0c0..c58260601 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -200,6 +200,7 @@ static void
tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level)
{
struct MeshTunnelTreeNode *c;
+ struct GNUNET_PeerIdentity id;;
uint16_t i;
for (i = 0; i < level; i++)
@@ -213,9 +214,13 @@ tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level)
if (n->status == MESH_PEER_RECONNECTING)
fprintf(stderr, "*");
- fprintf(stderr, "%u [%p] ", n->peer, n);
+ GNUNET_PEER_resolve(n->peer, &id);
+ fprintf(stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n);
if (NULL != n->parent)
- fprintf(stderr, "(-> %u)\n", n->parent->peer);
+ {
+ GNUNET_PEER_resolve(n->parent->peer, &id);
+ fprintf(stderr, "(-> %s [%u])\n", GNUNET_i2s(&id), n->parent->peer);
+ }
else
fprintf(stderr, "(root)\n");
for (c = n->children_head; NULL != c; c = c->next)
@@ -233,7 +238,17 @@ tree_node_destroy (struct MeshTunnelTreeNode *parent)
{
struct MeshTunnelTreeNode *n;
struct MeshTunnelTreeNode *next;
+#if MESH_TREE_DEBUG
+ struct GNUNET_PeerIdentity id;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tree: Destroying node %u\n",
+ parent->peer);
+ GNUNET_PEER_resolve (parent->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tree: (%s)\n",
+ GNUNET_i2s (&id));
+#endif
n = parent->children_head;
while (NULL != n)
{
@@ -321,11 +336,12 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
{
tree_mark_peers_disconnected (tree, n, cb);
}
- if (MESH_PEER_READY == parent->status && NULL != cb)
+ if (MESH_PEER_READY == parent->status)
{
- cb (parent);
+ if (NULL != cb)
+ cb (parent);
+ parent->status = MESH_PEER_RECONNECTING;
}
- parent->status = MESH_PEER_RECONNECTING;
/* Remove and free info about first hop */
GNUNET_PEER_resolve(parent->peer, &id);
@@ -416,8 +432,9 @@ tree_update_first_hops (struct MeshTunnelTree *tree,
* NULL when not found
*/
struct MeshTunnelTreeNode *
-tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
- MeshNodeDisconnectCB cb)
+tree_del_path (struct MeshTunnelTree *t,
+ GNUNET_PEER_Id peer_id,
+ MeshNodeDisconnectCB cb)
{
struct MeshTunnelTreeNode *parent;
struct MeshTunnelTreeNode *node;
@@ -797,6 +814,9 @@ iterate_free (void *cls, const GNUNET_HashCode * key, void *value)
void
tree_destroy (struct MeshTunnelTree *t)
{
+#if MESH_TREE_DEBUG
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n");
+#endif
tree_node_destroy(t->root);
GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL);
GNUNET_CONTAINER_multihashmap_destroy(t->first_hops);
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c
index 9a983f298..58bc6bd20 100644
--- a/src/mesh/test_mesh_path_api.c
+++ b/src/mesh/test_mesh_path_api.c
@@ -101,8 +101,9 @@ main (int argc, char *argv[])
for (i = 0; i < 10; i++)
{
pi[i] = get_pi(i);
- GNUNET_break (i != GNUNET_PEER_intern(pi[i]));
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i,
+ GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i]));
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n",
+ i + 1,
GNUNET_h2s(&pi[i]->hashPubKey));
}
tree = GNUNET_malloc(sizeof(struct MeshTunnelTree));
@@ -188,7 +189,6 @@ main (int argc, char *argv[])
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
path->length--;
- tree_debug(tree);
tree_add_path(tree, path, &cb);
tree_debug(tree);
@@ -377,7 +377,7 @@ main (int argc, char *argv[])
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
failed++;
}
- if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
+ if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 2)
{
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
failed++;
@@ -395,7 +395,7 @@ main (int argc, char *argv[])
return 1;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n");
- path_destroy(path);
+ GNUNET_free (path);
finish();
return 0;