- added some message types, dns code
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 15 Feb 2012 18:15:52 +0000 (18:15 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 15 Feb 2012 18:15:52 +0000 (18:15 +0000)
src/gns/gns_api.c
src/gns/gnunet-service-gns.c

index 46b140ac7e7c7c798d5d96a1554d4a22d9be9ff1..e6b1b95137b398d9e1000750804d830b935b83e7 100644 (file)
@@ -254,7 +254,17 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode *
                 struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont,
                 void *cont_cls)
 {
-       /* add record to local db, dht; sign etc */
+       /**
+        * build add record message
+        */
+       struct GNUNET_GNS_Record *record;
+
+       record = GNUNET_malloc(sizeof (struct GNUNET_GNS_Record));
+       /* TODO fill */
+       queue_record_msg(handle, record);
+}
+
+
 }
 
 
@@ -283,7 +293,7 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
                       size_t xquery_size, GNUNET_GNS_LookupIterator iter,
                       void *iter_cls)
 {
-  /* look for local entries, start dht lookup, return lookup_handle */
+  /* IPC to look for local entries, start dht lookup, return lookup_handle */
 }
 
 
@@ -295,7 +305,6 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
 void
 GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle)
 {
-  struct GNUNET_DHT_Handle *handle;
        /* TODO Stop dht lookups */
 }
 
index 8ca022d3f54a5fd60762cefec8480b56a90bb1dd..ba368122c6f980be0836cd6e6a13e57517359bcd 100644 (file)
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_transport_service.h"
+#include "gnunet_dns_service.h"
 #include "gnunet_gns_service.h"
 #include "gnunet-service-gns.h"
 
 
 /**
- * Our handle to the BLOCK library.
+ * Our handle to the DNS handler library
  */
-struct GNUNET_BLOCK_Context *GDS_block_context;
+struct GNUNET_DNS_Handle *dns_handler;
 
 /**
  * The configuration the GNS service is running with
@@ -49,7 +50,58 @@ const struct GNUNET_CONFIGURATION_Handle *GDS_cfg;
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-       /* TODO: Do sth here */
+       GNUNET_DNS_disconnect(dns_handle);
+}
+
+/**
+ * The DNS request handler
+ *
+ * @param cls closure
+ * @param rh request handle to user for reply
+ * @param request_length number of bytes in request
+ * @param request udp payload of the DNS request
+ */
+void
+handle_dns_request(void *cls,
+                                                                        struct GNUNET_DNS_RequestHandle *rh,
+                                                                        size_t request_length,
+                                                                        const char *request)
+{
+       /**
+        * TODO: parse request for tld
+        * Queue rh and gns handle (or use cls)
+        * How should lookup behave:
+        *  - sync and return result or "NX"
+        *  - async like dht with iter
+        *  Maybe provide both, useful for cli app
+        **/
+  struct GNUNET_DNSPARSER_Packet *p;
+       char buf[INET6_ADDRSTRLEN];
+       int namelen;
+       
+       p = GNUNET_DNSPARSER_parse (request, request_length);
+       if (NULL == p)
+       {
+               fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n");
+               GNUNET_DNS_request_forward (rh);
+               return;
+       }
+       /* TODO factor out */
+       for (i=0;i<p->num_queries;i++)
+       {
+               namelen = strlen(&p->queries[i]->name);
+               if (namelen >= 7)
+               {
+                       if (0 == strcmp(&p->queries[i]->name, ".gnunet"))
+                       {
+                               GNUNET_DNS_request_answer(rh, 0 /*length*/, NULL/*reply*/);
+                       }
+                       else
+                       {
+                               GNUNET_DNS_request_forward (rh);
+                       }
+               }
+       }
 }
 
 
@@ -64,9 +116,35 @@ static void
 run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+       /* The IPC message types */
+       static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+               /* callback, cls, type, size */
+               {&handle_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_LOOKUP,
+                       sizeof (struct GNUNET_GNS_Lookup)},
+               {&handle_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_ADD,
+                       sizeof (struct GNUNET_GNS_Record)},
+               {NULL, NULL, 0, 0}
+       };
+       
+       nc = GNUNET_SERVER_notification_context_create (server, 1);
+
+       /* TODO do some config parsing */
+
+       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
                                 NULL);
-       /* Do gnunet dns init here */
+       /**
+        * Do gnunet dns init here
+        * */
+       dns_handle = GNUNET_DNS_connect(c,
+                                                                                                                                       GNUNET_DNS_FLAG_PRE_RESOLUTION,
+                                                                                                                                       &handle_dns_request, /* rh */
+                                                                                                                                       NULL); /* Closure */
+       GNUNET_SERVER_add_handlers (server, handlers);
+       /**
+        * Esp the lookup would require to keep track of the clients' context
+        * See dht.
+        * GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
+        * */
 }
 
 
@@ -86,7 +164,6 @@ main (int argc, char *const *argv)
       (GNUNET_OK ==
        GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
                            NULL)) ? 0 : 1;
-  GDS_CLIENTS_done ();
   return ret;
 }