Allow the use of all ports and not just 4 per connection
authorPhilipp Tölke <toelke@in.tum.de>
Sat, 5 Mar 2011 11:17:07 +0000 (11:17 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Sat, 5 Mar 2011 11:17:07 +0000 (11:17 +0000)
src/vpn/gnunet-daemon-vpn-helper.c
src/vpn/gnunet-daemon-vpn.c
src/vpn/gnunet-daemon-vpn.h

index 9df2a8cc004fd568a9a09fa3bf879646db38472f..7d9eb7d6ea1a91fcf3f5c69552842916267afb25 100644 (file)
@@ -230,7 +230,7 @@ message_token(void *cls,
                GNUNET_free(key);
                if (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP) &&
                    (port_in_ports(me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
-                    port_in_ports(me->additional_ports, pkt6_udp->udp_hdr.dpt)))
+                    testBit(me->additional_ports, ntohs(pkt6_udp->udp_hdr.dpt))))
                  {
                    size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + sizeof(GNUNET_HashCode) + ntohs(pkt6_udp->udp_hdr.len);
                    struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc(size);
index fa5b1058fe34d517b4813f7e78909689aa348ae4..50c9d14b1ea21f0345b769998c63c1808b40f208 100644 (file)
@@ -264,7 +264,7 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
 
        memcpy(&value->desc, &pkt->service_descr, sizeof(struct GNUNET_vpn_service_descriptor));
 
-       value->additional_ports = 0;
+        memset(value->additional_ports, 0, 8192);
 
         if (GNUNET_NO ==
             GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
@@ -348,19 +348,71 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
     return;
 }
 
+/**
+ * Sets a bit active in a bitArray.
+ *
+ * @param bitArray memory area to set the bit in
+ * @param bitIdx which bit to set
+ */
+void
+setBit (char *bitArray, unsigned int bitIdx)
+{
+  size_t arraySlot;
+  unsigned int targetBit;
+
+  arraySlot = bitIdx / 8;
+  targetBit = (1L << (bitIdx % 8));
+  bitArray[arraySlot] |= targetBit;
+}
+
+/**
+ * Clears a bit from bitArray.
+ *
+ * @param bitArray memory area to set the bit in
+ * @param bitIdx which bit to unset
+ */
+void
+clearBit (char *bitArray, unsigned int bitIdx)
+{
+  size_t slot;
+  unsigned int targetBit;
+
+  slot = bitIdx / 8;
+  targetBit = (1L << (bitIdx % 8));
+  bitArray[slot] = bitArray[slot] & (~targetBit);
+}
+
+/**
+ * Checks if a bit is active in the bitArray
+ *
+ * @param bitArray memory area to set the bit in
+ * @param bitIdx which bit to test
+ * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
+ */
+int
+testBit (char *bitArray, unsigned int bitIdx)
+{
+  size_t slot;
+  unsigned int targetBit;
+
+  slot = bitIdx / 8;
+  targetBit = (1L << (bitIdx % 8));
+  if (bitArray[slot] & targetBit)
+    return GNUNET_YES;
+  else
+    return GNUNET_NO;
+}
+
+/**
+ * @brief Add the port to the list of additional ports in the map_entry
+ *
+ * @param me the map_entry
+ * @param port the port in host-byte-order
+ */
 static void
 add_additional_port (struct map_entry *me, uint16_t port)
 {
-  uint16_t *ps = (uint16_t *) & me->additional_ports;
-  unsigned int i;
-  for (i = 0; i < 4; i++)
-    {
-      if (ps[i] == 0)
-       {
-         ps[i] = port;
-         break;
-       }
-    }
+  setBit(me->additional_ports, port);
 }
 
 static int
@@ -415,8 +467,8 @@ receive_udp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel,
   GNUNET_assert (me != NULL);
   GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP));
   if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) &&
-      !port_in_ports(me->additional_ports, pkt6->udp_hdr.spt)) {
-      add_additional_port(me, pkt6->udp_hdr.spt);
+      !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) {
+      add_additional_port(me, ntohs(pkt6->udp_hdr.spt));
   }
 
   pkt6->udp_hdr.crc = 0;
index 36f3dcbe72153056c256090046d4c20ab118ae57..e0e688f99e968b74390905b2949c739653a4c369 100644 (file)
@@ -72,10 +72,35 @@ struct map_entry {
     struct GNUNET_vpn_service_descriptor desc;
     struct GNUNET_MESH_Tunnel *tunnel;
     uint16_t namelen;
-    uint64_t additional_ports;
+    char additional_ports[8192];
     /**
      * After this struct the name is located in DNS-Format!
      */
 };
 
+/**
+ * Sets a bit active in a bitArray.
+ *
+ * @param bitArray memory area to set the bit in
+ * @param bitIdx which bit to set
+ */
+void setBit (char *bitArray, unsigned int bitIdx);
+
+/**
+ * Clears a bit from bitArray.
+ *
+ * @param bitArray memory area to set the bit in
+ * @param bitIdx which bit to unset
+ */
+void clearBit (char *bitArray, unsigned int bitIdx);
+
+/**
+ * Checks if a bit is active in the bitArray
+ *
+ * @param bitArray memory area to set the bit in
+ * @param bitIdx which bit to test
+ * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
+ */
+int testBit (char *bitArray, unsigned int bitIdx);
+
 #endif /* end of include guard: GNUNET-DAEMON-VPN_H */