From: Nathan S. Evans Date: Thu, 17 Feb 2011 13:29:47 +0000 (+0000) Subject: Allow testing connection process to be stopped when asked. X-Git-Tag: initial-import-from-subversion-38251~19107 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0d95267569574f8381791e913e0ac6abf6d1e38b;p=oweals%2Fgnunet.git Allow testing connection process to be stopped when asked. --- diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 14c119ff9..07cbf7981 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c @@ -715,6 +715,11 @@ static unsigned int total_connections; */ static unsigned int previous_connections; +/** + * For counting failed connections during some duration. + */ +static unsigned int previous_failed_connections; + /** * Global used to count how many failed connections we have * been notified about (how many times has topology_callback @@ -2597,8 +2602,11 @@ topology_callback (void *cls, unsigned long long duration; unsigned long long total_duration; unsigned int new_connections; + unsigned int new_failed_connections; float conns_per_sec_recent; float conns_per_sec_total; + float failed_conns_per_sec_recent; + float failed_conns_per_sec_total; #if ONLY_TESTING if (repeat_connect_mode == GNUNET_YES) @@ -2615,26 +2623,40 @@ topology_callback (void *cls, repeat_connect_peer1 = NULL; repeat_connect_peer2 = NULL; repeat_connect_mode = GNUNET_NO; + GNUNET_TESTING_resume_connections(pg); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Resuming normal connection mode, debug connection was successful!\n"); } } } #endif + + if (GNUNET_TIME_absolute_get_difference (connect_last_time, GNUNET_TIME_absolute_get()).rel_value > GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, CONN_UPDATE_DURATION).rel_value) { /* Get number of new connections */ new_connections = total_connections - previous_connections; + + /* Get number of new FAILED connections */ + new_failed_connections = failed_connections - previous_failed_connections; + /* Get duration in seconds */ duration = GNUNET_TIME_absolute_get_difference (connect_last_time, GNUNET_TIME_absolute_get()).rel_value / 1000; total_duration = GNUNET_TIME_absolute_get_difference (connect_start_time, GNUNET_TIME_absolute_get()).rel_value / 1000; + + failed_conns_per_sec_recent = (float)new_failed_connections / duration; + failed_conns_per_sec_total = (float)failed_connections / total_duration; conns_per_sec_recent = (float)new_connections / duration; conns_per_sec_total = (float)total_connections / total_duration; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Conns/sec in last %d seconds: %f, Conns/sec for entire duration: %f\n", CONN_UPDATE_DURATION, (float)new_connections / duration, (float)total_connections / total_duration); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Recent: %f/s, Total: %f/s, Recent failed: %f/s, total failed %f/s\n", + conns_per_sec_recent, CONN_UPDATE_DURATION, conns_per_sec_total, + failed_conns_per_sec_recent, failed_conns_per_sec_total); connect_last_time = GNUNET_TIME_absolute_get(); previous_connections = total_connections; + previous_failed_connections = failed_connections; GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "have %u total_connections\n", total_connections); #if ONLY_TESTING /* These conditions likely mean we've entered the death spiral of doom */ @@ -2645,11 +2667,12 @@ topology_callback (void *cls, (repeat_connect_mode == GNUNET_NO)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Entering repeat connection attempt mode!\n"); - repeat_connect_peer1 = first_daemon; repeat_connect_peer2 = second_daemon; repeat_connect_mode = GNUNET_YES; - repeat_connect_task = GNUNET_SCHEDULER_add_now(&repeat_connect, NULL); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping NEW connections from being scheduled!\n"); + GNUNET_TESTING_stop_connections(pg); + repeat_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), &repeat_connect, NULL); } #endif @@ -2667,10 +2690,11 @@ topology_callback (void *cls, else { failed_connections++; +#if VERBOSE 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); -#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", first_daemon->shortname, second_daemon->shortname, emsg); diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index 6ddc4ea74..14a0bbd86 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h @@ -888,6 +888,20 @@ void GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyTopology cb, void *cls); +/** + * Stop the connection process temporarily. + * + * @param pg the peer group to stop connecting + */ +void GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg); + +/** + * Resume the connection process. + * + * @param pg the peer group to resume connecting + */ +void GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg); + /** * There are many ways to connect peers that are supported by this function. * To connect peers in the same topology that was created via the diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index f9b3cc3fc..fc527efe3 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -702,6 +702,11 @@ struct GNUNET_TESTING_PeerGroup * ssh connections per peer. */ struct OutstandingSSH *ssh_tail; + + /** + * Stop scheduling peers connecting. + */ + unsigned int stop_connects; }; struct UpdateContext @@ -2904,8 +2909,9 @@ static void preschedule_connect(struct ConnectTopologyContext *ct_ctx) random_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, pg->total); connection_iter = pg->peers[random_peer].connect_peers_head; +#if DEBUG_TESTING GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling connection between %d and %d\n", random_peer, connection_iter->index); - +#endif connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); connect_context->first = pg->peers[random_peer].daemon; connect_context->second = pg->peers[connection_iter->index].daemon; @@ -2967,7 +2973,7 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) return; - if (pg->outstanding_connects > pg->max_outstanding_connections) + if ((pg->outstanding_connects > pg->max_outstanding_connections) || (pg->stop_connects == GNUNET_YES)) { #if VERBOSE_TESTING > 2 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -4442,6 +4448,26 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, return; } +/** + * Stop the connection process temporarily. + * + * @param pg the peer group to stop connecting + */ +void GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) +{ + pg->stop_connects = GNUNET_YES; +} + +/** + * Resume the connection process temporarily. + * + * @param pg the peer group to resume connecting + */ +void GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) +{ + pg->stop_connects = GNUNET_NO; +} + /** * There are many ways to connect peers that are supported by this function. * To connect peers in the same topology that was created via the