}
-
-/**
- * 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.
}
+/**
+ * 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.
*
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.
*
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.
*
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.
*
#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"
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)
/* 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);
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)
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;
}
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;
/* 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;
/* 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;
* 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;
*/
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;
/* 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;
* @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;
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
{
}
-
/**
* Initialize the connections subsystem
*
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.
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
*
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.
*
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.
*
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.
*
int
GMP_is_neighbor (const struct MeshPeer *peer);
+
/**
* Add a connection to a neighboring peer.
*
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.
*
}
-/**
- * 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,
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);
+ }
}
}
+/**
+ * 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.
*
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.
*
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.
*