stats
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index 6f689100247e4cadb48cb5528924c6cba85769c3..6899ef5fbc00aff0579ecbfe9b9e7dcd0d702af0 100644 (file)
@@ -919,6 +919,10 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
       /* fatal error with client, free message queue! */
       while (NULL != (q = client->message_queue_head))
         {
+         GNUNET_STATISTICS_update (stats,
+                                   gettext_noop ("# bytes discarded (could not transmit to client)"),
+                                   ntohs (((const struct GNUNET_MessageHeader*)&q[1])->size),
+                                   GNUNET_NO);      
          GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
                                       client->message_queue_tail,
                                       q);
@@ -1055,6 +1059,20 @@ transmit_send_continuation (void *cls,
   struct MessageQueue *mq = cls;
   struct NeighbourList *n;
 
+  if (result == GNUNET_OK)
+    {
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# bytes successfully transmitted by plugins"),
+                               mq->message_buf_size,
+                               GNUNET_NO);      
+    }
+  else
+    {
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# bytes with transmission failure by plugins"),
+                               mq->message_buf_size,
+                               GNUNET_NO);      
+    }  
   n = find_neighbour(&mq->neighbour_id);
   GNUNET_assert (n != NULL);
   if (mq->specific_address != NULL)
@@ -1191,6 +1209,14 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
                      mq->message_buf_size,
                      GNUNET_i2s (&mq->neighbour_id));
 #endif
+         GNUNET_STATISTICS_update (stats,
+                                   gettext_noop ("# bytes in message queue for other peers"),
+                                   -mq->message_buf_size,
+                                   GNUNET_NO);
+         GNUNET_STATISTICS_update (stats,
+                                   gettext_noop ("# bytes discarded (no destination address available)"),
+                                   mq->message_buf_size,
+                                   GNUNET_NO);      
          if (mq->client != NULL)
            transmit_send_ok (mq->client, neighbour, GNUNET_NO);
          GNUNET_CONTAINER_DLL_remove (neighbour->messages_head,
@@ -1235,6 +1261,10 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
                          mq->specific_address->addrlen),
              rl->plugin->short_name);
 #endif
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# bytes in message queue for other peers"),
+                           -mq->message_buf_size,
+                           GNUNET_NO);
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# bytes transmitted to other peers"),
                            mq->message_buf_size,
@@ -1286,7 +1316,7 @@ transmit_to_peer (struct TransportClient *client,
           if (mq->client == client)
             {
               /* client transmitted to same peer twice
-                 before getting SendOk! */
+                 before getting SEND_OK! */
               GNUNET_break (0);
               return;
             }
@@ -1294,6 +1324,10 @@ transmit_to_peer (struct TransportClient *client,
         }
     }
 #endif
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# bytes in message queue for other peers"),
+                           message_buf_size,
+                           GNUNET_NO);
   mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size);
   mq->specific_address = peer_address;
   mq->client = client;
@@ -2200,7 +2234,7 @@ rerun_validation (void *cls,
               "PING", sizeof (struct TransportPingMessage));
 #endif
   GNUNET_STATISTICS_update (stats,
-                           gettext_noop ("# PING messages sent"),
+                           gettext_noop ("# PING messages sent for re-validation"),
                            1,
                            GNUNET_NO);
   transmit_to_peer (NULL, peer_address,
@@ -2277,6 +2311,10 @@ run_validation (void *cls,
   uint16_t hello_size;
   size_t tsize;
 
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# peer addresses scheduled for validation"),
+                           1,
+                           GNUNET_NO);      
   tp = find_transport (tname);
   if (tp == NULL)
     {
@@ -2285,6 +2323,10 @@ run_validation (void *cls,
                   _
                   ("Transport `%s' not loaded, will not try to validate peer address using this transport.\n"),
                   tname);
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# peer addresses not validated (no applicable transport plugin available)"),
+                               1,
+                               GNUNET_NO);      
       return GNUNET_OK;
     }
   GNUNET_HELLO_get_key (chvc->hello, &pk);
