+/**
+ * Get a chennel from a client
+ *
+ * @param c the client to check
+ * @param chid Channel ID, must be local (> 0x800...)
+ *
+ * @return non-NULL if channel exists in the clients lists
+ */
+struct MeshChannel *
+GML_channel_get (struct MeshClient *c, MESH_ChannelNumber chid)
+{
+ if (0 == (chid & GNUNET_MESH_LOCAL_CHANNEL_ID_CLI))
+ {
+ GNUNET_break_op (0);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "CHID %X not a local chid\n", chid);
+ return NULL;
+ }
+ if (chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
+ return GNUNET_CONTAINER_multihashmap32_get (c->incoming_channels, chid);
+ return GNUNET_CONTAINER_multihashmap32_get (c->own_channels, chid);
+}
+
+
+/**
+ * Add a channel to a client
+ *
+ * @param client Client.
+ * @param chid Channel ID.
+ * @param ch Channel.
+ */
+void
+GML_channel_add (struct MeshClient *client,
+ uint32_t chid,
+ struct MeshChannel *ch)
+{
+ if (chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
+ GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels, chid, ch,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ else if (chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_CLI)
+ GNUNET_CONTAINER_multihashmap32_put (client->own_channels, chid, ch,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ else
+ GNUNET_break (0);
+}
+
+
+/**
+ * Remove a channel from a client
+ *
+ * @param client Client.
+ * @param chid Channel ID.
+ * @param ch Channel.
+ */
+void
+GML_channel_remove (struct MeshClient *client,
+ uint32_t chid,
+ struct MeshChannel *ch)
+{
+ if (GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= chid)
+ GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, chid, ch);
+ else if (GNUNET_MESH_LOCAL_CHANNEL_ID_CLI <= chid)
+ GNUNET_CONTAINER_multihashmap32_remove (client->own_channels, chid, ch);
+ else
+ 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;
+}
+
+