stats
authorChristian Grothoff <christian@grothoff.org>
Sat, 13 Mar 2010 10:00:36 +0000 (10:00 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 13 Mar 2010 10:00:36 +0000 (10:00 +0000)
src/topology/Makefile.am
src/topology/gnunet-daemon-topology.c

index 6d7f766bc0d71317c2e2a2b0cdf91791071ecbf5..88d8800a1bcd3a4439399bb889b2fa9c8ad7aa8e 100644 (file)
@@ -13,6 +13,7 @@ gnunet_daemon_topology_SOURCES = \
 gnunet_daemon_topology_LDADD = \
   $(top_builddir)/src/core/libgnunetcore.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 f69bc146803ff45895572c5ae4a9d8549359547c..1d5b41522c3364f93aea23501ce7022741e1dac1 100644 (file)
@@ -29,6 +29,7 @@
 #include "gnunet_core_service.h"
 #include "gnunet_protocols.h"
 #include "gnunet_peerinfo_service.h"
+#include "gnunet_statistics_service.h"
 #include "gnunet_transport_service.h"
 #include "gnunet_util_lib.h"
 
@@ -208,6 +209,11 @@ static struct GNUNET_PeerIdentity my_identity;
  */
 static struct PeerList *peers;
 
+/**
+ * Handle for reporting statistics.
+ */
+static struct GNUNET_STATISTICS_Handle *stats;
+
 /**
  * Flag to disallow non-friend connections (pure F2F mode).
  */
@@ -263,6 +269,10 @@ disconnect_done (void *cls,
 {
   struct DisconnectList *dl = cls;
 
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# peers blacklisted"),
+                           1,
+                           GNUNET_NO);
   GNUNET_CONTAINER_DLL_remove (disconnect_head,
                               disconnect_tail,
                               dl);
@@ -314,6 +324,10 @@ whitelist_done (void *cls,
   struct PeerList *pl = cls;
 
   pl->wh = NULL;
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# peers blacklisted"),
+                           -1,
+                           GNUNET_NO);
 }
 
 
@@ -386,6 +400,10 @@ attempt_connect (struct PeerList *pos)
              "Asking core to connect to `%s'\n",
              GNUNET_i2s (&pos->id));
 #endif
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# connect requests issued to core"),
+                           1,
+                           GNUNET_NO);
   pos->connect_req = GNUNET_CORE_peer_request_connect (sched, cfg,
                                                       GNUNET_TIME_UNIT_MINUTES,
                                                       &pos->id,
@@ -669,6 +687,10 @@ connect_notify (void *cls,
              GNUNET_i2s (peer));
 #endif
   connection_count++;
+  GNUNET_STATISTICS_set (stats,
+                        gettext_noop ("# peers connected"),
+                        connection_count,
+                        GNUNET_NO);
   pos = find_peer (peer);
   if (pos == NULL)    
     {
@@ -698,6 +720,10 @@ connect_notify (void *cls,
           (GNUNET_YES != friends_only) )       
        whitelist_peers ();       
       friend_count++;
+      GNUNET_STATISTICS_set (stats,
+                            gettext_noop ("# friends connected"),
+                            connection_count,
+                            GNUNET_NO);
     }
   reschedule_hellos (pos);
 }
@@ -780,8 +806,18 @@ disconnect_notify (void *cls,
       return;
     }
   connection_count--;
+  GNUNET_STATISTICS_set (stats,
+                        gettext_noop ("# peers connected"),
+                        connection_count,
+                        GNUNET_NO);
   if (pos->is_friend)
-    friend_count--; 
+    {
+      friend_count--; 
+      GNUNET_STATISTICS_set (stats,
+                            gettext_noop ("# friends connected"),
+                            connection_count,
+                            GNUNET_NO);
+    }
   if ( (connection_count < target_connection_count) ||
        (friend_count < minimum_friend_count) )
     try_add_peers ();   
@@ -1127,6 +1163,10 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
     }
   GNUNET_free (data);
   GNUNET_free (fn);
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# friends in configuration"),
+                           entries_found,
+                           GNUNET_NO);
   if ( (minimum_friend_count > entries_found) &&
        (friends_only == GNUNET_NO) )
     {
@@ -1169,6 +1209,10 @@ handle_encrypted_hello (void *cls,
              "HELLO",
              GNUNET_i2s (other));
 #endif         
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# HELLO messages received"),
+                           1,
+                           GNUNET_NO);
   if (transport != NULL)
     GNUNET_TRANSPORT_offer_hello (transport,
                                  message);
@@ -1236,6 +1280,10 @@ hello_advertising_ready (void *cls,
                      (unsigned int) want,
                      "HELLO");
 #endif         
+         GNUNET_STATISTICS_update (stats,
+                                   gettext_noop ("# HELLO messages gossipped"),
+                                   1,
+                                   GNUNET_NO);
        }
     }
   pl->next_hello_allowed = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
@@ -1278,6 +1326,11 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       GNUNET_TRANSPORT_blacklist_cancel (dl->rh);
       GNUNET_free (dl);
     }
+  if (stats != NULL)
+    {
+      GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+      stats = NULL;
+    }
 }
 
 
@@ -1306,6 +1359,7 @@ run (void *cls,
 
   sched = s;
   cfg = c;
+  stats = GNUNET_STATISTICS_create (sched, "topology", cfg);
   autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg,
                                                      "TOPOLOGY",
                                                      "AUTOCONNECT");