gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6270 - GNUnet/src/applications/fs/gap


From: gnunet
Subject: [GNUnet-SVN] r6270 - GNUnet/src/applications/fs/gap
Date: Tue, 12 Feb 2008 21:55:11 -0700 (MST)

Author: grothoff
Date: 2008-02-12 21:55:10 -0700 (Tue, 12 Feb 2008)
New Revision: 6270

Modified:
   GNUnet/src/applications/fs/gap/fs.c
   GNUnet/src/applications/fs/gap/gap.c
   GNUnet/src/applications/fs/gap/plan.c
   GNUnet/src/applications/fs/gap/querymanager.c
   GNUnet/src/applications/fs/gap/shared.c
   GNUnet/src/applications/fs/gap/test_linear_topology.c
Log:
adding stats

Modified: GNUnet/src/applications/fs/gap/fs.c
===================================================================
--- GNUnet/src/applications/fs/gap/fs.c 2008-02-13 03:58:27 UTC (rev 6269)
+++ GNUnet/src/applications/fs/gap/fs.c 2008-02-13 04:55:10 UTC (rev 6270)
@@ -74,8 +74,12 @@
 
 static int stat_gap_query_received;
 
+static int stat_gap_query_drop_busy;
+
 static int stat_gap_content_received;
 
+static int stat_gap_content_found_locally;
+
 static int stat_gap_trust_awarded;
 
 /**
@@ -523,6 +527,8 @@
   enum GNUNET_FS_RoutingPolicy policy;
   double preference;
 
+  if (stats != NULL)
+    stats->change (stat_gap_query_received, 1);
   if (test_load_too_high ())
     {
 #if DEBUG_GAP
@@ -537,6 +543,8 @@
                      "Dropping query from %s, this peer is too busy.\n",
                      sender == NULL ? "localhost" : (char *) &enc);
 #endif
+      if (stats != NULL)
+       stats->change (stat_gap_query_drop_busy, 1);
       return GNUNET_OK;
     }
   size = ntohs (msg->size);
@@ -559,9 +567,6 @@
       GNUNET_GE_BREAK_OP (ectx, 0);
       return GNUNET_SYSERR;     /* malformed query */
     }
-  if (stats != NULL)
-    stats->change (stat_gap_query_received, 1);
-
   bloomfilter_size =
     size - (sizeof (P2P_gap_query_MESSAGE) +
             (query_count - 1) * sizeof (GNUNET_HashCode));
@@ -578,13 +583,24 @@
     {
       prio = -identity->changeHostTrust (sender, -prio);
       if (netLoad < GAP_IDLE_LOAD_THRESHOLD + prio)
-        policy = GNUNET_FS_RoutingPolicy_ALL;
+       {
+         policy = GNUNET_FS_RoutingPolicy_ALL;
+       }
       else if (netLoad < 90 + 10 * prio)
-        policy =
-          GNUNET_FS_RoutingPolicy_ANSWER | GNUNET_FS_RoutingPolicy_FORWARD;
+       {
+         policy =
+           GNUNET_FS_RoutingPolicy_ANSWER | GNUNET_FS_RoutingPolicy_FORWARD;
+       }
       else if (netLoad < 100)
+       {
         policy = GNUNET_FS_RoutingPolicy_ANSWER;
-      return GNUNET_OK;         /* drop */
+       }
+      else
+       {
+         if (stats != NULL)
+           stats->change (stat_gap_query_drop_busy, 1);
+         return GNUNET_OK;         /* drop */
+       }
     }
   if ((policy & GNUNET_FS_RoutingPolicy_INDIRECT) == 0)
       /* kill the priority (since we cannot benefit) */
@@ -658,8 +674,13 @@
       GNUNET_GE_BREAK_OP (ectx, 0);
       return GNUNET_SYSERR;     /* invalid! */
     }
