From d656d0f85549e69a05490286b1ed5d7b06abede8 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 12 Mar 2012 10:32:05 +0000 Subject: [PATCH] -new test --- src/gns/Makefile.am | 25 ++++---- src/gns/test_gns_simple_delegated_lookup.c | 69 ++++++++++++++-------- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 912468774..8d7b9bb4a 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -28,7 +28,8 @@ bin_PROGRAMS = \ check_PROGRAMS = \ test_gns_simple_shorten \ - test_gns_simple_lookup + test_gns_simple_lookup \ + test_gns_simple_delegated_lookup # test_gns_simple_lookup @@ -63,16 +64,18 @@ test_gns_simple_lookup_DEPENDENCIES = \ $(top_builddir)/src/gns/libgnunetgns.la \ $(top_builddir)/src/testing/libgnunettesting.la -#test_gns_simple_delegated_lookup_SOURCES = \ -# test_gns_simple_delegated_lookup.c -#test_gns_simple_delegated_lookup_LDADD = \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# $(top_builddir)/src/namestore/libgnunetnamestore.la \ -# $(top_builddir)/src/testing/libgnunettesting.la -#test_gns_simple_delegated_lookup_DEPENDENCIES = \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# $(top_builddir)/src/namestore/libgnunetnamestore.la \ -# $(top_builddir)/src/testing/libgnunettesting.la +test_gns_simple_delegated_lookup_SOURCES = \ + test_gns_simple_delegated_lookup.c +test_gns_simple_delegated_lookup_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing/libgnunettesting.la +test_gns_simple_delegated_lookup_DEPENDENCIES = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing/libgnunettesting.la #test_gns_dht_delegated_lookup_SOURCES = \ # test_gns_dht_delegated_lookup.c diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c index 8e6e7753d..b80f2bbf0 100644 --- a/src/gns/test_gns_simple_delegated_lookup.c +++ b/src/gns/test_gns_simple_delegated_lookup.c @@ -80,6 +80,8 @@ static int ok; static struct GNUNET_NAMESTORE_Handle *namestore_handle; +static struct GNUNET_GNS_Handle *gns_handle; + const struct GNUNET_CONFIGURATION_Handle *cfg; /** @@ -98,43 +100,38 @@ 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, int32_t success, const char *emsg) +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_log (GNUNET_ERROR_TYPE_DEBUG, - "disconnecting from namestore\n"); - GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); - - 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 { @@ -147,6 +144,28 @@ finish_testing (void *cls, int32_t success, const char *emsg) 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. @@ -236,7 +255,9 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, rd.data_size = sizeof(struct in_addr); rd.data = web; rd.record_type = GNUNET_DNSPARSER_TYPE_A; - sig = GNUNET_NAMESTORE_create_signature(bob_key, TEST_RECORD_NAME, + sig = GNUNET_NAMESTORE_create_signature(bob_key, + GNUNET_TIME_absolute_get_forever(), + TEST_RECORD_NAME, &rd, 1); GNUNET_NAMESTORE_record_put (namestore_handle, @@ -246,7 +267,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 1, &rd, sig, - &finish_testing, + &commence_testing, NULL); } -- 2.25.1