fix
authorChristian Grothoff <christian@grothoff.org>
Mon, 15 Mar 2010 07:58:30 +0000 (07:58 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 15 Mar 2010 07:58:30 +0000 (07:58 +0000)
src/core/Makefile.am
src/core/gnunet-service-core.c
src/hostlist/hostlist-client.c
src/hostlist/hostlist-server.c

index 605b8d2ce535304c520e5594782756d81a15f7db..8947218740caaf0ac87096d261dfb18987bea08b 100644 (file)
@@ -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)
index 8f22313e6d70830af2a8ea0be98cdb118146a7f8..eabb2d9469ac7f38cc0d847340f697331b1a6b6c 100644 (file)
@@ -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);
index feef6230b92884d0bbcb2546a0d6cf282514dee0..3816385549664e908d59defd4f4bbeef4235002c 100644 (file)
@@ -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 <curl/curl.h>
 
@@ -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 */
index 11cd8b9066e1eb9d43463305577cafbd4a71b3d9..0982889d77894fa615046207665a021868002e28 100644 (file)
@@ -92,7 +92,7 @@ static struct GNUNET_PEERINFO_IteratorContext *pitr;
  */
 struct HostSet
 {
-  size_t size;
+  unsigned int size;
 
   char *data;
 };