X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Ftest_gns_dht_delegated_lookup.c;h=f9531751ad4e3638e0f4fae675d4350391244bb4;hb=39850a9dc3d789303b91816275314898c0ae80e2;hp=f81a8d02830776e1f9b52640acfaf11cec5274ce;hpb=f619430fc962cc50f48e980841c76ca7fe1e801e;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 f81a8d028..f9531751a 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c @@ -18,26 +18,12 @@ Boston, MA 02111-1307, USA. */ /** - * @file gns/test_gns_twopeer.c - * @brief base testcase for testing DHT service with - * two running peers. + * @file gns/test_gns_dht_delegated_lookup.c + * @brief test for record lookup via DHT * - * This testcase starts peers using the GNUNET_TESTING_daemons_start - * function call. On peer start, connects to the peers DHT service - * by calling GNUNET_DHT_connected. Once notified about all peers - * being started (by the peers_started_callback function), calls - * GNUNET_TESTING_connect_topology, which connects the peers in a - * "straight line" topology. On notification that all peers have - * been properly connected, calls the do_get function which initiates - * a GNUNET_DHT_get from the *second* peer. Once the GNUNET_DHT_get - * function starts, runs the do_put function to insert data at the first peer. - * If the GET is successful, schedules finish_testing - * to stop the test and shut down peers. If GET is unsuccessful - * after GET_TIMEOUT seconds, prints an error message and shuts down - * the peers. */ #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" @@ -47,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, 10) +#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" @@ -65,18 +48,11 @@ #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) -/* Globals */ - -/** - * Directory to store temp data in, defined in config file - */ -static char *test_directory; - -struct GNUNET_TESTING_Daemon *d1; - +#define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" /* 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; @@ -87,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 (); } @@ -119,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, @@ -132,7 +156,7 @@ on_lookup_result(void *cls, uint32_t rd_count, for (i=0; i