From f49e139a6fbcde654b2130e78665e48712713612 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Thu, 16 Feb 2012 20:05:40 +0000 Subject: [PATCH] - commit after up, ty! --- src/gns/Makefile.am | 16 ++- src/gns/gns.h | 5 + src/gns/gns_api.c | 56 ++++++++-- src/gns/gnunet-gns-add.c | 5 +- src/gns/gnunet-gns-lookup.c | 34 ++---- src/gns/gnunet-service-gns.c | 181 ++++++++++++++++++------------- src/include/gnunet_dht_service.h | 2 +- src/include/gnunet_gns_service.h | 2 +- 8 files changed, 187 insertions(+), 114 deletions(-) diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index aab5d5fba..1dbce3b66 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -12,14 +12,14 @@ pkgcfgdir= $(pkgdatadir)/config.d/ plugindir = $(libdir)/gnunet -pkgcfg_DATA = \ - dns.conf +#pkgcfg_DATA = \ +# dns.conf lib_LTLIBRARIES = \ libgnunetgns.la bin_PROGRAMS = \ - gnunet-service-gns $(HIJACKBIN) + gnunet-service-gns noinst_PROGRAMS = \ gnunet-gns-lookup gnunet-gns-add @@ -37,6 +37,15 @@ gnunet_gns_add_LDADD = \ gnunet_dns_add_DEPENDENCIES = \ libgnunetgns.la +gnunet_gns_lookup_SOURCES = \ + gnunet-gns-lookup.c +gnunet_gns_lookup_LDADD = \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) +gnunet_dns_lookup_DEPENDENCIES = \ + libgnunetgns.la + gnunet_service_gns_SOURCES = \ gnunet-service-gns.c gnunet_service_gns_LDADD = \ @@ -45,6 +54,7 @@ gnunet_service_gns_LDADD = \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/dns/libgnunetdns.la \ + $(top_builddir)/src/dns/libgnunetdnsparser.la \ $(GN_LIBINTL) libgnunetgns_la_SOURCES = \ diff --git a/src/gns/gns.h b/src/gns/gns.h index 695722b78..b7f0f306a 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h @@ -39,6 +39,11 @@ struct GNUNET_GNS_ClientLookupMessage */ struct GNUNET_MessageHeader header; + /** + * A key. TODO some uid + */ + GNUNET_HashCode key; + /** * Unique identifier for this request (for key collisions). */ diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index ed0b447a7..14c1220c9 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -230,6 +230,35 @@ try_connect (struct GNUNET_GNS_Handle *handle) return GNUNET_YES; } +/** + * Add the request corresponding to the given handle + * to the pending queue (if it is not already in there). + * + * @param cls the 'struct GNUNET_GNS_Handle*' + * @param key key for the request (not used) + * @param value the 'struct GNUNET_GNS_LookupHandle*' + * @return GNUNET_YES (always) + */ +static int +add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value) +{ + struct GNUNET_GNS_Handle *handle = cls; + struct GNUNET_GNS_LookupHandle *rh = value; + + if (GNUNET_NO == rh->message->in_pending_queue) + { +#if DEBUG_DHT + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Retransmitting request related to %s to GNS %p\n", GNUNET_h2s(key), + handle); +#endif + GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, + rh->message); + rh->message->in_pending_queue = GNUNET_YES; + } + return GNUNET_YES; +} + /** * Try reconnecting to the GNS service. * @@ -349,10 +378,8 @@ transmit_pending (void *cls, size_t size, void *buf) handle->th = NULL; if (buf == NULL) { -#if DEBUG_GNS - LOG (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission to GNS service failed! Reconnecting!\n"); -#endif do_disconnect (handle); return 0; } @@ -562,6 +589,7 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, /** * Perform an asynchronous Lookup operation on the GNS. + * TODO: Still not sure what we query for... "names" it is for now * * @param handle handle to the GNS service * @param timeout how long to wait for transmission of this request to the service @@ -572,18 +600,26 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, */ struct GNUNET_GNS_LookupHandle * GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, - struct GNUNET_TIME_Relative timeout, - const char * name, - enum GNUNET_GNS_RecordType type, - GNUNET_GNS_LookupIterator iter, - void *iter_cls) + struct GNUNET_TIME_Relative timeout, + const char * name, + enum GNUNET_GNS_RecordType type, + GNUNET_GNS_LookupIterator iter, + void *iter_cls) { /* IPC to look for local entries, start dht lookup, return lookup_handle */ struct GNUNET_GNS_ClientLookupMessage *lookup_msg; struct GNUNET_GNS_LookupHandle *lookup_handle; + GNUNET_HashCode key; size_t msize; struct PendingMessage *pending; + if (NULL == name) + { + return NULL; + } + + GNUNET_CRYPTO_hash (name, strlen(name), &key); + msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name); #if DEBUG_GNS LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lookup for %s in GNS %p\n", @@ -597,6 +633,7 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, lookup_msg->header.size = htons (msize); lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP); lookup_msg->namelen = strlen(name); + lookup_msg->key = key; memcpy(&lookup_msg[1], name, strlen(name)); handle->uid_gen++; lookup_msg->unique_id = handle->uid_gen; @@ -608,7 +645,8 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, lookup_handle->iter_cls = iter_cls; lookup_handle->message = pending; lookup_handle->unique_id = lookup_msg->unique_id; - GNUNET_CONTAINER_multihashmap_put (handle->active_requests, key, lookup_handle, + GNUNET_CONTAINER_multihashmap_put (handle->active_requests, &lookup_msg->key, + lookup_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); process_pending_messages (handle); return lookup_handle; diff --git a/src/gns/gnunet-gns-add.c b/src/gns/gnunet-gns-add.c index bb1d7e1f4..a1beebca3 100644 --- a/src/gns/gnunet-gns-add.c +++ b/src/gns/gnunet-gns-add.c @@ -144,8 +144,9 @@ run (void *cls, char *const *args, const char *cfgfile, if (verbose) FPRINTF (stderr, _("Issuing add request for `%s' with data `%s'!\n"), record_key, data); - GNUNET_GNS_add_record (gns_handle, &record_key, record_type, - strlen (data), data, expiration, timeout); + GNUNET_GNS_add_record (gns_handle, record_key, + 0/*RecordType*/, + strlen (data), data, expiration, timeout); } diff --git a/src/gns/gnunet-gns-lookup.c b/src/gns/gnunet-gns-lookup.c index 2d4f7cb02..f305baf0f 100644 --- a/src/gns/gnunet-gns-lookup.c +++ b/src/gns/gnunet-gns-lookup.c @@ -120,17 +120,12 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param data pointer to the result data */ static void -get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, enum GNUNET_BLOCK_Type type, - size_t size, const void *data) +lookup_result_iterator (void *cls, + const GNUNET_HashCode * key, + const struct GNUNET_GNS_Record *record, + unsigned int num_records) { - FPRINTF (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, - (unsigned int) size, (char *) data); - result_count++; + FPRINTF (stdout, "Results %d\n", num_records); } @@ -147,7 +142,6 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_TIME_Relative timeout; - GNUNET_HashCode key; cfg = c; @@ -159,9 +153,9 @@ run (void *cls, char *const *args, const char *cfgfile, return; } - lookup_handle = GNUNET_GNS_connect (cfg, 1); + gns_handle = GNUNET_GNS_connect (cfg, 1); - if (lookup_handle == NULL) + if (gns_handle == NULL) { if (verbose) FPRINTF (stderr, "%s", "Couldn't connect to GNS service!\n"); @@ -171,11 +165,6 @@ run (void *cls, char *const *args, const char *cfgfile, else if (verbose) FPRINTF (stderr, "%s", "Connected to GNS service!\n"); - if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ - query_type = GNUNET_BLOCK_TYPE_TEST; - - GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request); absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout); @@ -184,10 +173,11 @@ run (void *cls, char *const *args, const char *cfgfile, FPRINTF (stderr, "Issuing lookup request for %s!\n", query_key); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (absolute_timeout), &cleanup_task, NULL); - get_handle = - GNUNET_GNS_lookup_start (lookup_handle, timeout, query_type, &key, replication, - GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, - NULL); + lookup_handle = + GNUNET_GNS_lookup_start (gns_handle, timeout, query_key, + 0/*GNS_RecordType*/, + &lookup_result_iterator, + NULL); } diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 25e066d00..ca732c78e 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -27,20 +27,30 @@ #include "gnunet_util_lib.h" #include "gnunet_transport_service.h" #include "gnunet_dns_service.h" +#include "gnunet_dnsparser_lib.h" #include "gnunet_gns_service.h" -#include "gnunet-service-gns.h" +#include "gns.h" +/* TODO into gnunet_protocols */ +#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 +#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24 + /** * Our handle to the DNS handler library */ -struct GNUNET_DNS_Handle *dns_handler; +struct GNUNET_DNS_Handle *dns_handle; /** * The configuration the GNS service is running with */ const struct GNUNET_CONFIGURATION_Handle *GNS_cfg; +/** + * Our notification context. + */ +static struct GNUNET_SERVER_NotificationContext *nc; + /** * Task run during shutdown. * @@ -50,7 +60,7 @@ const struct GNUNET_CONFIGURATION_Handle *GNS_cfg; static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_DNS_disconnect(dns_handle); + GNUNET_DNS_disconnect(dns_handle); } /** @@ -63,55 +73,74 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ void handle_dns_request(void *cls, - struct GNUNET_DNS_RequestHandle *rh, - size_t request_length, - const char *request) + 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 - **/ + /** + * 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; - 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 - * Check tld and decide if we or - * legacy dns is responsible - **/ - for (i=0;inum_queries;i++) - { - namelen = strlen(&p->queries[i]->name); - if (namelen >= 7) - { - /** - * TODO off by 1? - * Move our tld/root to config file - * Generate fake DNS reply that replaces .gnunet with .org - **/ - if (0 == strcmp((&p->queries[i]->name)+(namelen-7), ".gnunet")) - { - GNUNET_DNS_request_answer(rh, 0 /*length*/, NULL/*reply*/); - } - else - { - GNUNET_DNS_request_forward (rh); - } - } - } + int namelen; + int i; + char *tail; + + 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 + * Check tld and decide if we or + * legacy dns is responsible + **/ + for (i=0;inum_queries;i++) + { + namelen = strlen(p->queries[i].name); + if (namelen >= 7) + { + /** + * TODO off by 1? + * Move our tld/root to config file + * Generate fake DNS reply that replaces .gnunet with .org + **/ + tail = p->queries[i].name+(namelen-7); + if (0 == strcmp(tail, ".gnunet")) + { + /* Do db lookup here. Make dht lookup if necessary */ + GNUNET_DNS_request_answer(rh, 0 /*length*/, NULL/*reply*/); + } + else + { + GNUNET_DNS_request_forward (rh); + } + } + } } +/*TODO*/ +static void +handle_client_record_lookup(void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ +} + +/*TODO*/ +static void +handle_client_record_add(void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ +} /** * Process GNS requests. @@ -124,35 +153,35 @@ static void run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { - /* The IPC message types */ - static const struct GNUNET_SERVER_MessageHandler handlers[] = { - /* callback, cls, type, size */ - {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_LOOKUP, - sizeof (struct GNUNET_GNS_Lookup)}, - {&handle_client_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, + /* The IPC message types */ + static const struct GNUNET_SERVER_MessageHandler handlers[] = { + /* callback, cls, type, size */ + {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP, + 0}, + /*{&handle_client_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_ADD, + 0},*/ + {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 - * */ - 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); - **/ + /** + * 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); + **/ } diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index fd89642c6..e533ef279 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -272,7 +272,7 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, * * @param handle The handle to the monitor request returned by monitor_start. * - * On return get_handle will no longer be valid, caller must not use again!!! + * On return handle will no longer be valid, caller must not use again!!! */ void GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle); diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index 780ddbcca..322a1c9bf 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -80,7 +80,7 @@ enum GNUNET_GNS_RecordType * @return NULL on error */ struct GNUNET_GNS_Handle * -GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg +GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len); -- 2.25.1