X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Ftest_gns_cname_lookup.c;h=643a79033d9933816ca9f05e4d8f5d61b24019ab;hb=39850a9dc3d789303b91816275314898c0ae80e2;hp=2c384cfa25e15b886a9834bea28d0f3ffc8d4938;hpb=9784a9d890a8ed194059d67494f24b8f327ef2b5;p=oweals%2Fgnunet.git diff --git a/src/gns/test_gns_cname_lookup.c b/src/gns/test_gns_cname_lookup.c index 2c384cfa2..643a79033 100644 --- a/src/gns/test_gns_cname_lookup.c +++ b/src/gns/test_gns_cname_lookup.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2009 Christian Grothoff (and other contributing authors) + (C) 2012 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -20,7 +20,7 @@ /** * @file gns/test_gns_cname_lookup.c * @brief base testcase for testing a local GNS record lookup - * + * @author Martin Schanzenbach */ #include "platform.h" #include "gnunet_testing_lib-new.h" @@ -31,15 +31,12 @@ #include "gnunet_dnsparser_lib.h" #include "gnunet_gns_service.h" -/* DEFINES */ -#define VERBOSE GNUNET_YES -/* Timeout for entire testcase */ +/** + * Timeout for entire testcase + */ #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) -/* If number of peers not in config file, use this number */ -#define DEFAULT_NUM_PEERS 2 - /* test records to resolve */ #define TEST_DOMAIN_PLUS "www.gads" #define TEST_DOMAIN_ZKEY "www2.gads" @@ -58,10 +55,9 @@ #define KEYFILE_BOB "zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey" -/* Globals */ /* Task handle to use to schedule test failure */ -GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier die_task; /* Global return value (0 for success, anything else for failure) */ static int ok; @@ -70,7 +66,8 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle; static struct GNUNET_GNS_Handle *gns_handle; -const struct GNUNET_CONFIGURATION_Handle *cfg; +static const struct GNUNET_CONFIGURATION_Handle *cfg; + /** * Check if the get_handle is being used, if so stop the request. Either @@ -83,10 +80,9 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) die_task = GNUNET_SCHEDULER_NO_TASK; if (NULL != gns_handle) { - GNUNET_GNS_disconnect(gns_handle); + GNUNET_GNS_disconnect (gns_handle); gns_handle = NULL; } - if (NULL != namestore_handle) { GNUNET_NAMESTORE_disconnect (namestore_handle); @@ -97,26 +93,30 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 1; } -static void -end_badly_now () + +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); + GNUNET_GNS_disconnect (gns_handle); + gns_handle = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); + GNUNET_SCHEDULER_shutdown (); } static void -on_lookup_result_cname (void *cls, uint32_t rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) +on_lookup_result_cname (void *cls, + uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) { - int i; + uint32_t i; if (GNUNET_SCHEDULER_NO_TASK != die_task) { GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_NO_TASK; } - GNUNET_NAMESTORE_disconnect (namestore_handle); namestore_handle = NULL; if (rd_count == 0) @@ -148,25 +148,23 @@ on_lookup_result_cname (void *cls, uint32_t rd_count, } } } - GNUNET_GNS_disconnect(gns_handle); - gns_handle = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); } + static void -on_lookup_result_dns (void *cls, uint32_t rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) +on_lookup_result_dns (void *cls, + uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) { struct in_addr a; - int i; + uint32_t i; char* addr; if (rd_count == 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup failed, rp_filtering?\n"); - ok = 2; + "CNAME to DNS delegation failed. System offline?\n"); } else { @@ -177,35 +175,35 @@ on_lookup_result_dns (void *cls, uint32_t rd_count, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); if (rd[i].record_type == GNUNET_GNS_RECORD_A) { - 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_DNS)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "%s correctly resolved to %s!\n", TEST_DOMAIN_DNS, addr); - ok = 0; - } + 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_DNS)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "%s correctly resolved to %s!\n", TEST_DOMAIN_DNS, addr); + ok = 0; + } } else { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); } } } - GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_CNAME, GNUNET_YES, NULL, &on_lookup_result_cname, TEST_DOMAIN_PLUS); } + static void on_lookup_result_zkey (void *cls, uint32_t rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) + const struct GNUNET_NAMESTORE_RecordData *rd) { struct in_addr a; - int i; + uint32_t i; char* addr; if (rd_count == 0) @@ -213,45 +211,49 @@ on_lookup_result_zkey (void *cls, uint32_t rd_count, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup failed, rp_filtering?\n"); ok = 2; + GNUNET_SCHEDULER_shutdown (); + return; } - else + ok = 1; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "name: %s\n", (char*)cls); + for (i=0; i