From 00eda546242086cee3dc920e2f82a7b5be3e0999 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 12 Mar 2012 13:12:37 +0000 Subject: -bugfixes, tests --- src/gns/Makefile.am | 29 +++++++------ src/gns/gns_api.c | 2 +- src/gns/gnunet-service-gns.c | 2 + src/gns/plugin_block_gns.c | 24 ++++++++++- src/gns/test_gns_dht_delegated_lookup.c | 75 +++++++++++++++++++++------------ src/namestore/namestore_common.c | 2 +- 6 files changed, 91 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 9aafedf16..08da0a8e2 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -30,7 +30,8 @@ check_PROGRAMS = \ test_gns_simple_shorten \ test_gns_simple_get_authority \ test_gns_simple_lookup \ - test_gns_simple_delegated_lookup + test_gns_simple_delegated_lookup \ + test_gns_dht_delegated_lookup # test_gns_simple_lookup @@ -78,18 +79,20 @@ test_gns_simple_delegated_lookup_DEPENDENCIES = \ $(top_builddir)/src/gns/libgnunetgns.la \ $(top_builddir)/src/testing/libgnunettesting.la -#test_gns_dht_delegated_lookup_SOURCES = \ -# test_gns_dht_delegated_lookup.c -#test_gns_dht_delegated_lookup_LDADD = \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# $(top_builddir)/src/namestore/libgnunetnamestore.la \ -# $(top_builddir)/src/dht/libgnunetdht.la \ -# $(top_builddir)/src/testing/libgnunettesting.la -#test_gns_dht_delegated_lookup_DEPENDENCIES = \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# $(top_builddir)/src/namestore/libgnunetnamestore.la \ -# $(top_builddir)/src/dht/libgnunetdht.la \ -# $(top_builddir)/src/testing/libgnunettesting.la +test_gns_dht_delegated_lookup_SOURCES = \ + test_gns_dht_delegated_lookup.c +test_gns_dht_delegated_lookup_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/dht/libgnunetdht.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing/libgnunettesting.la +test_gns_dht_delegated_lookup_DEPENDENCIES = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/dht/libgnunetdht.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing/libgnunettesting.la test_gns_simple_shorten_SOURCES = \ test_gns_simple_shorten.c diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index d15f1908e..d6709a96e 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -636,7 +636,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, } msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name); qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry)); qe->gns_handle = handle; diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 09054d2b9..480d6bea9 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -863,6 +863,8 @@ process_delegation_result_dht(void* cls, int rd_size; GNUNET_HashCode zone, name_hash; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got DHT result\n"); + if (data == NULL) return; diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 4c8ab3eb9..329088280 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c @@ -75,6 +75,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, uint32_t record_xquery; unsigned int record_match; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "BLOCK_TEST\n"); + if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; if (reply_block_size == 0) @@ -90,6 +93,15 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, GNUNET_CRYPTO_hash_xor(&pkey_hash, &name_hash, &query_key); + struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp; + struct GNUNET_CRYPTO_HashAsciiEncoded xor_got; + GNUNET_CRYPTO_hash_to_enc (&query_key, &xor_exp); + GNUNET_CRYPTO_hash_to_enc (query, &xor_got); + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "BLOCK_TEST for %s got %s expected %s\n", + name, (char*) &xor_got, (char*) &xor_exp); + /* Check query key against public key */ if (0 != GNUNET_CRYPTO_hash_cmp(query, &query_key)) return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; @@ -124,6 +136,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, { exp = GNUNET_TIME_absolute_min (exp, rd[i].expiration); + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Got record of size %d\n", rd[i].data_size); if ((record_xquery != 0) && (rd[i].record_type == record_xquery)) @@ -131,6 +146,10 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, record_match++; } } + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Verifying signature of %d records for name %s\n", + rd_count, name); if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, exp, @@ -144,9 +163,12 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, } } - //No record matches query if ((record_xquery != 0) && (record_match == 0)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "No record matches query!\n"); return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + } GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Records match\n"); diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c index dc73c7b58..6fc4a42bb 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c @@ -83,6 +83,8 @@ static int ok; static struct GNUNET_NAMESTORE_Handle *namestore_handle; +static struct GNUNET_GNS_Handle *gns_handle; + static struct GNUNET_DHT_Handle *dht_handle; const struct GNUNET_CONFIGURATION_Handle *cfg; @@ -108,42 +110,39 @@ shutdown_callback (void *cls, const char *emsg) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); } -/** - * Function scheduled to be run on the successful start of services - * tries to look up the dns record for TEST_DOMAIN - */ + static void -finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +on_lookup_result(void *cls, uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) { - struct hostent *he; struct in_addr a; + int i; char* addr; - - GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); - GNUNET_DHT_disconnect(dht_handle); - - he = gethostbyname (TEST_DOMAIN); - - if (!he) + + if (rd_count == 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "gethostbyname failed, rp_filtering?\n"); + "Lookup failed, rp_filtering?\n"); ok = 2; } else { ok = 1; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", he->h_name); - while (*he->h_addr_list) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); + for (i=0; ih_addr_list++, sizeof(a)); - addr = inet_ntoa(a); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); - if (0 == strcmp(addr, TEST_IP)) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); + if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + memcpy(&a, rd[i].data, sizeof(a)); + addr = inet_ntoa(a); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); + if (0 == strcmp(addr, TEST_IP)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s correctly resolved to %s!\n", TEST_DOMAIN, addr); - ok = 0; + ok = 0; + } } else { @@ -156,6 +155,28 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_YES, GNUNET_NO); } + +/** + * Function scheduled to be run on the successful start of services + * tries to look up the dns record for TEST_DOMAIN + */ +static void +commence_testing (void *cls, int32_t success, const char *emsg) +{ + GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); + + gns_handle = GNUNET_GNS_connect(cfg); + + if (NULL == gns_handle) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to GNS!\n"); + } + + GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A, + &on_lookup_result, TEST_DOMAIN); +} + /** * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut * down the peers without freeing memory associated with GET request. @@ -214,7 +235,7 @@ put_dht(void *cls, int32_t success, const char *emsg) nrb->public_key = bob_pkey; nrb->rd_count = htonl(1); memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1); - memcpy(&nrb[1], TEST_RECORD_NAME, strlen(TEST_RECORD_NAME)); + strcpy(&nrb[1], TEST_RECORD_NAME); nrb_data = (char*)&nrb[1]; nrb_data += strlen(TEST_RECORD_NAME) + 1; @@ -247,7 +268,7 @@ put_dht(void *cls, int32_t success, const char *emsg) NULL, NULL); GNUNET_free (nrb); - GNUNET_SCHEDULER_add_delayed(TIMEOUT, &finish_testing, NULL); + GNUNET_SCHEDULER_add_delayed(TIMEOUT, &commence_testing, NULL); } static void @@ -345,7 +366,7 @@ check () int ret; /* Arguments for GNUNET_PROGRAM_run */ - char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */ + char *const argv[] = { "test-gns-dht-delegated-lookup", /* Name to give running binary */ "-c", "test_gns_simple_lookup.conf", /* Config file to use */ #if VERBOSE @@ -359,12 +380,12 @@ check () /* Run the run function as a new program */ ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, - "test-gns-simple-lookup", "nohelp", options, &run, + "test-gns-dht-delegated-lookup", "nohelp", options, &run, &ok); if (ret != GNUNET_OK) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "`test-gns-simple-lookup': Failed with error code %d\n", ret); + "`test-gns-dht-delegated-lookup': Failed with error code %d\n", ret); } return ok; } diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c index b8236edf0..72a2625ae 100644 --- a/src/namestore/namestore_common.c +++ b/src/namestore/namestore_common.c @@ -86,7 +86,7 @@ GNUNET_NAMESTORE_records_get_size (unsigned int rd_count, ret = sizeof (struct NetworkRecord) * rd_count; for (i=0;i= ret); + GNUNET_assert ((ret + rd[i].data_size) >= ret); ret += rd[i].data_size; } return ret; -- cgit v1.2.3