diff options
Diffstat (limited to 'src/dht/test_dht_twopeer_put_get.c')
-rw-r--r-- | src/dht/test_dht_twopeer_put_get.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c index 48bf9f8..44150e3 100644 --- a/src/dht/test_dht_twopeer_put_get.c +++ b/src/dht/test_dht_twopeer_put_get.c @@ -129,9 +129,15 @@ static struct GNUNET_DHT_Handle *peer1dht; static struct GNUNET_DHT_Handle *peer2dht; /** + * Handle for our PUT operation. + */ +static struct GNUNET_DHT_PutHandle *put_op; + + +/** * Check whether peers successfully shut down. */ -void +static void shutdown_callback (void *cls, const char *emsg) { if (emsg != NULL) @@ -164,6 +170,11 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + if (NULL != put_op) + { + GNUNET_DHT_put_cancel (put_op); + put_op = NULL; + } if (peer1dht != NULL) GNUNET_DHT_disconnect (peer1dht); @@ -174,6 +185,7 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); } + /** * 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 @@ -242,10 +254,11 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, * Schedule the GET request for some time in the future. */ static void -put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +put_finished (void *cls, int success) { GNUNET_HashCode key; /* Key for data lookup */ + put_op = NULL; GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &end_badly, @@ -253,7 +266,7 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ global_get_handle = - GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_DHT_get_start (peer2dht, GNUNET_BLOCK_TYPE_TEST, &key, 1, GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, NULL); } @@ -272,9 +285,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (data, 43, sizeof (data)); /* Insert the data at the first peer */ - GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, - sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); + put_op = GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, + sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); } @@ -299,29 +312,23 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, if (emsg == NULL) { total_connections++; -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", first_daemon->shortname, second_daemon->shortname, distance); -#endif } -#if VERBOSE else { failed_connections++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peer %s to peer %s with error :\n%s\n", first_daemon->shortname, second_daemon->shortname, emsg); } -#endif if (total_connections == expected_connections) { -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created %d total connections, which is our target number! Starting next phase of testing.\n", total_connections); -#endif GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test gets"); @@ -389,10 +396,8 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, if (peers_left == 0) /* Indicates all peers started */ { -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %d daemons started, now connecting peers!\n", num_peers); -#endif expected_connections = -1; if ((pg != NULL)) /* Sanity check */ { @@ -463,9 +468,6 @@ check () char *const argv[] = { "test-dht-twopeer-put-get", /* Name to give running binary */ "-c", "test_dht_twopeer_data.conf", /* Config file to use */ -#if VERBOSE - "-L", "DEBUG", -#endif NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { @@ -490,11 +492,7 @@ main (int argc, char *argv[]) int ret; GNUNET_log_setup ("test-dht-twopeer", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); ret = check (); /** |