/**
- * Search for a tunnel among the tunnels for a client
+ * Search for a tunnel among the incoming tunnels
*
- * @param c the client whose tunnels to search in
* @param tid the local id of the tunnel
*
* @return tunnel handler, NULL if doesn't exist
*/
static struct MeshTunnel *
-tunnel_get_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid)
+tunnel_get_incoming (MESH_TunnelNumber tid)
{
GNUNET_HashCode hash;
+ GNUNET_assert (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV);
GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
+ return GNUNET_CONTAINER_multihashmap_get (incoming_tunnels, &hash);
+}
+
+
+/**
+ * Search for a tunnel among the tunnels for a client
+ *
+ * @param c the client whose tunnels to search in
+ * @param tid the local id of the tunnel
+ *
+ * @return tunnel handler, NULL if doesn't exist
+ */
+static struct MeshTunnel *
+tunnel_get_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid)
+{
if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
{
- return GNUNET_CONTAINER_multihashmap_get (incoming_tunnels, &hash);
+ return tunnel_get_incoming (tid);
+ }
+ else
+ {
+ GNUNET_HashCode hash;
+
+ GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
+ return GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
}
- return GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
}
{
t->peers_total++;
GNUNET_array_append (peer->tunnels, peer->ntunnels, t);
- GNUNET_CONTAINER_multihashmap_put(
+ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(
t->peers,
&id.hashPubKey,
peer,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
}
if (NULL != (p = peer->path_head))
t = GNUNET_malloc (sizeof (struct MeshTunnel));
t->id.oid = GNUNET_PEER_intern (pi);
t->id.tid = tid;
+ while (NULL != tunnel_get_incoming (next_local_tid))
+ next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
t->local_tid = next_local_tid++;
- /* FIXME test if taken */
- next_local_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
+ next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
t->tree = tree_new(t, t->id.oid);
GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
while (NULL != tunnel_get_by_pi (myid, next_tid))
next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
t->id.tid = next_tid++;
+ next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
t->id.oid = myid;
t->local_tid = ntohl (t_msg->tunnel_id);
#if MESH_DEBUG