X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Ftest_gns_dht_delegated_lookup.c;h=f9531751ad4e3638e0f4fae675d4350391244bb4;hb=39850a9dc3d789303b91816275314898c0ae80e2;hp=14a8cb100c9905882c1ada34540d5c7f3ac5370f;hpb=deb0d815d8e7b0456401713d920345ba1ca12236;p=oweals%2Fgnunet.git diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c index 14a8cb100..f9531751a 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c @@ -23,7 +23,7 @@ * */ #include "platform.h" -#include "gnunet_testing_lib.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_core_service.h" #include "block_gns.h" #include "gnunet_signatures.h" @@ -33,17 +33,14 @@ #include "gnunet_dht_service.h" #include "gnunet_gns_service.h" -/* DEFINES */ -#define VERBOSE GNUNET_YES - /* 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 +/* Timeout for entire testcase */ +#define DHT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) /* test records to resolve */ -#define TEST_DOMAIN "www.bob.gnunet" +#define TEST_DOMAIN "www.bob.gads" #define TEST_IP "127.0.0.1" #define TEST_RECORD_NAME "www" @@ -53,18 +50,9 @@ #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" -/* Globals */ - -/** - * Directory to store temp data in, defined in config file - */ -static char *test_directory; - -struct GNUNET_TESTING_Daemon *d1; - - /* Task handle to use to schedule test failure */ -GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier wait_task; /* Global return value (0 for success, anything else for failure) */ static int ok; @@ -75,27 +63,67 @@ static struct GNUNET_GNS_Handle *gns_handle; static struct GNUNET_DHT_Handle *dht_handle; -const struct GNUNET_CONFIGURATION_Handle *cfg; +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; +static struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; +static struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; -struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; -struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; -struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; /** - * 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 != dht_handle) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); - if (ok == 0) - ok = 2; + GNUNET_DHT_disconnect (dht_handle); + dht_handle = NULL; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); + if (NULL != namestore_handle) + { + GNUNET_NAMESTORE_disconnect (namestore_handle); + namestore_handle = NULL; + } + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + ok = 1; +} + + +static void +end_badly_now () +{ + + if (GNUNET_SCHEDULER_NO_TASK != wait_task) + { + GNUNET_SCHEDULER_cancel (wait_task); + wait_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); +} + + +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_GNS_disconnect(gns_handle); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); + GNUNET_SCHEDULER_shutdown (); } @@ -107,6 +135,14 @@ on_lookup_result(void *cls, uint32_t rd_count, int i; char* addr; + 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, @@ -120,7 +156,7 @@ on_lookup_result(void *cls, uint32_t rd_count, for (i=0; i