#define LOG(level, ...) GNUNET_log_from(level,"mesh-chn",__VA_ARGS__)
+#define MESH_RETRANSMIT_TIME GNUNET_TIME_UNIT_SECONDS
#define MESH_RETRANSMIT_MARGIN 4
+
/**
* All the states a connection can be in.
*/
* @param ch Channel to which add the client.
* @param c Client which to add to the channel.
*/
-static void
-channel_add_client (struct MeshChannel *ch, struct MeshClient *c)
+void
+GMCH_add_client (struct MeshChannel *ch, struct MeshClient *c)
{
struct MeshTunnel3 *t = ch->t;
}
/* Assign local id as destination */
- while (NULL != GML_channel_get (c, t->next_local_chid))
- t->next_local_chid = (t->next_local_chid + 1) | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
- ch->lid_dest = t->next_local_chid++;
- t->next_local_chid = t->next_local_chid | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
+ ch->lid_dest = GML_get_next_chid (c);
/* Store in client's hashmap */
- if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap32_put (c->incoming_channels,
- ch->lid_dest, ch,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
- {
- GNUNET_break (0);
- return;
- }
+ GML_channel_add (c, ch->lid_dest, ch);
GNUNET_break (NULL == ch->dest_rel);
ch->dest_rel = GNUNET_new (struct MeshChannelReliability);
*/
payload = (struct GNUNET_MESH_Data *) ©[1];
fwd = (rel == ch->root_rel);
- c = tunnel_get_connection (ch->t, fwd);
+ c = GMT_get_connection (ch->t, fwd);
hop = connection_get_hop (c, fwd);
for (q = hop->queue_head; NULL != q; q = q->next)
{
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! RETRANSMIT %u\n", copy->mid);
- send_prebuilt_message_channel (&payload->header, ch, fwd);
+ GMCH_send_prebuilt_message (&payload->header, ch, fwd);
GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO);
}
else
{
struct MeshTunnel3 *t = ch->t;
struct MeshConnection *c;
- struct MeshFlowControl *fc;
uint32_t allowed;
uint32_t to_allow;
uint32_t allow_per_connection;
fwd ? "FWD" : "BCK", peer2s (ch->t->peer), ch->gid);
/* Count connections, how many messages are already allowed */
+ cs = GMT_count_connections (t);
for (cs = 0, allowed = 0, c = t->connection_head; NULL != c; c = c->next)
{
fc = fwd ? &c->fwd_fc : &c->bck_fc;
- if (GMC_is_pid_bigger(fc->last_pid_recv, fc->last_ack_sent))
+ if (GMC_is_pid_bigger (fc->last_pid_recv, fc->last_ack_sent))
{
GNUNET_break (0);
continue;
{
continue;
}
- connection_send_ack (c, allow_per_connection, fwd);
+ GMC_send_ack (c, allow_per_connection, fwd);
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
*/
struct GNUNET_CONTAINER_MultiHashMap32 *own_channels;
- /**
+ /**
* Tunnels this client has accepted, indexed by incoming local id
*/
struct GNUNET_CONTAINER_MultiHashMap32 *incoming_channels;
+ /**
+ * Channel ID for the next incoming channel.
+ */
+ MESH_ChannelNumber next_chid;
+
/**
* Handle to communicate with the client
*/
if (NULL == client)
return;
- c = GNUNET_malloc (sizeof (struct MeshClient));
+ c = GNUNET_new (struct MeshClient);
c->handle = client;
c->id = next_client_id++; /* overflow not important: just for debug */
+ c->next_chid = GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
GNUNET_SERVER_client_keep (client);
GNUNET_SERVER_client_set_user_context (client, c);
GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
GNUNET_break (0);
}
+
/**
* Remove a channel from a client
*
GNUNET_break (0);
}
+
+/**
+ * Get the tunnel's next free local channel ID.
+ *
+ * @param c Client.
+ *
+ * @return LID of a channel free to use.
+ */
+MESH_ChannelNumber
+GML_get_next_chid (struct MeshClient *c)
+{
+ MESH_ChannelNumber chid;
+
+ while (NULL != GML_channel_get (c, c->next_chid))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", c->next_chid);
+ c->next_chid = (c->next_chid + 1) | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
+ }
+ chid = c->next_chid;
+ c->next_chid = (c->next_chid + 1) | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
+
+ return chid;
+}
+
+
/**
* Check if client has registered with the service and has not disconnected
*
*/
MESH_ChannelNumber next_chid;
- /**
- * Channel ID for the next incoming channel.
- */
- MESH_ChannelNumber next_local_chid;
-
/**
* Pending message count.
*/
t = GNUNET_new (struct MeshTunnel3);
t->next_chid = 0;
- t->next_local_chid = GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
// if (GNUNET_OK !=
// GNUNET_CONTAINER_multihashmap_put (tunnels, tid, t,
// GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
}
-
/**
- * Get the tunnel's next free Channel ID.
+ * Get the tunnel's next free global channel ID.
*
* @param t Tunnel.
*
- * @return ID of a channel free to use.
+ * @return GID of a channel free to use.
*/
MESH_ChannelNumber
GMT_get_next_chid (struct MeshTunnel3 *t)