[tor-commits] [tor/master] Merge branch 'circuit_queue_cap-0.2.5-squashed'

nickm at torproject.org nickm at torproject.org
Fri Jun 14 05:50:24 UTC 2013


commit 6f5a720d151e8d43d0e76221dee842bc159af710
Merge: b1f44fc bd6bd1c
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Jun 14 01:50:17 2013 -0400

    Merge branch 'circuit_queue_cap-0.2.5-squashed'
    
    Conflicts:
    	src/or/relay.c

 changes/bug9063 |    4 +++
 src/or/or.h     |   21 ++++++++++++
 src/or/relay.c  |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 119 insertions(+), 1 deletion(-)

diff --cc src/or/relay.c
index f0861f2,2fe6448..58ca4e9
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@@ -2493,7 -2498,84 +2509,84 @@@ append_cell_to_circuit_queue(circuit_t 
      streams_blocked = circ->streams_blocked_on_p_chan;
    }
  
+   /* Are we a middle circuit about to exceed ORCIRC_MAX_MIDDLE_CELLS? */
+   if ((circ->n_chan != NULL) && CIRCUIT_IS_ORCIRC(circ)) {
+     orcirc = TO_OR_CIRCUIT(circ);
+     if (orcirc->p_chan) {
+       /* We are a middle circuit if we have both n_chan and p_chan */
+       /* We'll need to know the current preferred maximum */
+       tgt_max_middle_cells = get_max_middle_cells();
+       if (tgt_max_middle_cells > 0) {
+         /* Do we need to initialize middle_max_cells? */
+         if (orcirc->max_middle_cells == 0) {
+           orcirc->max_middle_cells = tgt_max_middle_cells;
+         } else {
+           if (tgt_max_middle_cells > orcirc->max_middle_cells) {
+             /* If we want to increase the cap, we can do so right away */
+             orcirc->max_middle_cells = tgt_max_middle_cells;
+           } else if (tgt_max_middle_cells < orcirc->max_middle_cells) {
+             /*
+              * If we're shrinking the cap, we can't shrink past either queue;
+              * compare tgt_max_middle_cells rather than tgt_max_middle_cells *
+              * ORCIRC_MAX_MIDDLE_KILL_THRESH so the queues don't shrink enough
+              * to generate spurious warnings, either.
+              */
+             n_len = circ->n_chan_cells.n;
+             p_len = orcirc->p_chan_cells.n;
+             tmp = tgt_max_middle_cells;
+             if (tmp < n_len) tmp = n_len;
+             if (tmp < p_len) tmp = p_len;
+             orcirc->max_middle_cells = tmp;
+           }
+           /* else no change */
+         }
+       } else {
+         /* tgt_max_middle_cells == 0 indicates we should disable the cap */
+         orcirc->max_middle_cells = 0;
+       }
+ 
+       /* Now we know orcirc->max_middle_cells is set correctly */
+       if (orcirc->max_middle_cells > 0) {
+         hard_max_middle_cells =
+           (uint32_t)(((double)orcirc->max_middle_cells) *
+                      ORCIRC_MAX_MIDDLE_KILL_THRESH);
+ 
+         if ((unsigned)queue->n + 1 >= hard_max_middle_cells) {
+           /* Queueing this cell would put queue over the kill theshold */
+           log_warn(LD_CIRC,
+                    "Got a cell exceeding the hard cap of %u in the "
+                    "%s direction on middle circ ID %u on chan ID "
+                    U64_FORMAT "; killing the circuit.",
+                    hard_max_middle_cells,
+                    (direction == CELL_DIRECTION_OUT) ? "n" : "p",
+                    (direction == CELL_DIRECTION_OUT) ?
+                      circ->n_circ_id : orcirc->p_circ_id,
+                    U64_PRINTF_ARG(
+                      (direction == CELL_DIRECTION_OUT) ?
+                         circ->n_chan->global_identifier :
+                         orcirc->p_chan->global_identifier));
+           circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
+           return;
+         } else if ((unsigned)queue->n + 1 == orcirc->max_middle_cells) {
+           /* Only use ==, not >= for this test so we don't spam the log */
+           log_warn(LD_CIRC,
+                    "While trying to queue a cell, reached the soft cap of %u "
+                    "in the %s direction on middle circ ID %u "
+                    "on chan ID " U64_FORMAT ".",
+                    orcirc->max_middle_cells,
+                    (direction == CELL_DIRECTION_OUT) ? "n" : "p",
+                    (direction == CELL_DIRECTION_OUT) ?
+                      circ->n_circ_id : orcirc->p_circ_id,
+                    U64_PRINTF_ARG(
+                      (direction == CELL_DIRECTION_OUT) ?
+                         circ->n_chan->global_identifier :
+                         orcirc->p_chan->global_identifier));
+         }
+       }
+     }
+   }
+ 
 -  cell_queue_append_packed_copy(queue, cell, chan->wide_circ_ids);
 +  cell_queue_append_packed_copy(queue, cell, chan->wide_circ_ids, 1);
  
    /* If we have too many cells on the circuit, we should stop reading from
     * the edge streams for a while. */



More information about the tor-commits mailing list