From 3f9ae35bfadfe670fed3eca58e413fe726c71457 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 21 Apr 2010 08:13:08 +0000 Subject: [PATCH] --- src/hostlist/hostlist-client.c | 23 +++++++- .../test_gnunet_daemon_hostlist_learning.c | 57 +++++++++++++++---- 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index de8366ced..39f975cc0 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -486,6 +486,7 @@ static uint64_t checked_sub (uint64_t val1, uint64_t val2) */ static void update_hostlist ( ) { + char *stat; if ( (use_preconfigured_list == GNUNET_NO) && ( NULL != current_hostlist ) ) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -497,10 +498,15 @@ static void update_hostlist ( ) { current_hostlist->times_used++; current_hostlist->quality = checked_add ( current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); + GNUNET_asprintf (&stat, + gettext_noop("Learned URI `%s' downloaded"), + current_hostlist->hostlist_uri); + GNUNET_STATISTICS_update ( stats, - gettext_noop("Learned URI downloaded"), + stat, 1, GNUNET_YES); + GNUNET_free (stat); } else current_hostlist->quality = checked_sub ( current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD ); @@ -1071,6 +1077,11 @@ advertisement_handler (void *cls, GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist); linked_list_size++; + GNUNET_STATISTICS_set (stats, + gettext_noop("# advertised hostlist URIs"), + linked_list_size, + GNUNET_NO); + if (MAX_NUMBER_HOSTLISTS >= linked_list_size) return GNUNET_OK; @@ -1084,6 +1095,12 @@ advertisement_handler (void *cls, (unsigned long long) lowest_quality->quality); GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, lowest_quality); linked_list_size--; + + GNUNET_STATISTICS_set (stats, + gettext_noop("# advertised hostlist URIs"), + linked_list_size, + GNUNET_NO); + GNUNET_free (lowest_quality); return GNUNET_OK; } @@ -1199,6 +1216,10 @@ load_hostlist_file () gettext_noop("# hostlist URIs read from file"), counter, GNUNET_YES); + GNUNET_STATISTICS_set (stats, + gettext_noop("# advertised hostlist URIs"), + linked_list_size, + GNUNET_NO); GNUNET_free_non_null (uri); emsg = NULL; diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index 346ab6808..58f02bbd9 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -39,12 +39,15 @@ * How long until wait until testcases fails */ #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) -#define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) +#define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) static int timeout; static int adv_arrived; +static int learned_hostlist_saved; static int learned_hostlist_downloaded; +static char * current_adv_uri; + static struct GNUNET_SCHEDULER_Handle *sched; static GNUNET_SCHEDULER_TaskIdentifier timeout_task; @@ -125,14 +128,13 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } static int -process_stat (void *cls, +process_downloads (void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent) { - - if ( GNUNET_YES == GNUNET_YES) + if ( (value == 1) && (learned_hostlist_downloaded == GNUNET_NO) ) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Client has successfully downloaded advertised URI \n")); @@ -143,18 +145,46 @@ process_stat (void *cls, return GNUNET_OK; } +static int +process_uris_recv (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) +{ + if ( (value == 1) && (learned_hostlist_saved == GNUNET_NO)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Client has successfully saved advertised URI \n")); + learned_hostlist_saved = GNUNET_YES; + } + return GNUNET_OK; +} + /** * Check the server statistics regularly */ static void check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + char *stat; + GNUNET_asprintf (&stat, + gettext_noop("Learned URI `%s' downloaded"), + current_adv_uri); + GNUNET_STATISTICS_get (learn_peer.stats, + "hostlist", + stat, + GNUNET_TIME_UNIT_MINUTES, + NULL, + &process_downloads, + NULL); + GNUNET_free (stat); GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", - gettext_noop("Learned URI downloaded"), + gettext_noop("# advertised hostlist URIs"), GNUNET_TIME_UNIT_MINUTES, NULL, - &process_stat, + &process_uris_recv, NULL); check_task = GNUNET_SCHEDULER_add_delayed (sched, CHECK_INTERVALL, @@ -173,7 +203,6 @@ static int ad_arrive_handler (void *cls, { char *hostname; char *expected_uri = GNUNET_malloc (MAX_URL_LEN); - char *recv_uri; unsigned long long port; size_t size; @@ -206,16 +235,16 @@ static int ad_arrive_handler (void *cls, } incoming = (const struct GNUNET_MessageHeader *) message; - recv_uri = (char*) &incoming[1]; - if ( 0 == strcmp( expected_uri, recv_uri ) ) + current_adv_uri = strdup ((char*) &incoming[1]); + if ( 0 == strcmp( expected_uri, current_adv_uri ) ) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Recieved hostlist advertisement with URI `%s'as expected\n", recv_uri); + "Recieved hostlist advertisement with URI `%s'as expected\n", current_adv_uri); adv_arrived = GNUNET_YES; } else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Expected URI `%s' and recieved URI `%s' differ\n", expected_uri, recv_uri); + "Expected URI `%s' and recieved URI `%s' differ\n", expected_uri, current_adv_uri); GNUNET_free ( expected_uri ); GNUNET_free ( hostname ); return GNUNET_OK; @@ -412,6 +441,12 @@ check () "Learning peer did not recieve advertisement from server\n"); return GNUNET_YES; } + if ( learned_hostlist_saved == GNUNET_NO ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Advertisement hostlist was not saved in datastore\n"); + return GNUNET_YES; + } if (learned_hostlist_downloaded == GNUNET_NO) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, -- 2.25.1