From 1c468a36db041ad0c0bb0aaf6750f4a6df30d84a Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Mon, 31 Oct 2011 17:12:30 +0000 Subject: [PATCH] Fixed tree behavior for relay peers, adapted testcase to look for it. --- src/mesh/mesh_tunnel_tree.c | 28 +++++++++++++++++--- src/mesh/test_mesh_path_api.c | 48 +++++++++++++++++++++++++++++++---- 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) 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 @@ tree_add_path (struct MeshTunnelTree *t, 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 @@ tree_add_path (struct MeshTunnelTree *t, 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 @@ tree_add_path (struct MeshTunnelTree *t, 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; 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) { GNUNET_free(pi[i]); } - tree_destroy(tree); exit(0); } @@ -244,7 +243,8 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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; } -- 2.25.1