diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-04-17 16:19:45 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-04-17 18:06:46 -0400 |
commit | 780d1b44cf24ad8ef321b99d8fc591f110456f98 (patch) | |
tree | 3a412cdbbafba942afbc265a9a99b9c33bd23b7c /src/or/connection.c | |
parent | a2acb9b9e9f1a6e21625b2d77c2e7df4e35f3599 (diff) | |
download | tor-780d1b44cf24ad8ef321b99d8fc591f110456f98.tar.gz tor-780d1b44cf24ad8ef321b99d8fc591f110456f98.zip |
Move responsibility for recording read/written bytes
Previously this was done as part of the refill callback, but there's
no real reason to do it like that. Since we're trying to remove the
refill callback completely, we can do this work as part of
record_num_bytes_transferred_impl(), which already does quite a lot
of this.
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 7dc4ecf5c2..d80c680462 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -85,6 +85,7 @@ #include "ext_orport.h" #include "geoip.h" #include "main.h" +#include "hibernate.h" #include "hs_common.h" #include "hs_ident.h" #include "nodelist.h" @@ -2989,6 +2990,10 @@ global_write_bucket_low(connection_t *conn, size_t attempt, int priority) return 0; } +/** When did we last tell the accounting subsystem about transmitted + * bandwidth? */ +static time_t last_recorded_accounting_at = 0; + /** Helper: adjusts our bandwidth history and informs the controller as * appropriate, given that we have just read <b>num_read</b> bytes and written * <b>num_written</b> bytes on <b>conn</b>. */ @@ -3019,6 +3024,20 @@ record_num_bytes_transferred_impl(connection_t *conn, } if (conn->type == CONN_TYPE_EXIT) rep_hist_note_exit_bytes(conn->port, num_written, num_read); + + /* Remember these bytes towards statistics. */ + stats_increment_bytes_read_and_written(num_read, num_written); + + /* Remember these bytes towards accounting. */ + if (accounting_is_enabled(get_options())) { + if (now > last_recorded_accounting_at && last_recorded_accounting_at) { + accounting_add_bytes(num_read, num_written, + now - last_recorded_accounting_at); + } else { + accounting_add_bytes(num_read, num_written, 0); + } + last_recorded_accounting_at = now; + } } /** We just read <b>num_read</b> and wrote <b>num_written</b> bytes @@ -5196,6 +5215,7 @@ connection_free_all(void) tor_free(last_interface_ipv4); tor_free(last_interface_ipv6); + last_recorded_accounting_at = 0; } /** Log a warning, and possibly emit a control event, that <b>received</b> came |