From f38edaf6e06e6786da37aa48e0818dce898a05d3 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 20 Apr 2010 15:15:39 +0000 Subject: [PATCH] --- src/hostlist/Makefile.am | 1 + src/hostlist/hostlist-client.c | 6 +- .../test_gnunet_daemon_hostlist_learning.c | 61 ++++++++++++++++--- src/hostlist/test_learning_adv_peer.conf | 2 +- src/hostlist/test_learning_learn_peer.conf | 2 +- 5 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/hostlist/Makefile.am b/src/hostlist/Makefile.am index c4cc55f41..7bc9ffd3a 100644 --- a/src/hostlist/Makefile.am +++ b/src/hostlist/Makefile.am @@ -48,6 +48,7 @@ test_gnunet_daemon_hostlist_learning_LDADD = \ $(top_builddir)/src/transport/libgnunettransport.la \ $(top_builddir)/src/arm/libgnunetarm.la \ $(top_builddir)/src/core/libgnunetcore.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la EXTRA_DIST = \ diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index 1dc74ad50..de8366ced 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -497,6 +497,10 @@ static void update_hostlist ( ) { current_hostlist->times_used++; current_hostlist->quality = checked_add ( current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); + GNUNET_STATISTICS_update ( stats, + gettext_noop("Learned URI downloaded"), + 1, + GNUNET_YES); } else current_hostlist->quality = checked_sub ( current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD ); @@ -1192,7 +1196,7 @@ load_hostlist_file () GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%u hostlist URIs loaded from file\n"), counter); GNUNET_STATISTICS_set (stats, - gettext_noop("# hostlis URIs read from file"), + gettext_noop("# hostlist URIs read from file"), counter, GNUNET_YES); diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index fb9446bc4..346ab6808 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -28,6 +28,7 @@ #include "gnunet_core_service.h" #include "gnunet_transport_service.h" #include "gnunet_resolver_service.h" +#include "gnunet_statistics_service.h" #define VERBOSE GNUNET_YES @@ -42,6 +43,7 @@ static int timeout; static int adv_arrived; +static int learned_hostlist_downloaded; static struct GNUNET_SCHEDULER_Handle *sched; @@ -55,6 +57,7 @@ struct PeerContext struct GNUNET_MessageHeader *hello; struct GNUNET_ARM_Handle *arm; struct GNUNET_CORE_Handle *core; + struct GNUNET_STATISTICS_Handle *stats; #if START_ARM pid_t arm_pid; #endif @@ -121,14 +124,38 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) clean_up (NULL, tc); } +static int +process_stat (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) +{ + + if ( GNUNET_YES == GNUNET_YES) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Client has successfully downloaded advertised URI \n")); + learned_hostlist_downloaded = GNUNET_YES; + } + if ( GNUNET_NO != learned_hostlist_downloaded ) + shutdown_testcase(); + return GNUNET_OK; +} + /** * Check the server statistics regularly */ static void check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Checking server stats...\n"); + GNUNET_STATISTICS_get (learn_peer.stats, + "hostlist", + gettext_noop("Learned URI downloaded"), + GNUNET_TIME_UNIT_MINUTES, + NULL, + &process_stat, + NULL); check_task = GNUNET_SCHEDULER_add_delayed (sched, CHECK_INTERVALL, &check_statistics, @@ -191,7 +218,6 @@ static int ad_arrive_handler (void *cls, "Expected URI `%s' and recieved URI `%s' differ\n", expected_uri, recv_uri); GNUNET_free ( expected_uri ); GNUNET_free ( hostname ); - shutdown_testcase(); return GNUNET_OK; } @@ -228,10 +254,11 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) result = remove (filename); if (result == 0) GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Hostlist hostlist file `%s' was removed\n"),filename); + _("Hostlist file `%s' was removed\n"),filename); } } - GNUNET_free ( filename ); + if ( NULL != filename) GNUNET_free ( filename ); + GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); p->core = GNUNET_CORE_connect (sched, p->cfg, @@ -243,6 +270,8 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) NULL, GNUNET_NO, learn_handlers ); GNUNET_assert ( NULL != p->core ); + p->stats = GNUNET_STATISTICS_create (sched, "hostlist", p->cfg); + GNUNET_assert ( NULL != p->stats ); } @@ -334,6 +363,7 @@ run (void *cls, { timeout = GNUNET_NO; adv_arrived = GNUNET_NO; + learned_hostlist_downloaded = GNUNET_NO; sched = s; timeout_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, @@ -370,10 +400,25 @@ check () argv, "test-gnunet-daemon-hostlist", "nohelp", options, &run, NULL); - if ( (timeout == GNUNET_YES) || (adv_arrived == GNUNET_NO)) + if (timeout == GNUNET_YES) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Testcase could not set up two communicating peers, timeout\n"); return GNUNET_YES; - else - return GNUNET_NO; + } + if (adv_arrived == GNUNET_NO) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Learning peer did not recieve advertisement from server\n"); + return GNUNET_YES; + } + if (learned_hostlist_downloaded == GNUNET_NO) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Advertisement hostlist could not be downloaded from server\n"); + return GNUNET_YES; + } + return GNUNET_NO; } int diff --git a/src/hostlist/test_learning_adv_peer.conf b/src/hostlist/test_learning_adv_peer.conf index d77c43ced..9af51e8f2 100644 --- a/src/hostlist/test_learning_adv_peer.conf +++ b/src/hostlist/test_learning_adv_peer.conf @@ -37,7 +37,7 @@ WEAKRANDOM = YES HTTPPORT = 12981s SERVERS = http://localhost:12980/ OPTIONS = -b -p -a -DEBUG = YES +DEBUG = NO HOSTLISTFILE = hostlists_adv_peer.file #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist diff --git a/src/hostlist/test_learning_learn_peer.conf b/src/hostlist/test_learning_learn_peer.conf index 09fbc37a4..4bdb039e7 100644 --- a/src/hostlist/test_learning_learn_peer.conf +++ b/src/hostlist/test_learning_learn_peer.conf @@ -36,7 +36,7 @@ WEAKRANDOM = YES HTTPPORT = 12980 SERVERS = http://localhost:12981/ OPTIONS = -b -p -e -DEBUG = YES +#DEBUG = YES HOSTLISTFILE = hostlists_learn_peer.file #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist -- 2.25.1