[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [tor/master 5/8] Describe the recent timeouts reallocation behavior.



Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Wed, 10 Feb 2010 12:25:06 -0800
Subject: Describe the recent timeouts reallocation behavior.
Commit: 2b95d1c0ee463b278dbb8de008338687cd340e87

---
 src/or/circuitbuild.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 4ef6bfa..08ee584 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -135,6 +135,12 @@ circuit_build_times_recent_circuit_count(void)
   return num;
 }
 
+/**
+ * This function is called when we get a consensus update.
+ *
+ * It checks to see if we have changed any consensus parameters
+ * that require reallocation or discard of previous stats.
+ */
 void
 circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
                                          networkstatus_t *ns)
@@ -149,6 +155,19 @@ circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
 
     tor_assert(num > 0);
     tor_assert(cbt->liveness.timeouts_after_firsthop);
+
+    /*
+     * Technically this is a circular array that we are reallocating
+     * and memcopying. However, since it only consists of either 1s
+     * or 0s, and is only used in a statistical test to determine when
+     * we should discard our history after a sufficient number of 1's
+     * have been reached, it is fine if order is not preserved or
+     * elements are lost.
+     *
+     * cbtrecentcount should only be changing in cases of severe network
+     * distress anyway, so memory correctness here is paramount over
+     * doing acrobatics to preserve the array.
+     */
     recent_circs = tor_malloc_zero(sizeof(int8_t)*num);
     memcpy(recent_circs, cbt->liveness.timeouts_after_firsthop,
            sizeof(int8_t)*MIN(num, cbt->liveness.num_recent_circs));
-- 
1.6.5