diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-12-04 12:43:29 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-12-04 12:43:29 +0000 |
commit | cfe312d47e0685df7f753727bded7f28096e5a86 (patch) | |
tree | f0dfe78e35a456f08b7a557b9ac15651184b95eb /src/gns | |
parent | 71c8f1cd446bbd38e2e5ffda87355c10d28bb873 (diff) | |
download | gnunet-cfe312d47e0685df7f753727bded7f28096e5a86.tar.gz gnunet-cfe312d47e0685df7f753727bded7f28096e5a86.zip |
add cfg option to disable caching
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index ec6b37da0..ede81b49d 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -455,6 +455,10 @@ static struct CacheOps *co_head; | |||
455 | */ | 455 | */ |
456 | static struct CacheOps *co_tail; | 456 | static struct CacheOps *co_tail; |
457 | 457 | ||
458 | /** | ||
459 | * Use namecache | ||
460 | */ | ||
461 | static int use_cache; | ||
458 | 462 | ||
459 | /** | 463 | /** |
460 | * Global configuration. | 464 | * Global configuration. |
@@ -1925,6 +1929,31 @@ handle_dht_response (void *cls, | |||
1925 | co); | 1929 | co); |
1926 | } | 1930 | } |
1927 | 1931 | ||
1932 | static void | ||
1933 | start_dht_request (struct GNS_ResolverHandle *rh, struct GNUNET_HashCode query) | ||
1934 | { | ||
1935 | struct GNS_ResolverHandle *rx; | ||
1936 | GNUNET_assert (NULL == rh->get_handle); | ||
1937 | rh->get_handle = GNUNET_DHT_get_start (dht_handle, | ||
1938 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
1939 | &query, | ||
1940 | DHT_GNS_REPLICATION_LEVEL, | ||
1941 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
1942 | NULL, 0, | ||
1943 | &handle_dht_response, rh); | ||
1944 | rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap, | ||
1945 | rh, | ||
1946 | GNUNET_TIME_absolute_get ().abs_value_us); | ||
1947 | if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries) | ||
1948 | { | ||
1949 | /* fail longest-standing DHT request */ | ||
1950 | rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap); | ||
1951 | GNUNET_assert (NULL != rx); | ||
1952 | rx->proc (rx->proc_cls, 0, NULL); | ||
1953 | GNS_resolver_lookup_cancel (rx); | ||
1954 | } | ||
1955 | } | ||
1956 | |||
1928 | 1957 | ||
1929 | /** | 1958 | /** |
1930 | * Process a record that was stored in the namecache. | 1959 | * Process a record that was stored in the namecache. |
@@ -1937,15 +1966,11 @@ handle_namecache_block_response (void *cls, | |||
1937 | const struct GNUNET_GNSRECORD_Block *block) | 1966 | const struct GNUNET_GNSRECORD_Block *block) |
1938 | { | 1967 | { |
1939 | struct GNS_ResolverHandle *rh = cls; | 1968 | struct GNS_ResolverHandle *rh = cls; |
1940 | struct GNS_ResolverHandle *rx; | ||
1941 | struct AuthorityChain *ac = rh->ac_tail; | 1969 | struct AuthorityChain *ac = rh->ac_tail; |
1942 | const char *label = ac->label; | 1970 | const char *label = ac->label; |
1943 | const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority; | 1971 | const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority; |
1944 | struct GNUNET_HashCode query; | 1972 | struct GNUNET_HashCode query; |
1945 | 1973 | ||
1946 | GNUNET_GNSRECORD_query_from_public_key (auth, | ||
1947 | label, | ||
1948 | &query); | ||
1949 | GNUNET_assert (NULL != rh->namecache_qe); | 1974 | GNUNET_assert (NULL != rh->namecache_qe); |
1950 | rh->namecache_qe = NULL; | 1975 | rh->namecache_qe = NULL; |
1951 | if ( (GNUNET_NO == rh->only_cached) && | 1976 | if ( (GNUNET_NO == rh->only_cached) && |
@@ -1954,30 +1979,14 @@ handle_namecache_block_response (void *cls, | |||
1954 | { | 1979 | { |
1955 | /* namecache knows nothing; try DHT lookup */ | 1980 | /* namecache knows nothing; try DHT lookup */ |
1956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1981 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1957 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", | 1982 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", |
1958 | ac->label, | 1983 | ac->label, |
1959 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority), | 1984 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority), |
1960 | GNUNET_h2s (&query)); | 1985 | GNUNET_h2s (&query)); |
1961 | GNUNET_assert (NULL == rh->get_handle); | 1986 | GNUNET_GNSRECORD_query_from_public_key (auth, |
1962 | rh->get_handle = GNUNET_DHT_get_start (dht_handle, | 1987 | label, |
1963 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 1988 | &query); |
1964 | &query, | 1989 | start_dht_request(rh, query); |
1965 | DHT_GNS_REPLICATION_LEVEL, | ||
1966 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
1967 | NULL, 0, | ||
1968 | &handle_dht_response, rh); | ||
1969 | rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap, | ||
1970 | rh, | ||
1971 | GNUNET_TIME_absolute_get ().abs_value_us); | ||
1972 | if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries) | ||
1973 | { | ||
1974 | /* fail longest-standing DHT request */ | ||
1975 | rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap); | ||
1976 | GNUNET_assert (NULL != rx); | ||
1977 | rx->proc (rx->proc_cls, 0, NULL); | ||
1978 | GNS_resolver_lookup_cancel (rx); | ||
1979 | } | ||
1980 | return; | ||
1981 | } | 1990 | } |
1982 | 1991 | ||
1983 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1992 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2029,11 +2038,16 @@ recursive_gns_resolution_namecache (struct GNS_ResolverHandle *rh) | |||
2029 | GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority, | 2038 | GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority, |
2030 | ac->label, | 2039 | ac->label, |
2031 | &query); | 2040 | &query); |
2032 | rh->namecache_qe = GNUNET_NAMECACHE_lookup_block (namecache_handle, | 2041 | if (GNUNET_YES == use_cache) |
2042 | { | ||
2043 | rh->namecache_qe = GNUNET_NAMECACHE_lookup_block (namecache_handle, | ||
2033 | &query, | 2044 | &query, |
2034 | &handle_namecache_block_response, | 2045 | &handle_namecache_block_response, |
2035 | rh); | 2046 | rh); |
2036 | GNUNET_assert (NULL != rh->namecache_qe); | 2047 | GNUNET_assert (NULL != rh->namecache_qe); |
2048 | } | ||
2049 | else | ||
2050 | start_dht_request (rh, query); | ||
2037 | } | 2051 | } |
2038 | 2052 | ||
2039 | 2053 | ||
@@ -2402,6 +2416,13 @@ GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | |||
2402 | dht_lookup_heap = | 2416 | dht_lookup_heap = |
2403 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2417 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2404 | max_allowed_background_queries = max_bg_queries; | 2418 | max_allowed_background_queries = max_bg_queries; |
2419 | if (GNUNET_SYSERR == (use_cache = GNUNET_CONFIGURATION_get_value_yesno (c, | ||
2420 | "gns", | ||
2421 | "USE_CACHE"))) | ||
2422 | use_cache = GNUNET_YES; | ||
2423 | if (GNUNET_NO == use_cache) | ||
2424 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namecache disabled\n"); | ||
2425 | |||
2405 | if (GNUNET_OK != | 2426 | if (GNUNET_OK != |
2406 | GNUNET_CONFIGURATION_get_value_string (c, | 2427 | GNUNET_CONFIGURATION_get_value_string (c, |
2407 | "gns", | 2428 | "gns", |