From: Martin Schanzenbach Date: Wed, 15 Feb 2012 18:15:52 +0000 (+0000) Subject: - added some message types, dns code X-Git-Tag: initial-import-from-subversion-38251~14844 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d5e18c09d882a938f10524bd685a0c67dbc8cbc8;p=oweals%2Fgnunet.git - added some message types, dns code --- diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 46b140ac7..e6b1b9513 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -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 */ } diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 8ca022d3f..ba368122c 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -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,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;inum_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; }