mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Extract length-deciding function from package_raw_inbuf.
This commit is contained in:
parent
e4d1187584
commit
530d1179ff
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user