gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r14596 - gnunet/src/vpn


From: gnunet
Subject: [GNUnet-SVN] r14596 - gnunet/src/vpn
Date: Sat, 5 Mar 2011 12:17:07 +0100

Author: toelke
Date: 2011-03-05 12:17:07 +0100 (Sat, 05 Mar 2011)
New Revision: 14596

Modified:
   gnunet/src/vpn/gnunet-daemon-vpn-helper.c
   gnunet/src/vpn/gnunet-daemon-vpn.c
   gnunet/src/vpn/gnunet-daemon-vpn.h
Log:
Allow the use of all ports and not just 4 per connection

Modified: gnunet/src/vpn/gnunet-daemon-vpn-helper.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn-helper.c   2011-03-04 14:55:33 UTC (rev 
14595)
+++ gnunet/src/vpn/gnunet-daemon-vpn-helper.c   2011-03-05 11:17:07 UTC (rev 
14596)
@@ -230,7 +230,7 @@
                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);

Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c  2011-03-04 14:55:33 UTC (rev 14595)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c  2011-03-05 11:17:07 UTC (rev 14596)
@@ -264,7 +264,7 @@
 
        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 @@
     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 @@
   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;

Modified: gnunet/src/vpn/gnunet-daemon-vpn.h
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.h  2011-03-04 14:55:33 UTC (rev 14595)
+++ gnunet/src/vpn/gnunet-daemon-vpn.h  2011-03-05 11:17:07 UTC (rev 14596)
@@ -72,10 +72,35 @@
     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 */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]