gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18917 - in gnunet/src: dns include vpn


From: gnunet
Subject: [GNUnet-SVN] r18917 - in gnunet/src: dns include vpn
Date: Mon, 2 Jan 2012 06:03:07 +0100

Author: grothoff
Date: 2012-01-02 06:03:07 +0100 (Mon, 02 Jan 2012)
New Revision: 18917

Modified:
   gnunet/src/dns/dns_api.c
   gnunet/src/dns/gnunet-service-dns.c
   gnunet/src/include/gnunet_dns_service.h
   gnunet/src/vpn/gnunet-daemon-vpn.c
   gnunet/src/vpn/gnunet-daemon-vpn.h
Log:
-again moving towards DNS API sanity

Modified: gnunet/src/dns/dns_api.c
===================================================================
--- gnunet/src/dns/dns_api.c    2012-01-02 04:40:19 UTC (rev 18916)
+++ gnunet/src/dns/dns_api.c    2012-01-02 05:03:07 UTC (rev 18917)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file vpn/gnunet-daemon-vpn-dns.c
+ * @file dns/dns_api.c
  * @brief
  * @author Philipp Toelke
  */
@@ -56,7 +56,7 @@
 
   const struct GNUNET_CONFIGURATION_Handle *cfg;
 
-  GNUNET_SCHEDULER_Task process_answer_cb;
+  GNUNET_DNS_ResponseCallback process_answer_cb;
   
   void *process_answer_cb_cls;
 };
@@ -177,11 +177,8 @@
 #endif
     return;
   }
-  void *pkt = GNUNET_malloc (ntohs (msg->size));
-
-  memcpy (pkt, msg, ntohs (msg->size));
-
-  GNUNET_SCHEDULER_add_now (h->process_answer_cb, pkt);
+  h->process_answer_cb (h->process_answer_cb_cls,
+                       (const struct answer_packet*) msg);
   GNUNET_CLIENT_receive (h->dns_connection, &dns_answer_handler, h,
                          GNUNET_TIME_UNIT_FOREVER_REL);
 }
@@ -192,7 +189,7 @@
  */
 struct GNUNET_DNS_Handle *
 GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                   GNUNET_SCHEDULER_Task cb,
+                   GNUNET_DNS_ResponseCallback cb,
                    void *cb_cls)
 {
   struct GNUNET_DNS_Handle *h;

Modified: gnunet/src/dns/gnunet-service-dns.c
===================================================================
--- gnunet/src/dns/gnunet-service-dns.c 2012-01-02 04:40:19 UTC (rev 18916)
+++ gnunet/src/dns/gnunet-service-dns.c 2012-01-02 05:03:07 UTC (rev 18917)
@@ -386,7 +386,7 @@
 }
 
 
-void
+static void
 mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
               const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
 {
@@ -1212,7 +1212,7 @@
   return GNUNET_YES;
 }
 
-void
+static void
 handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen,
                  int r);
 
@@ -1320,7 +1320,7 @@
                                  &read_response, NULL);
 }
 
