aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2012-09-26 11:51:39 -0700
committerAndrea Shepard <andrea@torproject.org>2012-10-10 00:43:18 -0700
commit8004448635d63fa829d2a836214c42c1609c3f01 (patch)
treeb3bde2dd719f6cb57c15eca91c976767f41af672
parentc3ebd0340cca67dc4dd44bd18849100ebba39051 (diff)
downloadtor-8004448635d63fa829d2a836214c42c1609c3f01.tar
tor-8004448635d63fa829d2a836214c42c1609c3f01.tar.gz
Handle n_mux/p_mux properly in circuitmux.c
-rw-r--r--src/or/circuitmux.c30
-rw-r--r--src/or/or.h7
2 files changed, 27 insertions, 10 deletions
diff --git a/src/or/circuitmux.c b/src/or/circuitmux.c
index 2a7d075ae..ede2486bf 100644
--- a/src/or/circuitmux.c
+++ b/src/or/circuitmux.c
@@ -340,7 +340,8 @@ circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ,
/*
* Figure out which channel we're using, and get the circuit's current
- * cell count and circuit ID.
+ * cell count and circuit ID; assert that the circuit is not already
+ * attached to another mux.
*/
if (direction == CELL_DIRECTION_OUT) {
/* It's n_chan */
@@ -376,13 +377,16 @@ circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ,
"Circuit %u on channel " U64_FORMAT " was already attached to "
"cmux %p (trying to attach to %p)",
circ_id, U64_PRINTF_ARG(channel_id),
- circ->mux, cmux);
+ ((direction == CELL_DIRECTION_OUT) ?
+ circ->n_mux : TO_OR_CIRCUIT(circ)->p_mux),
+ cmux);
/*
- * The mux pointer on the circuit should match this cmux, and the
- * direction in result should match; otherwise assert.
+ * The mux pointer on this circuit and the direction in result should
+ * match; otherwise assert.
*/
- tor_assert(circ->mux == cmux);
+ if (direction == CELL_DIRECTION_OUT) tor_assert(circ->n_mux == cmux);
+ else tor_assert(TO_OR_CIRCUIT(circ)->p_mux == cmux);
tor_assert(hashent->muxinfo.direction == direction);
/*
@@ -407,8 +411,12 @@ circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ,
"Attaching circuit %u on channel " U64_FORMAT " to cmux %p",
circ_id, U64_PRINTF_ARG(channel_id), cmux);
- /* Assert that the circuit doesn't already have a mux */
- tor_assert(circ->mux == NULL);
+ /*
+ * Assert that the circuit doesn't already have a mux for this
+ * direction.
+ */
+ if (direction == CELL_DIRECTION_OUT) tor_assert(circ->n_mux == NULL);
+ else tor_assert(TO_OR_CIRCUIT(circ)->p_mux == NULL);
/* Insert it in the map */
hashent = tor_malloc_zero(sizeof(*hashent));
@@ -419,8 +427,9 @@ circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ,
HT_INSERT(chanid_circid_muxinfo_map, cmux->chanid_circid_map,
hashent);
- /* Set the circuit's mux */
- circ->mux = cmux;
+ /* Set the circuit's mux for this direction */
+ if (direction == CELL_DIRECTION_OUT) circ->n_mux = cmux;
+ else TO_OR_CIRCUIT(circ)->p_mux = cmux;
/* Make sure the next/prev pointers are NULL */
if (direction == CELL_DIRECTION_OUT) {
@@ -494,6 +503,9 @@ circuitmux_detach_circuit(circuitmux_t *cmux, circuit_t *circ)
/* Consistency check: the direction must match the direction searched */
tor_assert(last_searched_direction == hashent->muxinfo.direction);
+ /* Clear the circuit's mux for this direction */
+ if (last_searched_direction == CELL_DIRECTION_OUT) circ->n_mux = NULL;
+ else TO_OR_CIRCUIT(circ)->p_mux = NULL;
/* Free the hash entry */
tor_free(hashent);
diff --git a/src/or/or.h b/src/or/or.h
index 3555a08c7..a0fcf8f49 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2650,7 +2650,7 @@ typedef struct circuit_t {
* Circuit mux associated with n_chan to which this circuit is attached;
* NULL if we have no n_chan.
*/
- circuitmux_t *mux;
+ circuitmux_t *n_mux;
/** Queue of cells waiting to be transmitted on n_chan */
cell_queue_t n_chan_cells;
@@ -2916,6 +2916,11 @@ typedef struct or_circuit_t {
cell_queue_t p_chan_cells;
/** The channel that is previous in this circuit. */
channel_t *p_chan;
+ /**
+ * Circuit mux associated with p_chan to which this circuit is attached;
+ * NULL if we have no p_chan.
+ */
+ circuitmux_t *p_mux;
/** Linked list of Exit streams associated with this circuit. */
edge_connection_t *n_streams;
/** Linked list of Exit streams associated with this circuit that are