[or-cvs] [tor/master 2/3] Add a max_cells arg to connection_edge_process_raw_inbuf
nickm at torproject.org
nickm at torproject.org
Mon Sep 13 22:59:21 UTC 2010
Author: Nick Mathewson <nickm at torproject.org>
Date: Mon, 13 Sep 2010 16:05:22 -0400
Subject: Add a max_cells arg to connection_edge_process_raw_inbuf
Commit: b582eb32b820e53dcd8ac9db58f6000b88cf2e4e
I'm going to use this to implement more fairness in
circuit_resume_edge_reading_helper in an attempt to fix bug 1298.
(Updated with fixes from arma and Sebastian)
---
src/or/connection_edge.c | 2 +-
src/or/relay.c | 27 ++++++++++++++++++++-------
src/or/relay.h | 3 ++-
3 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index df182c6..6a3a5ef 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -147,7 +147,7 @@ connection_edge_process_inbuf(edge_connection_t *conn, int package_partial)
return 0;
case AP_CONN_STATE_OPEN:
case EXIT_CONN_STATE_OPEN:
- if (connection_edge_package_raw_inbuf(conn, package_partial) < 0) {
+ if (connection_edge_package_raw_inbuf(conn, package_partial, NULL) < 0) {
/* (We already sent an end cell if possible) */
connection_mark_for_close(TO_CONN(conn));
return -1;
diff --git a/src/or/relay.c b/src/or/relay.c
index 7608674..7d3d780 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -946,7 +946,7 @@ connection_edge_process_relay_cell_not_open(
}
/* handle anything that might have queued */
- if (connection_edge_package_raw_inbuf(conn, 1) < 0) {
+ if (connection_edge_package_raw_inbuf(conn, 1, NULL) < 0) {
/* (We already sent an end cell if possible) */
connection_mark_for_close(TO_CONN(conn));
return 0;
@@ -1241,7 +1241,7 @@ connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ,
}
connection_start_reading(TO_CONN(conn));
/* handle whatever might still be on the inbuf */
- if (connection_edge_package_raw_inbuf(conn, 1) < 0) {
+ if (connection_edge_package_raw_inbuf(conn, 1, NULL) < 0) {
/* (We already sent an end cell if possible) */
connection_mark_for_close(TO_CONN(conn));
return 0;
@@ -1307,15 +1307,19 @@ uint64_t stats_n_data_cells_received = 0;
* ever received were completely full of data. */
uint64_t stats_n_data_bytes_received = 0;
-/** While conn->inbuf has an entire relay payload of bytes on it,
- * and the appropriate package windows aren't empty, grab a cell
- * and send it down the circuit.
+/** 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.
+ *
+ * If *<b>max_cells</b> is given, package no more than max_cells. Decrement
+ * *<b>max_cells</b> by the number of cells packaged.
*
* Return -1 (and send a RELAY_COMMAND_END cell if necessary) if conn should
* be marked for close, else return 0.
*/
int
-connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial)
+connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial,
+ int *max_cells)
{
size_t amount_to_process, length;
char payload[CELL_PAYLOAD_SIZE];
@@ -1331,6 +1335,9 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial)
return 0;
}
+ if (max_cells && *max_cells <= 0)
+ return 0;
+
repeat_connection_edge_package_raw_inbuf:
circ = circuit_get_by_edge_conn(conn);
@@ -1392,6 +1399,12 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial)
}
log_debug(domain,"conn->package_window is now %d",conn->package_window);
+ if (max_cells) {
+ *max_cells -= 1;
+ if (*max_cells <= 0)
+ return 0;
+ }
+
/* handle more if there's more, or return 0 if there isn't */
goto repeat_connection_edge_package_raw_inbuf;
}
@@ -1470,7 +1483,7 @@ circuit_resume_edge_reading_helper(edge_connection_t *conn,
conn->cpath_layer == layer_hint)) {
connection_start_reading(TO_CONN(conn));
/* handle whatever might still be on the inbuf */
- if (connection_edge_package_raw_inbuf(conn, 1)<0) {
+ if (connection_edge_package_raw_inbuf(conn, 1, NULL)<0) {
/* (We already sent an end cell if possible) */
connection_mark_for_close(TO_CONN(conn));
continue;
diff --git a/src/or/relay.h b/src/or/relay.h
index 0ef17b6..66d1757 100644
--- a/src/or/relay.h
+++ b/src/or/relay.h
@@ -27,7 +27,8 @@ int connection_edge_send_command(edge_connection_t *fromconn,
uint8_t relay_command, const char *payload,
size_t payload_len);
int connection_edge_package_raw_inbuf(edge_connection_t *conn,
- int package_partial);
+ int package_partial,
+ int *max_cells);
void connection_edge_consider_sending_sendme(edge_connection_t *conn);
extern uint64_t stats_n_data_cells_packaged;
--
1.7.1
More information about the tor-commits
mailing list