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

[or-cvs] r9174: Update the state file less often when AvoidDiskWrites is set (in tor/trunk: . doc src/or)



Author: nickm
Date: 2006-12-23 21:45:46 -0500 (Sat, 23 Dec 2006)
New Revision: 9174

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/doc/TODO
   tor/trunk/src/or/circuitbuild.c
   tor/trunk/src/or/hibernate.c
   tor/trunk/src/or/rephist.c
   tor/trunk/src/or/router.c
Log:
 r11679@Kushana:  nickm | 2006-12-23 21:38:41 -0500
 Update the state file less often when AvoidDiskWrites is set.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r11679] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2006-12-24 02:45:41 UTC (rev 9173)
+++ tor/trunk/ChangeLog	2006-12-24 02:45:46 UTC (rev 9174)
@@ -43,6 +43,7 @@
       dirserver has given us a 503, we try not to use it until an hour
       has gone by, or until we have no dirservers that haven't given us
       a 503.
+    - The state file gets saved less often when AvoidDiskWrites is set.
 
   o Security bugfixes:
     - Stop sending the HttpProxyAuthenticator string to directory

Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO	2006-12-24 02:45:41 UTC (rev 9173)
+++ tor/trunk/doc/TODO	2006-12-24 02:45:46 UTC (rev 9174)
@@ -154,7 +154,7 @@
     flash memory (e.g. Linksys routers or USB keys).
     o Add AvoidDiskWrites config option.
     . only write state file when it's "changed"
-      - crank up the numbers if avoiddiskwrites is on.
+      o crank up the numbers if avoiddiskwrites is on.
       - some things may not want to get written at all.
     - stop writing identity key / fingerprint / etc every restart
     - more?

Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2006-12-24 02:45:41 UTC (rev 9173)
+++ tor/trunk/src/or/circuitbuild.c	2006-12-24 02:45:46 UTC (rev 9174)
@@ -2412,10 +2412,12 @@
 static void
 entry_guards_changed(void)
 {
+  time_t when;
   entry_guards_dirty = 1;
 
   /* or_state_save() will call entry_guards_update_state(). */
-  or_state_mark_dirty(get_or_state(), time(NULL)+600);
+  when = get_options()->AvoidDiskWrites ? time(NULL) + 3600 : time(NULL)+600;
+  or_state_mark_dirty(get_or_state(), when);
 }
 
 /** If the entry guard info has not changed, do nothing and return.
@@ -2466,7 +2468,8 @@
         next = &(line->next);
       }
     });
-  or_state_mark_dirty(get_or_state(), 0);
+  if (!get_options()->AvoidDiskWrites)
+    or_state_mark_dirty(get_or_state(), 0);
   entry_guards_dirty = 0;
 }
 

Modified: tor/trunk/src/or/hibernate.c
===================================================================
--- tor/trunk/src/or/hibernate.c	2006-12-24 02:45:41 UTC (rev 9173)
+++ tor/trunk/src/or/hibernate.c	2006-12-24 02:45:46 UTC (rev 9174)
@@ -581,8 +581,10 @@
     ROUND_UP(n_bytes_written_in_interval);
   state->AccountingSecondsActive = n_seconds_active_in_interval;
   state->AccountingExpectedUsage = expected_bandwidth_usage;
-  or_state_mark_dirty(state, now+60);
 
+  or_state_mark_dirty(state,
+                      now+(get_options()->AvoidDiskWrites ? 7200 : 60));
+
   return r;
 }
 #undef ROUND_UP
@@ -767,7 +769,9 @@
 
   hibernate_state = new_state;
   accounting_record_bandwidth_usage(now, get_or_state());
-  or_state_mark_dirty(get_or_state(), 0);
+
+  or_state_mark_dirty(get_or_state(),
+                      get_options()->AvoidDiskWrites ? now+600 : 0);
 }
 
 /** Called when we've been hibernating and our timeout is reached. */
@@ -835,7 +839,9 @@
   }
 
   accounting_record_bandwidth_usage(now, get_or_state());
-  or_state_mark_dirty(get_or_state(), 0);
+
+  or_state_mark_dirty(get_or_state(),
+                      get_options()->AvoidDiskWrites ? now+600 : 0);
 }
 
 /** Called when hibernate_end_time has arrived. */

Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c	2006-12-24 02:45:41 UTC (rev 9173)
+++ tor/trunk/src/or/rephist.c	2006-12-24 02:45:46 UTC (rev 9174)
@@ -669,8 +669,11 @@
        * force these values to the defaults. */
       /* FFFF we should pull the default out of config.c's state table,
        * so we don't have two defaults. */
-      if (*s_begins != 0 || *s_interval != 900)
-        or_state_mark_dirty(get_or_state(), time(NULL)+600);
+      if (*s_begins != 0 || *s_interval != 900) {
+        time_t now = time(NULL);
+        time_t save_at = get_options()->AvoidDiskWrites ? now+3600 : now+600;
+        or_state_mark_dirty(state, save_at);
+      }
       *s_begins = 0;
       *s_interval = 900;
       *s_values = smartlist_create();
@@ -687,8 +690,9 @@
       smartlist_split_string(*s_values, buf, ",", SPLIT_SKIP_SPACE, 0);
   }
   tor_free(buf);
-  if (server_mode(get_options()))
+  if (server_mode(get_options())) {
     or_state_mark_dirty(get_or_state(), time(NULL)+(2*3600));
+  }
 }
 
 /** Set bandwidth history from our saved state. */

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2006-12-24 02:45:41 UTC (rev 9173)
+++ tor/trunk/src/or/router.c	2006-12-24 02:45:46 UTC (rev 9174)
@@ -156,7 +156,7 @@
   state->LastRotatedOnionKey = onionkey_set_at = now;
   tor_mutex_release(key_lock);
   mark_my_descriptor_dirty();
-  or_state_mark_dirty(state, 0);
+  or_state_mark_dirty(state, get_options()->AvoidDiskWrites ? now+3600 : 0);
   return;
  error:
   log_warn(LD_GENERAL, "Couldn't rotate onion key.");
@@ -308,7 +308,7 @@
      * start the clock ticking now so that we will eventually rotate it even
      * if we don't stay up for a full MIN_ONION_KEY_LIFETIME. */
     state->LastRotatedOnionKey = time(NULL);
-    or_state_mark_dirty(state, 0);
+    or_state_mark_dirty(state, options->AvoidDiskWrites ? time(NULL)+3600 : 0);
   }
 
   tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_onion_key.old",datadir);