-presumably better fix for instantly resolving names in master zone
authorChristian Grothoff <christian@grothoff.org>
Tue, 4 Mar 2014 11:26:26 +0000 (11:26 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 4 Mar 2014 11:26:26 +0000 (11:26 +0000)
src/gns/gns.h
src/gns/gns_api.c
src/gns/gnunet-gns.c
src/gns/gnunet-service-gns.c
src/gns/gnunet-service-gns_resolver.c
src/gns/gnunet-service-gns_resolver.h
src/include/gnunet_gns_service.h

index a8402b196f43adad19a7cb9b714f1253c5e68066..35ff969f29962c823d736ec4167b1d051bea9d2a 100644 (file)
@@ -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?
index 66bd005cf0b4dd364e8851fb0d187e96071e7898..9f7f28b7185c5cfe1bb6e6a8ebb9a88d2606ed3b 100644 (file)
@@ -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)
index 7951eb5693434ddf23a3967bda9ba90020bc8e72..f59239b9d44da47afbbac07dd547e497289c0582 100644 (file)
@@ -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);
 }
 
index 87dfed2465452917336c7576026ecaf1d583457d..28e6c3cc73a6d6bcb2f56ab5bccea5c013e05e8f 100644 (file)
@@ -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",
index 8e4de4b7d3805bd4f9401b0e991f25804abe434d..d1e95896114c1399fa4fc81fffe1a84ad57a71e5 100644 (file)
@@ -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);
index ffb7142a76d8c9239e2423ec9000d2d60eec3629..baad44e383335bbf83f9d5ee13e21a8d0f836a22 100644 (file)
@@ -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);
 
index bfe9fbc5b35b25e7b0a38fe1cff490a95b0050a6..e3f42001c0bf673a2f613e99dbbd63449db494d4 100644 (file)
@@ -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);