diff options
author | David Goulet <dgoulet@torproject.org> | 2019-01-08 12:09:01 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2019-04-29 12:17:57 -0400 |
commit | ed8593b9e0838f694eeb6315db38f6fadbc5ab71 (patch) | |
tree | 5ad7d1e9a394d753805afa8d46eace898a59d2c8 /src/core/or/sendme.c | |
parent | e5806dcea891cf9c6aa4d55c6d5deae9792792d7 (diff) | |
download | tor-ed8593b9e0838f694eeb6315db38f6fadbc5ab71.tar.gz tor-ed8593b9e0838f694eeb6315db38f6fadbc5ab71.zip |
sendme: Modernize and cleanup old moved code
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/core/or/sendme.c')
-rw-r--r-- | src/core/or/sendme.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/core/or/sendme.c b/src/core/or/sendme.c index 3e00721d26..f3acf47147 100644 --- a/src/core/or/sendme.c +++ b/src/core/or/sendme.c @@ -14,40 +14,48 @@ #include "core/or/relay.h" #include "core/or/sendme.h" -/** Called when we've just received a relay data cell, when - * we've just finished flushing all bytes to stream <b>conn</b>, - * or when we've flushed *some* bytes to the stream <b>conn</b>. +/** Called when we've just received a relay data cell, when we've just + * finished flushing all bytes to stream <b>conn</b>, or when we've flushed + * *some* bytes to the stream <b>conn</b>. * - * If conn->outbuf is not too full, and our deliver window is - * low, send back a suitable number of stream-level sendme cells. + * If conn->outbuf is not too full, and our deliver window is low, send back a + * suitable number of stream-level sendme cells. */ void sendme_connection_edge_consider_sending(edge_connection_t *conn) { - circuit_t *circ; + tor_assert(conn); - if (connection_outbuf_too_full(TO_CONN(conn))) - return; + int log_domain = TO_CONN(conn)->type == CONN_TYPE_AP ? LD_APP : LD_EXIT; - circ = circuit_get_by_edge_conn(conn); - if (!circ) { - /* this can legitimately happen if the destroy has already - * arrived and torn down the circuit */ - log_info(LD_APP,"No circuit associated with conn. Skipping."); - return; + /* Don't send it if we still have data to deliver. */ + if (connection_outbuf_too_full(TO_CONN(conn))) { + goto end; } - while (conn->deliver_window <= STREAMWINDOW_START - STREAMWINDOW_INCREMENT) { - log_debug(conn->base_.type == CONN_TYPE_AP ?LD_APP:LD_EXIT, - "Outbuf %d, Queuing stream sendme.", - (int)conn->base_.outbuf_flushlen); + if (circuit_get_by_edge_conn(conn) == NULL) { + /* This can legitimately happen if the destroy has already arrived and + * torn down the circuit. */ + log_info(log_domain, "No circuit associated with edge connection. " + "Skipping sending SENDME."); + goto end; + } + + while (conn->deliver_window <= + (STREAMWINDOW_START - STREAMWINDOW_INCREMENT)) { + log_debug(log_domain, "Outbuf %" TOR_PRIuSZ ", queuing stream SENDME.", + TO_CONN(conn)->outbuf_flushlen); conn->deliver_window += STREAMWINDOW_INCREMENT; if (connection_edge_send_command(conn, RELAY_COMMAND_SENDME, NULL, 0) < 0) { - log_warn(LD_APP,"connection_edge_send_command failed. Skipping."); - return; /* the circuit's closed, don't continue */ + log_warn(LD_BUG, "connection_edge_send_command failed while sending " + "a SENDME. Circuit probably closed, skipping."); + goto end; /* The circuit's closed, don't continue */ } } + + end: + return; } /** Check if the deliver_window for circuit <b>circ</b> (at hop |