gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r18952 - in gnunet/src: dns include
Date: Mon, 2 Jan 2012 20:24:13 +0100

Author: grothoff
Date: 2012-01-02 20:24:13 +0100 (Mon, 02 Jan 2012)
New Revision: 18952

Modified:
   gnunet/src/dns/dns_api_new.c
   gnunet/src/dns/dns_new.h
   gnunet/src/include/gnunet_dns_service-new.h
   gnunet/src/include/gnunet_dnsparser_lib.h
Log:
-moving DNS API into the new direction outlined in my last comment

Modified: gnunet/src/dns/dns_api_new.c
===================================================================
--- gnunet/src/dns/dns_api_new.c        2012-01-02 17:07:20 UTC (rev 18951)
+++ gnunet/src/dns/dns_api_new.c        2012-01-02 19:24:13 UTC (rev 18952)
@@ -224,8 +224,7 @@
   struct GNUNET_DNS_Handle *dh = cls;
   const struct GNUNET_DNS_Request *req;
   struct GNUNET_DNS_RequestHandle *rh;
-  const char *name;
-  uint16_t name_len;
+  size_t payload_length;
 
   /* the service disconnected, reconnect after short wait */
   if (msg == NULL)
@@ -236,20 +235,18 @@
                                       &reconnect, dh);
     return;
   }
-  /* the service did something strange, reconnect immediately */
-  req = (const struct GNUNET_DNS_Request *) msg;
-  name = (const char*) &req[1];
-
   if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST) ||
-       (ntohs (msg->size) < sizeof (struct GNUNET_DNS_Request)) ||
-       (ntohs (msg->size) != sizeof (struct GNUNET_DNS_Request) + ntohs 
(req->rdata_length) + (name_len = ntohs (req->name_length))) ||
-       (name[name_len-1] != '\0') )
+       (ntohs (msg->size) < sizeof (struct GNUNET_DNS_Request)) )
   {
+    /* the service did something strange, reconnect immediately */
     GNUNET_break (0);
     disconnect (dh);
     dh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, dh);
     return;
   }
+  req = (const struct GNUNET_DNS_Request *) msg;
+  GNUNET_break (ntohl (req->reserved) == 0);
+  payload_length = ntohs (req->header.size) - sizeof (struct 
GNUNET_DNS_Request);
   GNUNET_CLIENT_receive (dh->dns_connection, 
                         &request_handler, dh,
                          GNUNET_TIME_UNIT_FOREVER_REL);
@@ -262,12 +259,8 @@
   dh->pending_requests++;
   dh->rh (dh->rh_cls,
          rh,
-         name,
-         ntohs (req->dns_type),
-         ntohs (req->dns_class),
-         ntohl (req->dns_ttl),
-         ntohs (req->rdata_length),
-         &name[name_len]);
+         payload_length,
+         (const char*) &req[1]);
 }
 
 
@@ -393,10 +386,8 @@
   qe->msg = &resp->header;
   resp->header.size = htons (sizeof (struct GNUNET_DNS_Response));
   resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE);
-  resp->dns_ttl = htonl (0);
+  resp->drop_flag = htonl (1);
   resp->request_id = rh->request_id;
-  resp->drop_flag = htons (0);
-  resp->rdata_length = htons (0);
   queue_reply (rh->dh, qe);
   GNUNET_free (rh);
 }
@@ -426,29 +417,26 @@
   qe->msg = &resp->header;
   resp->header.size = htons (sizeof (struct GNUNET_DNS_Response));
   resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE);
-  resp->dns_ttl = htonl (0);
   resp->request_id = rh->request_id;
-  resp->drop_flag = htons (1);
-  resp->rdata_length = htons (0);
+  resp->drop_flag = htonl (0);
   queue_reply (rh->dh, qe);
   GNUNET_free (rh);
 }
 
 
 /**
- * If a GNUNET_DNS_RequestHandler calls this function, the request is supposed 
to
- * be answered with the data provided to this call (with the modifications the 
function might have made).
+ * If a GNUNET_DNS_RequestHandler calls this function, the request is
+ * supposed to be answered with the data provided to this call (with
+ * the modifications the function might have made).
  *
  * @param rh request that should now be answered
- * @param dns_ttl seconds that the RR stays valid, can be updated
- * @param rdata_length size of rdata, can be updated 
- * @param rdata record data, can be updated
+ * @param reply_length size of reply (uint16_t to force sane size)
+ * @param reply reply data
  */
 void
-GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,                
   