@@ -2312,6 +2354,10 @@ run_validation (void *cls,
                  tname,
                  GNUNET_i2s (&id));
 #endif
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# peer addresses not validated (in progress)"),
+                               1,
+                               GNUNET_NO);      
       return GNUNET_OK;
     }
   va = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
@@ -2357,6 +2403,10 @@ run_validation (void *cls,
              "HELLO", hello_size,
              "PING", sizeof (struct TransportPingMessage));
 #endif
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# PING messages sent for initial validation"),
+                           1,
+                           GNUNET_NO);      
   transmit_to_peer (NULL, peer_address,
                    GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                    HELLO_VERIFICATION_TIMEOUT,
@@ -2460,16 +2510,33 @@ check_hello_validated (void *cls,
                      "HELLO",
                      GNUNET_i2s (&target));
 #endif
+         GNUNET_STATISTICS_update (stats,
+                                   gettext_noop ("# new HELLOs requiring full validation"),
+                                   1,
+                                   GNUNET_NO);      
          GNUNET_HELLO_iterate_addresses (chvc->hello,
                                          GNUNET_NO, 
                                          &run_validation, 
                                          chvc);
        }
+      else
+       {
+         GNUNET_STATISTICS_update (stats,
+                                   gettext_noop ("# duplicate HELLO (peer known)"),
+                                   1,
+                                   GNUNET_NO);      
+       }
       GNUNET_free (chvc);
       return;
-    }
+    } 
   if (h == NULL)
     return;
+#if DEBUG_TRANSPORT
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Peerinfo had `%s' message for peer `%4s', validating only new addresses.\n",
+             "HELLO",
+             GNUNET_i2s (peer));
+#endif
   chvc->hello_known = GNUNET_YES;
   n = find_neighbour (peer);
   if (n != NULL)
@@ -2515,7 +2582,10 @@ process_hello (struct TransportPlugin *plugin,
   if (GNUNET_SCHEDULER_get_load (sched,
                                 GNUNET_SCHEDULER_PRIORITY_BACKGROUND) > MAX_HELLO_LOAD)
     {
-      /* TODO: call to stats? */
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# HELLOs ignored due to high load"),
+                               1,
+                               GNUNET_NO);      
       return GNUNET_OK;
     }
   hello = (const struct GNUNET_HELLO_Message *) message;
@@ -2527,6 +2597,16 @@ process_hello (struct TransportPlugin *plugin,
   GNUNET_CRYPTO_hash (&publicKey,
                       sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
                       &target.hashPubKey);
+  if (0 == memcmp (&my_identity,
+                  &target,
+                  sizeof (struct GNUNET_PeerIdentity)))
+    {
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# HELLOs ignored for validation (is my own HELLO)"),
+                               1,
+                               GNUNET_NO);      
+      return GNUNET_OK;      
+    }
 #if DEBUG_TRANSPORT > 1
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Processing `%s' message for `%4s' of size %u\n",
@@ -2631,6 +2711,14 @@ disconnect_neighbour (struct NeighbourList *n, int check)
   /* free all messages on the queue */
   while (NULL != (mq = n->messages_head))
     {
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# bytes in message queue for other peers"),
+                               -mq->message_buf_size,
+                               GNUNET_NO);
+      GNUNET_STATISTICS_update (stats,
+                               gettext_noop ("# bytes discarded due to disconnect"),
+                               mq->message_buf_size,
+                               GNUNET_NO);
       GNUNET_CONTAINER_DLL_remove (n->messages_head,
                                   n->messages_tail,
                                   mq);
@@ -2976,6 +3064,10 @@ handle_hello (void *cls,
 {
   int ret;
 
+  GNUNET_STATISTICS_update (stats,
+                           gettext_noop ("# HELLOs received from clients"),
+                           1,
+                           GNUNET_NO);      
   ret = process_hello (NULL, message);
   GNUNET_SERVER_receive_done (client, ret);
 }