From: Nathan S. Evans Date: Wed, 30 Jun 2010 15:58:44 +0000 (+0000) Subject: two peer start, connect, ensure core connect message made it to the dht, disconnect... X-Git-Tag: initial-import-from-subversion-38251~21112 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=444781955f83b5d541d7ee4556bcf864f4a2d38a;p=oweals%2Fgnunet.git two peer start, connect, ensure core connect message made it to the dht, disconnect, stop peers --- diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 2d54eeb9c..c4229a344 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -46,8 +46,6 @@ #define DEBUG_DHT_API GNUNET_NO -#define DEFAULT_DHT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - struct PendingMessage { /** @@ -548,7 +546,7 @@ finish_retransmission (struct GNUNET_DHT_Handle *handle, int code) */ void service_message_handler (void *cls, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { struct GNUNET_DHT_Handle *handle = cls; struct GNUNET_DHT_RouteResultMessage *dht_msg; @@ -567,9 +565,12 @@ service_message_handler (void *cls, #endif GNUNET_CLIENT_disconnect (handle->client, GNUNET_YES); handle->client = GNUNET_CLIENT_connect (handle->sched, - "dht", - handle->cfg); - + "dht", + handle->cfg); + if (handle->current != NULL) + { + finish(handle, GNUNET_SYSERR); /* If there was a current message, kill it! */ + } if (GNUNET_CONTAINER_multihashmap_iterate(handle->outstanding_requests, &retransmit_iterator, handle) > 0) { handle->retransmit_stage = DHT_RETRANSMITTING; @@ -992,10 +993,9 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle, route_handle->uid); #endif message->unique_id = GNUNET_htonll (route_handle->uid); - GNUNET_assert (route_handle->dht_handle->current == NULL); pending = GNUNET_malloc (sizeof (struct PendingMessage)); pending->msg = (struct GNUNET_MessageHeader *) message; - pending->timeout = DEFAULT_DHT_TIMEOUT; + pending->timeout = GNUNET_TIME_relative_get_forever(); pending->cont = cont; pending->cont_cls = cont_cls; pending->unique_id = 0; /* When finished is called, free pending->msg */ diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index a2e0f4db7..c918a808a 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -779,10 +779,27 @@ void handle_core_connect (void *cls, struct GNUNET_TIME_Relative latency, uint32_t distance) { + int ret; + char *data; + size_t data_size = 42; + data = GNUNET_malloc (data_size); + memset (data, 43, data_size); + #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s Receives core connect message for peer %s distance %d!\n", my_short_id, "dht", GNUNET_i2s(peer), distance); #endif + if (datacache != NULL) + { + ret = GNUNET_DATACACHE_put (datacache, &peer->hashPubKey, data_size, + data, 130, + GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), + GNUNET_TIME_UNIT_MINUTES)); +#if DEBUG_DHT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s Inserting data %s, type %d into datacache, return value was %d\n", my_short_id, GNUNET_h2s(&peer->hashPubKey), 130, ret); +#endif + } } /** diff --git a/src/dht/test_dht_api_peer1.conf b/src/dht/test_dht_api_peer1.conf index c02567efd..5b12c23e1 100644 --- a/src/dht/test_dht_api_peer1.conf +++ b/src/dht/test_dht_api_peer1.conf @@ -9,7 +9,7 @@ PORT = 2094 INDEXDB = $SERVICEHOME/idxinfo.lst [dht] -DEBUG = NO +DEBUG = YES AUTOSTART = YES ACCEPT_FROM6 = ::1; ACCEPT_FROM = 127.0.0.1; diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c index 3890b7699..c1472210e 100644 --- a/src/dht/test_dht_twopeer.c +++ b/src/dht/test_dht_twopeer.c @@ -35,11 +35,21 @@ #define DEFAULT_NUM_PEERS 2 /* Structs */ -/* ... */ + +struct PeerGetContext +{ + struct GNUNET_PeerIdentity *peer; + + struct GNUNET_DHT_Handle *dht_handle; + + struct GNUNET_DHT_GetHandle *get_handle; +}; /* Globals */ static char *test_directory; +static struct PeerGetContext curr_get_ctx; + static unsigned int expected_connections; static unsigned long long peers_left; @@ -50,6 +60,10 @@ static struct GNUNET_SCHEDULER_Handle *sched; static unsigned long long num_peers; +static unsigned int total_gets; + +static unsigned int gets_succeeded; + static unsigned int total_connections; static unsigned int failed_connections; @@ -58,6 +72,14 @@ GNUNET_SCHEDULER_TaskIdentifier die_task; static int ok; +static struct GNUNET_PeerIdentity peer1id; + +static struct GNUNET_PeerIdentity peer2id; + +static struct GNUNET_DHT_Handle *peer1dht; + +static struct GNUNET_DHT_Handle *peer2dht; + /** * Check whether peers successfully shut down. */ @@ -75,18 +97,95 @@ static void finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) { GNUNET_assert (pg != NULL); + GNUNET_assert (peer1dht != NULL); + GNUNET_assert (peer2dht != NULL); + GNUNET_DHT_disconnect(peer1dht); + GNUNET_DHT_disconnect(peer2dht); GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); ok = 0; } static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) +end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) { + if (peer1dht != NULL) + GNUNET_DHT_disconnect(peer1dht); + + if (peer2dht != NULL) + GNUNET_DHT_disconnect(peer2dht); + if (pg != NULL) GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); +} + +static void +end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) +{ + if (curr_get_ctx.get_handle != NULL) + { + GNUNET_DHT_get_stop(curr_get_ctx.get_handle, &end_badly_cont, NULL); + } + ok = 1; } +/* Forward declaration */ +static void +do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); + +/** + * Iterator called on each result obtained for a DHT + * operation that expects a reply + * + * @param cls closure + * @param exp when will this value expire + * @param key key of the result + * @param type type of the result + * @param size number of bytes in data + * @param data pointer to the result data + */ +void get_result_iterator (void *cls, + struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, + uint32_t type, + uint32_t size, + const void *data) +{ + struct PeerGetContext *get_context = cls; + if (0 != memcmp(&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode))) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key returned is not the same key as was searched for!\n"); + GNUNET_SCHEDULER_cancel(sched, die_task); + GNUNET_SCHEDULER_add_now(sched, &end_badly, "key mismatch in get response!\n"); + return; + } + + if (get_context->peer == &peer2id) + { + get_context->peer = &peer1id; + get_context->dht_handle = peer2dht; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received first correct GET request response!\n"); + GNUNET_DHT_get_stop(get_context->get_handle, &do_get, get_context); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received second correct GET request response!\n"); + GNUNET_SCHEDULER_cancel(sched, die_task); + GNUNET_DHT_get_stop(get_context->get_handle, &finish_testing, NULL); + } + + +} + +static void +do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) +{ + struct PeerGetContext *get_context = cls; + + get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, GNUNET_TIME_relative_get_forever(), 130, &get_context->peer->hashPubKey, &get_result_iterator, get_context, NULL, NULL); +} + + void topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, @@ -126,23 +225,19 @@ topology_callback (void *cls, total_connections); #endif GNUNET_SCHEDULER_cancel (sched, die_task); - die_task = GNUNET_SCHEDULER_NO_TASK; - //GNUNET_SCHEDULER_add_now (sched, &next_phase, NULL); - GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); + die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, + &end_badly, "from test gets"); + + curr_get_ctx.dht_handle = peer1dht; + curr_get_ctx.peer = &peer2id; + GNUNET_SCHEDULER_add_now (sched, &do_get, &curr_get_ctx); + //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_get, &curr_get_ctx); } else if (total_connections + failed_connections == expected_connections) { GNUNET_SCHEDULER_cancel (sched, die_task); die_task = GNUNET_SCHEDULER_add_now (sched, - &end_badly, "from topology_callback (too many failed connections)"); - } - else - { -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Have %d total connections, %d failed connections, Want %d\n", - total_connections, failed_connections, expected_connections); -#endif + &end_badly, "from topology_callback (too many failed connections)"); } } @@ -151,20 +246,13 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) { expected_connections = -1; if ((pg != NULL) && (peers_left == 0)) - { - expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0); -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Have %d expected connections\n", expected_connections); -#endif - } + expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0); GNUNET_SCHEDULER_cancel (sched, die_task); if (expected_connections == GNUNET_SYSERR) - { - die_task = GNUNET_SCHEDULER_add_now (sched, - &end_badly, "from connect topology (bad return)"); - } + die_task = GNUNET_SCHEDULER_add_now (sched, + &end_badly, "from connect topology (bad return)"); + die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, @@ -179,32 +267,47 @@ peers_started_callback (void *cls, { if (emsg != NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with error: `%s'\n", emsg); return; } GNUNET_assert (id != NULL); -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", - (num_peers - peers_left) + 1, num_peers); -#endif + if (peers_left == num_peers) + { + memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); + peer1dht = GNUNET_DHT_connect(sched, cfg, 100); + if (peer1dht == NULL) + { + GNUNET_SCHEDULER_cancel (sched, die_task); + GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n"); + } + } + else + { + memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); + peer2dht = GNUNET_DHT_connect(sched, cfg, 100); + if (peer2dht == NULL) + { + GNUNET_SCHEDULER_cancel (sched, die_task); + GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n"); + } + } + - //GNUNET_DHT_connect(); peers_left--; if (peers_left == 0) { #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All %d daemons started, now creating topology!\n", + "All %d daemons started, now connecting peers!\n", num_peers); #endif GNUNET_SCHEDULER_cancel (sched, die_task); /* Set up task in case topology creation doesn't finish * within a reasonable amount of time */ die_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 5), + TIMEOUT, &end_badly, "from peers_started_callback"); GNUNET_SCHEDULER_add_now(sched, &connect_topology, NULL); @@ -219,7 +322,6 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { sched = s; - ok = 1; if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) { @@ -233,7 +335,8 @@ run (void *cls, num_peers = DEFAULT_NUM_PEERS; peers_left = num_peers; - + total_gets = num_peers; + gets_succeeded = 0; /* Set up a task to end testing if peer start fails */ die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, diff --git a/src/dht/test_dht_twopeer_data.conf b/src/dht/test_dht_twopeer_data.conf index c0640847b..4ea86e82a 100644 --- a/src/dht/test_dht_twopeer_data.conf +++ b/src/dht/test_dht_twopeer_data.conf @@ -10,7 +10,7 @@ INDEXDB = $SERVICEHOME/idxinfo.lst [dht] #AUTOSTART = YES -DEBUG = YES +DEBUG = NO AUTOSTART = YES ACCEPT_FROM6 = ::1; ACCEPT_FROM = 127.0.0.1;