From 41d573de1a9bd510a15ec971762c0d7dc77f2901 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 13 Aug 2013 17:32:35 +0000 Subject: -simplifying GNS API --- src/gns/gns.h | 118 +-------- src/gns/gns_api.c | 489 +------------------------------------ src/gns/gnunet-service-gns.c | 563 +------------------------------------------ 3 files changed, 13 insertions(+), 1157 deletions(-) (limited to 'src/gns') diff --git a/src/gns/gns.h b/src/gns/gns.h index a7697be1d..c8d27b673 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2012 Christian Grothoff (and other contributing authors) + (C) 2012-2013 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 @@ -28,9 +28,9 @@ #include "gnunet_gns_service.h" /** - * Name of the GADS TLD. + * Name of the GNS TLD. */ -#define GNUNET_GNS_TLD "gads" +#define GNUNET_GNS_TLD "gnu" /** * Name of the zone key TLD. @@ -61,29 +61,24 @@ struct GNUNET_GNS_ClientLookupMessage uint32_t id GNUNET_PACKED; /** - * If use_default_zone is empty this zone is used for lookup + * Zone that is to be used for lookup */ - struct GNUNET_CRYPTO_ShortHashCode zone; + struct GNUNET_CRYPTO_EccPublicKey zone; /** * Only check cached results */ - uint32_t only_cached GNUNET_PACKED; - - /** - * Should we look up in the given zone, instead of the default zone? - */ - uint32_t have_zone GNUNET_PACKED; + int16_t only_cached GNUNET_PACKED; /** * Is a shorten key attached? */ - uint32_t have_key GNUNET_PACKED; + int16_t have_key GNUNET_PACKED; /** * the type of record to look up */ - /* int */ uint32_t type; + int32_t type; /** * The key for shorten, if 'have_key' is set @@ -119,103 +114,6 @@ struct GNUNET_GNS_ClientLookupResultMessage }; -/** - * Message from client to GNS service to shorten names. - */ -struct GNUNET_GNS_ClientShortenMessage -{ - /** - * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN - */ - struct GNUNET_MessageHeader header; - - /** - * Unique identifier for this request - */ - uint32_t id GNUNET_PACKED; - - /** - * If use_default_zone is empty this zone is used for lookup - */ - struct GNUNET_CRYPTO_ShortHashCode zone; - - /** - * Shorten zone - */ - struct GNUNET_CRYPTO_ShortHashCode shorten_zone; - - /** - * Private zone - */ - struct GNUNET_CRYPTO_ShortHashCode private_zone; - - /** - * Should we look up in the default zone? - */ - uint32_t use_default_zone GNUNET_PACKED; - - /* Followed by the name to shorten up */ -}; - - -/** - * Message from GNS service to client: shorten result. - */ -struct GNUNET_GNS_ClientShortenResultMessage -{ - /** - * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN_RESULT - */ - struct GNUNET_MessageHeader header; - - /** - * Unique identifier for this request (for key collisions). - */ - uint32_t id GNUNET_PACKED; - - /* followed by the shortened name or '\0' for no result*/ - -}; - - -/** - * Message from client to GNS service to lookup an authority of a name. - */ -struct GNUNET_GNS_ClientGetAuthMessage -{ - /** - * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH - */ - struct GNUNET_MessageHeader header; - - /** - * Unique identifier for this request - */ - uint32_t id GNUNET_PACKED; - - /* Followed by the name to get authority for */ -}; - - -/** - * Message from GNS service to client: authority result. - */ -struct GNUNET_GNS_ClientGetAuthResultMessage -{ - /** - * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH_RESULT - */ - struct GNUNET_MessageHeader header; - - /** - * Unique identifier for this request (for key collisions). - */ - uint32_t id GNUNET_PACKED; - - /* followed by the authority part of the name or '\0' for no result*/ - -}; - GNUNET_NETWORK_STRUCT_END #endif diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 64f5144c6..9bc85efea 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -73,82 +73,6 @@ struct GNUNET_GNS_LookupRequest }; -/** - * Handle to a shorten request - */ -struct GNUNET_GNS_ShortenRequest -{ - /** - * DLL - */ - struct GNUNET_GNS_ShortenRequest *next; - - /** - * DLL - */ - struct GNUNET_GNS_ShortenRequest *prev; - - /** - * handle to gns - */ - struct GNUNET_GNS_Handle *gns_handle; - - /** - * processor to call on shorten result - */ - GNUNET_GNS_ShortenResultProcessor shorten_proc; - - /** - * processor closure - */ - void *proc_cls; - - /** - * request id - */ - uint32_t r_id; - -}; - - -/** - * Handle to GetAuthorityRequest - */ -struct GNUNET_GNS_GetAuthRequest -{ - /** - * DLL - */ - struct GNUNET_GNS_GetAuthRequest *next; - - /** - * DLL - */ - struct GNUNET_GNS_GetAuthRequest *prev; - - /** - * handle to gns - */ - struct GNUNET_GNS_Handle *gns_handle; - - /** - * processor to call on authority lookup result - */ - GNUNET_GNS_GetAuthResultProcessor auth_proc; - - /** - * processor closure - */ - void *proc_cls; - - /** - * request id - */ - uint32_t r_id; - -}; - - /** * Entry in our list of messages to be (re-)transmitted. */ @@ -215,16 +139,6 @@ struct GNUNET_GNS_Handle */ struct PendingMessage *pending_tail; - /** - * Head of linked list of shorten messages we would like to transmit. - */ - struct GNUNET_GNS_ShortenRequest *shorten_head; - - /** - * Tail of linked list of shorten messages we would like to transmit. - */ - struct GNUNET_GNS_ShortenRequest *shorten_tail; - /** * Head of linked list of lookup messages we would like to transmit. */ @@ -234,16 +148,6 @@ struct GNUNET_GNS_Handle * Tail of linked list of lookup messages we would like to transmit. */ struct GNUNET_GNS_LookupRequest *lookup_tail; - - /** - * Head of linked list of authority lookup messages we would like to transmit. - */ - struct GNUNET_GNS_GetAuthRequest *get_auth_head; - - /** - * Tail of linked list of authority lookup messages we would like to transmit. - */ - struct GNUNET_GNS_GetAuthRequest *get_auth_tail; /** * Reconnect task @@ -317,24 +221,12 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void force_reconnect (struct GNUNET_GNS_Handle *handle) { - struct GNUNET_GNS_ShortenRequest *st; struct GNUNET_GNS_LookupRequest *lh; - struct GNUNET_GNS_GetAuthRequest *ga; struct PendingMessage *p; GNUNET_CLIENT_disconnect (handle->client); handle->client = NULL; handle->in_receive = GNUNET_NO; - for (st = handle->shorten_head; NULL != st; st = st->next) - { - p = (struct PendingMessage *) &st[1]; - if (GNUNET_NO == p->transmitted) - continue; - p->transmitted = GNUNET_NO; - GNUNET_CONTAINER_DLL_insert (handle->pending_head, - handle->pending_tail, - p); - } for (lh = handle->lookup_head; NULL != lh; lh = lh->next) { p = (struct PendingMessage *) &lh[1]; @@ -345,16 +237,6 @@ force_reconnect (struct GNUNET_GNS_Handle *handle) handle->pending_tail, p); } - for (ga = handle->get_auth_head; NULL != ga; ga = ga->next) - { - p = (struct PendingMessage *) &ga[1]; - if (GNUNET_NO == p->transmitted) - continue; - p->transmitted = GNUNET_NO; - GNUNET_CONTAINER_DLL_insert (handle->pending_head, - handle->pending_tail, - p); - } handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, &reconnect_task, @@ -469,101 +351,6 @@ transmit_pending (void *cls, size_t size, void *buf) } -/** - * Process a given reply that might match the given - * request. - * - * @param qe a queue entry - * @param msg the shorten msg received - */ -static void -process_shorten_reply (struct GNUNET_GNS_ShortenRequest *qe, - const struct GNUNET_GNS_ClientShortenResultMessage *msg) -{ - struct GNUNET_GNS_Handle *handle = qe->gns_handle; - struct PendingMessage *p = (struct PendingMessage *)&qe[1]; - const char *short_name; - size_t mlen; - - if (GNUNET_YES != p->transmitted) - { - /* service send reply to query we never managed to send!? */ - GNUNET_break (0); - force_reconnect (handle); - return; - } - mlen = ntohs (msg->header.size); - if (ntohs (msg->header.size) == sizeof (struct GNUNET_GNS_ClientShortenResultMessage)) - { - /* service reports resolution failed */ - short_name = NULL; - } - else - { - short_name = (const char *) &msg[1]; - if ('\0' != short_name[mlen - sizeof (struct GNUNET_GNS_ClientShortenResultMessage) - 1]) - { - GNUNET_break (0); - force_reconnect (handle); - return; - } - } - GNUNET_CONTAINER_DLL_remove (handle->shorten_head, handle->shorten_tail, qe); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received shortened reply `%s' from GNS service\n", - short_name); - qe->shorten_proc (qe->proc_cls, short_name); - GNUNET_free (qe); -} - - -/** - * Process a given reply that might match the given - * request. - * - * @param qe the handle to the request - * @param msg the message to process - */ -static void -process_get_auth_reply (struct GNUNET_GNS_GetAuthRequest *qe, - const struct GNUNET_GNS_ClientGetAuthResultMessage *msg) -{ - struct GNUNET_GNS_Handle *handle = qe->gns_handle; - struct PendingMessage *p = (struct PendingMessage *)&qe[1]; - const char *auth_name; - size_t mlen; - - if (GNUNET_YES != p->transmitted) - { - /* service send reply to query we never managed to send!? */ - GNUNET_break (0); - force_reconnect (handle); - return; - } - mlen = ntohs (msg->header.size); - if (mlen == sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage)) - { - auth_name = NULL; - } - else - { - auth_name = (const char*) &msg[1]; - if ('\0' != auth_name[mlen - sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage) - 1]) - { - GNUNET_break (0); - force_reconnect (handle); - return; - } - } - GNUNET_CONTAINER_DLL_remove (handle->get_auth_head, handle->get_auth_tail, qe); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received GET_AUTH reply `%s' from GNS service\n", - auth_name); - qe->auth_proc (qe->proc_cls, auth_name); - GNUNET_free (qe); -} - - /** * Process a given reply to the lookup request * @@ -621,11 +408,7 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_GNS_Handle *handle = cls; struct GNUNET_GNS_LookupRequest *lr; - struct GNUNET_GNS_ShortenRequest *sr; - struct GNUNET_GNS_GetAuthRequest *gar; const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; - const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg; - const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg; uint32_t r_id; if (NULL == msg) @@ -653,42 +436,6 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg) break; } break; - case GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got SHORTEN_RESULT msg\n"); - if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientShortenResultMessage)) - { - GNUNET_break (0); - force_reconnect (handle); - return; - } - shorten_msg = (const struct GNUNET_GNS_ClientShortenResultMessage *) msg; - r_id = ntohl (shorten_msg->id); - for (sr = handle->shorten_head; NULL != sr; sr = sr->next) - if (sr->r_id == r_id) - { - process_shorten_reply (sr, shorten_msg); - break; - } - break; - case GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got GET_AUTH_RESULT msg\n"); - if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage)) - { - GNUNET_break (0); - force_reconnect (handle); - return; - } - get_auth_msg = (const struct GNUNET_GNS_ClientGetAuthResultMessage *) msg; - r_id = ntohl (get_auth_msg->id); - for (gar = handle->get_auth_head; NULL != gar; gar = gar->next) - if (gar->r_id == r_id) - { - process_get_auth_reply (gar, get_auth_msg); - break; - } - break; default: GNUNET_break (0); force_reconnect (handle); @@ -710,7 +457,7 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_GNS_Handle *handle; - handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle)); + handle = GNUNET_new (struct GNUNET_GNS_Handle); handle->cfg = cfg; reconnect (handle); return handle; @@ -732,8 +479,6 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_assert (NULL == handle->lookup_head); - GNUNET_assert (NULL == handle->shorten_head); - GNUNET_assert (NULL == handle->get_auth_head); GNUNET_free (handle); } @@ -760,50 +505,6 @@ GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr) } -/** - * Cancel pending shorten request - * - * @param sr the lookup request to cancel - */ -void -GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr) -{ - struct PendingMessage *p = (struct PendingMessage*) &sr[1]; - - GNUNET_assert (NULL != sr->gns_handle); - if (GNUNET_NO == p->transmitted) - GNUNET_CONTAINER_DLL_remove (sr->gns_handle->pending_head, - sr->gns_handle->pending_tail, - p); - GNUNET_CONTAINER_DLL_remove (sr->gns_handle->shorten_head, - sr->gns_handle->shorten_tail, - sr); - GNUNET_free (sr); -} - - -/** - * Cancel pending get auth request - * - * @param gar the lookup request to cancel - */ -void -GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar) -{ - struct PendingMessage *p = (struct PendingMessage*) &gar[1]; - - GNUNET_assert (NULL != gar->gns_handle); - if (GNUNET_NO == p->transmitted) - GNUNET_CONTAINER_DLL_remove (gar->gns_handle->pending_head, - gar->gns_handle->pending_tail, - p); - GNUNET_CONTAINER_DLL_remove (gar->gns_handle->get_auth_head, - gar->gns_handle->get_auth_tail, - gar); - GNUNET_free (gar); -} - - /** * Perform an asynchronous Lookup operation on the GNS. * @@ -885,192 +586,4 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, } -/** - * Perform an asynchronous Lookup operation on the GNS. - * - * @param handle handle to the GNS service - * @param name the name to look up - * @param type the record type to look up - * @param only_cached GNUNET_YES to only check locally not DHT for performance - * @param shorten_key the private key of the shorten zone (can be NULL) - * @param proc processor to call on result - * @param proc_cls closure for processor - * @return handle to the lookup request - */ -struct GNUNET_GNS_LookupRequest * -GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, - const char *name, - int type, - int only_cached, - struct GNUNET_CRYPTO_EccPrivateKey *shorten_key, - GNUNET_GNS_LookupResultProcessor proc, - void *proc_cls) -{ - return GNUNET_GNS_lookup_zone (handle, name, - NULL, - type, only_cached, - shorten_key, - proc, proc_cls); -} - - -/** - * Perform a name shortening operation on the GNS. - * - * @param handle handle to the GNS service - * @param name the name to look up - * @param private_zone the public zone of the private zone - * @param shorten_zone the public zone of the shorten zone - * @param zone the zone to start the resolution in - * @param proc function to call on result - * @param proc_cls closure for processor - * @return handle to the operation - */ -struct GNUNET_GNS_ShortenRequest* -GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, - const char *name, - struct GNUNET_CRYPTO_ShortHashCode *private_zone, - struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, - struct GNUNET_CRYPTO_ShortHashCode *zone, - GNUNET_GNS_ShortenResultProcessor proc, - void *proc_cls) -{ - /* IPC to shorten gns names, return shorten_handle */ - struct GNUNET_GNS_ClientShortenMessage *shorten_msg; - struct GNUNET_GNS_ShortenRequest *sr; - size_t msize; - struct PendingMessage *pending; - - if (NULL == name) - { - GNUNET_break (0); - return NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten `%s' in GNS\n", name); - msize = sizeof (struct GNUNET_GNS_ClientShortenMessage) + strlen (name) + 1; - if (msize > UINT16_MAX) - { - GNUNET_break (0); - return NULL; - } - sr = GNUNET_malloc (sizeof (struct GNUNET_GNS_ShortenRequest) + - sizeof (struct PendingMessage) + msize); - sr->gns_handle = handle; - sr->shorten_proc = proc; - sr->proc_cls = proc_cls; - sr->r_id = handle->r_id_gen++; - GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head, - handle->shorten_tail, sr); - pending = (struct PendingMessage *)&sr[1]; - pending->size = msize; - pending->r_id = sr->r_id; - - shorten_msg = (struct GNUNET_GNS_ClientShortenMessage *) &pending[1]; - shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN); - shorten_msg->header.size = htons ((uint16_t) msize); - shorten_msg->id = htonl (sr->r_id); - shorten_msg->private_zone = *private_zone; - shorten_msg->shorten_zone = *shorten_zone; - if (NULL != zone) - { - shorten_msg->use_default_zone = htonl (GNUNET_NO); - memcpy (&shorten_msg->zone, zone, - sizeof (struct GNUNET_CRYPTO_ShortHashCode)); - } - else - { - shorten_msg->use_default_zone = htonl (GNUNET_YES); - memset (&shorten_msg->zone, 0, sizeof (struct GNUNET_CRYPTO_ShortHashCode)); - } - memcpy (&shorten_msg[1], name, strlen (name) + 1); - GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, - pending); - process_pending_messages (handle); - return sr; -} - - -/** - * Perform a name shortening operation on the GNS. - * - * @param handle handle to the GNS service - * @param name the name to look up - * @param private_zone the public zone of the private zone - * @param shorten_zone the public zone of the shorten zone - * @param proc function to call on result - * @param proc_cls closure for processor - * @return handle to the operation - */ -struct GNUNET_GNS_ShortenRequest* -GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, - const char *name, - struct GNUNET_CRYPTO_ShortHashCode *private_zone, - struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, - GNUNET_GNS_ShortenResultProcessor proc, - void *proc_cls) -{ - return GNUNET_GNS_shorten_zone (handle, name, - private_zone, shorten_zone, - NULL, proc, proc_cls); -} - - -/** - * Perform an authority lookup for a given name. - * - * @param handle handle to the GNS service - * @param name the name to look up authority for - * @param proc function to call on result - * @param proc_cls closure for processor - * @return handle to the operation - */ -struct GNUNET_GNS_GetAuthRequest* -GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle, - const char *name, - GNUNET_GNS_GetAuthResultProcessor proc, - void *proc_cls) -{ - struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg; - struct GNUNET_GNS_GetAuthRequest *gar; - size_t msize; - struct PendingMessage *pending; - - if (NULL == name) - { - GNUNET_break (0); - return NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying to look up authority for %s in GNS\n", name); - msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen (name) + 1; - if (msize > UINT16_MAX) - { - GNUNET_break (0); - return NULL; - } - gar = GNUNET_malloc (sizeof (struct GNUNET_GNS_GetAuthRequest) + - sizeof (struct PendingMessage) + msize); - gar->gns_handle = handle; - gar->auth_proc = proc; - gar->proc_cls = proc_cls; - gar->r_id = handle->r_id_gen++; - GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head, - handle->get_auth_tail, gar); - - pending = (struct PendingMessage *) &gar[1]; - pending->size = msize; - pending->r_id = gar->r_id; - get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1]; - get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH); - get_auth_msg->header.size = htons (msize); - get_auth_msg->id = htonl (gar->r_id); - memcpy (&get_auth_msg[1], name, strlen (name) + 1); - GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, - handle->pending_tail, - pending); - process_pending_messages (handle); - return gar; -} - - /* end of gns_api.c */ diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index e1fc507fb..822cc7d12 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -61,98 +61,6 @@ #define LATE_ITERATION_SPEEDUP_FACTOR 2 -/** - * Handle to a shorten operation from api - */ -struct ClientShortenHandle -{ - - /** - * List for all shorten requests - */ - struct ClientShortenHandle *next; - - /** - * List for all shorten requests - */ - struct ClientShortenHandle *prev; - - /** - * Handle to the requesting client - */ - struct GNUNET_SERVER_Client *client; - - /** - * Namestore lookup task - */ - struct GNUNET_NAMESTORE_QueueEntry *namestore_task; - - /** - * master zone - */ - struct GNUNET_CRYPTO_ShortHashCode root_zone; - - /** - * private zone - */ - struct GNUNET_CRYPTO_ShortHashCode private_zone; - - /** - * shorten zone - */ - struct GNUNET_CRYPTO_ShortHashCode shorten_zone; - - /** - * The request id - */ - uint32_t request_id; - - /** - * request type - */ - int type; - - /** - * name to shorten - */ - char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; - - /** - * name of private zone (relative to root) - */ - char private_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; - - /** - * name of shorten zone (relative to root) - */ - char shorten_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; - -}; - - -/** - * Handle to a get authority operation from api - */ -struct ClientGetAuthHandle -{ - /** - * Handle to the requesting client - */ - struct GNUNET_SERVER_Client *client; - - /** - * name to lookup authority - */ - char *name; - - /** - * request id - */ - uint32_t request_id; - -}; - - /** * Handle to a lookup operation from api */ @@ -277,16 +185,6 @@ static int v6_enabled; */ static int v4_enabled; -/** - * List for shorten requests - */ -static struct ClientShortenHandle *csh_head; - -/** - * List for shorten requests - */ -static struct ClientShortenHandle *csh_tail; - /** * Handle to the statistics service */ @@ -306,11 +204,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n"); - while (NULL != (csh_tmp = csh_head)) - { - GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp); - GNUNET_free (csh_tmp); - } GNUNET_SERVER_notification_context_destroy (nc); gns_interceptor_stop (); gns_resolver_cleanup (); @@ -580,433 +473,6 @@ publish_zone_dht_start (void *cls, /* END DHT ZONE PROPAGATION */ -/** - * Send shorten response back to client - * - * @param cls the closure containing a client shorten handle - * @param name the shortened name result or NULL if cannot be shortened - */ -static void -send_shorten_response (void* cls, const char* name) -{ - struct ClientShortenHandle *csh = cls; - struct GNUNET_GNS_ClientShortenResultMessage *rmsg; - size_t name_len; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending `%s' message with %s\n", - "SHORTEN_RESULT", name); - if (NULL == name) - name_len = 0; - else - name_len = strlen (name) + 1; - GNUNET_STATISTICS_update (statistics, - "Name shorten results", 1, GNUNET_NO); - - rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientShortenResultMessage) + - name_len); - - rmsg->id = csh->request_id; - rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); - rmsg->header.size = - htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + - name_len); - memcpy (&rmsg[1], name, name_len); - GNUNET_SERVER_notification_context_unicast (nc, csh->client, - &rmsg->header, - GNUNET_NO); - if (NULL != csh->namestore_task) - GNUNET_NAMESTORE_cancel (csh->namestore_task); - GNUNET_free (rmsg); - GNUNET_free (csh); -} - - -/** - * Lookup the zone infos and shorten name - * - * @param cls the client shorten handle - * @param key key of the zone - * @param expiration expiration of record - * @param name name found or null if no result - * @param rd_count number of records found - * @param rd record data - * @param signature - * - */ -static void -process_shorten_in_private_zone_lookup (void *cls, - const struct GNUNET_CRYPTO_EccPublicKey *key, - struct GNUNET_TIME_Absolute expiration, - const char *name, - unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd, - const struct GNUNET_CRYPTO_EccSignature *signature) -{ - struct ClientShortenHandle *csh = cls; - struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone; - struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone; - - csh->namestore_task = NULL; - if (0 == strcmp (csh->private_zone_id, "")) - pzone = NULL; - if (0 == rd_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No shorten zone in private zone!\n"); - strcpy (csh->shorten_zone_id, ""); - szone = NULL; - } - else - { - GNUNET_break (1 == rd_count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shorten zone %s found in private zone %s\n", - name, csh->private_zone_id); - - sprintf (csh->shorten_zone_id, "%s.%s", name, csh->private_zone_id); - } - GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); - gns_resolver_shorten_name (&csh->root_zone, - pzone, - szone, - csh->name, - csh->private_zone_id, - csh->shorten_zone_id, - &send_shorten_response, csh); - -} - - -/** - * Lookup the zone infos and shorten name - * - * @param cls the shorten handle - * @param key key of the zone - * @param expiration expiration of record - * @param name name found or null if no result - * @param rd_count number of records found - * @param rd record data - * @param signature - * - */ -static void -process_shorten_in_root_zone_lookup (void *cls, - const struct GNUNET_CRYPTO_EccPublicKey *key, - struct GNUNET_TIME_Absolute expiration, - const char *name, - unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd, - const struct GNUNET_CRYPTO_EccSignature *signature) -{ - struct ClientShortenHandle *csh = cls; - struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone; - struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone; - - csh->namestore_task = NULL; - if (0 == strcmp (csh->private_zone_id, "")) - pzone = NULL; - if (0 == rd_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No shorten zone in zone and no private zone!\n"); - - strcpy (csh->shorten_zone_id, ""); - GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); - szone = NULL; - gns_resolver_shorten_name (&csh->root_zone, - pzone, - szone, - csh->name, - csh->private_zone_id, - csh->shorten_zone_id, - &send_shorten_response, csh); - return; - } - GNUNET_break (rd_count == 1); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Private zone %s found in root zone\n", name); - strcpy (csh->private_zone_id, name); - csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, - pzone, - szone, - &process_shorten_in_private_zone_lookup, - csh); -} - - -/** - * Lookup the zone infos and shorten name - * - * @param cls the shorten handle - * @param key key of the zone - * @param expiration expiration of record - * @param name name found or null if no result - * @param rd_count number of records found - * @param rd record data - * @param signature - */ -static void -process_private_in_root_zone_lookup (void *cls, - const struct GNUNET_CRYPTO_EccPublicKey *key, - struct GNUNET_TIME_Absolute expiration, - const char *name, - unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd, - const struct GNUNET_CRYPTO_EccSignature *signature) -{ - struct ClientShortenHandle *csh = cls; - - csh->namestore_task = NULL; - if (0 == rd_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No private zone in root zone\n"); - strcpy (csh->private_zone_id, ""); - csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, - &csh->root_zone, - &csh->shorten_zone, - &process_shorten_in_root_zone_lookup, - csh); - return; - } - GNUNET_break (1 == rd_count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Private zone `%s' found in root zone\n", - name); - strcpy (csh->private_zone_id, name); - csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, - &csh->private_zone, - &csh->shorten_zone, - &process_shorten_in_private_zone_lookup, - csh); -} - - -/** - * Handle a shorten message from the api - * - * @param cls the closure (unused) - * @param client the client - * @param message the message - */ -static void -handle_shorten (void *cls, - struct GNUNET_SERVER_Client * client, - const struct GNUNET_MessageHeader * message) -{ - struct ClientShortenHandle *csh; - const char *utf_in; - char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; - char* nameptr = name; - uint16_t msg_size; - const struct GNUNET_GNS_ClientShortenMessage *sh_msg; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message\n", "SHORTEN"); - msg_size = ntohs (message->size); - if (msg_size < sizeof (struct GNUNET_GNS_ClientShortenMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - sh_msg = (const struct GNUNET_GNS_ClientShortenMessage *) message; - utf_in = (const char *) &sh_msg[1]; - if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientShortenMessage) - 1]) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - csh = GNUNET_malloc(sizeof (struct ClientShortenHandle)); - csh->client = client; - csh->request_id = sh_msg->id; - GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); - GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "SHORTEN: Converted `%s' to `%s'\n", - utf_in, - nameptr); - GNUNET_SERVER_notification_context_add (nc, client); - if (strlen (name) < strlen (GNUNET_GNS_TLD)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "SHORTEN: %s is too short\n", name); - GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); - send_shorten_response(csh, name); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } - if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "SHORTEN: %s is too long\n", name); - GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); - send_shorten_response(csh, name); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } - if ( (! is_gads_tld (name)) && - (! is_zkey_tld (name)) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "%s is not our domain. Returning\n", name); - GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); - send_shorten_response (csh, name); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } - csh->shorten_zone = sh_msg->shorten_zone; - csh->private_zone = sh_msg->private_zone; - strcpy (csh->name, name); - if (1 == ntohl(sh_msg->use_default_zone)) - csh->root_zone = zone_hash; //Default zone - else - csh->root_zone = sh_msg->zone; - csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, - &csh->root_zone, - &csh->private_zone, - &process_private_in_root_zone_lookup, - csh); - GNUNET_STATISTICS_update (statistics, - "Name shorten attempts", 1, GNUNET_NO); - GNUNET_SERVER_receive_done (client, GNUNET_OK); -} - - -/** - * Send get authority response back to client - * - * @param cls the closure containing a client get auth handle - * @param name the name of the authority, or NULL on error - */ -static void -send_get_auth_response (void *cls, - const char* name) -{ - struct ClientGetAuthHandle *cah = cls; - struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending `%s' message with `%s'\n", - "GET_AUTH_RESULT", name); - if (NULL != name) - { - GNUNET_STATISTICS_update (statistics, - "Authorities resolved", 1, GNUNET_NO); - } - if (NULL == name) - name = ""; - rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage) - + strlen (name) + 1); - - rmsg->id = cah->request_id; - rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT); - rmsg->header.size = - htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) + - strlen (name) + 1); - strcpy ((char*)&rmsg[1], name); - - GNUNET_SERVER_notification_context_unicast (nc, cah->client, - &rmsg->header, - GNUNET_NO); - GNUNET_SERVER_receive_done (cah->client, GNUNET_OK); - GNUNET_free(rmsg); - GNUNET_free_non_null(cah->name); - GNUNET_free(cah); -} - - -/** - * Handle a get authority message from the api - * - * @param cls the closure - * @param client the client - * @param message the message - */ -static void -handle_get_authority (void *cls, - struct GNUNET_SERVER_Client * client, - const struct GNUNET_MessageHeader * message) -{ - struct ClientGetAuthHandle *cah; - const char *utf_in; - char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; - char* nameptr = name; - uint16_t msg_size; - const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message\n", "GET_AUTH"); - msg_size = ntohs(message->size); - if (msg_size < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - GNUNET_SERVER_notification_context_add (nc, client); - sh_msg = (const struct GNUNET_GNS_ClientGetAuthMessage *) message; - utf_in = (const char *) &sh_msg[1]; - if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientGetAuthMessage) - 1]) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr); - cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); - cah->client = client; - cah->request_id = sh_msg->id; - if (strlen (name) < strlen(GNUNET_GNS_TLD)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GET_AUTH: `%s' is too short. Returning\n", name); - cah->name = NULL; - send_get_auth_response(cah, name); - return; - } - if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "GET_AUTH: `%s' is too long", name); - cah->name = NULL; - send_get_auth_response(cah, name); - return; - } - if (0 != strcmp (name + strlen (name) - strlen (GNUNET_GNS_TLD), - GNUNET_GNS_TLD)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GET_AUTH: %s is not our domain. Returning\n", name); - cah->name = NULL; - send_get_auth_response (cah, name); - return; - } - - if (0 == strcmp (name, GNUNET_GNS_TLD)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GET_AUTH: %s is us. Returning\n", name); - cah->name = NULL; - send_get_auth_response(cah, name); - return; - } - - cah->name = GNUNET_malloc (strlen (name) - - strlen (GNUNET_GNS_TLD) + 1); - memcpy (cah->name, name, - strlen (name) - strlen (GNUNET_GNS_TLD)); - - /* Start delegation resolution in our namestore */ - gns_resolver_get_authority (zone_hash, zone_hash, name, - &send_get_auth_response, cah); - GNUNET_STATISTICS_update (statistics, - "Authority lookup attempts", 1, GNUNET_NO); -} - - /** * Reply to client with the result from our lookup. * @@ -1187,11 +653,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { - {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0}, - {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0}, - {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0} + { &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0}, + {NULL, NULL, 0, 0} }; - char* keyfile; struct GNUNET_CRYPTO_EccPublicKey pkey; unsigned long long max_parallel_bg_queries = 0; int ignore_pending = GNUNET_NO; @@ -1199,24 +663,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns", - "ZONEKEY", &keyfile)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No private key for root zone specified!\n"); - GNUNET_SCHEDULER_shutdown (); - return; - } - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Using keyfile %s for root zone.\n", keyfile); - - zone_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); - GNUNET_CRYPTO_ecc_key_get_public (zone_key, &pkey); - GNUNET_CRYPTO_short_hash (&pkey, - sizeof(struct GNUNET_CRYPTO_EccPublicKey), - &zone_hash); - GNUNET_free(keyfile); namestore_handle = GNUNET_NAMESTORE_connect (c); if (NULL == namestore_handle) { @@ -1313,9 +759,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, } /** - * Schedule periodic put - * for our records - * We have roughly an hour for all records; + * Schedule periodic put for our records We have roughly an hour for + * all records; */ first_zone_iteration = GNUNET_YES; zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL); -- cgit v1.2.3