-                          uint32_t dns_ttl,
-                          uint16_t rdata_length,
-                          char *rdata)
+GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,         
+                          uint16_t reply_length,
+                          const char *reply)
 {
   struct ReplyQueueEntry *qe;
   struct GNUNET_DNS_Response *resp;
@@ -459,23 +447,21 @@
       GNUNET_free (rh);
       return;
   }
-  if (rdata_length + sizeof (struct GNUNET_DNS_Response) >= 
GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  if (reply_length + sizeof (struct GNUNET_DNS_Response) >= 
GNUNET_SERVER_MAX_MESSAGE_SIZE)
   {
     GNUNET_break (0);
     GNUNET_free (rh);
     return;
   }
   qe = GNUNET_malloc (sizeof (struct ReplyQueueEntry) +
-                     sizeof (struct GNUNET_DNS_Response) + rdata_length);
+                     sizeof (struct GNUNET_DNS_Response) + reply_length);
   resp = (struct GNUNET_DNS_Response*) &qe[1];
   qe->msg = &resp->header;
-  resp->header.size = htons (sizeof (struct GNUNET_DNS_Response) + 
rdata_length);
+  resp->header.size = htons (sizeof (struct GNUNET_DNS_Response) + 
reply_length);
   resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE);
-  resp->dns_ttl = htonl (dns_ttl);
+  resp->drop_flag = htons (2);
   resp->request_id = rh->request_id;
-  resp->drop_flag = htons (0);
-  resp->rdata_length = htons (rdata_length);
-  memcpy (&resp[1], rdata, rdata_length);
+  memcpy (&resp[1], reply, reply_length);
   queue_reply (rh->dh, qe);
   GNUNET_free (rh);
 }

Modified: gnunet/src/dns/dns_new.h
===================================================================
--- gnunet/src/dns/dns_new.h    2012-01-02 17:07:20 UTC (rev 18951)
+++ gnunet/src/dns/dns_new.h    2012-01-02 19:24:13 UTC (rev 18952)
@@ -39,39 +39,17 @@
   struct GNUNET_MessageHeader header;
 
   /**
-   * A DNS type (GNUNET_DNS_TYPE_*)
+   * Always zero.
    */
-  uint16_t dns_type GNUNET_PACKED;
+  uint32_t reserved GNUNET_PACKED;
   
   /**
-   * A DNS class (usually 1).
-   */
-  uint16_t dns_class GNUNET_PACKED;
-
-  /**
    * Unique request ID.
    */
   uint64_t request_id GNUNET_PACKED;
 
-  /**
-   * TTL if rdata is present, otherwise 0.
-   */
-  uint32_t dns_ttl GNUNET_PACKED;
+  /* followed by original DNS request (without UDP header) */
 
-  /**
-   * Number of bytes of rdata that follow at the end.
-   */
-  uint16_t rdata_length GNUNET_PACKED;
-
-  /**
-   * Number of bytes of the name that follow right now (including 
0-termination).
-   */
-  uint16_t name_length GNUNET_PACKED;
-  
-  /* followed by char name[name_length] */
-
-  /* followed by char rdata[rdata_length] */
-
 };
 
 
@@ -86,28 +64,17 @@
   struct GNUNET_MessageHeader header;
 
   /**
-   * TTL if rdata is present, otherwise 0.
+   * Zero to drop, 1 for no change (no payload), 2 for update (message has 
payload).
    */
-  uint32_t dns_ttl GNUNET_PACKED;
-
+  uint32_t drop_flag GNUNET_PACKED;
+  
   /**
-   * Unique request ID, matches the original request.
+   * Unique request ID.
    */
   uint64_t request_id GNUNET_PACKED;
 
-  /**
-   * 1 to drop request, 0 to forward if there is no response
-   * or to answer if there is a response.
-   */
-  uint16_t drop_flag GNUNET_PACKED;
+  /* followed by original DNS request (without UDP header) */
 
-  /**
-   * Number of bytes of rdata that follow at the end.
-   */
-  uint16_t rdata_length GNUNET_PACKED;
-
-  /* followed by char rdata[rdata_length] */
-
 };
 
 

Modified: gnunet/src/include/gnunet_dns_service-new.h
===================================================================
--- gnunet/src/include/gnunet_dns_service-new.h 2012-01-02 17:07:20 UTC (rev 
18951)
+++ gnunet/src/include/gnunet_dns_service-new.h 2012-01-02 19:24:13 UTC (rev 
18952)
@@ -29,30 +29,8 @@
 #include "gnunet_common.h"
 #include "gnunet_util_lib.h"
 
