[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19813 - gnunet/src/gns
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19813 - gnunet/src/gns |
Date: |
Wed, 15 Feb 2012 19:15:52 +0100 |
Author: schanzen
Date: 2012-02-15 19:15:52 +0100 (Wed, 15 Feb 2012)
New Revision: 19813
Modified:
gnunet/src/gns/gns_api.c
gnunet/src/gns/gnunet-service-gns.c
Log:
- added some message types, dns code
Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c 2012-02-15 13:39:46 UTC (rev 19812)
+++ gnunet/src/gns/gns_api.c 2012-02-15 18:15:52 UTC (rev 19813)
@@ -254,10 +254,20 @@
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);
}
+}
+
+
/**
* Perform an asynchronous Lookup operation on the GNS.
*
@@ -283,7 +293,7 @@
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 @@
void
GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle)
{
- struct GNUNET_DHT_Handle *handle;
/* TODO Stop dht lookups */
}
Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-02-15 13:39:46 UTC (rev 19812)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-02-15 18:15:52 UTC (rev 19813)
@@ -26,14 +26,15 @@
#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,10 +50,61 @@
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);
+ }
+ }
+ }
+}
+
/**
* Process GNS requests.
*
@@ -64,9 +116,35 @@
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 @@
(GNUNET_OK ==
GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
NULL)) ? 0 : 1;
- GDS_CLIENTS_done ();
return ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19813 - gnunet/src/gns,
gnunet <=