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

[or-cvs] [tor/maint-0.2.2 06/10] refactor and recomment; no actual changes



Author: Roger Dingledine <arma@xxxxxxxxxxxxxx>
Date: Wed, 29 Sep 2010 18:01:22 -0400
Subject: refactor and recomment; no actual changes
Commit: 7f10707c42e69ef69395aecf7984d16107c78331

---
 src/or/circuitbuild.c |   19 ++++++++++++-------
 src/or/circuitbuild.h |    1 +
 src/or/circuituse.c   |    5 +++--
 src/or/or.h           |    5 +++--
 4 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 7a0a215..5dfabcc 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -149,6 +149,14 @@ circuit_build_times_min_circs_to_observe(void)
   return num;
 }
 
+/** Return true iff <b>cbt</b> has recorded enough build times that we
+ * want to start acting on the timeout it implies. */
+int
+circuit_build_times_enough_to_compute(circuit_build_times_t *cbt)
+{
+  return cbt->total_build_times >= circuit_build_times_min_circs_to_observe();
+}
+
 double
 circuit_build_times_quantile_cutoff(void)
 {
@@ -292,8 +300,8 @@ circuit_build_times_reset(circuit_build_times_t *cbt)
 /**
  * Initialize the buildtimes structure for first use.
  *
- * Sets the initial timeout value based to either the
- * config setting or BUILD_TIMEOUT_INITIAL_VALUE.
+ * Sets the initial timeout values based on either the config setting,
+ * the consensus param, or the default (CBT_DEFAULT_TIMEOUT_INITIAL_VALUE).
  */
 void
 circuit_build_times_init(circuit_build_times_t *cbt)
@@ -918,9 +926,7 @@ int
 circuit_build_times_needs_circuits(circuit_build_times_t *cbt)
 {
   /* Return true if < MIN_CIRCUITS_TO_OBSERVE */
-  if (cbt->total_build_times < circuit_build_times_min_circs_to_observe())
-    return 1;
-  return 0;
+  return !circuit_build_times_enough_to_compute(cbt);
 }
 
 /**
@@ -1205,9 +1211,8 @@ static int
 circuit_build_times_set_timeout_worker(circuit_build_times_t *cbt)
 {
   build_time_t max_time;
-  if (cbt->total_build_times < circuit_build_times_min_circs_to_observe()) {
+  if (!circuit_build_times_enough_to_compute(cbt))
     return 0;
-  }
 
   if (!circuit_build_times_update_alpha(cbt))
     return 0;
diff --git a/src/or/circuitbuild.h b/src/or/circuitbuild.h
index 7cc5c28..9d666ec 100644
--- a/src/or/circuitbuild.h
+++ b/src/or/circuitbuild.h
@@ -79,6 +79,7 @@ void bridges_retry_all(void);
 void entry_guards_free_all(void);
 
 extern circuit_build_times_t circ_times;
+int circuit_build_times_enough_to_compute(circuit_build_times_t *cbt);
 void circuit_build_times_update_state(circuit_build_times_t *cbt,
                                       or_state_t *state);
 int circuit_build_times_parse_state(circuit_build_times_t *cbt,
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 6ecb925..66ee0c4 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -278,8 +278,9 @@ void
 circuit_expire_building(time_t now)
 {
   circuit_t *victim, *next_circ = global_circuitlist;
-  /* circ_times.timeout is BUILD_TIMEOUT_INITIAL_VALUE if we haven't
-   * decided on a customized one yet */
+  /* circ_times.timeout_ms and circ_times.close_ms are from
+   * circuit_build_times_get_initial_timeout() if we haven't computed
+   * custom timeouts yet */
   time_t general_cutoff = now - tor_lround(circ_times.timeout_ms/1000);
   time_t begindir_cutoff = now - tor_lround(circ_times.timeout_ms/2000);
   time_t fourhop_cutoff = now - tor_lround(4*circ_times.timeout_ms/3000);
diff --git a/src/or/or.h b/src/or/or.h
index dc46684..c90b039 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2979,8 +2979,9 @@ typedef uint32_t build_time_t;
  * Maximum count of timeouts that finish the first hop in the past
  * RECENT_CIRCUITS before calculating a new timeout.
  *
- * This tells us to abandon timeout history and set
- * the timeout back to BUILD_TIMEOUT_INITIAL_VALUE.
+ * This tells us whether to abandon timeout history and set
+ * the timeout back to whatever circuit_build_times_get_initial_timeout()
+ * gives us.
  */
 #define CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT (CBT_DEFAULT_RECENT_CIRCUITS*9/10)
 
-- 
1.7.1