gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r7889 - GNUnet/src/applications/fs/gap
Date: Sat, 15 Nov 2008 17:30:48 -0700 (MST)

Author: grothoff
Date: 2008-11-15 17:30:47 -0700 (Sat, 15 Nov 2008)
New Revision: 7889

Modified:
   GNUnet/src/applications/fs/gap/gap.c
   GNUnet/src/applications/fs/gap/plan.c
Log:
constant time get_average_priority

Modified: GNUnet/src/applications/fs/gap/gap.c
===================================================================
--- GNUnet/src/applications/fs/gap/gap.c        2008-11-15 11:20:54 UTC (rev 
7888)
+++ GNUnet/src/applications/fs/gap/gap.c        2008-11-16 00:30:47 UTC (rev 
7889)
@@ -52,6 +52,10 @@
  */
 static struct RequestList **table;
 
+static unsigned long long total_priority;
+
+static unsigned int active_request_count;
+
 static GNUNET_CoreAPIForPlugins *coreAPI;
 
 static GNUNET_Datastore_ServiceAPI *datastore;
@@ -299,6 +303,7 @@
             }
           if (stats != NULL)
             stats->change (stat_gap_query_refreshed, 1);
+         total_priority += priority;
           rl->value += priority;
           rl->remaining_value += priority;
           rl->expiration = newTTL;
@@ -320,7 +325,7 @@
             }
           /* update BF */
           if (rl->bloomfilter != NULL)
-            GNUNET_bloomfilter_free (rl->bloomfilter);
+           GNUNET_bloomfilter_free (rl->bloomfilter);
           rl->bloomfilter_mutator = filter_mutator;
           rl->bloomfilter_size = filter_size;
           if (filter_size > 0)
@@ -365,6 +370,8 @@
         table[index] = rl->next;
       else
         prev->next = rl->next;
+      active_request_count--;
+      total_priority -= rl->value;
       GNUNET_FS_SHARED_free_request_list (rl);
     }
   /* create new table entry */
@@ -392,6 +399,8 @@
   rl->response_target = peer;
   rl->policy = policy;
   rl->next = table[index];
+  active_request_count++;
+  total_priority += rl->value;
   table[index] = rl;
   if (stats != NULL)
     stats->change (stat_gap_query_routed, 1);
@@ -488,7 +497,8 @@
       GNUNET_FS_PLAN_success (rid, NULL, rl->response_target, rl);
       value += rl->value;
       rl_value = rl->value;
-      rl->value = 0;
+      total_priority -= rl->value;
+      rl->value = 0;      
 
       if (rl->type == GNUNET_ECRS_BLOCKTYPE_DATA)
         {
@@ -496,6 +506,8 @@
             table[index] = rl->next;
           else
             prev->next = rl->next;
+         active_request_count--;
+         total_priority -= rl->value;
           GNUNET_FS_SHARED_free_request_list (rl);
           if (prev == NULL)
             rl = table[index];
@@ -547,24 +559,12 @@
 unsigned int
 GNUNET_FS_GAP_get_average_priority ()
 {
-  struct RequestList *rl;
   unsigned long long tot;
-  unsigned int i;
   unsigned int active;
 
-  tot = 0;
-  active = 0;
   GNUNET_mutex_lock (GNUNET_FS_lock);
-  for (i = 0; i < table_size; i++)
-    {
-      rl = table[i];
-      while (rl != NULL)
-        {
-          tot += rl->value;
-          active++;
-          rl = rl->next;
-        }
-    }
+  tot = total_priority);
+  active = active_request_count);
   GNUNET_mutex_unlock (GNUNET_FS_lock);
   if (active == 0)
     return 0;
@@ -599,6 +599,8 @@
                 table[i] = rl->next;
               else
                 prev->next = rl->next;
+             active_request_count--;
+             total_priority -= rl->value;
               GNUNET_FS_SHARED_free_request_list (rl);
               if (prev == NULL)
                 rl = table[i];
@@ -721,6 +723,8 @@
       while (NULL != (rl = table[i]))
         {
           table[i] = rl->next;
+         active_request_count--;
+         total_priority -= rl->value;
           GNUNET_FS_SHARED_free_request_list (rl);
         }
     }
@@ -737,6 +741,8 @@
       coreAPI->service_release (stats);
       stats = NULL;
     }
+  GNUNET_GE_BREAK(NULL, active_request_count == 0);
+  GNUNET_GE_BREAK(NULL, total_priority == 0);
   return 0;
 }
 

Modified: GNUnet/src/applications/fs/gap/plan.c
===================================================================
--- GNUnet/src/applications/fs/gap/plan.c       2008-11-15 11:20:54 UTC (rev 
7888)
+++ GNUnet/src/applications/fs/gap/plan.c       2008-11-16 00:30:47 UTC (rev 
7889)
@@ -370,6 +370,7 @@
   struct PeerRankings *rankings;
   struct ClientInfoList *info;
   struct RequestList *request;
+  unsigned int avg_priority;
 };
 
 /**
@@ -450,7 +451,7 @@
     prio = history->last_good_prio - GNUNET_random_u32 
(GNUNET_RANDOM_QUALITY_WEAK, 2); /* fall over time */
   if (prio > 1)
     {
-      allowable_prio = GNUNET_FS_GAP_get_average_priority () + 1;
+      allowable_prio = rpc->avg_priority + 1;
       if (prio > allowable_prio)
         prio = allowable_prio;
     }
@@ -551,6 +552,7 @@
   rpc.info = info;
   rpc.request = request;
   rpc.rankings = NULL;
+  rpc.avg_priority = GNUNET_FS_GAP_get_average_priority ();
   total_peers = coreAPI->p2p_connections_iterate (rank_peers, &rpc);
   /* use request type, priority, system load and
      entropy of ranking to determine number of peers





reply via email to

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