[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Extract length-deciding function from package_raw_inbuf.
commit 530d1179ffe54ad0db2678142154fdd20f71cf53
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Fri May 17 10:29:35 2019 -0400
Extract length-deciding function from package_raw_inbuf.
---
src/core/or/relay.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/src/core/or/relay.c b/src/core/or/relay.c
index 05fee57a1..7a121780a 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;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits