aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-31 17:12:30 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-31 17:12:30 +0000
commit1c468a36db041ad0c0bb0aaf6750f4a6df30d84a (patch)
tree4639623eebae2fe185826b36263a4a425072ca14 /src/mesh
parenta38370ae1e835d9ad452788ad1fc6424926fe31c (diff)
downloadgnunet-1c468a36db041ad0c0bb0aaf6750f4a6df30d84a.tar.gz
gnunet-1c468a36db041ad0c0bb0aaf6750f4a6df30d84a.zip
Fixed tree behavior for relay peers, adapted testcase to look for it.
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_tunnel_tree.c28
-rw-r--r--src/mesh/test_mesh_path_api.c48
2 files changed, 68 insertions, 8 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index 50f6dc5c7..d052a3c4d 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -108,7 +108,25 @@ path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
108 108
109 GNUNET_PEER_resolve (peer, &id); 109 GNUNET_PEER_resolve (peer, &id);
110 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey); 110 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
111 GNUNET_break (NULL != r); 111 if (NULL == r)
112 {
113 struct MeshTunnelTreeNode *n;
114
115 n = tree_find_peer(t->root, peer);
116 if (NULL != t->me && NULL != n)
117 {
118 tree_update_first_hops(t, n, NULL);
119 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
120 GNUNET_assert (NULL != r);
121 }
122 else
123 {
124 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
125 "Tree structure inconsistent! me: %p, n: %p",
126 t->me, n);
127 GNUNET_break (0);
128 }
129 }
112 130
113 return r; 131 return r;
114} 132}
@@ -570,7 +588,6 @@ tree_add_path (struct MeshTunnelTree *t,
570 struct GNUNET_PeerIdentity id; 588 struct GNUNET_PeerIdentity id;
571 GNUNET_PEER_Id myid; 589 GNUNET_PEER_Id myid;
572 int me; 590 int me;
573// int oldnode_is_me;
574 unsigned int i; 591 unsigned int i;
575 592
576#if MESH_TREE_DEBUG 593#if MESH_TREE_DEBUG
@@ -640,9 +657,12 @@ tree_add_path (struct MeshTunnelTree *t,
640 while (i < p->length) 657 while (i < p->length)
641 { 658 {
642#if MESH_TREE_DEBUG 659#if MESH_TREE_DEBUG
660 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
661 "tree: Adding peer %u to %u.\n",
662 p->peers[i], parent->peer);
643 GNUNET_PEER_resolve(p->peers[i], &id); 663 GNUNET_PEER_resolve(p->peers[i], &id);
644 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 664 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
645 "tree: Adding peer %s.\n", 665 "tree: Adding peer %s.\n",
646 GNUNET_i2s (&id)); 666 GNUNET_i2s (&id));
647 GNUNET_PEER_resolve(parent->peer, &id); 667 GNUNET_PEER_resolve(parent->peer, &id);
648 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 668 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -671,6 +691,8 @@ tree_add_path (struct MeshTunnelTree *t,
671 n = tree_node_new(parent, p->peers[i]); 691 n = tree_node_new(parent, p->peers[i]);
672 n->t = t->t; 692 n->t = t->t;
673 n->status = MESH_PEER_RELAY; 693 n->status = MESH_PEER_RELAY;
694 if (n->peer == myid)
695 t->me = n;
674 } 696 }
675 i++; 697 i++;
676 parent = n; 698 parent = n;
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c
index eb3ce57db..e7c2a6fdf 100644
--- a/src/mesh/test_mesh_path_api.c
+++ b/src/mesh/test_mesh_path_api.c
@@ -125,7 +125,6 @@ finish(void)
125 { 125 {
126 GNUNET_free(pi[i]); 126 GNUNET_free(pi[i]);
127 } 127 }
128 tree_destroy(tree);
129 exit(0); 128 exit(0);
130} 129}
131 130
@@ -244,7 +243,8 @@ main (int argc, char *argv[])
244 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); 243 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
245 GNUNET_free (node2); 244 GNUNET_free (node2);
246 245
247 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding new shorter first path...\n"); 246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
247 "test: Adding new shorter first path...\n");
248 path->length = 2; 248 path->length = 2;
249 path->peers[1] = 4; 249 path->peers[1] = 4;
250 cb_call = 1; 250 cb_call = 1;
@@ -262,15 +262,53 @@ main (int argc, char *argv[])
262 test_assert (2, MESH_PEER_RELAY, 1, 0); 262 test_assert (2, MESH_PEER_RELAY, 1, 0);
263 test_assert (1, MESH_PEER_ROOT, 2, 0); 263 test_assert (1, MESH_PEER_ROOT, 2, 0);
264 264
265 GNUNET_free (path->peers);
266 GNUNET_free (path);
267 tree_destroy (tree);
268
269 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test:\n");
270 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n");
271 for (i = 0; i < 10; i++)
272 {
273 pi[i] = get_pi(i);
274 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i]));
275 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n",
276 i + 1,
277 GNUNET_h2s(&pi[i]->hashPubKey));
278 }
279 tree = GNUNET_malloc(sizeof(struct MeshTunnelTree));
280 tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
281 tree->root = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
282 tree->root->peer = 1;
283 path = path_new (3);
284 path->peers[0] = 1;
285 path->peers[1] = 2;
286 path->peers[2] = 3;
287 path->length = 3;
288
289 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
290 tree_add_path(tree, path, &cb);
291 tree_debug(tree);
292 tree->me = tree_find_peer (tree->root, 2);
293
294 test_assert (3, MESH_PEER_SEARCHING, 0, 3);
295 test_assert (2, MESH_PEER_RELAY, 1, 0);
296 test_assert (1, MESH_PEER_ROOT, 1, 0);
297
298 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
299 tree_add_path(tree, path, &cb);
300
301 GNUNET_free (path->peers);
302 GNUNET_free (path);
303 tree_destroy (tree);
304
265 if (failed > 0) 305 if (failed > 0)
266 { 306 {
267 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); 307 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);
268 return 1; 308 return 1;
269 } 309 }
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n"); 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n");
271 GNUNET_free (path->peers);
272 GNUNET_free (path);
273 finish(); 311 finish();
274 312
275 return 0; 313 return 0;
276} 314}