gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21893 - in gnunet/src: gns include


From: gnunet
Subject: [GNUnet-SVN] r21893 - in gnunet/src: gns include
Date: Mon, 11 Jun 2012 17:50:41 +0200

Author: schanzen
Date: 2012-06-11 17:50:40 +0200 (Mon, 11 Jun 2012)
New Revision: 21893

Modified:
   gnunet/src/gns/gns.h
   gnunet/src/gns/gns_api.c
   gnunet/src/gns/gnunet-gns-proxy.c
   gnunet/src/gns/gnunet-gns.c
   gnunet/src/gns/gnunet-service-gns.c
   gnunet/src/gns/gnunet-service-gns_interceptor.c
   gnunet/src/gns/gnunet-service-gns_resolver.c
   gnunet/src/gns/gnunet-service-gns_resolver.h
   gnunet/src/include/gnunet_gns_service.h
Log:
-add cached flag for performance

Modified: gnunet/src/gns/gns.h
===================================================================
--- gnunet/src/gns/gns.h        2012-06-11 15:10:21 UTC (rev 21892)
+++ gnunet/src/gns/gns.h        2012-06-11 15:50:40 UTC (rev 21893)
@@ -53,6 +53,11 @@
   uint32_t id GNUNET_PACKED;
 
   /**
+   * Only check cached results
+   */
+  uint32_t only_cached GNUNET_PACKED;
+
+  /**
    * Should we look up in the default zone?
    */
   uint32_t use_default_zone GNUNET_PACKED;

Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c    2012-06-11 15:10:21 UTC (rev 21892)
+++ gnunet/src/gns/gns_api.c    2012-06-11 15:50:40 UTC (rev 21893)
@@ -642,6 +642,7 @@
  * @param zone the zone to start the resolution in
  * @param shorten_zone the zone where to shorten names into
  * @param type the record type to look up
+ * @param only_cached GNUNET_NO to only check locally not DHT for performance
  * @param proc processor to call on result
  * @param proc_cls closure for processor
  * @return handle to the get
@@ -652,6 +653,7 @@
                    struct GNUNET_CRYPTO_ShortHashCode *zone,
                    struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                    enum GNUNET_GNS_RecordType type,
