From: Bart Polot Date: Wed, 9 Oct 2013 08:32:49 +0000 (+0000) Subject: - sync X-Git-Tag: initial-import-from-subversion-38251~6677 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dcba7f93f6cbccbd5f103675109fb1ebb88d6b41;p=oweals%2Fgnunet.git - sync --- diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index 6e99d2b30..7802e34a0 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c @@ -404,43 +404,6 @@ channel_add_client (struct MeshChannel *ch, struct MeshClient *c) } - -/** - * Is the root client for this channel on this peer? - * - * @param ch Channel. - * @param fwd Is this for fwd traffic? - * - * @return GNUNET_YES in case it is. - */ -static int -channel_is_origin (struct MeshChannel *ch, int fwd) -{ - struct MeshClient *c; - - c = fwd ? ch->root : ch->dest; - return NULL != c; -} - - -/** - * Is the destination client for this channel on this peer? - * - * @param ch Channel. - * @param fwd Is this for fwd traffic? - * - * @return GNUNET_YES in case it is. - */ -static int -channel_is_terminal (struct MeshChannel *ch, int fwd) -{ - struct MeshClient *c; - - c = fwd ? ch->dest : ch->root; - return NULL != c; -} - - /** * Destroy all reliable messages queued for a channel, * during a channel destruction. @@ -1112,6 +1075,20 @@ GMCH_get_id (const struct MeshChannel *ch) } +/** + * Get the channel tunnel. + * + * @param ch Channel to get the tunnel from. + * + * @return tunnel of the channel. + */ +struct MeshTunnel3 * +GMCH_get_tunnel (const struct MeshChannel *ch) +{ + return ch->t; +} + + /** * Get free buffer space towards the client on a specific channel. * @@ -1124,20 +1101,56 @@ unsigned int GMCH_get_buffer (struct MeshChannel *ch, int fwd) { struct MeshChannelReliability *rel; - + rel = fwd ? ch->dest_rel : ch->root_rel; - + /* If rel is NULL it means that the end is not yet created, * most probably is a loopback channel at the point of sending * the ChannelCreate to itself. */ if (NULL == rel) return 64; - + return (64 - rel->n_recv); } +/** + * Is the root client for this channel on this peer? + * + * @param ch Channel. + * @param fwd Is this for fwd traffic? + * + * @return GNUNET_YES in case it is. + */ +int +GMCH_is_origin (struct MeshChannel *ch, int fwd) +{ + struct MeshClient *c; + + c = fwd ? ch->root : ch->dest; + return NULL != c; +} + + +/** + * Is the destination client for this channel on this peer? + * + * @param ch Channel. + * @param fwd Is this for fwd traffic? + * + * @return GNUNET_YES in case it is. + */ +int +GMCH_is_terminal (struct MeshChannel *ch, int fwd) +{ + struct MeshClient *c; + + c = fwd ? ch->dest : ch->root; + return NULL != c; +} + + /** * Notify the destination client that a new incoming channel was created. * diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index 8af9937b0..154e92b0d 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h @@ -57,6 +57,16 @@ struct MeshChannel; MESH_ChannelNumber GMCH_get_id (const struct MeshChannel *ch); +/** + * Get the channel tunnel. + * + * @param ch Channel to get the tunnel from. + * + * @return tunnel of the channel. + */ +struct MeshTunnel3 * +GMCH_get_tunnel (const struct MeshChannel *ch); + /** * Get free buffer space towards the client on a specific channel. * @@ -68,6 +78,28 @@ GMCH_get_id (const struct MeshChannel *ch); unsigned int GMCH_get_buffer (struct MeshChannel *ch, int fwd); +/** + * Is the root client for this channel on this peer? + * + * @param ch Channel. + * @param fwd Is this for fwd traffic? + * + * @return GNUNET_YES in case it is. + */ +int +GMCH_is_origin (struct MeshChannel *ch, int fwd); + +/** + * Is the destination client for this channel on this peer? + * + * @param ch Channel. + * @param fwd Is this for fwd traffic? + * + * @return GNUNET_YES in case it is. + */ +int +GMCH_is_terminal (struct MeshChannel *ch, int fwd); + /** * Send an end-to-end ACK message for the most recent in-sequence payload. * diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 7c3cb08bb..edcb79953 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -32,6 +32,7 @@ #include "gnunet-service-mesh_connection.h" #include "gnunet-service-mesh_peer.h" #include "gnunet-service-mesh_tunnel.h" +#include "gnunet-service-mesh_channel.h" #include "mesh_protocol_enc.h" #include "mesh_path.h" @@ -1048,7 +1049,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, LOG (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n", GNUNET_i2s (&id[i])); path->peers[i] = GNUNET_PEER_intern (&id[i]); - if (path->peers[i] == myid) + if (path->peers[i] == my_short_id) own_pos = i; } if (own_pos == 0 && path->peers[own_pos] != myid) @@ -1056,7 +1057,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, /* create path: self not found in path through self */ GNUNET_break_op (0); path_destroy (path); - connection_destroy (c); + GMC_destroy (c); return GNUNET_OK; } LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); @@ -1086,9 +1087,9 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, orig_peer->tunnel = tunnel_new (); orig_peer->tunnel->peer = orig_peer; } - tunnel_add_connection (orig_peer->tunnel, c); - if (MESH_TUNNEL_NEW == c->t->state) - tunnel_change_state (c->t, MESH_TUNNEL_WAITING); + GMT_add_connection (orig_peer->tunnel, c); + if (MESH_TUNNEL_NEW == GMT_get_state (c->t)) + GMT_change_state (c->t, MESH_TUNNEL_WAITING); send_connection_ack (c, GNUNET_NO); if (MESH_CONNECTION_SENT == c->state) @@ -1199,15 +1200,14 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer, if (GMC_is_terminal (c, GNUNET_YES)) { LOG (GNUNET_ERROR_TYPE_DEBUG, " Connection ACK for us!\n"); - if (MESH_TUNNEL_READY != c->t->state) - tunnel_change_state (c->t, MESH_TUNNEL_READY); - connection_change_state (c, MESH_CONNECTION_READY); - tunnel_send_queued_data (c->t, GNUNET_NO); + GMC_change_state (c, MESH_CONNECTION_READY); + GMT_change_state (c->t, MESH_TUNNEL_READY); + GMT_send_queued_data (c->t, GNUNET_NO); return GNUNET_OK; } LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); - send_prebuilt_message_connection (message, c, NULL, fwd); + GMC_send_prebuilt_message (message, c, NULL, fwd); return GNUNET_OK; } @@ -1287,16 +1287,16 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; } id = GNUNET_PEER_search (peer); - if (id == connection_get_prev_hop (c)->id) + if (id == GMP_get_short_id (connection_get_prev_hop (c))) fwd = GNUNET_YES; - else if (id == connection_get_next_hop (c)->id) + else if (id == GMP_get_short_id (connection_get_next_hop (c))) fwd = GNUNET_NO; else { GNUNET_break_op (0); return GNUNET_OK; } - send_prebuilt_message_connection (message, c, NULL, fwd); + GMC_send_prebuilt_message (message, c, NULL, fwd); c->destroy = GNUNET_YES; return GNUNET_OK; @@ -1353,7 +1353,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, /* Check if origin is as expected */ neighbor = connection_get_hop (c, !fwd); - if (peer_get (peer)->id != neighbor->id) + if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor)) { GNUNET_break_op (0); return GNUNET_OK; @@ -1502,13 +1502,13 @@ GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer, /* Is this a forward or backward ACK? */ id = GNUNET_PEER_search (peer); - if (connection_get_next_hop (c)->id == id) + if (GMP_get_short_id (connection_get_next_hop (c)) == id) { LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); fc = &c->fwd_fc; fwd = GNUNET_YES; } - else if (connection_get_prev_hop (c)->id == id) + else if (GMP_get_short_id (connection_get_prev_hop (c)) == id) { LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); fc = &c->bck_fc; @@ -1585,12 +1585,12 @@ GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer, * this way of discerining FWD/BCK should not be a problem. */ id = GNUNET_PEER_search (peer); - if (connection_get_next_hop (c)->id == id) + if (GMP_get_short_id (connection_get_next_hop (c)) == id) { LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); fc = &c->fwd_fc; } - else if (connection_get_prev_hop (c)->id == id) + else if (GMP_get_short_id (connection_get_prev_hop (c)) == id) { LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); fc = &c->bck_fc; @@ -1625,7 +1625,7 @@ GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer, */ int GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct GNUNET_MESH_ConnectionKeepAlive *msg; struct MeshConnection *c; @@ -1649,7 +1649,7 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, /* Check if origin is as expected */ neighbor = connection_get_hop (c, fwd); - if (peer_get (peer)->id != neighbor->id) + if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor)) { GNUNET_break_op (0); return GNUNET_OK; @@ -1676,8 +1676,8 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, * @param ch Channel, if any. * @param fwd Is this a fwd ACK? (will go dest->root) */ -static void -send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) +void +GMC_send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) { unsigned int buffer; @@ -1686,8 +1686,10 @@ send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) fwd ? "FWD" : "BCK", c, ch); if (NULL == c || GMC_is_terminal (c, fwd)) { + struct MeshTunnel3 *t; LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all connections\n"); - buffer = GMT_get_buffer (NULL == c ? ch->t : c->t, fwd); + t = (NULL == c) ? GMCH_get_tunnel (ch) : GMC_get_tunnel (c); + buffer = GMT_get_buffer (t, fwd); } else { @@ -1721,7 +1723,6 @@ send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) } - /** * Initialize the connections subsystem * @@ -1866,6 +1867,19 @@ GMC_get_state (const struct MeshConnection *c) return c->state; } +/** + * Get the connection tunnel. + * + * @param c Connection to get the tunnel from. + * + * @return tunnel of the connection. + */ +struct MeshTunnel3 * +GMC_get_tunnel (const struct MeshConnection *c) +{ + return c->t; +} + /** * Get free buffer space in a connection. diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index c2d396969..2552623c3 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h @@ -207,6 +207,17 @@ int GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message); +/** + * Send an ACK on the appropriate connection/channel, depending on + * the direction and the position of the peer. + * + * @param c Which connection to send the hop-by-hop ACK. + * @param ch Channel, if any. + * @param fwd Is this a fwd ACK? (will go dest->root) + */ +void +GMC_send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd); + /** * Initialize the connections subsystem * @@ -263,6 +274,16 @@ GMC_get_id (const struct MeshConnection *c); enum MeshConnectionState GMC_get_state (const struct MeshConnection *c); +/** + * Get the connection tunnel. + * + * @param c Connection to get the tunnel from. + * + * @return tunnel of the connection. + */ +struct MeshTunnel3 * +GMC_get_tunnel (const struct MeshConnection *c); + /** * Get free buffer space in a connection. * diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 05fb90f39..2c3967d8a 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -1569,6 +1569,21 @@ GMP_get_id (const struct MeshPeer *peer) return GNUNET_PEER_resolve2 (peer->id); } + +/** + * Get the Short ID of a peer. + * + * @param peer Peer to get from. + * + * @return Short ID of peer. + */ +GNUNET_PEER_Id +GMP_get_short_id (const struct MeshPeer *peer) +{ + return 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 b5c165e9a..6ac3e3801 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h @@ -93,7 +93,7 @@ void GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t); /** - * Chech whether there is a direct (core level) connection to peer. + * Check whether there is a direct (core level) connection to peer. * * @param peer Peer to check. * @@ -102,6 +102,7 @@ GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t); int GMP_is_neighbor (const struct MeshPeer *peer); + /** * Add a connection to a neighboring peer. * @@ -130,6 +131,16 @@ GMP_remove_connection (struct MeshPeer *peer, struct MeshConnection *c); struct GNUNET_PeerIdentity * GMP_get_id (const struct MeshPeer *peer); +/** + * Get the Short ID of a peer. + * + * @param peer Peer to get from. + * + * @return Short ID of peer. + */ +GNUNET_PEER_Id +GMP_get_short_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 8a240f4a8..e709a0be5 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -289,36 +289,6 @@ tunnel_get_connection (struct MeshTunnel3 *t, int fwd) } -/** - * Send all cached messages that we can, tunnel is online. - * - * @param t Tunnel that holds the messages. - * @param fwd Is this fwd? - */ -static void -tunnel_send_queued_data (struct MeshTunnel3 *t, int fwd) -{ - struct MeshTunnelQueue *tq; - struct MeshTunnelQueue *next; - unsigned int room; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "tunnel_send_queued_data on tunnel %s\n", - GMP_2s (t->peer)); - 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) - { - next = tq->next; - room--; - GNUNET_CONTAINER_DLL_remove (t->tq_head, t->tq_tail, tq); - GMCH_send_prebuilt_message ((struct GNUNET_MessageHeader *) &tq[1], - tq->ch, fwd); - - GNUNET_free (tq); - } -} - void handle_data (struct MeshTunnel3 *t, const struct GNUNET_MESH_Data *msg, @@ -565,7 +535,38 @@ GMT_queue_data (struct MeshTunnel3 *t, GNUNET_CONTAINER_DLL_insert_tail (t->tq_head, t->tq_tail, tq); if (MESH_TUNNEL_READY == t->state) - tunnel_send_queued_data (t, fwd); + GMT_send_queued_data (t, fwd); +} + + +/** + * Send all cached messages that we can, tunnel is online. + * + * @param t Tunnel that holds the messages. + * @param fwd Is this fwd? + */ +void +GMT_send_queued_data (struct MeshTunnel3 *t, int fwd) +{ + struct MeshTunnelQueue *tq; + struct MeshTunnelQueue *next; + unsigned int room; + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GMT_send_queued_data on tunnel %s\n", + GMP_2s (t->peer)); + 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) + { + next = tq->next; + room--; + GNUNET_CONTAINER_DLL_remove (t->tq_head, t->tq_tail, tq); + GMCH_send_prebuilt_message ((struct GNUNET_MessageHeader *) &tq[1], + tq->ch, fwd); + + GNUNET_free (tq); + } } @@ -951,6 +952,19 @@ GMT_count_channels (struct MeshTunnel3 *t) } +/** + * Get the state of a tunnel. + * + * @param t Tunnel. + * + * @return Tunnel's state. + */ +enum MeshTunnelState +GMT_get_state (struct MeshTunnel3 *t) +{ + return t->state; +} + /** * Get the total buffer space for a tunnel. * diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index afa0ee169..71fa5780e 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -175,6 +175,15 @@ GMT_queue_data (struct MeshTunnel3 *t, struct GNUNET_MessageHeader *msg, int fwd); +/** + * Send all cached messages that we can, tunnel is online. + * + * @param t Tunnel that holds the messages. + * @param fwd Is this fwd? + */ +void +GMT_send_queued_data (struct MeshTunnel3 *t, int fwd); + /** * Count established (ready) connections of a tunnel. * @@ -195,6 +204,16 @@ GMT_count_connections (struct MeshTunnel3 *t); unsigned int GMT_count_channels (struct MeshTunnel3 *t); +/** + * Get the state of a tunnel. + * + * @param t Tunnel. + * + * @return Tunnel's state. + */ +enum MeshTunnelState +GMT_get_state (struct MeshTunnel3 *t); + /** * Get the total buffer space for a tunnel. *