-moving DNS API into the new direction outlined in my last comment
authorChristian Grothoff <christian@grothoff.org>
Mon, 2 Jan 2012 19:24:13 +0000 (19:24 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 2 Jan 2012 19:24:13 +0000 (19:24 +0000)
src/dns/dns_api_new.c
src/dns/dns_new.h
src/include/gnunet_dns_service-new.h
src/include/gnunet_dnsparser_lib.h

index 0b654e139270e7904f8dd05a09399028bede4cee..a61676a479d99f8e60067e3828cb2878e3177ed6 100644 (file)
@@ -224,8 +224,7 @@ request_handler (void *cls,
   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 @@ request_handler (void *cls,
                                       &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 @@ request_handler (void *cls,
   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 @@ GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh)
   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 @@ GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh)
   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_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,
       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);
 }
index 4f3493db241988310bfb88bedc4c654396cadbd9..7cf3a316a4676dbbaa56140dbfc08b71494c3db0 100644 (file)
@@ -39,38 +39,16 @@ struct GNUNET_DNS_Request
   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;
-
-  /**
-   * 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] */
+  /* followed by original DNS request (without UDP header) */
 
 };
 
@@ -86,27 +64,16 @@ struct GNUNET_DNS_Response
   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;
-
-  /**
-   * Number of bytes of rdata that follow at the end.
-   */
-  uint16_t rdata_length GNUNET_PACKED;
-
-  /* followed by char rdata[rdata_length] */
+  /* followed by original DNS request (without UDP header) */
 
 };
 
index a05f2cd17bd3cfeac8448b2f31c97ff1cb1d050f..06b9a87a10d25a99e3393cc9741302744e5d6cca 100644 (file)
 #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
@@ -82,21 +60,14 @@ struct GNUNET_DNS_RequestHandle;
  * 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 @@ GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *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);
+                          uint16_t reply_length,
+                          const char *reply);
 
 
 /**
index 37e31d24f9485a42abc91b011d036e6f8f57cf61..3aa289e7065f93baf02762e9498ff02d34e9056a 100644 (file)
 #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