-  if (stats != NULL)
-    stats->change (stat_gap_content_received, 1);
+  if (stats != NULL) 
+    {
+      if (sender != NULL) 
+       stats->change (stat_gap_content_received, 1);
+      else
+       stats->change (stat_gap_content_found_locally, 1);
+    }
   expiration = GNUNET_ntohll (msg->expiration);
   /* forward to other peers */
   prio = GNUNET_FS_GAP_handle_response (sender,
@@ -727,8 +748,12 @@
     {
       stat_gap_query_received =
         stats->create (gettext_noop ("# gap requests total received"));
+      stat_gap_query_drop_busy =
+        stats->create (gettext_noop ("# gap requests dropped due to load"));
       stat_gap_content_received =
         stats->create (gettext_noop ("# gap content total received"));
+      stat_gap_content_received =
+        stats->create (gettext_noop ("# gap content found locally"));
       stat_gap_trust_awarded =
         stats->create (gettext_noop ("# gap total trust awarded"));
     }

Modified: GNUnet/src/applications/fs/gap/gap.c
===================================================================
--- GNUnet/src/applications/fs/gap/gap.c        2008-02-13 03:58:27 UTC (rev 
6269)
+++ GNUnet/src/applications/fs/gap/gap.c        2008-02-13 04:55:10 UTC (rev 
6270)
@@ -28,6 +28,7 @@
 #include "gnunet_util.h"
 #include "gnunet_protocols.h"
 #include "gnunet_datastore_service.h"
+#include "gnunet_stats_service.h"
 #include "gap.h"
 #include "fs.h"
 #include "ondemand.h"
@@ -63,7 +64,17 @@
  */
 static unsigned int random_qsel;
 
+static GNUNET_Stats_ServiceAPI *stats;
 
+static int stat_gap_query_dropped;
+
+static int stat_gap_query_dropped_redundant;
+
+static int stat_gap_query_routed;
+
+static int stat_gap_query_refreshed;
+
+
 static unsigned int
 get_table_index (const GNUNET_HashCode * key)
 {
@@ -224,8 +235,12 @@
              /* ignore */
              GNUNET_FS_PT_change_rc (peer, -1);
              GNUNET_mutex_unlock (GNUNET_FS_lock);
+             if (stats != NULL)
+               stats->change(stat_gap_query_dropped_redundant, 1);
              return;
            }
+         if (stats != NULL)
+           stats->change(stat_gap_query_refreshed, 1);
          rl->value += priority;
          rl->remaining_value += priority;
          rl->expiration = newTTL;
@@ -272,6 +287,8 @@
       /* do not process */
       GNUNET_FS_PT_change_rc (peer, -1);
       GNUNET_mutex_unlock (GNUNET_FS_lock);
+      if (stats != NULL)
+       stats->change(stat_gap_query_dropped, 1);
       return;
     }
   /* delete oldest table entry */
@@ -323,9 +340,12 @@
                           datastore_value_processor, rl);
 
   /* if not found or not unique, forward */
-  if ((ret != 1) || (type != GNUNET_ECRS_BLOCKTYPE_DATA))
+  if ( ((ret != 1) || (type != GNUNET_ECRS_BLOCKTYPE_DATA)) &&
+       (0 != (policy & GNUNET_FS_RoutingPolicy_FORWARD)) )
     GNUNET_FS_PLAN_request (NULL, peer, rl);    
   GNUNET_mutex_unlock (GNUNET_FS_lock);
+  if (stats != NULL)
+    stats->change(stat_gap_query_routed, 1);
 }
 
 /**
@@ -517,6 +537,18 @@
                     coreAPI->
                     register_notify_peer_disconnect
                     (&cleanup_on_peer_disconnect, NULL));
+  stats = capi->request_service ("stats");
+  if (stats != NULL)
+    {
+      stat_gap_query_dropped =
+        stats->create (gettext_noop ("# gap queries dropped (table full)"));
+      stat_gap_query_dropped_redundant =
+        stats->create (gettext_noop ("# gap queries dropped (redundant)"));
+      stat_gap_query_routed =
+        stats->create (gettext_noop ("# gap queries routed"));
+      stat_gap_query_refreshed =
+        stats->create (gettext_noop ("# gap queries refreshed existing 
record"));
+    }
   cron = GNUNET_cron_create (coreAPI->ectx);
   GNUNET_cron_start (cron);
   return 0;
@@ -547,6 +579,11 @@
   datastore = NULL;
   GNUNET_cron_stop (cron);
   GNUNET_cron_destroy (cron);
+  if (stats != NULL)
+    {
+      coreAPI->release_service (stats);
+      stats = NULL;
+    }
   return 0;
 }
 

Modified: GNUnet/src/applications/fs/gap/plan.c
===================================================================
--- GNUnet/src/applications/fs/gap/plan.c       2008-02-13 03:58:27 UTC (rev 
6269)
+++ GNUnet/src/applications/fs/gap/plan.c       2008-02-13 04:55:10 UTC (rev 
6270)
@@ -27,6 +27,7 @@
 #include "platform.h"
 #include <math.h>
 #include "gnunet_protocols.h"
+#include "gnunet_stats_service.h"
 #include "plan.h"
 #include "pid_table.h"
 #include "fs_dht.h"
@@ -40,6 +41,7 @@
  */ 
 #define MAX_ENTRIES_PER_PEER 64
 
