summaryrefslogtreecommitdiff
path: root/src/or/circuitlist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-12-03 02:12:37 +0000
committerNick Mathewson <nickm@torproject.org>2005-12-03 02:12:37 +0000
commit148a1e969d4c700409f0765d8b937b29b09881fb (patch)
tree52c124da78607a0b3940bcfe0db5903283f32a5a /src/or/circuitlist.c
parent502cb5961102e46853c18a0f93c3a279d31a2213 (diff)
downloadtor-148a1e969d4c700409f0765d8b937b29b09881fb.tar.gz
tor-148a1e969d4c700409f0765d8b937b29b09881fb.zip
Shave off another 4.7%: remove a linear search when figuring out which circuits wanted us to open a given OR connection.
svn:r5489
Diffstat (limited to 'src/or/circuitlist.c')
-rw-r--r--src/or/circuitlist.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 78cda53343..908ecc35e1 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -19,6 +19,9 @@ const char circuitlist_c_id[] = "$Id$";
/** A global list of all circuits at this hop. */
circuit_t *global_circuitlist=NULL;
+/** A list of all the circuits in CIRCUIT_STATE_OR_WAIT. */
+smartlist_t *circuits_pending_or_conns=NULL;
+
static void circuit_free(circuit_t *circ);
static void circuit_free_cpath(crypt_path_t *cpath);
static void circuit_free_cpath_node(crypt_path_t *victim);
@@ -131,6 +134,36 @@ circuit_set_circid_orconn(circuit_t *circ, uint16_t id,
++conn->n_circuits;
}
+/** Add <b>circ</b> to the list of circuits waiting for us to connect to
+ * an OR. */
+void
+circuit_set_state(circuit_t *circ, int state)
+{
+ tor_assert(circ);
+ if (state == circ->state)
+ return;
+ if (circ->state == CIRCUIT_STATE_OR_WAIT) {
+ /* remove from waiting-circuit list. */
+ if (!circuits_pending_or_conns)
+ circuits_pending_or_conns = smartlist_create();
+ smartlist_remove(circuits_pending_or_conns, circ);
+ }
+ if (state == CIRCUIT_STATE_OR_WAIT) {
+ /* add to waiting-circuit list. */
+ if (!circuits_pending_or_conns)
+ circuits_pending_or_conns = smartlist_create();
+ smartlist_add(circuits_pending_or_conns, circ);
+ }
+ circ->state = state;
+}
+
+/** Remove <b>circ</b> from the list of circuits waiting for us to connect to
+ * an OR. */
+void
+circuit_clear_state_orwait(circuit_t *circ)
+{
+}
+
/** Add <b>circ</b> to the global list of circuits. This is called only from
* within circuit_new.
*/
@@ -302,6 +335,8 @@ circuit_free_all(void)
circuit_free(global_circuitlist);
global_circuitlist = next;
}
+ smartlist_free(circuits_pending_or_conns);
+ circuits_pending_or_conns = NULL;
}
/** Deallocate space associated with the cpath node <b>victim</b>. */
@@ -638,6 +673,10 @@ _circuit_mark_for_close(circuit_t *circ, int line, const char *file)
}
circuit_rep_hist_note_result(circ);
}
+ if (circ->state == CIRCUIT_STATE_OR_WAIT) {
+ if (circuits_pending_or_conns)
+ smartlist_remove(circuits_pending_or_conns, circ);
+ }
if (CIRCUIT_IS_ORIGIN(circ)) {
control_event_circuit_status(circ,
(circ->state == CIRCUIT_STATE_OPEN)?CIRC_EVENT_CLOSED:CIRC_EVENT_FAILED);
@@ -784,6 +823,13 @@ assert_circuit_ok(const circuit_t *c)
tor_assert(c->p_digest);
}
}
+ if (c->state == CIRCUIT_STATE_OR_WAIT && !c->marked_for_close) {
+ tor_assert(circuits_pending_or_conns &&
+ smartlist_isin(circuits_pending_or_conns, c));
+ } else {
+ tor_assert(!circuits_pending_or_conns || !
+ !smartlist_isin(circuits_pending_or_conns, c));
+ }
if (c->cpath) {
assert_cpath_ok(c->cpath);
}