From bd742f26f08fed45b48eeb1567447acd7a77d350 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Thu, 16 Feb 2012 14:21:22 +0000 Subject: [PATCH] - added makefile, borrowed lots of code from dht for client handling --- src/gns/Makefile.am | 62 +++++ src/gns/gns.h | 93 +++++++ src/gns/gns_api.c | 400 +++++++++++++++++++++++++++---- src/gns/gnunet-gns-add.c | 8 +- src/gns/gnunet-service-gns.c | 22 +- src/include/gnunet_gns_service.h | 57 +++-- 6 files changed, 563 insertions(+), 79 deletions(-) create mode 100644 src/gns/Makefile.am create mode 100644 src/gns/gns.h diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am new file mode 100644 index 000000000..aab5d5fba --- /dev/null +++ b/src/gns/Makefile.am @@ -0,0 +1,62 @@ +INCLUDES = -I$(top_srcdir)/src/include + +if MINGW + WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols +endif + +if USE_COVERAGE + AM_CFLAGS = --coverage -O0 +endif + +pkgcfgdir= $(pkgdatadir)/config.d/ + +plugindir = $(libdir)/gnunet + +pkgcfg_DATA = \ + dns.conf + +lib_LTLIBRARIES = \ + libgnunetgns.la + +bin_PROGRAMS = \ + gnunet-service-gns $(HIJACKBIN) + +noinst_PROGRAMS = \ + gnunet-gns-lookup gnunet-gns-add + +#check_SCRIPTS = \ +# test_gnunet_dns.sh + + +gnunet_gns_add_SOURCES = \ + gnunet-gns-add.c +gnunet_gns_add_LDADD = \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) +gnunet_dns_add_DEPENDENCIES = \ + libgnunetgns.la + +gnunet_service_gns_SOURCES = \ + gnunet-service-gns.c +gnunet_service_gns_LDADD = \ + $(top_builddir)/src/tun/libgnunettun.la \ + $(top_builddir)/src/mesh/libgnunetmesh.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/dns/libgnunetdns.la \ + $(GN_LIBINTL) + +libgnunetgns_la_SOURCES = \ + gns_api.c gns.h +libgnunetgns_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la $(XLIB) +libgnunetgns_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) + +if ENABLE_TEST_RUN +TESTS = $(check_PROGRAMS) $(check_SCRIPTS) +endif + +EXTRA_DIST = \ + $(check_SCRIPTS) diff --git a/src/gns/gns.h b/src/gns/gns.h new file mode 100644 index 000000000..e35df7858 --- /dev/null +++ b/src/gns/gns.h @@ -0,0 +1,93 @@ +/* + This file is part of GNUnet + (C) 2012 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +/** + * @file gns/gns.h + * @brief IPC messages between GNS API and GNS service + * @author Martin Schanzenbach + */ +#ifndef GNS_H +#define GNS_H + +GNUNET_NETWORK_STRUCT_BEGIN + + +/** + * Message from client to GNS service to lookup records. + */ +struct GNUNET_GNS_ClientLookupMessage +{ + /** + * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP + */ + struct GNUNET_MessageHeader header; + + /** + * Unique identifier for this request (for key collisions). + */ + uint64_t unique_id; + + /** + * the type of record to look up + */ + int type; + + /** + * Length of name to lookup + */ + uint32_t namelen; + + /* Followed by the name to look up */ +}; + + +/** + * Message from GNS service to client: new results. + */ +struct GNUNET_GNS_ClientResultMessage +{ + /** + * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT + */ + struct GNUNET_MessageHeader header; + + /** + * Unique identifier for this request (for key collisions). + */ + uint64_t unique_id; + + /** + * A key. TODO some uid + */ + GNUNET_HashCode key; + + /** + * The number of records contained in response + */ + uint32_t num_records; + + /* followed by num_records GNUNET_GNS_Records*/ + +}; + + +GNUNET_NETWORK_STRUCT_END + +#endif diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index e6b1b9513..ed0b447a7 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -31,11 +31,79 @@ #include "gnunet_hello_lib.h" #include "gnunet_protocols.h" #include "gnunet_dht_service.h" +#include "gns.h" +#include "gnunet_gns_service.h" #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) +/* TODO into gnunet_protocols */ +#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 +#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24 + +/** + * Entry in our list of messages to be (re-)transmitted. + */ +struct PendingMessage +{ + /** + * This is a doubly-linked list. + */ + struct PendingMessage *prev; + + /** + * This is a doubly-linked list. + */ + struct PendingMessage *next; + + /** + * Message that is pending, allocated at the end + * of this struct. + */ + const struct GNUNET_MessageHeader *msg; + + /** + * Handle to the GNS API context. + */ + struct GNUNET_GNS_Handle *handle; + + /** + * Continuation to call when the request has been + * transmitted (for the first time) to the service; can be NULL. + */ + GNUNET_SCHEDULER_Task cont; + + /** + * Closure for 'cont'. + */ + void *cont_cls; + + /** + * Timeout task for this message + */ + GNUNET_SCHEDULER_TaskIdentifier timeout_task; + + /** + * Unique ID for this request + */ + uint64_t unique_id; + + /** + * Free the saved message once sent, set to GNUNET_YES for messages + * that do not receive responses; GNUNET_NO if this pending message + * is aliased from a 'struct GNUNET_DHT_RouteHandle' and will be freed + * from there. + */ + + int free_on_send; + /** + * GNUNET_YES if this message is in our pending queue right now. + */ + int in_pending_queue; + +}; + /** * Handle to a Lookup request */ @@ -67,8 +135,17 @@ struct GNUNET_GNS_LookupHandle */ uint64_t unique_id; + struct PendingMessage *message; + }; +/** + * A GNS Record. + */ +struct GNUNET_GNS_Record +{ + enum GNUNET_GNS_RecordType type; +}; /** * Connection to the GNS service. @@ -91,6 +168,21 @@ struct GNUNET_GNS_Handle */ struct GNUNET_CLIENT_TransmitHandle *th; + /** + * Head of linked list of messages we would like to transmit. + */ + struct PendingMessage *pending_head; + + /** + * Tail of linked list of messages we would like to transmit. + */ + struct PendingMessage *pending_tail; + + /** + * Hash map containing the current outstanding unique requests. + */ + struct GNUNET_CONTAINER_MultiHashMap *active_requests; + GNUNET_SCHEDULER_TaskIdentifier reconnect_task; /** @@ -110,6 +202,12 @@ struct GNUNET_GNS_Handle int in_receive; }; +/** + * Try to send messages from list of messages to send + * @param handle GNS_Handle + */ +static void +process_pending_messages (struct GNUNET_GNS_Handle *handle); /** * Try to (re)connect to the GNS service. @@ -143,7 +241,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_GNS_Handle *handle = cls; -#if DEBUG_DHT +#if DEBUG_GNS LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with GNS %p\n", handle); #endif handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; @@ -156,7 +254,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; if (GNUNET_YES != try_connect (handle)) { -#if DEBUG_DHT +#if DEBUG_GNS LOG (GNUNET_ERROR_TYPE_DEBUG, "GNS reconnect failed(!)\n"); #endif return; @@ -190,11 +288,215 @@ do_disconnect (struct GNUNET_GNS_Handle *handle) GNUNET_SCHEDULER_add_delayed (handle->retry_time, &try_reconnect, handle); } +/** + * Transmit the next pending message, called by notify_transmit_ready + */ +static size_t +transmit_pending (void *cls, size_t size, void *buf); + +/** + * Handler for messages received from the GNS service + * + * @param cls the 'struct GNUNET_GNS_Handle' + * @param msg the incoming message + */ +static void +message_handler (void *cls, const struct GNUNET_MessageHeader *msg); + +/** + * Try to send messages from list of messages to send + */ +static void +process_pending_messages (struct GNUNET_GNS_Handle *handle) +{ + struct PendingMessage *head; + + if (handle->client == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "process_pending_messages called, but client is null, reconnecting\n"); + do_disconnect (handle); + return; + } + if (handle->th != NULL) + return; + if (NULL == (head = handle->pending_head)) + return; + handle->th = + GNUNET_CLIENT_notify_transmit_ready (handle->client, + ntohs (head->msg->size), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &transmit_pending, + handle); + if (NULL != handle->th) + return; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "notify_transmit_ready returned NULL, reconnecting\n"); + do_disconnect (handle); +} + + +/** + * Transmit the next pending message, called by notify_transmit_ready + */ +static size_t +transmit_pending (void *cls, size_t size, void *buf) +{ + struct GNUNET_GNS_Handle *handle = cls; + struct PendingMessage *head; + size_t tsize; + + handle->th = NULL; + if (buf == NULL) + { +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission to GNS service failed! Reconnecting!\n"); +#endif + do_disconnect (handle); + return 0; + } + if (NULL == (head = handle->pending_head)) + return 0; + + tsize = ntohs (head->msg->size); + if (size < tsize) + { + process_pending_messages (handle); + return 0; + } + memcpy (buf, head->msg, tsize); + GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, + head); + head->in_pending_queue = GNUNET_NO; + if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (head->timeout_task); + head->timeout_task = GNUNET_SCHEDULER_NO_TASK; + } + if (GNUNET_YES == head->free_on_send) + GNUNET_free (head); + process_pending_messages (handle); +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Forwarded request of %u bytes to GNS service\n", (unsigned int) tsize); +#endif + if (GNUNET_NO == handle->in_receive) + { +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting to process replies from GNS\n"); +#endif + handle->in_receive = GNUNET_YES; + GNUNET_CLIENT_receive (handle->client, &message_handler, handle, + GNUNET_TIME_UNIT_FOREVER_REL); + } + return tsize; +} + +/** + * Process a given reply that might match the given + * request. + * + * @param cls the 'struct GNUNET_GNS_ClientResultMessage' + * @param key query of the request + * @param value the 'struct GNUNET_GNS_LookupHandle' of a request matching the same key + * @return GNUNET_YES to continue to iterate over all results, + * GNUNET_NO if the reply is malformed + */ +static int +process_reply (void *cls, const GNUNET_HashCode * key, void *value) +{ + const struct GNUNET_GNS_ClientResultMessage *gns_msg = cls; + struct GNUNET_GNS_LookupHandle *lookup_handle = value; + const struct GNUNET_GNS_Record *records; + uint32_t num_records; + size_t meta_length; + size_t msize; + + if (gns_msg->unique_id != lookup_handle->unique_id) + { + /* UID mismatch */ +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Ignoring reply for %s: UID mismatch: %llu/%llu\n", GNUNET_h2s (key), + gns_msg->unique_id, lookup_handle->unique_id); +#endif + return GNUNET_YES; + } + msize = ntohs (gns_msg->header.size); + num_records = ntohl (gns_msg->num_records); + meta_length = + sizeof (struct GNUNET_GNS_ClientResultMessage) + + sizeof (struct GNUNET_GNS_Record) * (num_records); + if ((msize < meta_length) || + (num_records > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_GNS_Record))) + { + GNUNET_break (0); + return GNUNET_NO; + } +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n", + (unsigned int) (msize - meta_length), GNUNET_h2s (key)); +#endif + records = (const struct GNUNET_GNS_Record *) &gns_msg[1]; + lookup_handle->iter (lookup_handle->iter_cls, key, records, num_records); + return GNUNET_YES; +} + + +/** + * Handler for messages received from the GNS service + * + * @param cls the 'struct GNUNET_GNS_Handle' + * @param msg the incoming message + */ +static void +message_handler (void *cls, const struct GNUNET_MessageHeader *msg) +{ + struct GNUNET_GNS_Handle *handle = cls; + const struct GNUNET_GNS_ClientResultMessage *gns_msg; + + if (msg == NULL) + { +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Error receiving data from GNS service, reconnecting\n"); +#endif + do_disconnect (handle); + return; + } + if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT) + { + GNUNET_break (0); + do_disconnect (handle); + return; + } + if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientResultMessage)) + { + GNUNET_break (0); + do_disconnect (handle); + return; + } + gns_msg = (const struct GNUNET_GNS_ClientResultMessage *) msg; +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply for `%s' from GNS service %p\n", + &gns_msg->name, handle); +#endif + /* TODO uniquely identify requests... maybe hash(name) or uid */ + GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, + &gns_msg->key, &process_reply, + (void *) gns_msg); + GNUNET_CLIENT_receive (handle->client, &message_handler, handle, + GNUNET_TIME_UNIT_FOREVER_REL); +} + /** * Initialize the connection with the GNS service. * * @param cfg configuration to use + * @param ht_len size of the internal hash table to use for parallel requests * @return handle to the GNS service, or NULL on error */ struct GNUNET_GNS_Handle * @@ -225,7 +527,7 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) { - /* disco from GNS */ + /* disco from GNS */ } @@ -233,38 +535,28 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) * Add a new record to the GNS. * * @param handle handle to GNS service - * @param key the key to store under - * @param desired_replication_level estimate of how many - * nearest peers this request should reach - * @param options routing options for this message - * @param type type of the value - * @param size number of bytes in data; must be less than 64k - * @param data the data to store + * @param record the record to store * @param exp desired expiration time for the value * @param timeout how long to wait for transmission of this request - * @param cont continuation to call when done (transmitting request to service) - * @param cont_cls closure for cont */ void -GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode * key, - uint32_t desired_replication_level, - enum GNUNET_DHT_RouteOption options, - enum GNUNET_BLOCK_Type type, size_t size, const char *data, - struct GNUNET_TIME_Absolute exp, - struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont, - void *cont_cls) +GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, + const char* name, + enum GNUNET_GNS_RecordType type, + size_t size, const char *data, + struct GNUNET_TIME_Absolute exp, + struct GNUNET_TIME_Relative timeout) { - /** - * build add record message - */ - struct GNUNET_GNS_Record *record; - - record = GNUNET_malloc(sizeof (struct GNUNET_GNS_Record)); - /* TODO fill */ - queue_record_msg(handle, record); -} - + /** + * build add record message + */ + struct GNUNET_GNS_Record *record; + record = GNUNET_malloc(sizeof (struct GNUNET_GNS_Record)); + /** + * TODO + * queue_record_msg(handle, record); + **/ } @@ -273,13 +565,7 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode * * * @param handle handle to the GNS service * @param timeout how long to wait for transmission of this request to the service - * @param type expected type of the response object - * @param key the key to look up - * @param desired_replication_level estimate of how many - nearest peers this request should reach - * @param options routing options for this message - * @param xquery extended query data (can be NULL, depending on type) - * @param xquery_size number of bytes in xquery + * @param name the name to look up * @param iter function to call on each result * @param iter_cls closure for iter * @return handle to stop the async get @@ -287,13 +573,45 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode * struct GNUNET_GNS_LookupHandle * GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, struct GNUNET_TIME_Relative timeout, - enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, - uint32_t desired_replication_level, - enum GNUNET_DHT_RouteOption options, const void *xquery, - size_t xquery_size, GNUNET_GNS_LookupIterator iter, + 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; + size_t msize; + struct PendingMessage *pending; + + msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name); +#if DEBUG_GNS + LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lookup for %s in GNS %p\n", + name, handle); +#endif + pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); + lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1]; + pending->msg = &lookup_msg->header; + pending->handle = handle; + pending->free_on_send = GNUNET_NO; + lookup_msg->header.size = htons (msize); + lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP); + lookup_msg->namelen = strlen(name); + memcpy(&lookup_msg[1], name, strlen(name)); + handle->uid_gen++; + lookup_msg->unique_id = handle->uid_gen; + GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, + pending); + pending->in_pending_queue = GNUNET_YES; + lookup_handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_LookupHandle)); + lookup_handle->iter = iter; + 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_MULTIHASHMAPOPTION_MULTIPLE); + process_pending_messages (handle); + return lookup_handle; } @@ -305,7 +623,7 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, void GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle) { - /* TODO Stop dht lookups */ + /* TODO Stop dht lookups */ } diff --git a/src/gns/gnunet-gns-add.c b/src/gns/gnunet-gns-add.c index bc4843a96..bb1d7e1f4 100644 --- a/src/gns/gnunet-gns-add.c +++ b/src/gns/gnunet-gns-add.c @@ -134,9 +134,6 @@ run (void *cls, char *const *args, const char *cfgfile, else if (verbose) FPRINTF (stderr, _("Connected to %s service!\n"), "GNS"); - if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ - query_type = GNUNET_BLOCK_TYPE_TEST; - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request); expiration = @@ -147,9 +144,8 @@ 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 (gns_handle, &record_key, replication, GNUNET_DHT_RO_NONE, record_type, - strlen (data), data, expiration, timeout, &message_sent_cont, - NULL); + GNUNET_GNS_add_record (gns_handle, &record_key, record_type, + strlen (data), data, expiration, timeout); } diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index ba368122c..25e066d00 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -39,7 +39,7 @@ struct GNUNET_DNS_Handle *dns_handler; /** * The configuration the GNS service is running with */ -const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; +const struct GNUNET_CONFIGURATION_Handle *GNS_cfg; /** * Task run during shutdown. @@ -76,7 +76,6 @@ handle_dns_request(void *cls, * 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); @@ -86,13 +85,22 @@ handle_dns_request(void *cls, GNUNET_DNS_request_forward (rh); return; } - /* TODO factor out */ + /** + * 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) { - if (0 == strcmp(&p->queries[i]->name, ".gnunet")) + /** + * 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*/); } @@ -119,9 +127,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, /* 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, + {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_LOOKUP, sizeof (struct GNUNET_GNS_Lookup)}, - {&handle_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_ADD, + {&handle_client_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_ADD, sizeof (struct GNUNET_GNS_Record)}, {NULL, NULL, 0, 0} }; @@ -144,7 +152,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, * 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_gns_service.h b/src/include/gnunet_gns_service.h index 405fcd2fc..235785116 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -48,14 +48,32 @@ struct GNUNET_GNS_Handle; */ struct GNUNET_GNS_LookupHandle; +/** + * A single GNS record. + */ +struct GNUNET_GNS_Record; + +/** + * Records types + */ +enum GNUNET_GNS_RecordType +{ + GNUNET_GNS_RECORD_A, + GNUNET_GNS_RECORD_AAAA, + GNUNET_GNS_RECORD_MX, + GNUNET_GNS_RECORD_PKEY +}; + /** * Initialize the connection with the GNS service. * * @param cfg configuration to use + * @param ht_len size of the internal hash table to use for parallel lookups * @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); /** @@ -86,13 +104,12 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle); * @param cont_cls closure for cont */ void -GNUNET_GNS_add (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode * key, - uint32_t desired_replication_level, - enum GNUNET_DHT_RouteOption options, - enum GNUNET_BLOCK_Type type, size_t size, const char *data, - struct GNUNET_TIME_Absolute exp, - struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont, - void *cont_cls); +GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, + const char* name, + enum GNUNET_GNS_RecordType type, + size_t size, const char *data, + struct GNUNET_TIME_Absolute exp, + struct GNUNET_TIME_Relative timeout); /** @@ -102,23 +119,14 @@ GNUNET_GNS_add (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode * key, * @param cls closure * @param exp when will this value expire * @param key key of the result - * @param get_path peers on reply path (or NULL if not recorded) - * @param get_path_length number of entries in get_path - * @param put_path peers on the PUT path (or NULL if not recorded) - * @param put_path_length number of entries in get_path + * @param records the records in reply + * @param num_records the number of records in reply * @param type type of the result - * @param size number of bytes in data - * @param data pointer to the result data */ typedef void (*GNUNET_GNS_LookupIterator) (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); + const struct GNUNET_GNS_Record *record, + unsigned int num_records); @@ -142,10 +150,9 @@ typedef void (*GNUNET_GNS_LookupIterator) (void *cls, struct GNUNET_GNS_LookupHandle * GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, struct GNUNET_TIME_Relative timeout, - enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, - uint32_t desired_replication_level, - enum GNUNET_DHT_RouteOption options, const void *xquery, - size_t xquery_size, GNUNET_GNS_LookupIterator iter, + const char * name, + enum GNUNET_GNS_RecordType type, + GNUNET_GNS_LookupIterator iter, void *iter_cls); -- 2.25.1