]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Don't update AccountingSoftLimitHitAt on startup
authorSebastian Hahn <sebastian@torproject.org>
Thu, 1 Sep 2011 03:21:50 +0000 (05:21 +0200)
committerSebastian Hahn <sebastian@torproject.org>
Thu, 1 Sep 2011 15:21:50 +0000 (17:21 +0200)
Add a "default" state which we use until we've decided whether we're
live or hibernating. This allows us to properly track whether we're
resuming a hibernation period or not. Fixes bug 2003.

changes/bug2003 [new file with mode: 0644]
src/or/hibernate.c

diff --git a/changes/bug2003 b/changes/bug2003
new file mode 100644 (file)
index 0000000..f1298dd
--- /dev/null
@@ -0,0 +1,8 @@
+  o Major bugfixes:
+    - Don't update the AccountingSoftLimitHitAt state file entry whenever
+      tor gets started. This prevents a wrong average bandwidth estimate,
+      which would cause relays to always start a new accounting interval at
+      the earliest possible moment. Fixes bug 2003; bugfix on 0.2.2.7-alpha.
+      Reported by BryonEldridge, who also helped immensely in tracking this
+      bug down. Thanks!
+
index aebce4cc883e96f8433d463ed5a256bcbce70bf0..badc96ba8e4ab6e7b8fb50437f4b3cda8c1daeeb 100644 (file)
@@ -41,14 +41,17 @@ typedef enum {
   HIBERNATE_STATE_LOWBANDWIDTH=3,
   /** We are hibernating, and we won't wake up till there's more bandwidth to
    * use. */
-  HIBERNATE_STATE_DORMANT=4
+  HIBERNATE_STATE_DORMANT=4,
+  /** We start out in state default, which means we havent decided which state
+   * we're in. */
+  HIBERNATE_STATE_INITIAL=5
 } hibernate_state_t;
 
 extern long stats_n_seconds_working; /* published uptime */
 
 /** Are we currently awake, asleep, running out of bandwidth, or shutting
  * down? */
-static hibernate_state_t hibernate_state = HIBERNATE_STATE_LIVE;
+static hibernate_state_t hibernate_state = HIBERNATE_STATE_INITIAL;
 /** If are hibernating, when do we plan to wake up? Set to 0 if we
  * aren't hibernating. */
 static time_t hibernate_end_time = 0;
@@ -804,10 +807,12 @@ static void
 hibernate_end(hibernate_state_t new_state)
 {
   tor_assert(hibernate_state == HIBERNATE_STATE_LOWBANDWIDTH ||
-             hibernate_state == HIBERNATE_STATE_DORMANT);
+             hibernate_state == HIBERNATE_STATE_DORMANT ||
+             hibernate_state == HIBERNATE_STATE_INITIAL);
 
   /* listeners will be relaunched in run_scheduled_events() in main.c */
-  log_notice(LD_ACCT,"Hibernation period ended. Resuming normal activity.");
+  if (hibernate_state != HIBERNATE_STATE_INITIAL)
+    log_notice(LD_ACCT,"Hibernation period ended. Resuming normal activity.");
 
   hibernate_state = new_state;
   hibernate_end_time = 0; /* no longer hibernating */
@@ -939,7 +944,8 @@ consider_hibernation(time_t now)
 
   /* Else, we aren't hibernating. See if it's time to start hibernating, or to
    * go dormant. */
-  if (hibernate_state == HIBERNATE_STATE_LIVE) {
+  if (hibernate_state == HIBERNATE_STATE_LIVE ||
+      hibernate_state == HIBERNATE_STATE_INITIAL) {
     if (hibernate_soft_limit_reached()) {
       log_notice(LD_ACCT,
                  "Bandwidth soft limit reached; commencing hibernation. "
@@ -951,6 +957,8 @@ consider_hibernation(time_t now)
                  "Commencing hibernation. We will wake up at %s local time.",
                  buf);
       hibernate_go_dormant(now);
+    } else if (hibernate_state == HIBERNATE_STATE_INITIAL) {
+      hibernate_end(HIBERNATE_STATE_LIVE);
     }
   }