gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34830 - gnunet/src/rps


From: gnunet
Subject: [GNUnet-SVN] r34830 - gnunet/src/rps
Date: Wed, 7 Jan 2015 15:00:13 +0100

Author: ch3
Date: 2015-01-07 15:00:13 +0100 (Wed, 07 Jan 2015)
New Revision: 34830

Modified:
   gnunet/src/rps/gnunet-service-rps.c
   gnunet/src/rps/gnunet-service-rps_sampler.c
Log:
moved part of _resize() from _sampler.c to -rps.c

Modified: gnunet/src/rps/gnunet-service-rps.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps.c 2015-01-07 12:39:55 UTC (rev 34829)
+++ gnunet/src/rps/gnunet-service-rps.c 2015-01-07 14:00:13 UTC (rev 34830)
@@ -411,20 +411,39 @@
 nse_callback(void *cls, struct GNUNET_TIME_Absolute timestamp, double 
logestimate, double std_dev)
 {
   double estimate;
+  unsigned int old_est;
   //double scale; // TODO this might go gloabal/config
 
-  LOG(GNUNET_ERROR_TYPE_DEBUG, "Received a ns estimate - logest: %f, std_dev: 
%f\n", logestimate, std_dev);
+  old_est = est_size;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+      "Received a ns estimate - logest: %f, std_dev: %f (old_est: %f)\n",
+      logestimate, std_dev, old_est);
   //scale = .01;
-  estimate = GNUNET_NSE_log_estimate_to_n(logestimate);
+  estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
   // GNUNET_NSE_log_estimate_to_n (logestimate);
-  estimate = pow(estimate, 1./3);
+  estimate = pow (estimate, 1./3);
   // TODO add if std_dev is a number
   // estimate += (std_dev * scale);
   if ( 0 < estimate ) {
-    LOG(GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
     est_size = estimate;
   } else
-    LOG(GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
+
+  /* If the NSE has changed adapt the lists accordingly */
+  // TODO respect the request rate, min, max
+  if (old_est > est_size*4)
+  { /* Shrinking */
+    RPS_sampler_resize (old_est/2);
+  }
+  else if (old_est < est_size)
+  { /* Growing */
+    if (est_size < old_est*2)
+      RPS_sampler_resize (old_est*2);
+    else
+      RPS_sampler_resize (est_size);
+  }
 }
 
 /**
@@ -641,12 +660,13 @@
   //n_arr = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, 
(unsigned int) gossip_list_size);
   LOG(GNUNET_ERROR_TYPE_DEBUG, "Going to send pushes to %f (%f * %u) peers.\n",
       alpha * gossip_list_size, alpha, gossip_list_size);
+  // TODO send to at least one
   for ( i = 0 ; i < alpha * gossip_list_size ; i++ )
   { // TODO compute length
-    peer = get_rand_peer(gossip_list, gossip_list_size);
+    peer = get_rand_peer (gossip_list, gossip_list_size);
     if (own_identity != peer)
     { // FIXME if this fails schedule/loop this for later
-      LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending PUSH to peer %s of gossiped 
list.\n", GNUNET_i2s(peer));
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PUSH to peer %s of gossiped 
list.\n", GNUNET_i2s (peer));
 
       ev = GNUNET_MQ_msg (push_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
       //ev = GNUNET_MQ_msg_extra();
@@ -664,14 +684,15 @@
 
   /* Send PULL requests */
   //n_arr = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, 
(unsigned int) sampler_list->size);
-  LOG(GNUNET_ERROR_TYPE_DEBUG, "Going to send pulls to %f (%f * %u) peers.\n",
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to send pulls to %f (%f * %u) peers.\n",
       beta * gossip_list_size, beta, gossip_list_size);
+  // TODO send to at least one
   for ( i = 0 ; i < beta * gossip_list_size ; i++ )
   { // TODO compute length
     peer = get_rand_peer(gossip_list, gossip_list_size);
     if (own_identity != peer)
     { // FIXME if this fails schedule/loop this for later
-      LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of 
gossiped list.\n", GNUNET_i2s(peer));
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of 
gossiped list.\n", GNUNET_i2s (peer));
 
       ev = GNUNET_MQ_msg(pull_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
       //ev = GNUNET_MQ_msg_extra();
@@ -684,9 +705,6 @@
   }
 
 
-  /* If the NSE has changed adapt the lists accordingly */
-  RPS_sampler_resize(est_size);
-
   GNUNET_array_grow(gossip_list, gossip_list_size, est_size);
 
 

Modified: gnunet/src/rps/gnunet-service-rps_sampler.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler.c 2015-01-07 12:39:55 UTC (rev 
34829)
+++ gnunet/src/rps/gnunet-service-rps_sampler.c 2015-01-07 14:00:13 UTC (rev 
34830)
@@ -156,7 +156,7 @@
 /**
  * Inedex to the sampler element that is the next to be returned
  */
-static struct RPS_SamplerElement **extended_samplers_index;
+static uint64_t extended_samplers_index;
 
 /**
  * Request counter.
@@ -349,17 +349,13 @@
 
   old_size = sampler->sampler_size;
 
-  if (old_size > new_size*4 &&
-      extra_size > new_size*4)
+  if (old_size > new_size)
   { /* Shrinking */
-
-    new_size /= 2;
-
     /* Temporary store those to properly call the removeCB on those later */
     rem_list = GNUNET_malloc ((old_size - new_size) * sizeof (struct 
RPS_SamplerElement *));
     memcpy (rem_list,
         &sampler->sampler_elements[new_size],
-        (old_size - new_size) * sizeof(struct RPS_SamplerElement *));
+        (old_size - new_size) * sizeof (struct RPS_SamplerElement *));
 
     LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Shrinking sampler %d -> %d\n", 
old_size, new_size);
     GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, 
new_size);
@@ -367,7 +363,6 @@
         "SAMPLER: sampler->sampler_elements now points to %p\n",
         sampler->sampler_elements);
 