-void
+static void
 handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen,
                  int r)
 {

Modified: gnunet/src/include/gnunet_dns_service.h
===================================================================
--- gnunet/src/include/gnunet_dns_service.h     2012-01-02 04:40:19 UTC (rev 
18916)
+++ gnunet/src/include/gnunet_dns_service.h     2012-01-02 05:03:07 UTC (rev 
18917)
@@ -37,38 +37,44 @@
 #include "gnunet_util_lib.h"
 
 
+/**
+ * Subtypes of DNS answers.
+ */
 enum GNUNET_DNS_ANSWER_Subtype
 {
-    /**
-     * Answers of this type contain a dns-packet that just has to be 
transmitted
-     */
+  /**
+   * Answers of this type contain a dns-packet that just has to be transmitted
+   */
   GNUNET_DNS_ANSWER_TYPE_IP,
 
-    /**
-     * Answers of this type contain an incomplete dns-packet. The IP-Address
-     * is all 0s. The addroffset points to it.
-     */
+  /**
+   * Answers of this type contain an incomplete dns-packet. The IP-Address
+   * is all 0s. The addroffset points to it.
+   */
   GNUNET_DNS_ANSWER_TYPE_SERVICE,
 
-    /**
-     * Answers of this type contain an incomplete dns-packet as answer to a
-     * PTR-Query. The resolved name is not allocated. The addroffset points to 
it.
-     */
+  /**
+   * Answers of this type contain an incomplete dns-packet as answer to a
+   * PTR-Query. The resolved name is not allocated. The addroffset points to 
it.
+   */
   GNUNET_DNS_ANSWER_TYPE_REV,
-
-    /**
-     * Answers of this type contains an IP6-Address but traffic to this IP 
should
-     * be routed through the GNUNet.
-     */
+  
+  /**
+   * Answers of this type contains an IP6-Address but traffic to this IP should
+   * be routed through the GNUNet.
+   */
   GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA,
+  
+  /**
+   * Answers of this type contains an IP4-Address but traffic to this IP should
+   * be routed through the GNUNet.
+   */
+  GNUNET_DNS_ANSWER_TYPE_REMOTE_A
 
-    /**
-     * Answers of this type contains an IP4-Address but traffic to this IP 
should
-     * be routed through the GNUNet.
-     */
-  GNUNET_DNS_ANSWER_TYPE_REMOTE_A
 };
 
+
+GNUNET_NETWORK_STRUCT_BEGIN
 struct GNUNET_vpn_service_descriptor
 {
   GNUNET_HashCode peer GNUNET_PACKED;
@@ -77,7 +83,7 @@
   uint32_t service_type GNUNET_PACKED;
 };
 
-GNUNET_NETWORK_STRUCT_BEGIN
+
 struct answer_packet
 {
   /* General data */
@@ -108,7 +114,9 @@
 
   unsigned char data[1];
 };
+GNUNET_NETWORK_STRUCT_END
 
+
 struct answer_packet_list
 {
   struct answer_packet_list *next GNUNET_PACKED;
@@ -116,18 +124,45 @@
   struct GNUNET_SERVER_Client *client;
   struct answer_packet pkt;
 };
-GNUNET_NETWORK_STRUCT_END
 
+
+/**
+ * Type of a function to be called by the DNS API whenever
+ * a DNS reply is obtained.
+ *
+ * @param cls closure
+ * @param pkt reply that we got
+ */
+typedef void (*GNUNET_DNS_ResponseCallback)(void *cls,
+                                           const struct answer_packet *pkt);
+
+
+/**
+ * Opaque DNS handle
+ */
 struct GNUNET_DNS_Handle;
 
+
 /**
  * Connect to the service-dns
+ *
+ * @param cfg configuration to use
+ * @param cb function to call with DNS replies
+ * @param cb_cls closure to pass to cb
+ * @return DNS handle 
  */
 struct GNUNET_DNS_Handle *
 GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                   GNUNET_SCHEDULER_Task cb,
+                   GNUNET_DNS_ResponseCallback cb,
                    void *cb_cls);
 
+
+/**
+ * Signal the DNS service that it needs to re-initialize the DNS
+ * hijacking (the network setup has changed significantly).
+ *
+ * @param h DNS handle
+ */
 void
 GNUNET_DNS_restart_hijack (struct GNUNET_DNS_Handle *h);
 
@@ -170,7 +205,11 @@
                             size_t udp_packet_len,
                             const char *udp_packet);
 
-
+/**
+ * Disconnect from the DNS service.
+ *
+ * @param h DNS handle
+ */
 void
 GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h);
 

Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c  2012-01-02 04:40:19 UTC (rev 18916)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c  2012-01-02 05:03:07 UTC (rev 18917)
@@ -80,7 +80,48 @@
 
 GNUNET_SCHEDULER_TaskIdentifier shs_task;
 
+
 /**
+ * Sets a bit active in a bitArray.
+ *
+ * @param bitArray memory area to set the bit in
+ * @param bitIdx which bit to set
+ */
+static void
+setBit (char *bitArray, unsigned int bitIdx)
+{
+  size_t arraySlot;
+  unsigned int targetBit;
+
+  arraySlot = bitIdx / 8;
+  targetBit = (1L << (bitIdx % 8));
+  bitArray[arraySlot] |= 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;
+}
+
+
+/**
  * Function scheduled as very last function, cleans up after us
  *{{{
  */
@@ -510,12 +551,9 @@
  * doing nothing for "real" services.
  */
 void
