diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-07-10 08:44:46 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-07-10 09:25:28 -0400 |
commit | 27c5cadf7e86551c7d62d27b107098266bb4c11b (patch) | |
tree | a8a039a4f73554319420e6548fcc59caefbe7de5 | |
parent | a81827d99ffdd36d87ca91637f022558783d44ac (diff) | |
download | tor-27c5cadf7e86551c7d62d27b107098266bb4c11b.tar.gz tor-27c5cadf7e86551c7d62d27b107098266bb4c11b.zip |
Record IPv6 bandwidth history as appropriate.
-rw-r--r-- | src/core/mainloop/connection.c | 5 | ||||
-rw-r--r-- | src/core/or/circuitlist.c | 8 | ||||
-rw-r--r-- | src/feature/stats/bwhist.c | 8 | ||||
-rw-r--r-- | src/feature/stats/bwhist.h | 4 |
4 files changed, 18 insertions, 7 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c index 960735fc22..2f3c70365a 100644 --- a/src/core/mainloop/connection.c +++ b/src/core/mainloop/connection.c @@ -3366,11 +3366,12 @@ record_num_bytes_transferred_impl(connection_t *conn, rep_hist_note_or_conn_bytes(conn->global_identifier, num_read, num_written, now); + const bool is_ipv6 = (conn->socket_family == AF_INET6); if (num_read > 0) { - bwhist_note_bytes_read(num_read, now); + bwhist_note_bytes_read(num_read, now, is_ipv6); } if (num_written > 0) { - bwhist_note_bytes_written(num_written, now); + bwhist_note_bytes_written(num_written, now, is_ipv6); } if (conn->type == CONN_TYPE_EXIT) rep_hist_note_exit_bytes(conn->port, num_written, num_read); diff --git a/src/core/or/circuitlist.c b/src/core/or/circuitlist.c index f0f182e5d6..28b3fa8ff0 100644 --- a/src/core/or/circuitlist.c +++ b/src/core/or/circuitlist.c @@ -2167,6 +2167,12 @@ circuit_synchronize_written_or_bandwidth(const circuit_t *c, else cell_size = CELL_MAX_NETWORK_SIZE; + /* If we know the channel, find out if it's IPv6. */ + tor_addr_t remote_addr; + bool is_ipv6 = chan && + channel_get_addr_if_possible(chan, &remote_addr) && + tor_addr_family(&remote_addr) == AF_INET6; + /* The missing written bytes are the cell counts times their cell * size plus TLS per cell overhead */ written_sync = cells*(cell_size+TLS_PER_CELL_OVERHEAD); @@ -2174,7 +2180,7 @@ circuit_synchronize_written_or_bandwidth(const circuit_t *c, /* Report the missing bytes as written, to avoid asymmetry. * We must use time() for consistency with rephist, even though on * some very old rare platforms, approx_time() may be faster. */ - bwhist_note_bytes_written(written_sync, time(NULL)); + bwhist_note_bytes_written(written_sync, time(NULL), is_ipv6); } /** Mark <b>circ</b> to be closed next time we call diff --git a/src/feature/stats/bwhist.c b/src/feature/stats/bwhist.c index 44717f33ba..e74a2881f5 100644 --- a/src/feature/stats/bwhist.c +++ b/src/feature/stats/bwhist.c @@ -205,7 +205,7 @@ bwhist_init(void) * earlier than the latest <b>when</b> you've heard of. */ void -bwhist_note_bytes_written(uint64_t num_bytes, time_t when) +bwhist_note_bytes_written(uint64_t num_bytes, time_t when, bool ipv6) { /* Maybe a circular array for recent seconds, and step to a new point * every time a new second shows up. Or simpler is to just to have @@ -216,16 +216,20 @@ bwhist_note_bytes_written(uint64_t num_bytes, time_t when) * somewhere. See bwhist_bandwidth_assess() below. */ add_obs(write_array, when, num_bytes); + if (ipv6) + add_obs(write_array_ipv6, when, num_bytes); } /** Remember that we wrote <b>num_bytes</b> bytes in second <b>when</b>. * (like bwhist_note_bytes_written() above) */ void -bwhist_note_bytes_read(uint64_t num_bytes, time_t when) +bwhist_note_bytes_read(uint64_t num_bytes, time_t when, bool ipv6) { /* if we're smart, we can make this func and the one above share code */ add_obs(read_array, when, num_bytes); + if (ipv6) + add_obs(read_array_ipv6, when, num_bytes); } /** Remember that we wrote <b>num_bytes</b> directory bytes in second diff --git a/src/feature/stats/bwhist.h b/src/feature/stats/bwhist.h index 17d2a8394a..d556f5a026 100644 --- a/src/feature/stats/bwhist.h +++ b/src/feature/stats/bwhist.h @@ -15,8 +15,8 @@ void bwhist_init(void); void bwhist_free_all(void); -void bwhist_note_bytes_read(uint64_t num_bytes, time_t when); -void bwhist_note_bytes_written(uint64_t num_bytes, time_t when); +void bwhist_note_bytes_read(uint64_t num_bytes, time_t when, bool ipv6); +void bwhist_note_bytes_written(uint64_t num_bytes, time_t when, bool ipv6); void bwhist_note_dir_bytes_read(uint64_t num_bytes, time_t when); void bwhist_note_dir_bytes_written(uint64_t num_bytes, time_t when); |