X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Ftest_gns_cname_lookup.c;h=643a79033d9933816ca9f05e4d8f5d61b24019ab;hb=39850a9dc3d789303b91816275314898c0ae80e2;hp=f1045fda733f6a2e306556e5b3d1ca0487aae91d;hpb=146d71432ed366ccd3e576f4b3e261ace67cf757;p=oweals%2Fgnunet.git diff --git a/src/gns/test_gns_cname_lookup.c b/src/gns/test_gns_cname_lookup.c index f1045fda7..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,10 +20,10 @@ /** * @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.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_core_service.h" #include "block_dns.h" #include "gnunet_signatures.h" @@ -31,23 +31,20 @@ #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.gnunet" -#define TEST_DOMAIN_ZKEY "www2.gnunet" -#define TEST_DOMAIN_DNS "www3.gnunet" +#define TEST_DOMAIN_PLUS "www.gads" +#define TEST_DOMAIN_ZKEY "www2.gads" +#define TEST_DOMAIN_DNS "www3.gads" #define TEST_IP_PLUS "127.0.0.1" #define TEST_IP_ZKEY "127.0.0.2" #define TEST_IP_DNS "131.159.74.67" -#define TEST_RECORD_CNAME_SERVER "server.gnunet" +#define TEST_RECORD_CNAME_SERVER "server.gads" #define TEST_RECORD_CNAME_PLUS "server.+" #define TEST_RECORD_CNAME_ZKEY "www.188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey" #define TEST_RECORD_CNAME_DNS "gnunet.org" @@ -58,17 +55,9 @@ #define KEYFILE_BOB "zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey" -/* Globals */ - -/** - * Directory to store temp data in, defined in config file - */ -static char *test_directory; - -static struct GNUNET_TESTING_PeerGroup *pg; /* 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; @@ -77,31 +66,59 @@ 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 whether peers successfully shut down. + * Check if the get_handle is being used, if so stop the request. Either + * way, schedule the end_badly_cont function which actually shuts down the + * test. */ -void -shutdown_callback (void *cls, const char *emsg) +static void +end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - if (emsg != NULL) + die_task = GNUNET_SCHEDULER_NO_TASK; + if (NULL != gns_handle) + { + GNUNET_GNS_disconnect (gns_handle); + gns_handle = NULL; + } + if (NULL != namestore_handle) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); - if (ok == 0) - ok = 2; + GNUNET_NAMESTORE_disconnect (namestore_handle); + namestore_handle = NULL; } + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + ok = 1; +} + - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + 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) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -115,7 +132,7 @@ on_lookup_result_cname (void *cls, uint32_t rd_count, for (i=0; i