From cacbf3f6aecbba4e3f0aebc77698df88215ac9fd Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 15 Mar 2010 07:58:30 +0000 Subject: fix --- src/core/Makefile.am | 1 + src/core/gnunet-service-core.c | 32 ++++++++++++++++++++++++++++---- src/hostlist/hostlist-client.c | 31 +++++++++++++++++++++++++++++-- src/hostlist/hostlist-server.c | 2 +- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 605b8d2ce..894721874 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -34,6 +34,7 @@ gnunet_service_core_SOURCES = \ gnunet_service_core_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/transport/libgnunettransport.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 8f22313e6..eabb2d946 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -37,6 +37,7 @@ #include "gnunet_peerinfo_service.h" #include "gnunet_protocols.h" #include "gnunet_signatures.h" +#include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" #include "core.h" @@ -689,6 +690,11 @@ static struct GNUNET_SERVER_NotificationContext *notifier; */ static struct Neighbour *neighbours; +/** + * For creating statistics. + */ +static struct GNUNET_STATISTICS_Handle *stats; + /** * Sum of all preferences among all neighbours. */ @@ -737,6 +743,7 @@ update_preference_sum (unsigned long long inc) preference_sum += n->current_preference; n = n->next; } + GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), preference_sum, GNUNET_NO); } @@ -1094,8 +1101,10 @@ free_neighbour (struct Neighbour *n) GNUNET_SCHEDULER_cancel (sched, n->quota_update_task); if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (sched, n->dead_clean_task); - if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (sched, n->keep_alive_task); + if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (sched, n->keep_alive_task); + if (n->status == PEER_STATE_KEY_CONFIRMED) + GNUNET_STATISTICS_update (stats, gettext_noop ("# peers connected"), -1, GNUNET_NO); GNUNET_free_non_null (n->public_key); GNUNET_free_non_null (n->pending_ping); GNUNET_free_non_null (n->pending_pong); @@ -1141,6 +1150,7 @@ do_encrypt (struct Neighbour *n, (const struct GNUNET_CRYPTO_AesInitializationVector *) iv, out)); + GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, GNUNET_NO); #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for `%4s' using key %u\n", size, @@ -1286,6 +1296,7 @@ consider_free_neighbour (struct Neighbour *n) prev->next = n->next; GNUNET_assert (neighbour_count > 0); neighbour_count--; + GNUNET_STATISTICS_set (stats, gettext_noop ("# active neighbours"), neighbour_count, GNUNET_NO); free_neighbour (n); } @@ -1444,6 +1455,7 @@ do_decrypt (struct Neighbour *n, GNUNET_break (0); return GNUNET_SYSERR; } + GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes decrypted"), size, GNUNET_NO); #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from `%4s' using key %u\n", @@ -2050,6 +2062,7 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid) n->next = neighbours; neighbours = n; neighbour_count++; + GNUNET_STATISTICS_set (stats, gettext_noop ("# active neighbours"), neighbour_count, GNUNET_NO); n->peer = *pid; GNUNET_CRYPTO_aes_create_session_key (&n->encrypt_key); now = GNUNET_TIME_absolute_get (); @@ -2250,6 +2263,7 @@ handle_client_request_connect (void *cls, if ( (n->is_connected) || (n->th != NULL) ) return; /* already connected, or at least trying */ + GNUNET_STATISTICS_update (stats, gettext_noop ("# connection requests received"), 1, GNUNET_NO); #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core received `%s' request for `%4s', will try to establish connection\n", @@ -2721,7 +2735,7 @@ handle_pong (struct Neighbour *n, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Confirmed key via `%s' message for peer `%4s'\n", "PONG", GNUNET_i2s (&n->peer)); -#endif +#endif if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (sched, n->retry_set_key_task); @@ -3267,6 +3281,7 @@ handle_transport_receive (void *cls, GNUNET_break_op (0); return; } + GNUNET_STATISTICS_update (stats, gettext_noop ("# session keys received"), 1, GNUNET_NO); handle_set_key (n, (const struct SetKeyMessage *) message); break; case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: @@ -3290,6 +3305,7 @@ handle_transport_receive (void *cls, GNUNET_break_op (0); return; } + GNUNET_STATISTICS_update (stats, gettext_noop ("# ping messages received"), 1, GNUNET_NO); if ((n->status != PEER_STATE_KEY_RECEIVED) && (n->status != PEER_STATE_KEY_CONFIRMED)) { @@ -3311,6 +3327,7 @@ handle_transport_receive (void *cls, GNUNET_break_op (0); return; } + GNUNET_STATISTICS_update (stats, gettext_noop ("# pong messages received"), 1, GNUNET_NO); if ( (n->status != PEER_STATE_KEY_RECEIVED) && (n->status != PEER_STATE_KEY_CONFIRMED) ) { @@ -3336,7 +3353,10 @@ handle_transport_receive (void *cls, now = GNUNET_TIME_absolute_get (); n->last_activity = now; if (!up) - n->time_established = now; + { + GNUNET_STATISTICS_update (stats, gettext_noop ("# peers connected"), 1, GNUNET_NO); + n->time_established = now; + } if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (sched, n->keep_alive_task); n->keep_alive_task @@ -3545,12 +3565,15 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) neighbour_count--; free_neighbour (n); } + GNUNET_STATISTICS_set (stats, gettext_noop ("# active neighbours"), neighbour_count, GNUNET_NO); GNUNET_SERVER_notification_context_destroy (notifier); notifier = NULL; while (NULL != (c = clients)) handle_client_disconnect (NULL, c->client_handle); if (my_private_key != NULL) GNUNET_CRYPTO_rsa_key_free (my_private_key); + if (stats != NULL) + GNUNET_STATISTICS_destroy (stats, GNUNET_YES); } @@ -3620,6 +3643,7 @@ run (void *cls, &handle_transport_notify_connect, &handle_transport_notify_disconnect); GNUNET_assert (NULL != transport); + stats = GNUNET_STATISTICS_create (sched, "core", cfg); GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index feef6230b..381638554 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -28,6 +28,7 @@ #include "hostlist-client.h" #include "gnunet_core_service.h" #include "gnunet_hello_lib.h" +#include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" #include @@ -142,6 +143,10 @@ download_hostlist_processor (void *ptr, { return total; /* ok, no data or bogus data */ } + GNUNET_STATISTICS_update (stats, + gettext_noop ("# bytes downloaded from hostlist servers"), + (int64_t) total, + GNUNET_NO); left = total; while (left > 0) { @@ -159,6 +164,10 @@ download_hostlist_processor (void *ptr, msize = ntohs(msg->size); if (msize < sizeof(struct GNUNET_MessageHeader)) { + GNUNET_STATISTICS_update (stats, + gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), + 1, + GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Invalid `%s' message received from hostlist at `%s'\n"), "HELLO", @@ -175,10 +184,18 @@ download_hostlist_processor (void *ptr, "Received valid `%s' message from hostlist server.\n", "HELLO"); #endif + GNUNET_STATISTICS_update (stats, + gettext_noop ("# valid HELLOs downloaded from hostlist servers"), + 1, + GNUNET_NO); GNUNET_TRANSPORT_offer_hello (transport, msg); } else { + GNUNET_STATISTICS_update (stats, + gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), + 1, + GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Invalid `%s' message received from hostlist at `%s'\n"), "HELLO", @@ -495,7 +512,10 @@ download_hostlist () GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, _("Bootstrapping using hostlist at `%s'.\n"), current_url); - + GNUNET_STATISTICS_update (stats, + gettext_noop ("# hostlist downloads initiated"), + 1, + GNUNET_NO); if (proxy != NULL) CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); download_pos = 0; @@ -660,6 +680,10 @@ connect_handler (void *cls, uint32_t distance) { connection_count++; + GNUNET_STATISTICS_update (stats, + gettext_noop ("# active connections"), + 1, + GNUNET_NO); } @@ -675,6 +699,10 @@ disconnect_handler (void *cls, GNUNET_PeerIdentity * peer) { connection_count--; + GNUNET_STATISTICS_update (stats, + gettext_noop ("# active connections"), + -1, + GNUNET_NO); } @@ -783,7 +811,6 @@ GNUNET_HOSTLIST_client_stop () proxy = NULL; cfg = NULL; sched = NULL; - stats = NULL; } /* end of hostlist-client.c */ diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 11cd8b906..0982889d7 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -92,7 +92,7 @@ static struct GNUNET_PEERINFO_IteratorContext *pitr; */ struct HostSet { - size_t size; + unsigned int size; char *data; }; -- cgit v1.2.3