From: Christian Grothoff Date: Tue, 4 Mar 2014 11:26:26 +0000 (+0000) Subject: -presumably better fix for instantly resolving names in master zone X-Git-Tag: initial-import-from-subversion-38251~4639 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5c779811684d383940d6e3766ace4bdce7bc0ae6;p=oweals%2Fgnunet.git -presumably better fix for instantly resolving names in master zone --- diff --git a/src/gns/gns.h b/src/gns/gns.h index a8402b196..35ff969f2 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h @@ -66,9 +66,10 @@ struct GNUNET_GNS_ClientLookupMessage struct GNUNET_CRYPTO_EcdsaPublicKey zone; /** - * Only check cached results + * Local options for where to look for results + * (an `enum GNUNET_GNS_LocalOptions` in NBO). */ - int16_t only_cached GNUNET_PACKED; + int16_t options GNUNET_PACKED; /** * Is a shorten key attached? diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 66bd005cf..9f7f28b71 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -523,7 +523,7 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) * @param name the name to look up * @param zone the zone to start the resolution in * @param type the record type to look up - * @param only_cached #GNUNET_YES to only check locally (not in the DHT) + * @param options local options for the lookup * @param shorten_zone_key the private key of the shorten zone (can be NULL) * @param proc processor to call on result * @param proc_cls closure for @a proc @@ -534,7 +534,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t type, - int only_cached, + enum GNUNET_GNS_LocalOptions options, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls) @@ -576,7 +576,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP); lookup_msg->header.size = htons (msize); lookup_msg->id = htonl (lr->r_id); - lookup_msg->only_cached = htons (only_cached); + lookup_msg->options = htons ((uint16_t) options); lookup_msg->zone = *zone; lookup_msg->type = htonl (type); if (NULL != shorten_zone_key) diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 7951eb569..f59239b9d 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -66,9 +66,9 @@ static char *zone_ego_name; static char *public_key; /** - * Set to #GNUNET_YES if we must not use the DHT (only local lookup). + * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone. */ -static int only_cached; +static enum GNUNET_GNS_LocalOptions local_options; /** * raw output @@ -216,7 +216,7 @@ lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, lookup_name, pkey, rtype, - only_cached, + local_options, shorten_key, &process_lookup_result, lookup_name); @@ -349,13 +349,16 @@ identity_master_cb (void *cls, return; } GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); + /* main name is our own master zone, do no look for that in the DHT */ + local_options = GNUNET_GNS_LO_LOCAL_MASTER; + /* if the name is of the form 'label.gnu', never go to the DHT */ dot = NULL; if (NULL != lookup_name) dot = strchr (lookup_name, '.'); if ( (NULL != dot) && (0 == strcasecmp (dot, ".gnu")) ) - only_cached = GNUNET_YES; + local_options = GNUNET_GNS_LO_NO_DHT; lookup_with_public_key (&pkey); } diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 87dfed246..28e6c3cc7 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -788,7 +788,7 @@ handle_lookup (void *cls, ntohl (sh_msg->type), name, key, - ntohs (sh_msg->only_cached), + (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options), &send_lookup_response, clh); GNUNET_STATISTICS_update (statistics, "Lookup attempts", diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 8e4de4b7d..d1e958961 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -365,7 +365,7 @@ struct GNS_ResolverHandle /** * Use only cache */ - int only_cached; + enum GNUNET_GNS_LocalOptions options; /** * Desired type for the resolution. @@ -1779,7 +1779,7 @@ handle_gns_resolution_result (void *cls, g2dc->rh->proc = &handle_gns2dns_result; g2dc->rh->proc_cls = rh; g2dc->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; - g2dc->rh->only_cached = GNUNET_NO; + g2dc->rh->options = GNUNET_GNS_LO_DEFAULT; g2dc->rh->loop_limiter = rh->loop_limiter + 1; rh->g2dc = g2dc; start_resolver_lookup (g2dc->rh); @@ -2011,7 +2011,9 @@ handle_namecache_block_response (void *cls, GNUNET_assert (NULL != rh->namecache_qe); rh->namecache_qe = NULL; - if ( (GNUNET_NO == rh->only_cached) && + if ( ( (GNUNET_GNS_LO_DEFAULT == rh->options) || + ( (GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && + (ac != rh->ac_head) ) ) && ( (NULL == block) || (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) ) { @@ -2303,7 +2305,7 @@ start_resolver_lookup (struct GNS_ResolverHandle *rh) * @param record_type the record type to look up * @param name the name to look up * @param shorten_key a private key for use with PSEU import (can be NULL) - * @param only_cached #GNUNET_NO to only check locally not DHT for performance + * @param options local options to control local lookup * @param proc the processor to call on result * @param proc_cls the closure to pass to @a proc * @return handle to cancel operation @@ -2313,7 +2315,7 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t record_type, const char *name, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key, - int only_cached, + enum GNUNET_GNS_LocalOptions options, GNS_ResultProcessor proc, void *proc_cls) { struct GNS_ResolverHandle *rh; @@ -2330,7 +2332,7 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, rh->authority_zone = *zone; rh->proc = proc; rh->proc_cls = proc_cls; - rh->only_cached = only_cached; + rh->options = options; rh->record_type = record_type; rh->name = GNUNET_strdup (name); rh->name_resolution_pos = strlen (name); diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index ffb7142a7..baad44e38 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -26,6 +26,7 @@ #define GNS_RESOLVER_H #include "gns.h" #include "gnunet_dht_service.h" +#include "gnunet_gns_service.h" #include "gnunet_namecache_service.h" /** @@ -77,7 +78,7 @@ typedef void (*GNS_ResultProcessor)(void *cls, * @param record_type the record type to look up * @param name the name to look up * @param shorten_key optional private key for authority caching, can be NULL - * @param only_cached GNUNET_NO to only check locally not DHT for performance + * @param options options set to control local lookup * @param proc the processor to call * @param proc_cls the closure to pass to @a proc * @return handle to cancel operation @@ -87,7 +88,7 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t record_type, const char *name, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key, - int only_cached, + enum GNUNET_GNS_LocalOptions options, GNS_ResultProcessor proc, void *proc_cls); diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index bfe9fbc5b..e3f42001c 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2012-2013 Christian Grothoff (and other contributing authors) + (C) 2012-2014 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 @@ -87,6 +87,30 @@ typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls, const struct GNUNET_GNSRECORD_Data *rd); +/** + * Options for the GNS lookup. + */ +enum GNUNET_GNS_LocalOptions +{ + /** + * Defaults, look in cache, then in DHT. + */ + GNUNET_GNS_LO_DEFAULT = 0, + + /** + * Never look in the DHT, keep request to local cache. + */ + GNUNET_GNS_LO_NO_DHT = 1, + + /** + * For the rightmost label, only look in the cache (it + * is our master zone), for the others, the DHT is OK. + */ + GNUNET_GNS_LO_LOCAL_MASTER = 2 + +}; + + /** * Perform an asynchronous lookup operation on the GNS. * @@ -94,7 +118,7 @@ typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls, * @param name the name to look up * @param zone zone to look in * @param type the GNS record type to look for - * @param only_cached #GNUNET_YES to only check locally (not in the DHT) + * @param options local options for the lookup * @param shorten_zone_key the private key of the shorten zone (can be NULL); * specify to enable automatic shortening (given a PSEU * record, if a given pseudonym is not yet used in the @@ -109,7 +133,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t type, - int only_cached, + enum GNUNET_GNS_LocalOptions options, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls);