Browse Source

r11686@Kushana: nickm | 2006-12-23 22:05:57 -0500
More changes wrt unnecessary disk writes.


svn:r9176

Nick Mathewson 18 years ago
parent
commit
bf1014692f
4 changed files with 25 additions and 10 deletions
  1. 4 1
      ChangeLog
  2. 5 5
      doc/TODO
  3. 5 1
      src/or/hibernate.c
  4. 11 3
      src/or/router.c

+ 4 - 1
ChangeLog

@@ -43,7 +43,8 @@ Changes in version 0.1.2.5-xxxx - 200?-??-??
       dirserver has given us a 503, we try not to use it until an hour
       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
       has gone by, or until we have no dirservers that haven't given us
       a 503.
       a 503.
-    - The state file gets saved less often when AvoidDiskWrites is set.
+    - The state file and the bw_accounting file get saved less often when
+      AvoidDiskWrites is set.
     - We no longer look for identity and onion keys in "identity.key" and
     - We no longer look for identity and onion keys in "identity.key" and
       "onion.key" -- these were replaced by secret_id_key and
       "onion.key" -- these were replaced by secret_id_key and
       secret_onion_key in 0.0.8pre1.
       secret_onion_key in 0.0.8pre1.
@@ -90,6 +91,8 @@ Changes in version 0.1.2.5-xxxx - 200?-??-??
       user fix resolv.conf or specify nameservers explicitly. (Resolves
       user fix resolv.conf or specify nameservers explicitly. (Resolves
       bug 363.)
       bug 363.)
     - Stop accepting certain malformed ports in configured exit policies.
     - Stop accepting certain malformed ports in configured exit policies.
+    - Don't re-write the fingerprint file every restart, unless it has
+      changed.
 
 
   o Controller features:
   o Controller features:
     - Have GETINFO dir/status/* work on hosts with DirPort disabled.
     - Have GETINFO dir/status/* work on hosts with DirPort disabled.

+ 5 - 5
doc/TODO

@@ -150,14 +150,14 @@ N     - they don't count toward the 3-strikes rule
       - update dir-spec with what we decided for each of these
       - update dir-spec with what we decided for each of these
 
 
 
 
-Nd- Have a mode that doesn't write to disk much, so we can run Tor on
+  o Have a mode that doesn't write to disk much, so we can run Tor on
     flash memory (e.g. Linksys routers or USB keys).
     flash memory (e.g. Linksys routers or USB keys).
     o Add AvoidDiskWrites config option.
     o Add AvoidDiskWrites config option.
-    . only write state file when it's "changed"
+    o only write state file when it's "changed"
       o 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?
+      D some things may not want to get written at all.
+    o stop writing fingerprint every restart
+    D more?
 
 
 NR. Write path-spec.txt
 NR. Write path-spec.txt
 
 

+ 5 - 1
src/or/hibernate.c

@@ -544,6 +544,7 @@ accounting_record_bandwidth_usage(time_t now, or_state_t *state)
   time_t tmp;
   time_t tmp;
   int r;
   int r;
   uint64_t expected;
   uint64_t expected;
+  static time_t last_recorded;
 
 
   /* First, update bw_accounting. Until 0.1.2.5-x, this was the only place
   /* First, update bw_accounting. Until 0.1.2.5-x, this was the only place
    * we stored this information. The format is:
    * we stored this information. The format is:
@@ -572,7 +573,10 @@ accounting_record_bandwidth_usage(time_t now, or_state_t *state)
                (unsigned long)expected);
                (unsigned long)expected);
   tor_snprintf(fname, sizeof(fname), "%s/bw_accounting",
   tor_snprintf(fname, sizeof(fname), "%s/bw_accounting",
                get_options()->DataDirectory);
                get_options()->DataDirectory);
-  r = write_str_to_file(fname, buf, 0);
+  if (!get_options()->AvoidDiskWrites || (last_recorded + 3600 < now)) {
+    r = write_str_to_file(fname, buf, 0);
+    last_recorded = now;
+  }
 
 
   /* Now update the state */
   /* Now update the state */
   state->AccountingIntervalStart = interval_start_time;
   state->AccountingIntervalStart = interval_start_time;

+ 11 - 3
src/or/router.c

@@ -231,6 +231,7 @@ init_keys(void)
   const char *mydesc, *datadir;
   const char *mydesc, *datadir;
   crypto_pk_env_t *prkey;
   crypto_pk_env_t *prkey;
   char digest[20];
   char digest[20];
+  char *cp;
   or_options_t *options = get_options();
   or_options_t *options = get_options();
   or_state_t *state = get_or_state();
   or_state_t *state = get_or_state();
 
 
@@ -335,10 +336,17 @@ init_keys(void)
     log_err(LD_GENERAL,"Error writing fingerprint line");
     log_err(LD_GENERAL,"Error writing fingerprint line");
     return -1;
     return -1;
   }
   }
-  if (write_str_to_file(keydir, fingerprint_line, 0)) {
-    log_err(LD_FS, "Error writing fingerprint line to file");
-    return -1;
+  /* Check whether we need to write the fingerprint file. */
+  cp = NULL;
+  if (file_status(keydir) == FN_FILE)
+    cp = read_str_to_file(keydir, 0, NULL);
+  if (!cp && strcmp(cp, fingerprint_line)) {
+    if (write_str_to_file(keydir, fingerprint_line, 0)) {
+      log_err(LD_FS, "Error writing fingerprint line to file");
+      return -1;
+    }
   }
   }
+  tor_free(cp);
 
 
   log(LOG_NOTICE, LD_GENERAL,
   log(LOG_NOTICE, LD_GENERAL,
       "Your Tor server's identity key fingerprint is '%s %s'",
       "Your Tor server's identity key fingerprint is '%s %s'",