+
 /**
  * Linked list summarizing how good other peers
  * were at producing responses for a client.
@@ -192,6 +194,14 @@
  */
 static double LOG_2;
 
+static GNUNET_Stats_ServiceAPI *stats;
+
+static int stat_gap_query_sent;
+
+static int stat_gap_query_planned;
+
+static int stat_gap_query_success;
+
 /**
  * Find the entry in the client list corresponding
  * to the given client information.  If no such entry
@@ -320,6 +330,8 @@
   entry->plan_entries_next = request->plan_entries;
   request->plan_entries = entry;
 
+  if (stats != NULL)
+    stats->change(stat_gap_query_planned, 1);
   /* compute (random) insertion position in doubly-linked list */
   total = count_query_plan_entries(qpl);
   total = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, total + 1);
@@ -661,6 +673,8 @@
   req->last_prio_used = prio;
   req->last_ttl_used = ttl;
   req->remaining_value -= prio;
+  if (stats != NULL)
+    stats->change(stat_gap_query_sent, 1);
   return size;
 }
 
@@ -817,6 +831,8 @@
   hl->last_response_time = GNUNET_get_time ();
   hl->response_count++;
   GNUNET_mutex_unlock (GNUNET_FS_lock);
+  if (stats != NULL)
+    stats->change(stat_gap_query_success, 1);
 }
 
 /**
@@ -928,6 +944,16 @@
                                                        (P2P_gap_query_MESSAGE),
                                                        
GNUNET_FS_GAP_QUERY_POLL_PRIORITY,
                                                        &query_fill_callback));
+  stats = capi->request_service ("stats");
+  if (stats != NULL)
+    {
+      stat_gap_query_sent =
+        stats->create (gettext_noop ("# gap requests total sent"));
+      stat_gap_query_planned =
+        stats->create (gettext_noop ("# gap content total planned"));
+      stat_gap_query_success =
+        stats->create (gettext_noop ("# gap routes succeeded"));
+    }
   return 0;
 }
 
@@ -960,6 +986,11 @@
                     connection_unregister_send_callback (sizeof
                                                          
(P2P_gap_query_MESSAGE),
                                                          
&query_fill_callback));
+  if (stats != NULL)
+    {
+      coreAPI->release_service (stats);
+      stats = NULL;
+    }
   return 0;
 }
 

Modified: GNUnet/src/applications/fs/gap/querymanager.c
===================================================================
--- GNUnet/src/applications/fs/gap/querymanager.c       2008-02-13 03:58:27 UTC 
(rev 6269)
+++ GNUnet/src/applications/fs/gap/querymanager.c       2008-02-13 04:55:10 UTC 
(rev 6270)
@@ -29,6 +29,7 @@
 
 #include "platform.h"
 #include "gnunet_protocols.h"
+#include "gnunet_stats_service.h"
 #include "querymanager.h"
 #include "fs.h"
 #include "fs_dht.h"
@@ -71,6 +72,18 @@
  */
 static struct ClientDataList *clients;
 
+
+static GNUNET_Stats_ServiceAPI *stats;
+
+static int stat_gap_client_query_received;
+
+static int stat_gap_client_response_sent;
+
+static int stat_gap_client_query_tracked;
+
+static int stat_gap_client_query_injected;
+
+
 /**
  * A client is asking us to run a query.  The query should be issued
  * until either a unique response has been obtained or until the
@@ -90,7 +103,12 @@
   struct RequestList *request;
 
   GNUNET_GE_ASSERT (NULL, key_count > 0);
-
+  if (stats != NULL)
+    {
+      stats->change(stat_gap_client_query_tracked, 1);
+      stats->change(stat_gap_client_query_received, 1);
+      stats->change(stat_gap_client_query_injected, 1);
+    }
   request =
     GNUNET_malloc (sizeof (struct RequestList) +
                    (key_count - 1) * sizeof (GNUNET_HashCode));
@@ -189,7 +207,6 @@
  * If so, transmit to client and update response
  * lists and bloomfilter accordingly.
  *
- * @
  * @param value how much is this response worth to us?
  *        the function should increment value accordingly
  * @return GNUNET_OK if this was the last response
@@ -230,6 +247,8 @@
                               &msg->header,
                               (rl->type != GNUNET_ECRS_BLOCKTYPE_DATA)
                               ? GNUNET_NO : GNUNET_YES);
+  if (stats != NULL)
+    stats->change(stat_gap_client_response_sent, 1);    
   GNUNET_free (msg);
 
   /* update *value */
