summaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-11 15:50:40 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-11 15:50:40 +0000
commit366546f576315e0de97a700546d108a974161734 (patch)
tree87232a31739b479c7cde5b49b005923bc487fd42 /src/gns
parent16cf819a0feb38c36b046c59febae5bc511a3d1b (diff)
downloadgnunet-366546f576315e0de97a700546d108a974161734.tar.gz
gnunet-366546f576315e0de97a700546d108a974161734.zip
-add cached flag for performance
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gns.h5
-rw-r--r--src/gns/gns_api.c7
-rw-r--r--src/gns/gnunet-gns-proxy.c29
-rw-r--r--src/gns/gnunet-gns.c8
-rw-r--r--src/gns/gnunet-service-gns.c5
-rw-r--r--src/gns/gnunet-service-gns_interceptor.c1
-rw-r--r--src/gns/gnunet-service-gns_resolver.c20
-rw-r--r--src/gns/gnunet-service-gns_resolver.h5
8 files changed, 66 insertions, 14 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h
index 80ebb1288..686729dd7 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -53,6 +53,11 @@ struct GNUNET_GNS_ClientLookupMessage
53 uint32_t id GNUNET_PACKED; 53 uint32_t id GNUNET_PACKED;
54 54
55 /** 55 /**
56 * Only check cached results
57 */
58 uint32_t only_cached GNUNET_PACKED;
59
60 /**
56 * Should we look up in the default zone? 61 * Should we look up in the default zone?
57 */ 62 */
58 uint32_t use_default_zone GNUNET_PACKED; 63 uint32_t use_default_zone GNUNET_PACKED;
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 2cdb58a31..2e1e9712c 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -642,6 +642,7 @@ get_request_id (struct GNUNET_GNS_Handle *h)
642 * @param zone the zone to start the resolution in 642 * @param zone the zone to start the resolution in
643 * @param shorten_zone the zone where to shorten names into 643 * @param shorten_zone the zone where to shorten names into
644 * @param type the record type to look up 644 * @param type the record type to look up
645 * @param only_cached GNUNET_NO to only check locally not DHT for performance
645 * @param proc processor to call on result 646 * @param proc processor to call on result
646 * @param proc_cls closure for processor 647 * @param proc_cls closure for processor
647 * @return handle to the get 648 * @return handle to the get
@@ -652,6 +653,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
652 struct GNUNET_CRYPTO_ShortHashCode *zone, 653 struct GNUNET_CRYPTO_ShortHashCode *zone,
653 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, 654 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
654 enum GNUNET_GNS_RecordType type, 655 enum GNUNET_GNS_RecordType type,
656 int only_cached,
655 GNUNET_GNS_LookupResultProcessor proc, 657 GNUNET_GNS_LookupResultProcessor proc,
656 void *proc_cls) 658 void *proc_cls)
657{ 659{
@@ -686,6 +688,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
686 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP); 688 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
687 lookup_msg->header.size = htons (msize); 689 lookup_msg->header.size = htons (msize);
688 lookup_msg->id = htonl(qe->r_id); 690 lookup_msg->id = htonl(qe->r_id);
691 lookup_msg->only_cached = htonl(only_cached);
689 692
690 if (NULL != zone) 693 if (NULL != zone)
691 { 694 {
@@ -728,6 +731,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
728 * @param handle handle to the GNS service 731 * @param handle handle to the GNS service
729 * @param name the name to look up 732 * @param name the name to look up
730 * @param type the record type to look up 733 * @param type the record type to look up
734 * @param only_cached GNUNET_NO to only check locally not DHT for performance
731 * @param proc processor to call on result 735 * @param proc processor to call on result
732 * @param proc_cls closure for processor 736 * @param proc_cls closure for processor
733 * @return handle to the get 737 * @return handle to the get
@@ -736,12 +740,13 @@ struct GNUNET_GNS_QueueEntry *
736GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, 740GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
737 const char * name, 741 const char * name,
738 enum GNUNET_GNS_RecordType type, 742 enum GNUNET_GNS_RecordType type,
743 int only_cached,
739 GNUNET_GNS_LookupResultProcessor proc, 744 GNUNET_GNS_LookupResultProcessor proc,
740 void *proc_cls) 745 void *proc_cls)
741{ 746{
742 return GNUNET_GNS_lookup_zone (handle, name, 747 return GNUNET_GNS_lookup_zone (handle, name,
743 NULL, NULL, 748 NULL, NULL,
744 type, proc, proc_cls); 749 type, only_cached, proc, proc_cls);
745} 750}
746 751
747/** 752/**
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index eff7fbfbd..ea1219b29 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1010,14 +1010,26 @@ process_leho_lookup (void *cls,
1010 if (ctask->mhd->is_ssl) 1010 if (ctask->mhd->is_ssl)
1011 { 1011 {
1012 phost = (struct hostent*)gethostbyname (ctask->host); 1012 phost = (struct hostent*)gethostbyname (ctask->host);
1013 ssl_ip = inet_ntoa(*((struct in_addr*)(phost->h_addr))); 1013
1014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1014 if (phost!=NULL)
1015 "SSL target server: %s\n", ssl_ip); 1015 {
1016 sprintf (resolvename, "%s:%d:%s", ctask->leho, HTTPS_PORT, ssl_ip); 1016 ssl_ip = inet_ntoa(*((struct in_addr*)(phost->h_addr)));
1017 ctask->resolver = curl_slist_append ( ctask->resolver, resolvename); 1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1018 curl_easy_setopt (ctask->curl, CURLOPT_RESOLVE, ctask->resolver); 1018 "SSL target server: %s\n", ssl_ip);
1019 sprintf (curlurl, "https://%s%s", ctask->leho, ctask->url); 1019 sprintf (resolvename, "%s:%d:%s", ctask->leho, HTTPS_PORT, ssl_ip);
1020 curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); 1020 ctask->resolver = curl_slist_append ( ctask->resolver, resolvename);
1021 curl_easy_setopt (ctask->curl, CURLOPT_RESOLVE, ctask->resolver);
1022 sprintf (curlurl, "https://%s%s", ctask->leho, ctask->url);
1023 curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl);
1024 }
1025 else
1026 {
1027 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1028 "gethostbyname failed for %s!\n", ctask->host);
1029 ctask->download_successful = GNUNET_NO;
1030 ctask->download_error = GNUNET_YES;
1031 return;
1032 }
1021 } 1033 }
1022 1034
1023 if (CURLM_OK != (mret=curl_multi_add_handle (curl_multi, ctask->curl))) 1035 if (CURLM_OK != (mret=curl_multi_add_handle (curl_multi, ctask->curl)))
@@ -1067,6 +1079,7 @@ process_get_authority (void *cls,
1067 &local_gns_zone, 1079 &local_gns_zone,
1068 &local_shorten_zone, 1080 &local_shorten_zone,
1069 GNUNET_GNS_RECORD_LEHO, 1081 GNUNET_GNS_RECORD_LEHO,
1082 GNUNET_YES, //Only cached for performance
1070 &process_leho_lookup, 1083 &process_leho_lookup,
1071 ctask); 1084 ctask);
1072} 1085}
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 78fe513ec..6b0ae5dca 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -151,6 +151,7 @@ run (void *cls, char *const *args, const char *cfgfile,
151 struct GNUNET_CRYPTO_ShortHashCode *zone = NULL; 151 struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
152 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone = NULL; 152 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone = NULL;
153 struct GNUNET_CRYPTO_ShortHashCode user_zone; 153 struct GNUNET_CRYPTO_ShortHashCode user_zone;
154 struct GNUNET_CRYPTO_ShortHashCode user_shorten_zone;
154 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename; 155 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
155 156
156 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 157 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
@@ -197,12 +198,12 @@ run (void *cls, char *const *args, const char *cfgfile,
197 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); 198 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
198 GNUNET_CRYPTO_short_hash(&pkey, 199 GNUNET_CRYPTO_short_hash(&pkey,
199 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 200 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
200 &user_zone); 201 &user_shorten_zone);
201 shorten_zone = &user_zone; 202 shorten_zone = &user_shorten_zone;
202 GNUNET_CRYPTO_short_hash_to_enc (shorten_zone, &zonename); 203 GNUNET_CRYPTO_short_hash_to_enc (shorten_zone, &zonename);
203 if (!raw) 204 if (!raw)
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Using zone: %s!\n", &zonename); 206 "Using shorten zone: %s!\n", &zonename);
206 GNUNET_CRYPTO_rsa_key_free(key); 207 GNUNET_CRYPTO_rsa_key_free(key);
207 } 208 }
208 GNUNET_free(keyfile); 209 GNUNET_free(keyfile);
@@ -237,6 +238,7 @@ run (void *cls, char *const *args, const char *cfgfile,
237 GNUNET_GNS_lookup_zone (gns, lookup_name, 238 GNUNET_GNS_lookup_zone (gns, lookup_name,
238 zone, shorten_zone, 239 zone, shorten_zone,
239 rtype, 240 rtype,
241 GNUNET_YES, //Use DHT
240 &process_lookup_result, lookup_name); 242 &process_lookup_result, lookup_name);
241 } 243 }
242 244
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 8f8fbe41b..543ccf518 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -825,6 +825,7 @@ handle_lookup(void *cls,
825 char* nameptr = name; 825 char* nameptr = name;
826 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; 826 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
827 struct GNUNET_CRYPTO_ShortHashCode zone; 827 struct GNUNET_CRYPTO_ShortHashCode zone;
828 int only_cached;
828 829
829 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) 830 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
830 { 831 {
@@ -856,6 +857,8 @@ handle_lookup(void *cls,
856 clh->unique_id = sh_msg->id; 857 clh->unique_id = sh_msg->id;
857 clh->type = ntohl(sh_msg->type); 858 clh->type = ntohl(sh_msg->type);
858 clh->shorten_key = NULL; 859 clh->shorten_key = NULL;
860
861 only_cached = ntohl(sh_msg->only_cached);
859 862
860 if (strlen (name) > MAX_DNS_NAME_LENGTH) { 863 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
861 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 864 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -883,6 +886,7 @@ handle_lookup(void *cls,
883 gns_resolver_lookup_record(zone, zone, clh->type, name, 886 gns_resolver_lookup_record(zone, zone, clh->type, name,
884 key, 887 key,
885 default_lookup_timeout, 888 default_lookup_timeout,
889 only_cached,
886 &send_lookup_response, clh); 890 &send_lookup_response, clh);
887 } 891 }
888 else 892 else
@@ -890,6 +894,7 @@ handle_lookup(void *cls,
890 gns_resolver_lookup_record(zone, zone, clh->type, name, 894 gns_resolver_lookup_record(zone, zone, clh->type, name,
891 NULL, 895 NULL,
892 default_lookup_timeout, 896 default_lookup_timeout,
897 only_cached,
893 &send_lookup_response, clh); 898 &send_lookup_response, clh);
894 } 899 }
895} 900}
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index adb09ca7f..0e44755ed 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -246,6 +246,7 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
246 gns_resolver_lookup_record(our_zone, our_zone, q->type, q->name, 246 gns_resolver_lookup_record(our_zone, our_zone, q->type, q->name,
247 our_key, 247 our_key,
248 default_lookup_timeout, 248 default_lookup_timeout,
249 GNUNET_NO,
249 &reply_to_dns, ilh); 250 &reply_to_dns, ilh);
250} 251}
251 252
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index e2e99b56e..9883f7c45 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -638,6 +638,7 @@ dht_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
638 new_name, 638 new_name,
639 rh->priv_key, 639 rh->priv_key,
640 GNUNET_TIME_UNIT_FOREVER_REL, 640 GNUNET_TIME_UNIT_FOREVER_REL,
641 GNUNET_NO,
641 &background_lookup_result_processor, 642 &background_lookup_result_processor,
642 NULL); 643 NULL);
643 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 644 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1085,6 +1086,7 @@ dht_authority_lookup_timeout(void *cls,
1085 new_name, 1086 new_name,
1086 rh->priv_key, 1087 rh->priv_key,
1087 GNUNET_TIME_UNIT_FOREVER_REL, 1088 GNUNET_TIME_UNIT_FOREVER_REL,
1089 GNUNET_NO,
1088 &background_lookup_result_processor, 1090 &background_lookup_result_processor,
1089 NULL); 1091 NULL);
1090 1092
@@ -1496,7 +1498,7 @@ handle_record_ns(void* cls, struct ResolverHandle *rh,
1496 rh->status); 1498 rh->status);
1497 1499
1498 /** 1500 /**
1499 * There are 4 conditions that have to met for us to consult the DHT: 1501 * There are 5 conditions that have to met for us to consult the DHT:
1500 * 1. The entry in the DHT is RSL_RECORD_EXPIRED AND 1502 * 1. The entry in the DHT is RSL_RECORD_EXPIRED AND
1501 * 2. No entry in the NS existed AND 1503 * 2. No entry in the NS existed AND
1502 * 3. The zone queried is not the local resolver's zone AND 1504 * 3. The zone queried is not the local resolver's zone AND
@@ -1504,11 +1506,13 @@ handle_record_ns(void* cls, struct ResolverHandle *rh,
1504 * because if it was any other canonical name we either already queried 1506 * because if it was any other canonical name we either already queried
1505 * the DHT for the authority in the authority lookup phase (and thus 1507 * the DHT for the authority in the authority lookup phase (and thus
1506 * would already have an entry in the NS for the record) 1508 * would already have an entry in the NS for the record)
1509 * 5. We are not in cache only mode
1507 */ 1510 */
1508 if (rh->status & (RSL_RECORD_EXPIRED | !RSL_RECORD_EXISTS) && 1511 if (rh->status & (RSL_RECORD_EXPIRED | !RSL_RECORD_EXISTS) &&
1509 GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, 1512 GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
1510 &rh->private_local_zone) && 1513 &rh->private_local_zone) &&
1511 (strcmp(rh->name, "+") == 0)) 1514 (strcmp(rh->name, "+") == 0) &&
1515 (rh->only_cached == GNUNET_NO))
1512 { 1516 {
1513 rh->proc = &handle_record_dht; 1517 rh->proc = &handle_record_dht;
1514 resolve_record_dht(rh); 1518 resolve_record_dht(rh);
@@ -1822,6 +1826,15 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh,
1822 } 1826 }
1823 return; 1827 return;
1824 } 1828 }
1829
1830 if (rh->only_cached == GNUNET_YES)
1831 {
1832 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1833 "GNS_PHASE_DELEGATE_NS-%llu: Only cache resolution, no result\n",
1834 rh->id, rh->name);
1835 finish_lookup(rh, rlh, rd_count, rd);
1836 return;
1837 }
1825 1838
1826 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1839 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1827 "GNS_PHASE_DELEGATE_NS-%llu: Trying to resolve delegation for %s via DHT\n", 1840 "GNS_PHASE_DELEGATE_NS-%llu: Trying to resolve delegation for %s via DHT\n",
@@ -2060,6 +2073,7 @@ resolve_delegation_ns(struct ResolverHandle *rh)
2060 * @param name the name to look up 2073 * @param name the name to look up
2061 * @param key a private key for use with PSEU import (can be NULL) 2074 * @param key a private key for use with PSEU import (can be NULL)
2062 * @param timeout timeout for resolution 2075 * @param timeout timeout for resolution
2076 * @param only_cached GNUNET_NO to only check locally not DHT for performance
2063 * @param proc the processor to call on result 2077 * @param proc the processor to call on result
2064 * @param cls the closure to pass to proc 2078 * @param cls the closure to pass to proc
2065 */ 2079 */
@@ -2070,6 +2084,7 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
2070 const char* name, 2084 const char* name,
2071 struct GNUNET_CRYPTO_RsaPrivateKey *key, 2085 struct GNUNET_CRYPTO_RsaPrivateKey *key,
2072 struct GNUNET_TIME_Relative timeout, 2086 struct GNUNET_TIME_Relative timeout,
2087 int only_cached,
2073 RecordLookupProcessor proc, 2088 RecordLookupProcessor proc,
2074 void* cls) 2089 void* cls)
2075{ 2090{
@@ -2102,6 +2117,7 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
2102 rh->timeout = timeout; 2117 rh->timeout = timeout;
2103 rh->get_handle = NULL; 2118 rh->get_handle = NULL;
2104 rh->private_local_zone = pzone; 2119 rh->private_local_zone = pzone;
2120 rh->only_cached = only_cached;
2105 2121
2106 if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 2122 if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
2107 { 2123 {
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index 8222397c4..f1f25a5c1 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -114,6 +114,9 @@ struct ResolverHandle
114 /* has this query been answered? how many matches */ 114 /* has this query been answered? how many matches */
115 int answered; 115 int answered;
116 116
117 /* Use only cache */
118 int only_cached;
119
117 /* the authoritative zone to query */ 120 /* the authoritative zone to query */
118 struct GNUNET_CRYPTO_ShortHashCode authority; 121 struct GNUNET_CRYPTO_ShortHashCode authority;
119 122
@@ -284,6 +287,7 @@ gns_resolver_cleanup(ResolverCleanupContinuation cont);
284 * @param name the name to look up 287 * @param name the name to look up
285 * @param key optional private key for authority caching 288 * @param key optional private key for authority caching
286 * @param timeout timeout for the resolution 289 * @param timeout timeout for the resolution
290 * @param only_cached GNUNET_NO to only check locally not DHT for performance
287 * @param proc the processor to call 291 * @param proc the processor to call
288 * @param cls the closure to pass to proc 292 * @param cls the closure to pass to proc
289 */ 293 */
@@ -294,6 +298,7 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
294 const char* name, 298 const char* name,
295 struct GNUNET_CRYPTO_RsaPrivateKey *key, 299 struct GNUNET_CRYPTO_RsaPrivateKey *key,
296 struct GNUNET_TIME_Relative timeout, 300 struct GNUNET_TIME_Relative timeout,
301 int only_cached,
297 RecordLookupProcessor proc, 302 RecordLookupProcessor proc,
298 void* cls); 303 void* cls);
299 304