aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-11-02 10:14:48 +0000
committerBart Polot <bart@net.in.tum.de>2011-11-02 10:14:48 +0000
commit2ed57ce4ad8b7a3e5c404723c27695ed274ded9b (patch)
treef833fcc8b1f22d0996810f9349ec97570715b2c4 /src/mesh
parent205e3bf8b151fcce80e8682fa5dc722356b11689 (diff)
downloadgnunet-2ed57ce4ad8b7a3e5c404723c27695ed274ded9b.tar.gz
gnunet-2ed57ce4ad8b7a3e5c404723c27695ed274ded9b.zip
Fixed id counters' cycling
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 9939e1683..3920738d7 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1724,24 +1724,45 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1724 1724
1725 1725
1726/** 1726/**
1727 * Search for a tunnel among the tunnels for a client 1727 * Search for a tunnel among the incoming tunnels
1728 * 1728 *
1729 * @param c the client whose tunnels to search in
1730 * @param tid the local id of the tunnel 1729 * @param tid the local id of the tunnel
1731 * 1730 *
1732 * @return tunnel handler, NULL if doesn't exist 1731 * @return tunnel handler, NULL if doesn't exist
1733 */ 1732 */
1734static struct MeshTunnel * 1733static struct MeshTunnel *
1735tunnel_get_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid) 1734tunnel_get_incoming (MESH_TunnelNumber tid)
1736{ 1735{
1737 GNUNET_HashCode hash; 1736 GNUNET_HashCode hash;
1738 1737
1738 GNUNET_assert (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV);
1739 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); 1739 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
1740 return GNUNET_CONTAINER_multihashmap_get (incoming_tunnels, &hash);
1741}
1742
1743
1744/**
1745 * Search for a tunnel among the tunnels for a client
1746 *
1747 * @param c the client whose tunnels to search in
1748 * @param tid the local id of the tunnel
1749 *
1750 * @return tunnel handler, NULL if doesn't exist
1751 */
1752static struct MeshTunnel *
1753tunnel_get_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid)
1754{
1740 if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 1755 if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
1741 { 1756 {
1742 return GNUNET_CONTAINER_multihashmap_get (incoming_tunnels, &hash); 1757 return tunnel_get_incoming (tid);
1758 }
1759 else
1760 {
1761 GNUNET_HashCode hash;
1762
1763 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
1764 return GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
1743 } 1765 }
1744 return GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
1745} 1766}
1746 1767
1747 1768
@@ -2491,9 +2512,10 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2491 t = GNUNET_malloc (sizeof (struct MeshTunnel)); 2512 t = GNUNET_malloc (sizeof (struct MeshTunnel));
2492 t->id.oid = GNUNET_PEER_intern (pi); 2513 t->id.oid = GNUNET_PEER_intern (pi);
2493 t->id.tid = tid; 2514 t->id.tid = tid;
2515 while (NULL != tunnel_get_incoming (next_local_tid))
2516 next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
2494 t->local_tid = next_local_tid++; 2517 t->local_tid = next_local_tid++;
2495 /* FIXME test if taken */ 2518 next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
2496 next_local_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
2497 t->tree = tree_new(t, t->id.oid); 2519 t->tree = tree_new(t, t->id.oid);
2498 2520
2499 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 2521 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
@@ -3536,6 +3558,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
3536 while (NULL != tunnel_get_by_pi (myid, next_tid)) 3558 while (NULL != tunnel_get_by_pi (myid, next_tid))
3537 next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 3559 next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
3538 t->id.tid = next_tid++; 3560 t->id.tid = next_tid++;
3561 next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
3539 t->id.oid = myid; 3562 t->id.oid = myid;
3540 t->local_tid = ntohl (t_msg->tunnel_id); 3563 t->local_tid = ntohl (t_msg->tunnel_id);
3541#if MESH_DEBUG 3564#if MESH_DEBUG