Fixed testcase and small bugs in tree
authorBart Polot <bart@net.in.tum.de>
Thu, 27 Oct 2011 20:28:29 +0000 (20:28 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 27 Oct 2011 20:28:29 +0000 (20:28 +0000)
src/mesh/mesh_tunnel_tree.c
src/mesh/test_mesh_path_api.c

index a80cbb0c07d5763d11cbee32a7ad1194352b3a12..c58260601caf4e66bd373bb29ae4e0fcf37f4f7b 100644 (file)
@@ -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);
index 9a983f29829febad10d8bd67be78d2743fe140ca..58bc6bd20a0eed024bdd8de293c572df92fc2ed5 100644 (file)
@@ -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;