diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-05-17 10:29:35 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-05-23 08:28:46 -0400 |
commit | 530d1179ffe54ad0db2678142154fdd20f71cf53 (patch) | |
tree | 20536b3950954eebcf3ba37ca84ece1ec3232a36 /src | |
parent | e4d1187584038593a75140d9a8e47024c9eba04c (diff) | |
download | tor-530d1179ffe54ad0db2678142154fdd20f71cf53.tar.gz tor-530d1179ffe54ad0db2678142154fdd20f71cf53.zip |
Extract length-deciding function from package_raw_inbuf.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/or/relay.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/core/or/relay.c b/src/core/or/relay.c index 05fee57a1a..7a121780af 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -2027,6 +2027,29 @@ uint64_t stats_n_data_cells_received = 0; * ever received were completely full of data. */ uint64_t stats_n_data_bytes_received = 0; +/** + * Helper. Return the number of bytes that should be put into a cell from a + * given edge connection on which <b>n_available</b> bytes are available. + */ +static size_t +connection_edge_get_inbuf_bytes_to_package(size_t n_available, + int package_partial) +{ + if (!n_available) + return 0; + + size_t length = RELAY_PAYLOAD_SIZE; + + if (n_available < length) { /* not a full payload available */ + if (package_partial) + length = n_available; /* just take whatever's available now */ + else + return 0; /* nothing to do until we have a full payload */ + } + + return length; +} + /** If <b>conn</b> has an entire relay payload of bytes on its inbuf (or * <b>package_partial</b> is true), and the appropriate package windows aren't * empty, grab a cell and send it down the circuit. @@ -2099,18 +2122,11 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial, bytes_to_process = connection_get_inbuf_len(TO_CONN(conn)); } - if (!bytes_to_process) + length = connection_edge_get_inbuf_bytes_to_package(bytes_to_process, + package_partial); + if (!length) return 0; - length = RELAY_PAYLOAD_SIZE; - - if (bytes_to_process < length) { /* not a full payload available */ - if (package_partial) - length = bytes_to_process; /* just take whatever's available now */ - else - return 0; /* nothing to do until we have a full payload */ - } - stats_n_data_bytes_packaged += length; stats_n_data_cells_packaged += 1; |