aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-11-14 22:21:23 +0000
committerNick Mathewson <nickm@torproject.org>2004-11-14 22:21:23 +0000
commit3e6edf20cca98c01d73285ac1ce1f61f4e3e6d99 (patch)
treef59bf38b4e3846c942bd53c12c044e75b719a212 /src
parent402c75fb0616d03e006aed2504b24a266685a4a4 (diff)
downloadtor-3e6edf20cca98c01d73285ac1ce1f61f4e3e6d99.tar
tor-3e6edf20cca98c01d73285ac1ce1f61f4e3e6d99.tar.gz
Resolve some hibernating-related XXXX009s.
svn:r2875
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c4
-rw-r--r--src/or/hibernate.c10
-rw-r--r--src/or/main.c8
-rw-r--r--src/or/or.h1
4 files changed, 12 insertions, 11 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 6cfd16fd9..d30628134 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -310,6 +310,10 @@ options_act(void) {
return -1;
}
+ /* Set up accounting */
+ if (get_options()->AccountingMaxKB)
+ configure_accounting(time(NULL));
+
if(retry_all_listeners(1) < 0) {
log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
return -1;
diff --git a/src/or/hibernate.c b/src/or/hibernate.c
index af0205841..59990084e 100644
--- a/src/or/hibernate.c
+++ b/src/or/hibernate.c
@@ -83,7 +83,6 @@ static uint32_t expected_bandwidth_usage = 0;
static void reset_accounting(time_t now);
static int read_bandwidth_usage(void);
-static int record_bandwidth_usage(time_t now);
static time_t start_of_accounting_period_after(time_t now);
static time_t start_of_accounting_period_containing(time_t now);
static void accounting_set_wakeup_time(void);
@@ -316,12 +315,11 @@ accounting_set_wakeup_time(void)
(int)(unsigned char)digest[0], buf);
}
-/* XXXX009 This should also get called on HUP and shutdown. */
#define BW_ACCOUNTING_VERSION 1
/** Save all our bandwidth tracking information to disk. Return 0 on
* success, -1 on failure*/
-static int
-record_bandwidth_usage(time_t now)
+int
+accounting_record_bandwidth_usage(time_t now)
{
char buf[128];
char fname[512];
@@ -483,7 +481,7 @@ static void hibernate_begin(int new_state, time_t now) {
}
hibernate_state = new_state;
- record_bandwidth_usage(time(NULL));
+ accounting_record_bandwidth_usage(now);
}
/** Called when we've been hibernating and our timeout is reached. */
@@ -539,7 +537,7 @@ hibernate_go_dormant(time_t now) {
connection_mark_for_close(conn);
}
- record_bandwidth_usage(time(NULL));
+ accounting_record_bandwidth_usage(now);
}
/** Called when hibernate_end_time has arrived. */
diff --git a/src/or/main.c b/src/or/main.c
index cf6533db1..eeb97630f 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -737,6 +737,8 @@ static int do_hup(void) {
log_fn(LOG_NOTICE,"Received sighup. Reloading config.");
has_completed_circuit=0;
+ accounting_record_bandwidth_usage();
+
/* first, reload config variables, in case they've changed */
/* no need to provide argc/v, they've been cached inside init_from_config */
if (init_from_config(0, NULL) < 0) {
@@ -793,11 +795,6 @@ static int do_main_loop(void) {
stats_prev_global_read_bucket = global_read_bucket;
stats_prev_global_write_bucket = global_write_bucket;
- /*XXX009 move to options_act? */
- /* Set up accounting */
- if (get_options()->AccountingMaxKB)
- configure_accounting(time(NULL));
-
/* load the routers file, or assign the defaults. */
if(router_reload_router_list()) {
return -1;
@@ -1082,6 +1079,7 @@ void tor_cleanup(void) {
if(options->PidFile && options->command == CMD_RUN_TOR)
unlink(options->PidFile);
crypto_global_cleanup();
+ accounting_record_bandwidth_usage();
}
/** Read/create keys as needed, and echo our fingerprint to stdout. */
diff --git a/src/or/or.h b/src/or/or.h
index fa76c8145..35cc304a1 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1327,6 +1327,7 @@ int dns_resolve(connection_t *exitconn);
void configure_accounting(time_t now);
void accounting_run_housekeeping(time_t now);
void accounting_add_bytes(size_t n_read, size_t n_written, int seconds);
+int accounting_record_bandwidth_usage(time_t now);
void hibernate_begin_shutdown(void);
int we_are_hibernating(void);
void consider_hibernation(time_t now);