From 5b48f06a02b221f2263d3d531b70367209619e24 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Fri, 11 Oct 2013 12:23:57 +0000 Subject: [PATCH] - fixes in DHT handling --- src/mesh/gnunet-service-mesh_connection.c | 12 ++--- src/mesh/gnunet-service-mesh_connection.h | 9 ---- src/mesh/gnunet-service-mesh_peer.c | 53 ++++++++++++++++++++--- src/mesh/gnunet-service-mesh_peer.h | 12 +++++ src/mesh/gnunet-service-mesh_tunnel.c | 6 +-- 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index e9e16293a..0c03b2da4 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -568,7 +568,7 @@ send_connection_ack (struct MeshConnection *connection, int fwd) if (MESH_TUNNEL3_NEW == GMT_get_state (t)) GMT_change_state (t, MESH_TUNNEL3_WAITING); if (MESH_CONNECTION_READY != connection->state) - GMC_change_state (connection, MESH_CONNECTION_SENT); + connection_change_state (connection, MESH_CONNECTION_SENT); } @@ -613,7 +613,7 @@ connection_recreate (struct MeshConnection *c, int fwd) { LOG (GNUNET_ERROR_TYPE_DEBUG, "sending connection recreate\n"); if (fwd) - send_connection_create (c); + GMC_send_create (c); else send_connection_ack (c, GNUNET_NO); } @@ -1679,7 +1679,7 @@ GMC_init (const struct GNUNET_CONFIGURATION_Handle *c) GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_MSGS_QUEUE", &max_msgs_queue)) { - LOG_config_invalid (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "MESH", "MAX_MSGS_QUEUE", "MISSING"); GNUNET_SCHEDULER_shutdown (); return; @@ -1689,7 +1689,7 @@ GMC_init (const struct GNUNET_CONFIGURATION_Handle *c) GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_CONNECTIONS", &max_connections)) { - LOG_config_invalid (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "MESH", "MAX_CONNECTIONS", "MISSING"); GNUNET_SCHEDULER_shutdown (); return; @@ -1699,7 +1699,7 @@ GMC_init (const struct GNUNET_CONFIGURATION_Handle *c) GNUNET_CONFIGURATION_get_value_time (c, "MESH", "REFRESH_CONNECTION_TIME", &refresh_connection_time)) { - LOG_config_invalid (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "MESH", "REFRESH_CONNECTION_TIME", "MISSING"); GNUNET_SCHEDULER_shutdown (); return; @@ -2105,7 +2105,7 @@ enum MeshTunnel3State state; if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state) GMT_change_state (connection->t, MESH_TUNNEL3_WAITING); if (MESH_CONNECTION_NEW == connection->state) - GMC_change_state (connection, MESH_CONNECTION_SENT); + connection_change_state (connection, MESH_CONNECTION_SENT); } diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index b0ddeabd9..9e9dec512 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h @@ -334,15 +334,6 @@ void GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); -/** - * Change the tunnel state. - * - * @param c Connection whose state to change. - * @param state New state. - */ -void -GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state); - /** * Notify other peers on a connection of a broken link. Mark connections * to destroy after all traffic has been sent. diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 70b88afe3..3a38fc40a 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -247,13 +247,13 @@ notify_broken (void *cls, static void core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) { - struct MeshPeer *pi; + struct MeshPeer *mp; struct MeshPeerPath *path; LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n"); LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&my_full_id)); - pi = GMP_get (peer); - if (myid == pi->id) + mp = GMP_get (peer); + if (myid == mp->id) { LOG (GNUNET_ERROR_TYPE_DEBUG, " (self)\n"); path = path_new (1); @@ -262,15 +262,15 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) { LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (peer)); path = path_new (2); - path->peers[1] = pi->id; - GNUNET_PEER_change_rc (pi->id, 1); + path->peers[1] = mp->id; + GNUNET_PEER_change_rc (mp->id, 1); GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO); } path->peers[0] = myid; GNUNET_PEER_change_rc (myid, 1); - peer_add_path (pi, path, GNUNET_YES); + GMP_add_path (mp, path, GNUNET_YES); - pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); + mp->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); return; } @@ -1588,6 +1588,45 @@ GMP_remove_connection (struct MeshPeer *peer, c); } +/** + * Start the DHT search for new paths towards the peer: we don't have + * enough good connections. + * + * @param peer Destination peer. + */ +void +GMP_start_search (struct MeshPeer *peer) +{ + if (NULL != peer->search_h) + { + GNUNET_break (0); + return; + } + + peer->search_h = GMD_search (GMP_get_id (peer), &search_handler, peer); +} + + +/** + * Stop the DHT search for new paths towards the peer: we already have + * enough good connections. + * + * @param peer Destination peer. + */ +void +GMP_stop_search (struct MeshPeer *peer) +{ + if (NULL == peer->search_h) + { + GNUNET_break (0); + return; + } + + GMD_search_stop (peer->search_h); + peer->search_h = NULL; +} + + /** * Get the Full ID of a peer. * diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h index 97f928bfd..7cc48fb66 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h @@ -237,9 +237,21 @@ GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed); int GMP_remove_connection (struct MeshPeer *peer, const struct MeshConnection *c); +/** + * Start the DHT search for new paths towards the peer: we don't have + * enough good connections. + * + * @param peer Destination peer. + */ void GMP_start_search (struct MeshPeer *peer); +/** + * Stop the DHT search for new paths towards the peer: we already have + * enough good connections. + * + * @param peer Destination peer. + */ void GMP_stop_search (struct MeshPeer *peer); diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index a8cb883f6..e117a9481 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -1179,10 +1179,10 @@ GMT_is_loopback (const struct MeshTunnel3 *t) int GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p) { - struct MeshTConnection *c; + struct MeshTConnection *iter; - for (c = t->connection_head; NULL != c; c = c->next) - if (GMC_get_path (c) == p) + for (iter = t->connection_head; NULL != iter; iter = iter->next) + if (GMC_get_path (iter->c) == p) return GNUNET_YES; return GNUNET_NO; -- 2.25.1