]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a max_cells arg to connection_edge_process_raw_inbuf
authorNick Mathewson <nickm@torproject.org>
Mon, 13 Sep 2010 20:05:22 +0000 (16:05 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 13 Sep 2010 22:59:42 +0000 (18:59 -0400)
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
src/or/relay.c
src/or/relay.h

index df182c6194197e03701b9352be3a9c7a088f9413..6a3a5ef0a9d9fff394966dc193073463ce4a31d5 100644 (file)
@@ -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;
index 7608674a9f63a3135e9cd4a4f931e20186923dfd..7d3d780f2e6bb5e74c4084bace07515522bb87ec 100644 (file)
@@ -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;
index 0ef17b6ffd1f6434e6c466cfc725df614c3e03a0..66d17579a39661e7bf672367f2c45cd1cda6d2fe 100644 (file)
@@ -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;