From 366546f576315e0de97a700546d108a974161734 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 11 Jun 2012 15:50:40 +0000 Subject: [PATCH] -add cached flag for performance --- src/gns/gns.h | 5 ++++ src/gns/gns_api.c | 7 +++++- src/gns/gnunet-gns-proxy.c | 29 +++++++++++++++++------- src/gns/gnunet-gns.c | 8 ++++--- src/gns/gnunet-service-gns.c | 5 ++++ src/gns/gnunet-service-gns_interceptor.c | 1 + src/gns/gnunet-service-gns_resolver.c | 20 ++++++++++++++-- src/gns/gnunet-service-gns_resolver.h | 5 ++++ src/include/gnunet_gns_service.h | 4 ++++ 9 files changed, 70 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 @@ -52,6 +52,11 @@ struct GNUNET_GNS_ClientLookupMessage */ uint32_t id GNUNET_PACKED; + /** + * Only check cached results + */ + uint32_t only_cached GNUNET_PACKED; + /** * Should we look up in the default zone? */ 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) * @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 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, 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 @@ GNUNET_GNS_lookup_zone (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(qe->r_id); + lookup_msg->only_cached = htonl(only_cached); if (NULL != zone) { @@ -728,6 +731,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, * @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 @@ struct GNUNET_GNS_QueueEntry * 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); } /** 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, 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 @@ process_get_authority (void *cls, &local_gns_zone, &local_shorten_zone, GNUNET_GNS_RECORD_LEHO, + GNUNET_YES, //Only cached for performance &process_leho_lookup, ctask); } 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, 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 @@ run (void *cls, char *const *args, const char *cfgfile, 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 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_GNS_lookup_zone (gns, lookup_name, zone, shorten_zone, rtype, + GNUNET_YES, //Use DHT &process_lookup_result, lookup_name); } 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, 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 @@ handle_lookup(void *cls, 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 @@ handle_lookup(void *cls, gns_resolver_lookup_record(zone, zone, clh->type, name, key, default_lookup_timeout, + only_cached, &send_lookup_response, clh); } else @@ -890,6 +894,7 @@ handle_lookup(void *cls, gns_resolver_lookup_record(zone, zone, clh->type, name, NULL, default_lookup_timeout, + only_cached, &send_lookup_response, clh); } } 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, gns_resolver_lookup_record(our_zone, our_zone, q->type, q->name, our_key, default_lookup_timeout, + GNUNET_NO, &reply_to_dns, ilh); } 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) 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 @@ dht_authority_lookup_timeout(void *cls, new_name, rh->priv_key, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_NO, &background_lookup_result_processor, NULL); @@ -1496,7 +1498,7 @@ handle_record_ns(void* cls, struct ResolverHandle *rh, 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 @@ handle_record_ns(void* cls, struct ResolverHandle *rh, * 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 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, } 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 @@ resolve_delegation_ns(struct ResolverHandle *rh) * @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 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, const char* name, struct GNUNET_CRYPTO_RsaPrivateKey *key, struct GNUNET_TIME_Relative timeout, + int only_cached, RecordLookupProcessor proc, void* cls) { @@ -2102,6 +2117,7 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, 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) { 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 /* 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 @@ gns_resolver_cleanup(ResolverCleanupContinuation cont); * @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 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, const char* name, struct GNUNET_CRYPTO_RsaPrivateKey *key, struct GNUNET_TIME_Relative timeout, + int only_cached, RecordLookupProcessor proc, void* cls); diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index 1906aba45..4d04addf9 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -127,6 +127,7 @@ typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls, * @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 @@ struct GNUNET_GNS_QueueEntry * 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 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, * @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 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, 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); -- 2.25.1