- fixing stat values
authorMatthias Wachs <wachs@net.in.tum.de>
Fri, 11 May 2012 08:18:01 +0000 (08:18 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Fri, 11 May 2012 08:18:01 +0000 (08:18 +0000)
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_clients.c
src/transport/gnunet-service-transport_neighbours.c

index 679d5293760cf4084552c05e212b834bd7ebb1f3..981cd33faca4c04a78ff4491258d1d5d2c778af1 100644 (file)
@@ -221,6 +221,8 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
   struct GNUNET_TIME_Relative ret;
   struct GNUNET_HELLO_Address address;
   uint16_t type;
+  static unsigned int bytes_total_received;
+  static unsigned int bytes_payload_received;
 
   address.peer = *peer;
   address.address = sender_address;
@@ -231,6 +233,13 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
     goto end;
   type = ntohs (message->type);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received Message with type %u\n", type);
+
+  bytes_total_received += ntohs (message->size);
+  GNUNET_STATISTICS_set (GST_stats,
+                        gettext_noop
+                        ("# bytes total received"),
+                        bytes_total_received, GNUNET_NO);
+
   switch (type)
   {
   case GNUNET_MESSAGE_TYPE_HELLO:
@@ -273,6 +282,11 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
     break;
   default:
     /* should be payload */
+    bytes_payload_received += ntohs (message->size);
+    GNUNET_STATISTICS_set (GST_stats,
+                          gettext_noop
+                          ("# bytes payload received"),
+                          bytes_payload_received, GNUNET_NO);
     ret = process_payload (peer, &address, session, message, ats, ats_count);
     break;
   }
index 98844f830a3cb92413ba3840c155f472adfa8e78..b2981951d0d3df3c2e525fe7fcbc01e375367b81 100644 (file)
@@ -616,10 +616,7 @@ clients_handle_send (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  GNUNET_STATISTICS_update (GST_stats,
-                            gettext_noop
-                            ("# bytes payload received for other peers"), msize,
-                            GNUNET_NO);
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
               "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
index 07c48caba175cab506244ad50d69bf01d4b35118..bdb67dbca18f6b2e06ec6aac8a3d73cfc332cfae 100644 (file)
@@ -401,6 +401,9 @@ static GNUNET_TRANSPORT_PeerIterateCallback address_change_cb;
  */
 static int neighbours_connected;
 
+static unsigned int bytes_in_send_queue;
+static unsigned int bytes_received;
+
 /**
  * Lookup a neighbour entry in the neighbours hash map.
  *
@@ -710,6 +713,14 @@ transmit_send_continuation (void *cls,
       n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
     }
   }
+
+  GNUNET_assert (bytes_in_send_queue >= mq->message_buf_size);
+  bytes_in_send_queue -= mq->message_buf_size;
+  GNUNET_STATISTICS_set (GST_stats,
+                        gettext_noop
+                        ("# bytes in message queue for other peers"),
+                        bytes_in_send_queue, GNUNET_NO);
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message of type %u was %s\n",
               ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
               (success == GNUNET_OK) ? "successful" : "FAILED");
@@ -838,6 +849,8 @@ GST_neighbours_start (void *cls,
   address_change_cb = peer_address_cb;
   neighbours = GNUNET_CONTAINER_multihashmap_create (NEIGHBOUR_TABLE_SIZE);
   neighbours_connected = 0;
+  bytes_in_send_queue = 0;
+  bytes_received = 0;
 }
 
 
@@ -1977,10 +1990,11 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
   }
 
   GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader));
-  GNUNET_STATISTICS_update (GST_stats,
-                            gettext_noop
-                            ("# bytes in message queue for other peers"),
-                            msg_size, GNUNET_NO);
+  bytes_in_send_queue += msg_size;
+  GNUNET_STATISTICS_set (GST_stats,
+                        gettext_noop
+                        ("# bytes in message queue for other peers"),
+                        bytes_in_send_queue, GNUNET_NO);
   mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size);
   mq->cont = cont;
   mq->cont_cls = cont_cls;