From 50f061e6ca2df0c9473b87f79beb5225b1400f03 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 9 Oct 2013 01:30:25 +0000 Subject: - sync --- src/mesh/gnunet-service-mesh_connection.c | 62 ++++++++------- src/mesh/gnunet-service-mesh_peer.c | 28 +++++++ src/mesh/gnunet-service-mesh_peer.h | 15 ++++ src/mesh/gnunet-service-mesh_tunnel.c | 126 +++++++++++++++++------------- src/mesh/gnunet-service-mesh_tunnel.h | 31 +++++++- 5 files changed, 180 insertions(+), 82 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 0d7dfc5f0..7c3cb08bb 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -31,6 +31,7 @@ #include "gnunet-service-mesh_connection.h" #include "gnunet-service-mesh_peer.h" +#include "gnunet-service-mesh_tunnel.h" #include "mesh_protocol_enc.h" #include "mesh_path.h" @@ -314,7 +315,6 @@ GMC_state2s (enum MeshConnectionState s) } - /** * Initialize a Flow Control structure to the initial state. * @@ -726,8 +726,6 @@ connection_cancel_queues (struct MeshConnection *c, int fwd) } - - /** * Function called if a connection has been stalled for a while, * possibly due to a missed ACK. Poll the neighbor about its ACK status. @@ -951,6 +949,23 @@ register_neighbors (struct MeshConnection *c) } +/** + * + */ +static void +unregister_neighbors (struct MeshConnection *c) +{ + struct MeshPeer *peer; + + peer = connection_get_next_hop (c); + GMP_remove_connection (peer, c); + + peer = connection_get_prev_hop (c); + GMP_remove_connection (peer, c); + +} + + /******************************************************************************/ /******************************** API ***********************************/ /******************************************************************************/ @@ -1647,7 +1662,7 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO); - send_prebuilt_message_connection (message, c, NULL, fwd); + GMC_send_prebuilt_message (message, c, NULL, fwd); return GNUNET_OK; } @@ -1672,17 +1687,17 @@ send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) if (NULL == c || GMC_is_terminal (c, fwd)) { LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all connections\n"); - buffer = tunnel_get_buffer (NULL == c ? ch->t : c->t, fwd); + buffer = GMT_get_buffer (NULL == c ? ch->t : c->t, fwd); } else { LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from one connection\n"); - buffer = connection_get_buffer (c, fwd); + buffer = GMC_get_buffer (c, fwd); } LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer); - if ( (NULL != ch && channel_is_origin (ch, fwd)) || - (NULL != c && connection_is_origin (c, fwd)) ) + if ( (NULL != ch && GMCH_is_origin (ch, fwd)) || + (NULL != c && GMC_is_origin (c, fwd)) ) { LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); if (0 < buffer) @@ -1763,7 +1778,6 @@ GMC_new (const struct GNUNET_HashCode *cid, unsigned int own_pos) { struct MeshConnection *c; - unsigned int own_pos; c = GNUNET_new (struct MeshConnection); c->id = *cid; @@ -1795,7 +1809,7 @@ GMC_new (const struct GNUNET_HashCode *cid, } -static void +void GMC_destroy (struct MeshConnection *c) { struct MeshPeer *peer; @@ -1803,9 +1817,8 @@ GMC_destroy (struct MeshConnection *c) if (NULL == c) return; - LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying connection %s[%X]\n", - peer2s (c->t->peer), - c->id); + LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying connection %s\n", + GNUNET_h2s (&c->id)); /* Cancel all traffic */ connection_cancel_queues (c, GNUNET_YES); @@ -1817,17 +1830,12 @@ GMC_destroy (struct MeshConnection *c) if (GNUNET_SCHEDULER_NO_TASK != c->bck_maintenance_task) GNUNET_SCHEDULER_cancel (c->bck_maintenance_task); - /* Deregister from neighbors */ - peer = connection_get_next_hop (c); - if (NULL != peer && NULL != peer->connections) - GNUNET_CONTAINER_multihashmap_remove (peer->connections, &c->id, c); - peer = connection_get_prev_hop (c); - if (NULL != peer && NULL != peer->connections) - GNUNET_CONTAINER_multihashmap_remove (peer->connections, &c->id, c); + /* Unregister from neighbors */ + unregister_neighbors (c); /* Delete */ GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO); - GNUNET_CONTAINER_DLL_remove (c->t->connection_head, c->t->connection_tail, c); + GMT_remove_connection (c->t, c); GNUNET_free (c); } @@ -1909,7 +1917,6 @@ GMC_notify_broken (struct MeshConnection *c, struct MeshPeer *peer, struct GNUNET_PeerIdentity *my_full_id) { - struct MeshConnection *c = value; struct GNUNET_MESH_ConnectionBroken msg; int fwd; @@ -1920,18 +1927,18 @@ GMC_notify_broken (struct MeshConnection *c, { /* Local shutdown, no one to notify about this. */ GMC_destroy (c); - return GNUNET_YES; + return; } msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN); msg.cid = c->id; msg.peer1 = *my_full_id; - msg.peer2 = *GNUNET_PEER_resolve2 (peer->id); + msg.peer2 = *GMP_get_id (peer); GMC_send_prebuilt_message (&msg.header, c, NULL, fwd); c->destroy = GNUNET_YES; - return GNUNET_YES; + return; } @@ -2084,9 +2091,8 @@ GMC_send_destroy (struct MeshConnection *c) msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);; msg.cid = c->id; LOG (GNUNET_ERROR_TYPE_DEBUG, - " sending connection destroy for connection %s[%X]\n", - peer2s (c->t->peer), - c->id); + " sending connection destroy for connection %s\n", + GNUNET_h2s (&c->id)); if (GNUNET_NO == GMC_is_terminal (c, GNUNET_YES)) GMC_send_prebuilt_message (&msg.header, c, NULL, GNUNET_YES); diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 6c8963864..05fb90f39 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -1541,6 +1541,34 @@ GMP_add_connection (struct MeshPeer *peer, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); } + +int +GMP_remove_connection (struct MeshPeer *peer, + const struct MeshConnection *c) +{ + if (NULL == peer || NULL == peer->connections) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_CONTAINER_multihashmap_remove (peer->connections, + GMC_get_id (c), + c); +} + +/** + * Get the Full ID of a peer. + * + * @param peer Peer to get from. + * + * @return Full ID of peer. + */ +struct GNUNET_PeerIdentity * +GMP_get_id (const struct MeshPeer *peer) +{ + return GNUNET_PEER_resolve2 (peer->id); +} + /** * Get the static string for a peer ID. * diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h index 3a336fb37..b5c165e9a 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h @@ -40,6 +40,8 @@ extern "C" #include "platform.h" #include "gnunet_util_lib.h" +#include "gnunet-service-mesh_connection.h" + /** * Struct containing all information regarding a given peer */ @@ -115,6 +117,19 @@ GMP_is_neighbor (const struct MeshPeer *peer); int GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c); +int +GMP_remove_connection (struct MeshPeer *peer, struct MeshConnection *c); + +/** + * Get the Full ID of a peer. + * + * @param peer Peer to get from. + * + * @return Full ID of peer. + */ +struct GNUNET_PeerIdentity * +GMP_get_id (const struct MeshPeer *peer); + /** * Get the static string for a peer ID. * diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 62545b35c..8a240f4a8 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -289,58 +289,6 @@ tunnel_get_connection (struct MeshTunnel3 *t, int fwd) } -/** - * Get the total buffer space for a tunnel. - * - * @param t Tunnel. - * @param fwd Is this for FWD traffic? - * - * @return Buffer space offered by all connections in the tunnel. - */ -static unsigned int -tunnel_get_buffer (struct MeshTunnel3 *t, int fwd) -{ - struct MeshTConnection *iter; - unsigned int buffer; - - iter = t->connection_head; - buffer = 0; - - /* If terminal, return biggest channel buffer */ - if (NULL == iter || GMC_is_terminal (iter->c, fwd)) - { - struct MeshTChannel *iter_ch; - unsigned int ch_buf; - - if (NULL == t->channel_head) - return 64; - - for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) - { - ch_buf = GMCH_get_buffer (iter_ch->ch, fwd); - if (ch_buf > buffer) - buffer = ch_buf; - } - return buffer; - } - - /* If not terminal, return sum of connection buffers */ - while (NULL != iter) - { - if (GMC_get_state (iter->c) != MESH_CONNECTION_READY) - { - iter = iter->next; - continue; - } - - buffer += GMC_get_buffer (iter->c, fwd); - iter = iter->next; - } - - return buffer; -} - - /** * Send all cached messages that we can, tunnel is online. * @@ -357,7 +305,7 @@ tunnel_send_queued_data (struct MeshTunnel3 *t, int fwd) LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel_send_queued_data on tunnel %s\n", GMP_2s (t->peer)); - room = tunnel_get_buffer (t, fwd); + room = GMT_get_buffer (t, fwd); LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room); for (tq = t->tq_head; NULL != tq && room > 0; tq = next) { @@ -740,6 +688,27 @@ GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c) } +/** + * Remove a connection from a tunnel. + * + * @param t Tunnel. + * @param c Connection. + */ +void +GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c) +{ + struct MeshTConnection *aux; + + for (aux = t->connection_head; aux != NULL; aux = aux->next) + if (aux->c == c) + { + GNUNET_CONTAINER_DLL_remove (t->connection_head, t->connection_tail, aux); + GNUNET_free (aux); + return; + } +} + + /** * Tunnel is empty: destroy it. * @@ -982,6 +951,57 @@ GMT_count_channels (struct MeshTunnel3 *t) } +/** + * Get the total buffer space for a tunnel. + * + * @param t Tunnel. + * @param fwd Is this for FWD traffic? + * + * @return Buffer space offered by all connections in the tunnel. + */ +unsigned int +GMT_get_buffer (struct MeshTunnel3 *t, int fwd) +{ + struct MeshTConnection *iter; + unsigned int buffer; + + iter = t->connection_head; + buffer = 0; + + /* If terminal, return biggest channel buffer */ + if (NULL == iter || GMC_is_terminal (iter->c, fwd)) + { + struct MeshTChannel *iter_ch; + unsigned int ch_buf; + + if (NULL == t->channel_head) + return 64; + + for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) + { + ch_buf = GMCH_get_buffer (iter_ch->ch, fwd); + if (ch_buf > buffer) + buffer = ch_buf; + } + return buffer; + } + + /* If not terminal, return sum of connection buffers */ + while (NULL != iter) + { + if (GMC_get_state (iter->c) != MESH_CONNECTION_READY) + { + iter = iter->next; + continue; + } + + buffer += GMC_get_buffer (iter->c, fwd); + iter = iter->next; + } + + return buffer; +} + /** * Sends an already built message on a tunnel, choosing the best connection. * diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index 76b867cbc..afa0ee169 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -41,7 +41,7 @@ extern "C" #include "gnunet_util_lib.h" #include "gnunet-service-mesh_channel.h" - +#include "gnunet-service-mesh_connection.h" /** * All the states a tunnel can be in. @@ -142,6 +142,24 @@ GMT_destroy (struct MeshTunnel3 *t); void GMT_change_state (struct MeshTunnel3* t, enum MeshTunnelState state); +/** + * Add a connection to a tunnel. + * + * @param t Tunnel. + * @param c Connection. + */ +void +GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c); + + +/** + * Remove a connection from a tunnel. + * + * @param t Tunnel. + * @param c Connection. + */ +void +GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c); /** * Cache a message to be sent once tunnel is online. @@ -177,6 +195,17 @@ GMT_count_connections (struct MeshTunnel3 *t); unsigned int GMT_count_channels (struct MeshTunnel3 *t); +/** + * Get the total buffer space for a tunnel. + * + * @param t Tunnel. + * @param fwd Is this for FWD traffic? + * + * @return Buffer space offered by all connections in the tunnel. + */ +unsigned int +GMT_get_buffer (struct MeshTunnel3 *t, int fwd); + #if 0 /* keep Emacsens' auto-indent happy */ { #endif -- cgit v1.2.3