From 82e1974e76ae1c4a0002dfc2b81d3b3f07d50637 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 16 Mar 2012 08:39:00 +0000 Subject: [PATCH] -fixes --- src/gns/gnunet-service-gns.c | 41 ++++++++++++---------- src/gns/gnunet-service-gns_resolver.c | 36 +++++++++++-------- src/gns/gnunet-service-gns_resolver.h | 11 ++++++ src/gns/test_gns_dht_delegated_lookup.c | 2 +- src/gns/test_gns_simple_delegated_lookup.c | 2 +- src/gns/test_gns_simple_lookup.c | 2 +- src/gns/test_gns_simple_shorten.c | 2 +- 7 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 5c7c8b150..182655005 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -108,7 +108,7 @@ struct ClientLookupHandle /** * Our handle to the DHT */ -struct GNUNET_DHT_Handle *dht_handle; +static struct GNUNET_DHT_Handle *dht_handle; /** * Our zone's private key @@ -760,23 +760,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, &zone_hash); GNUNET_free(keyfile); - - if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (c, "gns", - "HIJACK_DNS")) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "DNS hijacking enabled... connecting to service.\n"); - - if (gns_interceptor_init(zone_hash, c) == GNUNET_SYSERR) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to enable the dns interceptor!\n"); - } - } - - - /** * handle to our local namestore */ @@ -801,6 +784,28 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n"); } + if (gns_resolver_init(namestore_handle, dht_handle) == GNUNET_SYSERR) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Unable to initialize resolver!\n"); + GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); + return; + } + + if (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_yesno (c, "gns", + "HIJACK_DNS")) + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "DNS hijacking enabled... connecting to service.\n"); + + if (gns_interceptor_init(zone_hash, c) == GNUNET_SYSERR) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to enable the dns interceptor!\n"); + } + } + //put_some_records(); //FIXME for testing /** diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 9b83794f5..a46a2fd61 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -47,22 +47,29 @@ /** * Our handle to the namestore service */ -struct GNUNET_NAMESTORE_Handle *namestore_handle; +static struct GNUNET_NAMESTORE_Handle *namestore_handle; /** * Resolver handle to the dht */ -struct GNUNET_DHT_Handle *dht_handle; +static struct GNUNET_DHT_Handle *dht_handle; /** - * Connects resolver to the dht - * -static void -connect_to_dht() + * Initialize the resolver + */ +int +gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, + struct GNUNET_DHT_Handle *dh) { - //FIXME + namestore_handle = nh; + dht_handle = dh; + if ((namestore_handle != NULL) && (dht_handle != NULL)) + { + return GNUNET_OK; + } + return GNUNET_SYSERR; } -*/ + /** * Helper function to free resolver handle @@ -274,7 +281,7 @@ resolve_record_dht(struct ResolverHandle *rh) GNUNET_HashCode lookup_key; struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls; - + GNUNET_CRYPTO_hash(rh->name, strlen(rh->name), &name_hash); GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); @@ -597,12 +604,11 @@ process_delegation_result_dht(void* cls, resolve_delegation_dht(rh); return; } - + /** - * should never get here unless false dht key/put - * block plugin should handle this - **/ - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "DHT authority lookup found no match!\n"); + * No pkey but name exists + */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DHT authority lookup found no match!\n"); rh->proc(rh->proc_cls, rh, 0, NULL); } @@ -808,7 +814,7 @@ resolve_delegation_dht(struct ResolverHandle *rh) uint32_t xquery; GNUNET_HashCode name_hash; GNUNET_HashCode lookup_key; - + GNUNET_CRYPTO_hash(rh->authority_name, strlen(rh->authority_name), &name_hash); diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 2b0c4755d..79e916015 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -2,6 +2,7 @@ #define GNS_RESOLVER_H #include "gns.h" +#include "gnunet_dht_service.h" #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) #define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT @@ -185,6 +186,16 @@ struct GetNameAuthorityHandle }; +/** + * Initialize the resolver + * + * @param nh handle to the namestore + * @param dh handle to the dht + * @returns GNUNET_OK on success + */ +int +gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, + struct GNUNET_DHT_Handle *dh); /** * Lookup of a record in a specific zone diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c index de393fa08..469ae36be 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c @@ -51,7 +51,7 @@ #define VERBOSE GNUNET_YES /* Timeout for entire testcase */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) /* If number of peers not in config file, use this number */ #define DEFAULT_NUM_PEERS 2 diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c index 6a12ecfe0..2bbc87584 100644 --- a/src/gns/test_gns_simple_delegated_lookup.c +++ b/src/gns/test_gns_simple_delegated_lookup.c @@ -50,7 +50,7 @@ #define VERBOSE GNUNET_YES /* Timeout for entire testcase */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) /* If number of peers not in config file, use this number */ #define DEFAULT_NUM_PEERS 2 diff --git a/src/gns/test_gns_simple_lookup.c b/src/gns/test_gns_simple_lookup.c index 76f7efece..8bd33fc47 100644 --- a/src/gns/test_gns_simple_lookup.c +++ b/src/gns/test_gns_simple_lookup.c @@ -49,7 +49,7 @@ #define VERBOSE GNUNET_YES /* Timeout for entire testcase */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) /* If number of peers not in config file, use this number */ #define DEFAULT_NUM_PEERS 2 diff --git a/src/gns/test_gns_simple_shorten.c b/src/gns/test_gns_simple_shorten.c index c9989dd17..c444dfe87 100644 --- a/src/gns/test_gns_simple_shorten.c +++ b/src/gns/test_gns_simple_shorten.c @@ -36,7 +36,7 @@ #define VERBOSE GNUNET_YES /* Timeout for entire testcase */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) /* If number of peers not in config file, use this number */ #define DEFAULT_NUM_PEERS 2 -- 2.25.1