diff options
author | David Goulet <dgoulet@torproject.org> | 2019-01-09 10:39:58 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2019-04-29 12:17:57 -0400 |
commit | 2d3c600915c22f1e9a7e9dcbba8358556ef64505 (patch) | |
tree | 3c6fd934689434d78ce5b9b2d6a8a7479f97b4ef /src/core/or/relay.c | |
parent | 9c42cc1eb22da8125ec9596920dfb9113912eac0 (diff) | |
download | tor-2d3c600915c22f1e9a7e9dcbba8358556ef64505.tar.gz tor-2d3c600915c22f1e9a7e9dcbba8358556ef64505.zip |
sendme: Add helper functions for DATA cell delivery
When we get a relay DATA cell delivered, we have to decrement the deliver
window on both the circuit and stream level.
This commit adds helper functions to handle the deliver window decrement.
Part of #26840
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/core/or/relay.c')
-rw-r--r-- | src/core/or/relay.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/core/or/relay.c b/src/core/or/relay.c index 132da21466..0eb2ba3f67 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -1548,8 +1548,11 @@ connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, return connection_exit_begin_conn(cell, circ); case RELAY_COMMAND_DATA: ++stats_n_data_cells_received; - if (( layer_hint && --layer_hint->deliver_window < 0) || - (!layer_hint && --circ->deliver_window < 0)) { + + /* Update our circuit-level deliver window that we received a DATA cell. + * If the deliver window goes below 0, we end the connection due to a + * protocol failure. */ + if (sendme_circuit_data_received(circ, layer_hint) < 0) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "(relay data) circ deliver_window below 0. Killing."); if (conn) { @@ -1560,9 +1563,8 @@ connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, } return -END_CIRC_REASON_TORPROTOCOL; } - log_debug(domain,"circ deliver_window now %d.", layer_hint ? - layer_hint->deliver_window : circ->deliver_window); + /* Consider sending a circuit-level SENDME cell. */ sendme_circuit_consider_sending(circ, layer_hint); if (rh.stream_id == 0) { @@ -1586,7 +1588,11 @@ connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, return 0; } - if (--conn->deliver_window < 0) { /* is it below 0 after decrement? */ + /* Update our stream-level deliver window that we just received a DATA + * cell. Going below 0 means we have a protocol level error so the + * circuit is closed. */ + + if (sendme_stream_data_received(conn) < 0) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "(relay data) conn deliver_window below 0. Killing."); return -END_CIRC_REASON_TORPROTOCOL; |