From e07e95edd35f1608ecba94b281818d27f63812e3 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Mon, 23 Apr 2018 20:06:34 +0000 Subject: Bug 25903: Perform accounting for new CIRC_BW fields. Two new values in each direction. DELIVERED counts valid end-to-end circuit data that is accepted by our end and OVERHEAD counts the slack unused data in each of the relay command cells for those accepted cells. Control port changes are in the next commit. --- src/or/circuituse.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/or/circuituse.c') diff --git a/src/or/circuituse.c b/src/or/circuituse.c index 47e29c28dd..a584e3eca8 100644 --- a/src/or/circuituse.c +++ b/src/or/circuituse.c @@ -3083,3 +3083,41 @@ mark_circuit_unusable_for_new_conns(origin_circuit_t *circ) circ->unusable_for_new_conns = 1; } +/** + * Add relay_body_len and RELAY_PAYLOAD_SIZE-relay_body_len to + * the valid delivered written fields and the overhead field, + * respectively. + */ +void +circuit_sent_valid_data(origin_circuit_t *circ, uint16_t relay_body_len) +{ + if (!circ) return; + + tor_assert_nonfatal(relay_body_len <= RELAY_PAYLOAD_SIZE); + + circ->n_delivered_written_circ_bw = + tor_add_u32_nowrap(circ->n_delivered_written_circ_bw, relay_body_len); + circ->n_overhead_written_circ_bw = + tor_add_u32_nowrap(circ->n_overhead_written_circ_bw, + RELAY_PAYLOAD_SIZE-relay_body_len); +} + +/** + * Add relay_body_len and RELAY_PAYLOAD_SIZE-relay_body_len to + * the valid delivered read field and the overhead field, + * respectively. + */ +void +circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len) +{ + if (!circ) return; + + tor_assert_nonfatal(relay_body_len <= RELAY_PAYLOAD_SIZE); + + circ->n_delivered_read_circ_bw = + tor_add_u32_nowrap(circ->n_delivered_read_circ_bw, relay_body_len); + circ->n_overhead_read_circ_bw = + tor_add_u32_nowrap(circ->n_overhead_read_circ_bw, + RELAY_PAYLOAD_SIZE-relay_body_len); +} + -- cgit v1.2.3-54-g00ecf