From: Bart Polot Date: Wed, 9 Oct 2013 15:52:55 +0000 (+0000) Subject: - local channel id better accounted for per-client X-Git-Tag: initial-import-from-subversion-38251~6656 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0c568b2d745a90d30ffdc10a88be8e46929218c3;p=oweals%2Fgnunet.git - local channel id better accounted for per-client --- diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index d280e336f..ba0ed6d61 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c @@ -33,8 +33,10 @@ #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. */ @@ -356,8 +358,8 @@ send_client_data (struct MeshChannel *ch, * @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; @@ -368,20 +370,10 @@ channel_add_client (struct MeshChannel *ch, struct MeshClient *c) } /* 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); @@ -540,7 +532,7 @@ channel_retransmit_message (void *cls, */ 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) { @@ -558,7 +550,7 @@ channel_retransmit_message (void *cls, { 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 @@ -588,7 +580,6 @@ channel_send_connections_ack (struct MeshChannel *ch, { struct MeshTunnel3 *t = ch->t; struct MeshConnection *c; - struct MeshFlowControl *fc; uint32_t allowed; uint32_t to_allow; uint32_t allow_per_connection; @@ -599,10 +590,11 @@ channel_send_connections_ack (struct MeshChannel *ch, 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; @@ -631,7 +623,7 @@ channel_send_connections_ack (struct MeshChannel *ch, { continue; } - connection_send_ack (c, allow_per_connection, fwd); + GMC_send_ack (c, allow_per_connection, fwd); } LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 776690a76..20f122ded 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -40,8 +40,6 @@ #define MESH_MAX_POLL_TIME GNUNET_TIME_relative_multiply (\ GNUNET_TIME_UNIT_MINUTES,\ 10) -#define MESH_RETRANSMIT_TIME GNUNET_TIME_UNIT_SECONDS - #define LOG(level, ...) GNUNET_log_from (level,"mesh-con",__VA_ARGS__) diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index 3fea3a714..1e3bf1669 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c @@ -58,11 +58,16 @@ struct MeshClient */ 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 */ @@ -177,9 +182,10 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *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); @@ -894,6 +900,7 @@ GML_channel_add (struct MeshClient *client, GNUNET_break (0); } + /** * Remove a channel from a client * @@ -914,6 +921,31 @@ GML_channel_remove (struct MeshClient *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 * diff --git a/src/mesh/gnunet-service-mesh_local.h b/src/mesh/gnunet-service-mesh_local.h index 637a87aeb..4befb24ac 100644 --- a/src/mesh/gnunet-service-mesh_local.h +++ b/src/mesh/gnunet-service-mesh_local.h @@ -106,6 +106,16 @@ GML_channel_remove (struct MeshClient *client, uint32_t chid, struct MeshChannel *ch); +/** + * 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); + /** * Check if client has registered with the service and has not disconnected * diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 362ce7e74..1ceb500ba 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -114,11 +114,6 @@ struct MeshTunnel3 */ MESH_ChannelNumber next_chid; - /** - * Channel ID for the next incoming channel. - */ - MESH_ChannelNumber next_local_chid; - /** * Pending message count. */ @@ -589,7 +584,6 @@ GMT_new (void) 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)) @@ -1074,13 +1068,12 @@ GMT_get_destination (struct MeshTunnel3 *t) } - /** - * 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)