gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17883 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r17883 - gnunet/src/mesh
Date: Mon, 31 Oct 2011 18:12:30 +0100

Author: bartpolot
Date: 2011-10-31 18:12:30 +0100 (Mon, 31 Oct 2011)
New Revision: 17883

Modified:
   gnunet/src/mesh/mesh_tunnel_tree.c
   gnunet/src/mesh/test_mesh_path_api.c
Log:
Fixed tree behavior for relay peers, adapted testcase to look for it.

Modified: gnunet/src/mesh/mesh_tunnel_tree.c
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.c  2011-10-31 16:27:32 UTC (rev 17882)
+++ gnunet/src/mesh/mesh_tunnel_tree.c  2011-10-31 17:12:30 UTC (rev 17883)
@@ -108,8 +108,26 @@
 
   GNUNET_PEER_resolve (peer, &id);
   r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
-  GNUNET_break (NULL != r);
+  if (NULL == r)
+  {
+    struct MeshTunnelTreeNode *n;
 
+    n = tree_find_peer(t->root, peer);
+    if (NULL != t->me && NULL != n)
+    {
+      tree_update_first_hops(t, n, NULL);
+      r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
+      GNUNET_assert (NULL != r);
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Tree structure inconsistent! me: %p, n: %p",
+                  t->me, n);
+      GNUNET_break (0);
+    }
+  }
+
   return r;
 }
 
@@ -570,7 +588,6 @@
   struct GNUNET_PeerIdentity id;
   GNUNET_PEER_Id myid;
   int me;
-//   int oldnode_is_me;
   unsigned int i;
 
 #if MESH_TREE_DEBUG
@@ -640,9 +657,12 @@
   while (i < p->length)
   {
 #if MESH_TREE_DEBUG
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "tree:   Adding peer %u to %u.\n",
+               p->peers[i], parent->peer);
     GNUNET_PEER_resolve(p->peers[i], &id);
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "tree:   Adding  peer %s.\n",
+               "tree:   Adding peer %s.\n",
                GNUNET_i2s (&id));
     GNUNET_PEER_resolve(parent->peer, &id);
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -671,6 +691,8 @@
       n = tree_node_new(parent, p->peers[i]);
       n->t = t->t;
       n->status = MESH_PEER_RELAY;
+      if (n->peer == myid)
+        t->me = n;
     }
     i++;
     parent = n;

Modified: gnunet/src/mesh/test_mesh_path_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_path_api.c        2011-10-31 16:27:32 UTC (rev 
17882)
+++ gnunet/src/mesh/test_mesh_path_api.c        2011-10-31 17:12:30 UTC (rev 
17883)
@@ -125,7 +125,6 @@
   {
     GNUNET_free(pi[i]);
   }
-  tree_destroy(tree);
   exit(0);
 }
 
@@ -244,7 +243,8 @@
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
   GNUNET_free (node2);
 
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding new shorter first 
path...\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "test: Adding new shorter first path...\n");
   path->length = 2;
   path->peers[1] = 4;
   cb_call = 1;
@@ -262,15 +262,53 @@
   test_assert (2, MESH_PEER_RELAY, 1, 0);
   test_assert (1, MESH_PEER_ROOT, 2, 0);
 
+  GNUNET_free (path->peers);
+  GNUNET_free (path);
+  tree_destroy (tree);
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test:\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n");
+  for (i = 0; i < 10; i++)
+  {
+      pi[i] = get_pi(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));
+  tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
+  tree->root = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
+  tree->root->peer = 1;
+  path = path_new (3);
+  path->peers[0] = 1;
+  path->peers[1] = 2;
+  path->peers[2] = 3;
+  path->length = 3;
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
+  tree_add_path(tree, path, &cb);
+  tree_debug(tree);
+  tree->me = tree_find_peer (tree->root, 2);
+
+  test_assert (3, MESH_PEER_SEARCHING, 0, 3);
+  test_assert (2, MESH_PEER_RELAY, 1, 0);
+  test_assert (1, MESH_PEER_ROOT, 1, 0);
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
+  tree_add_path(tree, path, &cb);
+  
+  GNUNET_free (path->peers);
+  GNUNET_free (path);
+  tree_destroy (tree);
+
   if (failed > 0)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);
     return 1;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n");
-  GNUNET_free (path->peers);
-  GNUNET_free (path);
   finish();
-
+  
   return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]