-    // TODO move extended_samplers_index
     for (i = new_size ; i < old_size ; i++)
     {/* Remove unneeded rest */
       LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX64 ". 
sampler\n", i);
@@ -376,19 +371,14 @@
       GNUNET_free (rem_list[i]);
     }
   }
-  else if (old_size < new_size)// ||
-      //extra_size < new_size) // needed?
+  else if (old_size < new_size)
   { /* Growing */
-    new_size *= 2; // TODO check overflow
-
     LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Growing sampler %d -> %d\n", 
old_size, new_size);
     GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, 
new_size);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "SAMPLER: sampler->sampler_elements now points to %p\n",
         sampler->sampler_elements);
 
-    // TODO move extended_samplers_index
-
     for ( i = old_size ; i < new_size ; i++ )
     { /* Add new sampler elements */
       sampler->sampler_elements[i] = RPS_sampler_elem_create ();
@@ -447,7 +437,7 @@
   RPS_sampler_resize (init_size);
   RPS_sampler_update_list (id); // no super nice desing but ok for the moment
 
-  extended_samplers_index = sampler->sampler_elements;
+  extended_samplers_index = 0;
 
   //GNUNET_assert (init_size == sampler->sampler_size);
 }
@@ -591,13 +581,12 @@
 
   // use _get_rand_peer_ ?
   peer = GNUNET_new (struct GNUNET_PeerIdentity);
-  *peer = (*extended_samplers_index)->peer_id;
-  RPS_sampler_elem_reinit (*extended_samplers_index);
-  if ( extended_samplers_index == 
&sampler->sampler_elements[sampler->sampler_size -1] )
-    extended_samplers_index = &sampler->sampler_elements[0];
+  *peer = sampler->sampler_elements[extended_samplers_index]->peer_id;
+  RPS_sampler_elem_reinit (sampler->sampler_elements[extended_samplers_index]);
+  if ( extended_samplers_index == sampler->sampler_size )
+    extended_samplers_index = 0;
   else
     extended_samplers_index++;
-  // TODO
   return peer;
 }
 




reply via email to

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