From ac4befb8c44d653f60924a088f5c6ffd671e13f6 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Tue, 11 Oct 2011 17:22:27 +0000 Subject: [PATCH] Fixes in path creation --- src/mesh/gnunet-service-mesh.c | 41 +++++++++++++--------------------- src/mesh/mesh_tunnel_tree.c | 20 +++++++---------- src/mesh/test_mesh_small.conf | 4 ++-- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 3806e5f8f..dfec4157f 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -1235,12 +1235,14 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, } } #if MESH_DEBUG - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: (first of GET: %s)\n", - GNUNET_h2s_full(&get_path[0].hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: (first of PUT: %s)\n", - GNUNET_h2s_full(&put_path[0].hashPubKey)); + if (get_path_length > 0) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "MESH: (first of GET: %s)\n", + GNUNET_h2s_full(&get_path[0].hashPubKey)); + if (put_path_length > 0) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "MESH: (first of PUT: %s)\n", + GNUNET_h2s_full(&put_path[0].hashPubKey)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: In total: %d hops\n", p->length); @@ -1412,8 +1414,6 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) * Add a path to a tunnel which we don't own, just to remember the next hop. * If destination node was already in the tunnel, the first hop information * will be replaced with the new path. - * The local node shouldn't be the first or last node in the path, just an - * intermediate hop. * * @param t Tunnel we want to add a new peer to * @param p Path to add @@ -1425,20 +1425,8 @@ tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p, unsigned int own_pos) { - struct GNUNET_PeerIdentity id; - struct GNUNET_PeerIdentity *hop; - - GNUNET_assert (own_pos < p->length - 1); - hop = GNUNET_CONTAINER_multihashmap_get (t->tree->first_hops, &id.hashPubKey); - if (NULL == hop) - hop = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)); - GNUNET_PEER_resolve(p->peers[own_pos + 1], hop); - GNUNET_PEER_resolve(p->peers[p->length - 1], &id); - GNUNET_CONTAINER_multihashmap_put( - t->tree->first_hops, - &id.hashPubKey, - hop, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + GNUNET_assert (0 != own_pos); + tree_add_path(t->tree, p, NULL); } @@ -1963,6 +1951,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, /* FIXME error. destroy tunnel? leave for timeout? */ return 0; } + tunnel_add_path (t, path, own_pos); + t->tree->me = tree_find_peer(t->tree->root, myid); if (own_pos == size - 1) { /* It is for us! Send ack. */ @@ -1972,7 +1962,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n"); - path_add_to_origin (orig_peer_info, path); /* inverts path! */ + path_add_to_origin (orig_peer_info, path); info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); info->origin = &t->id; info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); @@ -1986,6 +1976,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, } } info->handler_n = j; + info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK; + info->peer->infos[j] = info; info->peer->core_transmit[j] = GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100, GNUNET_TIME_UNIT_FOREVER_REL, peer, @@ -2001,12 +1993,11 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, { struct MeshPeerPath *path2; - path2 = path_duplicate(path); /* It's for somebody else! Retransmit. */ + path2 = path_duplicate(path); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting.\n"); path_add_to_peer(dest_peer_info, path); - tunnel_add_path (t, path, own_pos); path = path_duplicate(path2); path_add_to_origin(orig_peer_info, path2); send_create_path(dest_peer_info, path, t); diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index cea028670..7ad5bfbd7 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c @@ -313,7 +313,7 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, { tree_mark_peers_disconnected (tree, n, cb); } - if (MESH_PEER_READY == parent->status) + if (MESH_PEER_READY == parent->status && NULL != cb) { cb (parent); } @@ -420,7 +420,7 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, return n; } } - n = tree_find_peer (t->me, peer_id); + n = tree_find_peer (t->root, peer_id); if (NULL == n) return NULL; node = n; @@ -522,12 +522,14 @@ tree_add_path (struct MeshTunnelTree *t, unsigned int i; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Adding path [%u] towards peer %u to peer %u.\n", + "tree: Adding path [%u] towards peer %u.\n", p->length, - p->peers[p->length - 1], - t->me->peer); + p->peers[p->length - 1]); - myid = t->me->peer; + if (NULL != t->me) + myid = t->me->peer; + else + myid = 0; GNUNET_assert(0 != p->length); parent = n = t->root; if (n->peer != p->peers[0]) @@ -571,12 +573,6 @@ tree_add_path (struct MeshTunnelTree *t, } GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: All childen visited.\n"); - if (-1 == me) - { - /* New path deviates from tree before reaching us. What happened? */ - GNUNET_break (0); - return GNUNET_SYSERR; - } /* Add the rest of the path as a branch from parent. */ while (i < p->length) { diff --git a/src/mesh/test_mesh_small.conf b/src/mesh/test_mesh_small.conf index 833fab062..304d5ca10 100644 --- a/src/mesh/test_mesh_small.conf +++ b/src/mesh/test_mesh_small.conf @@ -62,8 +62,8 @@ NUM_PEERS = 16 WEAKRANDOM = YES TOPOLOGY = 2D_TORUS CONNECT_TOPOLOGY = NONE -TOPOLOGY_FILE = small.dat -#CONNECT_TOPOLOGY = ERDOS_RENYI +#TOPOLOGY_FILE = small.dat +CONNECT_TOPOLOGY = 2D_TORUS #CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM #CONNECT_TOPOLOGY_OPTION_MODIFIER = 25 #PERCENTAGE = 3 -- 2.25.1