[or-cvs] only play the accounting game if it"s possible you"ll choos...

Roger Dingledine arma at seul.org
Sat Nov 6 06:56:30 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	config.c hibernate.c main.c 
Log Message:
only play the accounting game if it's possible you'll choose to hibernate


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.209
retrieving revision 1.210
diff -u -d -r1.209 -r1.210
--- config.c	6 Nov 2004 05:18:10 -0000	1.209
+++ config.c	6 Nov 2004 06:56:27 -0000	1.210
@@ -1173,6 +1173,7 @@
   static char **backup_argv;
   static int backup_argc;
 
+  /* we don't use get_options() here, since it's null on the first call */
   oldoptions = global_options;
 
   if (argv) { /* first time we're called. save commandline args */

Index: hibernate.c
===================================================================
RCS file: /home/or/cvsroot/src/or/hibernate.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- hibernate.c	6 Nov 2004 05:18:11 -0000	1.6
+++ hibernate.c	6 Nov 2004 06:56:28 -0000	1.7
@@ -169,7 +169,6 @@
   n_seconds_active_in_interval = 0;
 }
 
-
 static INLINE int time_to_record_bandwidth_usage(time_t now)
 {
   /* Note every 5 minutes */
@@ -180,11 +179,6 @@
   static uint64_t last_written_bytes_noted = 0;
   static time_t last_time_noted = 0;
 
-  /* ???? Maybe only do this if accountingmaxkb is set ?
-  if (!get_options()->AccountingMaxKB)
-    return 0;
-  */
-
   if (last_time_noted + NOTE_INTERVAL <= now ||
       last_read_bytes_noted + NOTE_BYTES <= n_bytes_read_in_interval ||
       last_written_bytes_noted + NOTE_BYTES <= n_bytes_written_in_interval ||
@@ -240,6 +234,9 @@
 
   n_days_to_consider = n_days_in_interval - n_days_to_exhaust_bw;
 
+  /* XXX can we simplify this just by picking a random (non-deterministic)
+   * time to be up? If we go down and come up, then we pick a new one. Is
+   * that good enough? -RD */
   while (((unsigned char)digest[0]) > n_days_to_consider)
     crypto_digest(digest, digest, DIGEST_LEN);
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.355
retrieving revision 1.356
diff -u -d -r1.355 -r1.356
--- main.c	6 Nov 2004 05:18:11 -0000	1.355
+++ main.c	6 Nov 2004 06:56:28 -0000	1.356
@@ -529,7 +529,7 @@
     last_rotated_certificate = now;
   if (last_rotated_certificate+MAX_SSL_KEY_LIFETIME < now) {
     log_fn(LOG_INFO,"Rotating tls context.");
-    if (tor_tls_context_new(get_identity_key(), 1, get_options()->Nickname,
+    if (tor_tls_context_new(get_identity_key(), 1, options->Nickname,
                             MAX_SSL_KEY_LIFETIME) < 0) {
       log_fn(LOG_WARN, "Error reinitializing TLS context");
     }
@@ -540,7 +540,8 @@
 
   /** 1c. If we have to change the accounting interval or record
    * bandwidth used in this accounting interval, do so. */
-  accounting_run_housekeeping(now);
+  if (options->AccountingMaxKB)
+    accounting_run_housekeeping(now);
 
   /** 2. Every DirFetchPostPeriod seconds, we get a new directory and upload
    *    our descriptor (if we've passed our internal checks). */
@@ -576,7 +577,7 @@
     }
     rend_cache_clean(); /* should this go elsewhere? */
 
-    time_to_fetch_directory = now + get_options()->DirFetchPostPeriod;
+    time_to_fetch_directory = now + options->DirFetchPostPeriod;
   }
 
   /** 3a. Every second, we examine pending circuits and prune the
@@ -657,7 +658,8 @@
     seconds_elapsed = current_second ? (now.tv_sec - current_second) : 0;
     stats_n_bytes_read += bytes_read;
     stats_n_bytes_written += bytes_written;
-    accounting_add_bytes(bytes_read, bytes_written, seconds_elapsed);
+    if (get_options()->AccountingMaxKB)
+      accounting_add_bytes(bytes_read, bytes_written, seconds_elapsed);
     control_event_bandwidth_used((uint32_t)bytes_read,(uint32_t)bytes_written);
 
     connection_bucket_refill(&now);
@@ -818,7 +820,8 @@
   }
 
   /* Set up accounting */
-  configure_accounting(time(NULL));
+  if (get_options()->AccountingMaxKB)
+    configure_accounting(time(NULL));
 
   /* load the routers file, or assign the defaults. */
   if(router_reload_router_list()) {



More information about the tor-commits mailing list