summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-11-10 04:19:53 +0000
committerNick Mathewson <nickm@torproject.org>2004-11-10 04:19:53 +0000
commitc1bf171ed8c35f59724a18f9ccea8082fd1d7dfc (patch)
treee5dd05769750249099977a63910afdcb0549a63d
parentdf671e09cce3dffa2fa450f2af16f384c8267e4e (diff)
downloadtor-c1bf171ed8c35f59724a18f9ccea8082fd1d7dfc.tar.gz
tor-c1bf171ed8c35f59724a18f9ccea8082fd1d7dfc.zip
Fix a few bugs in accounting: parse bw_accounting correctly; set end time of continued interval; record used bandwidth on state change.tor-0.0.9pre5
svn:r2785
-rw-r--r--src/or/hibernate.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/or/hibernate.c b/src/or/hibernate.c
index 40b30aa2ff..281d60563e 100644
--- a/src/or/hibernate.c
+++ b/src/or/hibernate.c
@@ -178,6 +178,7 @@ configure_accounting(time_t now)
start_of_accounting_period_containing(interval_start_time)) {
log_fn(LOG_INFO, "Continuing accounting interval.");
/* We are in the interval we thought we were in. Do nothing.*/
+ interval_end_time = start_of_accounting_period_after(interval_start_time);
} else {
log_fn(LOG_WARN, "Mismatched accounting interval; starting a fresh one.");
reset_accounting(now);
@@ -228,8 +229,8 @@ reset_accounting(time_t now) {
static INLINE int
time_to_record_bandwidth_usage(time_t now)
{
- /* Note every 5 minutes */
-#define NOTE_INTERVAL (5*60)
+ /* Note every 60 sec */
+#define NOTE_INTERVAL (60)
/* Or every 20 megabytes */
#define NOTE_BYTES 20*(1024*1024)
static uint64_t last_read_bytes_noted = 0;
@@ -303,6 +304,7 @@ accounting_set_wakeup_time(void)
24*60*60 * (unsigned char)digest[0];
}
+/* 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*/
@@ -353,7 +355,7 @@ read_bandwidth_usage(void)
return 0;
}
elts = smartlist_create();
- smartlist_split_string(elts, s, "\n", SPLIT_SKIP_SPACE, SPLIT_IGNORE_BLANK);
+ smartlist_split_string(elts, s, "\n", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK,0);
tor_free(s);
if (smartlist_len(elts)<1 ||
@@ -469,6 +471,7 @@ static void hibernate_begin(int new_state, time_t now) {
}
hibernate_state = new_state;
+ record_bandwidth_usage(time(NULL));
}
/** Called when we've been hibernating and our timeout is reached. */
@@ -520,6 +523,8 @@ hibernate_go_dormant(void) {
log_fn(LOG_INFO,"Closing conn type %d", conn->type);
connection_mark_for_close(conn);
}
+
+ record_bandwidth_usage(time(NULL));
}
/** Called when hibernate_end_time has arrived. */