+                   int only_cached,
                    GNUNET_GNS_LookupResultProcessor proc,
                    void *proc_cls)
 {
@@ -686,6 +688,7 @@
   lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
   lookup_msg->header.size = htons (msize);
   lookup_msg->id = htonl(qe->r_id);
+  lookup_msg->only_cached = htonl(only_cached);
 
   if (NULL != zone)
   {
@@ -728,6 +731,7 @@
  * @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_NO to only check locally not DHT for performance
  * @param proc processor to call on result
  * @param proc_cls closure for processor
  * @return handle to the get
@@ -736,12 +740,13 @@
 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
                    const char * name,
                    enum GNUNET_GNS_RecordType type,
+                   int only_cached,
                    GNUNET_GNS_LookupResultProcessor proc,
                    void *proc_cls)
 {
   return GNUNET_GNS_lookup_zone (handle, name,
                                  NULL, NULL,
-                                 type, proc, proc_cls);
+                                 type, only_cached, proc, proc_cls);
 }
 
 /**

Modified: gnunet/src/gns/gnunet-gns-proxy.c
===================================================================
--- gnunet/src/gns/gnunet-gns-proxy.c   2012-06-11 15:10:21 UTC (rev 21892)
+++ gnunet/src/gns/gnunet-gns-proxy.c   2012-06-11 15:50:40 UTC (rev 21893)
@@ -1010,14 +1010,26 @@
   if (ctask->mhd->is_ssl)
   {
     phost = (struct hostent*)gethostbyname (ctask->host);
-    ssl_ip = inet_ntoa(*((struct in_addr*)(phost->h_addr)));
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "SSL target server: %s\n", ssl_ip);
-    sprintf (resolvename, "%s:%d:%s", ctask->leho, HTTPS_PORT, ssl_ip);
-    ctask->resolver = curl_slist_append ( ctask->resolver, resolvename);
-    curl_easy_setopt (ctask->curl, CURLOPT_RESOLVE, ctask->resolver);
-    sprintf (curlurl, "https://%s%s";, ctask->leho, ctask->url);
-    curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl);
+
+    if (phost!=NULL)
+    {
+      ssl_ip = inet_ntoa(*((struct in_addr*)(phost->h_addr)));
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "SSL target server: %s\n", ssl_ip);
+      sprintf (resolvename, "%s:%d:%s", ctask->leho, HTTPS_PORT, ssl_ip);
+      ctask->resolver = curl_slist_append ( ctask->resolver, resolvename);
+      curl_easy_setopt (ctask->curl, CURLOPT_RESOLVE, ctask->resolver);
+      sprintf (curlurl, "https://%s%s";, ctask->leho, ctask->url);
+      curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl);
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "gethostbyname failed for %s!\n", ctask->host);
+      ctask->download_successful = GNUNET_NO;
+      ctask->download_error = GNUNET_YES;
+      return;
+    }
   }
 
   if (CURLM_OK != (mret=curl_multi_add_handle (curl_multi, ctask->curl)))
@@ -1067,6 +1079,7 @@
                           &local_gns_zone,
                           &local_shorten_zone,
                           GNUNET_GNS_RECORD_LEHO,
+                          GNUNET_YES, //Only cached for performance
                           &process_leho_lookup,
                           ctask);
 }

Modified: gnunet/src/gns/gnunet-gns.c
===================================================================
--- gnunet/src/gns/gnunet-gns.c 2012-06-11 15:10:21 UTC (rev 21892)
+++ gnunet/src/gns/gnunet-gns.c 2012-06-11 15:50:40 UTC (rev 21893)
@@ -151,6 +151,7 @@
   struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
   struct GNUNET_CRYPTO_ShortHashCode *shorten_zone = NULL;
   struct GNUNET_CRYPTO_ShortHashCode user_zone;
+  struct GNUNET_CRYPTO_ShortHashCode user_shorten_zone;
   struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
 
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
@@ -197,12 +198,12 @@
       GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
       GNUNET_CRYPTO_short_hash(&pkey,
                          sizeof(struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
-                         &user_zone);
-      shorten_zone = &user_zone;
+                         &user_shorten_zone);
+      shorten_zone = &user_shorten_zone;
       GNUNET_CRYPTO_short_hash_to_enc (shorten_zone, &zonename);
       if (!raw)
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Using zone: %s!\n", &zonename);
+                    "Using shorten zone: %s!\n", &zonename);
       GNUNET_CRYPTO_rsa_key_free(key);
     }
     GNUNET_free(keyfile);
@@ -237,6 +238,7 @@
     GNUNET_GNS_lookup_zone (gns, lookup_name,
                             zone, shorten_zone,
                             rtype,
+                            GNUNET_YES, //Use DHT
                             &process_lookup_result, lookup_name);
   }
 

Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-06-11 15:10:21 UTC (rev 21892)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-06-11 15:50:40 UTC (rev 21893)
@@ -825,6 +825,7 @@
   char* nameptr = name;
   struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
   struct GNUNET_CRYPTO_ShortHashCode zone;
+  int only_cached;
 
   if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
   {
@@ -856,6 +857,8 @@
   clh->unique_id = sh_msg->id;
   clh->type = ntohl(sh_msg->type);
   clh->shorten_key = NULL;
+
+  only_cached = ntohl(sh_msg->only_cached);
   
   if (strlen (name) > MAX_DNS_NAME_LENGTH) {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -883,6 +886,7 @@
     gns_resolver_lookup_record(zone, zone, clh->type, name,
                                key,
                                default_lookup_timeout,
+                               only_cached,
                                &send_lookup_response, clh);
   }
   else
@@ -890,6 +894,7 @@
     gns_resolver_lookup_record(zone, zone, clh->type, name,
                                NULL,
                                default_lookup_timeout,
+                               only_cached,
                                &send_lookup_response, clh);
   }
 }

Modified: gnunet/src/gns/gnunet-service-gns_interceptor.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_interceptor.c     2012-06-11 15:10:21 UTC 
(rev 21892)
+++ gnunet/src/gns/gnunet-service-gns_interceptor.c     2012-06-11 15:50:40 UTC 
(rev 21893)
@@ -246,6 +246,7 @@
   gns_resolver_lookup_record(our_zone, our_zone, q->type, q->name,
                              our_key,
                              default_lookup_timeout,
+                             GNUNET_NO,
                              &reply_to_dns, ilh);
 }
 

Modified: gnunet/src/gns/gnunet-service-gns_resolver.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.c        2012-06-11 15:10:21 UTC 
(rev 21892)
+++ gnunet/src/gns/gnunet-service-gns_resolver.c        2012-06-11 15:50:40 UTC 
(rev 21893)
@@ -638,6 +638,7 @@
                              new_name,
                              rh->priv_key,
                              GNUNET_TIME_UNIT_FOREVER_REL,
+                             GNUNET_NO,
                              &background_lookup_result_processor,
                              NULL);
   rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1085,6 +1086,7 @@
                              new_name,
                              rh->priv_key,
                              GNUNET_TIME_UNIT_FOREVER_REL,
+                             GNUNET_NO,
                              &background_lookup_result_processor,
                              NULL);
 
@@ -1496,7 +1498,7 @@
                rh->status);
     
     /**
-     * There are 4 conditions that have to met for us to consult the DHT:
+     * There are 5 conditions that have to met for us to consult the DHT:
      * 1. The entry in the DHT is RSL_RECORD_EXPIRED AND
      * 2. No entry in the NS existed AND
      * 3. The zone queried is not the local resolver's zone AND
@@ -1504,11 +1506,13 @@
      *    because if it was any other canonical name we either already queried
      *    the DHT for the authority in the authority lookup phase (and thus
      *    would already have an entry in the NS for the record)
+     * 5. We are not in cache only mode
      */
     if (rh->status & (RSL_RECORD_EXPIRED | !RSL_RECORD_EXISTS) &&
         GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
                                      &rh->private_local_zone) &&
