- fix channel numbering
authorBart Polot <bart@net.in.tum.de>
Thu, 5 Dec 2013 18:57:08 +0000 (18:57 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 5 Dec 2013 18:57:08 +0000 (18:57 +0000)
src/mesh/gnunet-service-mesh_tunnel.c

index 8e1899a34937ad6720ad02893fa4aa683263a180..692a4c879a6ba2941f4e54850f831326ad77eaa0 100644 (file)
@@ -1975,14 +1975,28 @@ MESH_ChannelNumber
 GMT_get_next_chid (struct MeshTunnel3 *t)
 {
   MESH_ChannelNumber chid;
+  MESH_ChannelNumber mask;
+  int result;
+
+  /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID.
+   * If our ID is bigger or loopback tunnel, start at 0, bit 30 = 0
+   * If peer's ID is bigger, start at 0x4... bit 30 = 1
+   */
+  result = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, GMP_get_id (t->peer));
+  if (0 > result)
+    mask = 0x4000000;
+  else
+    mask = 0x0;
 
   while (NULL != GMT_get_channel (t, t->next_chid))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", t->next_chid);
     t->next_chid = (t->next_chid + 1) & ~GNUNET_MESH_LOCAL_CHANNEL_ID_CLI;
+    t->next_chid |= mask;
   }
   chid = t->next_chid;
   t->next_chid = (t->next_chid + 1) & ~GNUNET_MESH_LOCAL_CHANNEL_ID_CLI;
+  t->next_chid |= mask;
 
   return chid;
 }