aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_local.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-09 15:52:55 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-09 15:52:55 +0000
commit0c568b2d745a90d30ffdc10a88be8e46929218c3 (patch)
tree34cf233c1dbe1b4d9c98053c54f4f7dfec6641b7 /src/mesh/gnunet-service-mesh_local.c
parent84acdaf73e35f0851ec0fb6dc2c4d6afb840bd6e (diff)
downloadgnunet-0c568b2d745a90d30ffdc10a88be8e46929218c3.tar.gz
gnunet-0c568b2d745a90d30ffdc10a88be8e46929218c3.zip
- local channel id better accounted for per-client
Diffstat (limited to 'src/mesh/gnunet-service-mesh_local.c')
-rw-r--r--src/mesh/gnunet-service-mesh_local.c36
1 files changed, 34 insertions, 2 deletions
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,12 +58,17 @@ struct MeshClient
58 */ 58 */
59 struct GNUNET_CONTAINER_MultiHashMap32 *own_channels; 59 struct GNUNET_CONTAINER_MultiHashMap32 *own_channels;
60 60
61 /** 61 /**
62 * Tunnels this client has accepted, indexed by incoming local id 62 * Tunnels this client has accepted, indexed by incoming local id
63 */ 63 */
64 struct GNUNET_CONTAINER_MultiHashMap32 *incoming_channels; 64 struct GNUNET_CONTAINER_MultiHashMap32 *incoming_channels;
65 65
66 /** 66 /**
67 * Channel ID for the next incoming channel.
68 */
69 MESH_ChannelNumber next_chid;
70
71 /**
67 * Handle to communicate with the client 72 * Handle to communicate with the client
68 */ 73 */
69 struct GNUNET_SERVER_Client *handle; 74 struct GNUNET_SERVER_Client *handle;
@@ -177,9 +182,10 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
177 182
178 if (NULL == client) 183 if (NULL == client)
179 return; 184 return;
180 c = GNUNET_malloc (sizeof (struct MeshClient)); 185 c = GNUNET_new (struct MeshClient);
181 c->handle = client; 186 c->handle = client;
182 c->id = next_client_id++; /* overflow not important: just for debug */ 187 c->id = next_client_id++; /* overflow not important: just for debug */
188 c->next_chid = GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
183 GNUNET_SERVER_client_keep (client); 189 GNUNET_SERVER_client_keep (client);
184 GNUNET_SERVER_client_set_user_context (client, c); 190 GNUNET_SERVER_client_set_user_context (client, c);
185 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); 191 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
@@ -894,6 +900,7 @@ GML_channel_add (struct MeshClient *client,
894 GNUNET_break (0); 900 GNUNET_break (0);
895} 901}
896 902
903
897/** 904/**
898 * Remove a channel from a client 905 * Remove a channel from a client
899 * 906 *
@@ -914,6 +921,31 @@ GML_channel_remove (struct MeshClient *client,
914 GNUNET_break (0); 921 GNUNET_break (0);
915} 922}
916 923
924
925/**
926 * Get the tunnel's next free local channel ID.
927 *
928 * @param c Client.
929 *
930 * @return LID of a channel free to use.
931 */
932MESH_ChannelNumber
933GML_get_next_chid (struct MeshClient *c)
934{
935 MESH_ChannelNumber chid;
936
937 while (NULL != GML_channel_get (c, c->next_chid))
938 {
939 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", c->next_chid);
940 c->next_chid = (c->next_chid + 1) | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
941 }
942 chid = c->next_chid;
943 c->next_chid = (c->next_chid + 1) | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
944
945 return chid;
946}
947
948
917/** 949/**
918 * Check if client has registered with the service and has not disconnected 950 * Check if client has registered with the service and has not disconnected
919 * 951 *