-process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+process_answer (void *cls, 
+               const struct answer_packet *pkt)
 {
-  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
-    return;
-
-  struct answer_packet *pkt = cls;
   struct answer_packet_list *list;
 
   /* This answer is about a .gnunet-service
@@ -525,13 +563,18 @@
    */
   if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE)
   {
-    pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
 
     GNUNET_HashCode key;
 
     memset (&key, 0, sizeof (GNUNET_HashCode));
 
-    unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
+    list =
+        GNUNET_malloc (htons (pkt->hdr.size) +
+                       sizeof (struct answer_packet_list) -
+                       sizeof (struct answer_packet));
+    memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
+
+    unsigned char *c = ((unsigned char *) &list->pkt) + ntohs 
(pkt->addroffset);
     unsigned char *k = (unsigned char *) &key;
 
     new_ip6addr ((struct in6_addr*) c, 
@@ -576,12 +619,8 @@
       GNUNET_free (value);
 
 
-    list =
-        GNUNET_malloc (htons (pkt->hdr.size) +
-                       sizeof (struct answer_packet_list) -
-                       sizeof (struct answer_packet));
+    list->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
 
-    memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
 
   }
   else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV)
@@ -590,7 +629,7 @@
 
     memset (&key, 0, sizeof key);
     unsigned char *k = (unsigned char *) &key;
-    unsigned char *s = pkt->data + 12;
+    const unsigned char *s = pkt->data + 12;
     int i = 0;
 
     /* Whoever designed the reverse IPv6-lookup is batshit insane */
@@ -614,10 +653,7 @@
     uint16_t offset = ntohs (pkt->addroffset);
 
     if (map_entry == NULL)
-    {
-      GNUNET_free (pkt);
       return;
-    }
 
     GNUNET_CONTAINER_heap_update_cost (heap, map_entry->heap_node,
                                        GNUNET_TIME_absolute_get ().abs_value);
@@ -653,16 +689,23 @@
   }
   else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA)
   {
-    pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
 
     GNUNET_HashCode key;
 
     memset (&key, 0, sizeof (GNUNET_HashCode));
 
-    unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
+    list =
+        GNUNET_malloc (htons (pkt->hdr.size) +
+                       sizeof (struct answer_packet_list) -
+                       sizeof (struct answer_packet));
 
+    memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
+    list->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+
+    unsigned char *c = ((unsigned char *) &list->pkt) + ntohs 
(list->pkt.addroffset);
+
     new_ip6addr_remote ((struct in6_addr*) c,
-                       pkt->addr, pkt->addrsize);
+                       list->pkt.addr, list->pkt.addrsize);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "New mapping to 
%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
                 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9],
@@ -707,24 +750,25 @@
     else
       GNUNET_free (value);
 
+
+  }
+  else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_A)
+  {
     list =
         GNUNET_malloc (htons (pkt->hdr.size) +
                        sizeof (struct answer_packet_list) -
                        sizeof (struct answer_packet));
 
     memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
-  }
-  else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_A)
-  {
-    pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+    list->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
 
     GNUNET_HashCode key;
 
     memset (&key, 0, sizeof (GNUNET_HashCode));
 
-    unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
+    unsigned char *c = ((unsigned char *) &list->pkt) + ntohs 
(pkt->addroffset);
 
-    new_ip4addr_remote (c, pkt->addr, pkt->addrsize);
+    new_ip4addr_remote (c, list->pkt.addr, pkt->addrsize);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n", c[0],
                 c[1], c[2], c[3]);
     unsigned char *k = (unsigned char *) &key;
@@ -770,22 +814,13 @@
     else
       GNUNET_free (value);
 
-    list =
-        GNUNET_malloc (htons (pkt->hdr.size) +
-                       sizeof (struct answer_packet_list) -
-                       sizeof (struct answer_packet));
-
-    memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
   }
   else
   {
     GNUNET_break (0);
-    GNUNET_free (pkt);
     return;
   }
 
-  GNUNET_free (pkt);
-
   GNUNET_CONTAINER_DLL_insert_after (answer_proc_head, answer_proc_tail,
                                      answer_proc_tail, list);
 
@@ -794,62 +829,8 @@
   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

Modified: gnunet/src/vpn/gnunet-daemon-vpn.h
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.h  2012-01-02 04:40:19 UTC (rev 18916)
+++ gnunet/src/vpn/gnunet-daemon-vpn.h  2012-01-02 05:03:07 UTC (rev 18917)
@@ -34,15 +34,6 @@
 
 extern struct GNUNET_DNS_Handle *dns_handle;
 
-/**
- * This gets scheduled with cls pointing to an answer_packet and does 
everything
- * needed in order to send it to the helper.
- *
- * At the moment this means "inventing" and IPv6-Address for .gnunet-services 
and
- * doing nothing for "real" services.
- */
-void
-process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 void
 send_icmp6_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -100,24 +91,6 @@
 };
 
 /**
- * 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
@@ -127,6 +100,7 @@
 int
 testBit (char *bitArray, unsigned int bitIdx);
 
+
 struct remote_addr
 {
   char addrlen;




reply via email to

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