mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
Record IPv6 bandwidth history as appropriate.
This commit is contained in:
parent
a81827d99f
commit
27c5cadf7e
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user