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

[or-cvs] Hibernate if we start tor during the "wait for wakeup-time"...



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv13630/src/or

Modified Files:
	hibernate.c 
Log Message:
Hibernate if we start tor during the "wait for wakeup-time" phase of an accounting interval.  Log our hibernation plans better.

Index: hibernate.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/hibernate.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- hibernate.c	12 Nov 2004 16:39:02 -0000	1.17
+++ hibernate.c	14 Nov 2004 21:11:06 -0000	1.18
@@ -310,6 +310,10 @@
 
   interval_wakeup_time = interval_start_time +
     24*60*60 * (unsigned char)digest[0];
+
+  format_iso_time(buf, interval_wakeup_time);
+  log_fn(LOG_INFO, "Configured hibernation interval: Decided to wake up %d days into the interval, at %s GMT",
+         (int)(unsigned char)digest[0], buf);
 }
 
 /* XXXX009 This should also get called on HUP and shutdown. */
@@ -511,13 +515,16 @@
 /** If we aren't currently dormant, close all connections and become
  * dormant. */
 static void
-hibernate_go_dormant(void) {
+hibernate_go_dormant(time_t now) {
   connection_t *conn;
 
   if (hibernate_state == HIBERNATE_STATE_DORMANT)
     return;
+  else if (hibernate_state == HIBERNATE_STATE_LOWBANDWIDTH)
+    hibernate_state = HIBERNATE_STATE_DORMANT;
+  else
+    hibernate_begin(HIBERNATE_STATE_DORMANT, now);
 
-  hibernate_state = HIBERNATE_STATE_DORMANT;
   log_fn(LOG_NOTICE,"Going dormant. Blowing away remaining connections.");
 
   /* Close all OR/AP/exit conns. Leave dir conns because we still want
@@ -539,6 +546,8 @@
 static void
 hibernate_end_time_elapsed(time_t now)
 {
+  char buf[ISO_TIME_LEN+1];
+
   /* The interval has ended, or it is wakeup time.  Find out which. */
   accounting_run_housekeeping(now);
   if (interval_wakeup_time <= now) {
@@ -549,9 +558,14 @@
   } else {
     /* The interval has changed, and it isn't time to wake up yet. */
     hibernate_end_time = interval_wakeup_time;
-    if (hibernate_state != HIBERNATE_STATE_DORMANT)
+    format_iso_time(buf,interval_wakeup_time);
+    if (hibernate_state != HIBERNATE_STATE_DORMANT) {
       /* We weren't sleeping before; we should sleep now. */
-      hibernate_go_dormant();
+      log_fn(LOG_NOTICE, "Accounting period ended. Commencing hibernation until %s GMT",buf);
+      hibernate_go_dormant(now);
+    } else {
+      log_fn(LOG_NOTICE, "Accounting period ended. This period, we will hibernate until %s GMT",buf);
+    }
   }
 }
 
@@ -559,6 +573,8 @@
  * to start/stop hibernating.
  */
 void consider_hibernation(time_t now) {
+  int accounting_enabled = get_options()->AccountingMaxKB != 0;
+  char buf[ISO_TIME_LEN+1];
 
   /* If we're in 'exiting' mode, then we just shut down after the interval
    * elapses. */
@@ -575,7 +591,7 @@
   if(hibernate_state == HIBERNATE_STATE_DORMANT) {
     /* We've been hibernating because of bandwidth accounting. */
     tor_assert(hibernate_end_time);
-    if (hibernate_end_time > now) {
+    if (hibernate_end_time > now && accounting_enabled) {
       /* If we're hibernating, don't wake up until it's time, regardless of
        * whether we're in a new interval. */
       return ;
@@ -586,19 +602,25 @@
 
   /* Else, we aren't hibernating. See if it's time to start hibernating, or to
    * go dormant. */
-  if (hibernate_state == HIBERNATE_STATE_LIVE &&
-      hibernate_soft_limit_reached()) {
-    log_fn(LOG_NOTICE,"Bandwidth soft limit reached; commencing hibernation.");
-    hibernate_begin(HIBERNATE_STATE_LOWBANDWIDTH, now);
+  if (hibernate_state == HIBERNATE_STATE_LIVE) {
+    if (hibernate_soft_limit_reached()) {
+      log_fn(LOG_NOTICE,"Bandwidth soft limit reached; commencing hibernation.");
+      hibernate_begin(HIBERNATE_STATE_LOWBANDWIDTH, now);
+    } else if (accounting_enabled && now < interval_wakeup_time) {
+      format_iso_time(buf,interval_wakeup_time);
+      log_fn(LOG_NOTICE, "Commencing hibernation. We will wake up at %s GMT",buf);
+      hibernate_go_dormant(now);
+    }
   }
 
   if (hibernate_state == HIBERNATE_STATE_LOWBANDWIDTH) {
-    if (hibernate_hard_limit_reached()) {
-      hibernate_go_dormant();
+    if (!accounting_enabled) {
+      hibernate_end_time_elapsed(now);
+    } else if (hibernate_hard_limit_reached()) {
+      hibernate_go_dormant(now);
     } else if (hibernate_end_time <= now) {
       /* The hibernation period ended while we were still in lowbandwidth.*/
       hibernate_end_time_elapsed(now);
     }
   }
 }
-