-        (strcmp(rh->name, "+") == 0))
+        (strcmp(rh->name, "+") == 0) &&
+        (rh->only_cached == GNUNET_NO))
     {
       rh->proc = &handle_record_dht;
       resolve_record_dht(rh);
@@ -1822,6 +1826,15 @@
     }
     return;
   }
+
+  if (rh->only_cached == GNUNET_YES)
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "GNS_PHASE_DELEGATE_NS-%llu: Only cache resolution, no 
result\n",
+               rh->id, rh->name);
+    finish_lookup(rh, rlh, rd_count, rd);
+    return;
+  }
   
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
       "GNS_PHASE_DELEGATE_NS-%llu: Trying to resolve delegation for %s via 
DHT\n",
@@ -2060,6 +2073,7 @@
  * @param name the name to look up
  * @param key a private key for use with PSEU import (can be NULL)
  * @param timeout timeout for resolution
+ * @param only_cached GNUNET_NO to only check locally not DHT for performance
  * @param proc the processor to call on result
  * @param cls the closure to pass to proc
  */
@@ -2070,6 +2084,7 @@
                            const char* name,
                            struct GNUNET_CRYPTO_RsaPrivateKey *key,
                            struct GNUNET_TIME_Relative timeout,
+                           int only_cached,
                            RecordLookupProcessor proc,
                            void* cls)
 {
@@ -2102,6 +2117,7 @@
   rh->timeout = timeout;
   rh->get_handle = NULL;
   rh->private_local_zone = pzone;
+  rh->only_cached = only_cached;
 
   if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
   {

Modified: gnunet/src/gns/gnunet-service-gns_resolver.h
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.h        2012-06-11 15:10:21 UTC 
(rev 21892)
+++ gnunet/src/gns/gnunet-service-gns_resolver.h        2012-06-11 15:50:40 UTC 
(rev 21893)
@@ -114,6 +114,9 @@
   /* has this query been answered? how many matches */
   int answered;
 
+  /* Use only cache */
+  int only_cached;
+
   /* the authoritative zone to query */
   struct GNUNET_CRYPTO_ShortHashCode authority;
 
@@ -284,6 +287,7 @@
  * @param name the name to look up
  * @param key optional private key for authority caching
  * @param timeout timeout for the resolution
+ * @param only_cached GNUNET_NO to only check locally not DHT for performance
  * @param proc the processor to call
  * @param cls the closure to pass to proc
  */
@@ -294,6 +298,7 @@
                            const char* name,
                            struct GNUNET_CRYPTO_RsaPrivateKey *key,
                            struct GNUNET_TIME_Relative timeout,
+                           int only_cached,
                            RecordLookupProcessor proc,
                            void* cls);
 

Modified: gnunet/src/include/gnunet_gns_service.h
===================================================================
--- gnunet/src/include/gnunet_gns_service.h     2012-06-11 15:10:21 UTC (rev 
21892)
+++ gnunet/src/include/gnunet_gns_service.h     2012-06-11 15:50:40 UTC (rev 
21893)
@@ -127,6 +127,7 @@
  * @param handle handle to the GNS service
  * @param name the name to look up
  * @param type the GNUNET_GNS_RecordType to look for
+ * @param only_cached GNUNET_NO to only check locally not DHT for performance
  * @param proc function to call on result
  * @param proc_cls closure for processor
  *
@@ -136,6 +137,7 @@
 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
                          const char * name,
                          enum GNUNET_GNS_RecordType type,
+                         int only_cached,
                          GNUNET_GNS_LookupResultProcessor proc,
                          void *proc_cls);
 
@@ -148,6 +150,7 @@
  * @param zone the zone to start the resolution in
  * @param shorten_zone the zone where to shorten names into
  * @param type the GNUNET_GNS_RecordType to look for
+ * @param only_cached GNUNET_NO to only check locally not DHT for performance
  * @param proc function to call on result
  * @param proc_cls closure for processor
  *
@@ -159,6 +162,7 @@
                          struct GNUNET_CRYPTO_ShortHashCode *zone,
                          struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                          enum GNUNET_GNS_RecordType type,
+                         int only_cached,
                          GNUNET_GNS_LookupResultProcessor proc,
                          void *proc_cls);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]