@@ -318,6 +337,8 @@
               else
                 cl->requests = rl->next;
               GNUNET_FS_SHARED_free_request_list (rl);
+             if (stats != NULL)
+               stats->change(stat_gap_client_query_tracked, -1);
               if (prev == NULL)
                 rl = cl->requests;
               else
@@ -363,6 +384,8 @@
           rl = cl->requests;
           cl->requests = rl->next;
           GNUNET_FS_SHARED_free_request_list (rl);
+         if (stats != NULL)
+           stats->change(stat_gap_client_query_tracked, -1);
         }
       if (prev == NULL)
         clients = cl->next;
@@ -397,7 +420,11 @@
                (request->expiration > now)) &&
               (request->last_ttl_used * GNUNET_CRON_SECONDS +
                request->last_request_time < now))
-            GNUNET_FS_PLAN_request (client->client, 0, request);
+           {
+             GNUNET_FS_PLAN_request (client->client, 0, request);
+             if (stats != NULL)
+               stats->change(stat_gap_client_query_injected, 1);
+           }
 
           if ((request->anonymityLevel == 0) &&
               (request->last_dht_get + request->dht_back_off < now))
@@ -425,6 +452,19 @@
   GNUNET_cron_add_job (capi->cron,
                        &repeat_requests_job,
                        CHECK_REPEAT_FREQUENCY, CHECK_REPEAT_FREQUENCY, NULL);
+
+  stats = capi->request_service ("stats");
+  if (stats != NULL)
+    {
+      stat_gap_client_query_received =
+        stats->create (gettext_noop ("# gap client queries received"));
+      stat_gap_client_response_sent =
+        stats->create (gettext_noop ("# gap replies sent to clients"));
+      stat_gap_client_query_tracked =
+        stats->create (gettext_noop ("# gap client requests tracked"));
+      stat_gap_client_query_injected =
+        stats->create (gettext_noop ("# gap client requests injected"));
+    }
   return 0;
 }
 
@@ -439,6 +479,11 @@
                     cs_exit_handler_unregister (&handle_client_exit));
   while (clients != NULL)
     handle_client_exit(clients->client);    
+  if (stats != NULL)
+    {
+      coreAPI->release_service (stats);
+      stats = NULL;
+    }
   return 0;
 }
 

Modified: GNUnet/src/applications/fs/gap/shared.c
===================================================================
--- GNUnet/src/applications/fs/gap/shared.c     2008-02-13 03:58:27 UTC (rev 
6269)
+++ GNUnet/src/applications/fs/gap/shared.c     2008-02-13 04:55:10 UTC (rev 
6270)
@@ -64,6 +64,7 @@
     GNUNET_bloomfilter_free (rl->bloomfilter);
   GNUNET_FS_PT_change_rc (rl->primary_target, -1);
   GNUNET_FS_PT_change_rc (rl->response_target, -1);
+  memset(rl, 0, sizeof(struct RequestList)); /* mark as freed */
   GNUNET_free (rl);
 }
 

Modified: GNUnet/src/applications/fs/gap/test_linear_topology.c
===================================================================
--- GNUnet/src/applications/fs/gap/test_linear_topology.c       2008-02-13 
03:58:27 UTC (rev 6269)
+++ GNUnet/src/applications/fs/gap/test_linear_topology.c       2008-02-13 
04:55:10 UTC (rev 6270)
@@ -35,7 +35,7 @@
 
 #define START_PEERS 1
 
-#define PEER_COUNT 2
+#define PEER_COUNT 4
 
 #define SIZE 1024 * 1024 * 2
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]