-/**
- * A few common DNS types.
- */
-#define GNUNET_DNS_TYPE_A 1
-#define GNUNET_DNS_TYPE_NS 2
-#define GNUNET_DNS_TYPE_CNAME 5
-#define GNUNET_DNS_TYPE_SOA 6
-#define GNUNET_DNS_TYPE_PTR 12
-#define GNUNET_DNS_TYPE_MX 15
-#define GNUNET_DNS_TYPE_TXT 16
-#define GNUNET_DNS_TYPE_AAAA 28
-#define GNUNET_DNS_TYPE_IXFR 251
-#define GNUNET_DNS_TYPE_AXFR 252
 
 /**
- * A few common DNS classes (ok, only one is common, but I list a
- * couple more to make it clear what we're talking about here).
- */
-#define GNUNET_DNS_CLASS_INTERNET 1
-#define GNUNET_DNS_CLASS_CHAOS 3
-#define GNUNET_DNS_CLASS_HESIOD 4
-
-
-/**
  * Opaque DNS handle
  */
 struct GNUNET_DNS_Handle;
@@ -82,21 +60,14 @@
  * functions call GNUNET_DNS_request_drop, the response is dropped.
  *
  * @param cls closure
- * @param name name of the node to which the record pertains
- * @param dns_type type of RR
- * @param dns_class class code
- * @param dns_ttl seconds that the RR stays valid, can be updated
- * @param rdata_length size of rdata, can be updated 
- * @param rdata record data, can be updated
+ * @param rh request handle to user for reply
+ * @param request_length number of bytes in request
+ * @param request udp payload of the DNS request
  */
 typedef void (*GNUNET_DNS_RequestHandler)(void *cls,
                                          struct GNUNET_DNS_RequestHandle *rh,
-                                         const char *name,
-                                         uint16_t dns_type,
-                                         uint16_t dns_class,
-                                         uint32_t dns_ttl,
-                                         uint16_t rdata_length,
-                                         const char *rdata);
+                                         size_t request_length,
+                                         const char *request);
 
 
 /**
@@ -124,19 +95,18 @@
 
 
 /**
- * If a GNUNET_DNS_RequestHandler calls this function, the request is supposed 
to
- * be answered with the data provided to this call (with the modifications the 
function might have made).
+ * If a GNUNET_DNS_RequestHandler calls this function, the request is
+ * supposed to be answered with the data provided to this call (with
+ * the modifications the function might have made).
  *
  * @param rh request that should now be answered
- * @param dns_ttl seconds that the RR stays valid, can be updated
- * @param rdata_length size of rdata, can be updated 
- * @param rdata record data, can be updated
+ * @param reply_length size of reply (uint16_t to force sane size)
+ * @param reply reply data
  */
 void
 GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,                
   
-                          uint32_t dns_ttl,
-                          uint16_t rdata_length,
-                          char *rdata);
+                          uint16_t reply_length,
+                          const char *reply);
 
 
 /**

Modified: gnunet/src/include/gnunet_dnsparser_lib.h
===================================================================
--- gnunet/src/include/gnunet_dnsparser_lib.h   2012-01-02 17:07:20 UTC (rev 
18951)
+++ gnunet/src/include/gnunet_dnsparser_lib.h   2012-01-02 19:24:13 UTC (rev 
18952)
@@ -29,6 +29,29 @@
 #include "platform.h"
 #include "gnunet_common.h"
 
+/**
+ * A few common DNS types.
+ */
+#define GNUNET_DNS_TYPE_A 1
+#define GNUNET_DNS_TYPE_NS 2
+#define GNUNET_DNS_TYPE_CNAME 5
+#define GNUNET_DNS_TYPE_SOA 6
+#define GNUNET_DNS_TYPE_PTR 12
+#define GNUNET_DNS_TYPE_MX 15
+#define GNUNET_DNS_TYPE_TXT 16
+#define GNUNET_DNS_TYPE_AAAA 28
+#define GNUNET_DNS_TYPE_IXFR 251
+#define GNUNET_DNS_TYPE_AXFR 252
+
+/**
+ * A few common DNS classes (ok, only one is common, but I list a
+ * couple more to make it clear what we're talking about here).
+ */
+#define GNUNET_DNS_CLASS_INTERNET 1
+#define GNUNET_DNS_CLASS_CHAOS 3
+#define GNUNET_DNS_CLASS_HESIOD 4
+
+
 // DNS-Stuff
 GNUNET_NETWORK_STRUCT_BEGIN
 




reply via email to

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