diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-02-05 17:42:40 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-02-05 17:42:40 +0000 |
commit | 03ef2156c93523cb548ea20b41e554b939964c29 (patch) | |
tree | 8b0c0fe57fa44ef512279fa895dfda73fadcf0be /src/or/circuitlist.c | |
parent | 6149ab01f86ddc406b2232292d693a1702122c89 (diff) | |
download | tor-03ef2156c93523cb548ea20b41e554b939964c29.tar.gz tor-03ef2156c93523cb548ea20b41e554b939964c29.zip |
r11637@catbus: nickm | 2007-02-05 12:41:51 -0500
Fix an XXXX012, and make circuits_pending_or_conns a static variable. In addition to cleaning up the code, this may also resolve Bug 386 if Roger has the right intuition there.
svn:r9482
Diffstat (limited to 'src/or/circuitlist.c')
-rw-r--r-- | src/or/circuitlist.c | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c index 2296ca765f..ce8ba5f73a 100644 --- a/src/or/circuitlist.c +++ b/src/or/circuitlist.c @@ -21,7 +21,7 @@ const char circuitlist_c_id[] = circuit_t *global_circuitlist=NULL; /** A list of all the circuits in CIRCUIT_STATE_OR_WAIT. */ -smartlist_t *circuits_pending_or_conns=NULL; +static smartlist_t *circuits_pending_or_conns=NULL; static void circuit_free(circuit_t *circ); static void circuit_free_cpath(crypt_path_t *cpath); @@ -165,15 +165,14 @@ circuit_set_state(circuit_t *circ, int state) tor_assert(circ); if (state == circ->state) return; + if (!circuits_pending_or_conns) + circuits_pending_or_conns = smartlist_create(); if (circ->state == CIRCUIT_STATE_OR_WAIT) { /* remove from waiting-circuit list. */ - if (circuits_pending_or_conns) - smartlist_remove(circuits_pending_or_conns, circ); + 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; @@ -194,6 +193,45 @@ circuit_add(circuit_t *circ) } } +/** Append to <b>out</b> the number of circuits in state OR_WAIT, waiting for + * the given connection. */ +void +circuit_get_all_pending_on_or_conn(smartlist_t *out, or_connection_t *or_conn) +{ + tor_assert(out); + tor_assert(or_conn); + + if (!circuits_pending_or_conns) + return; + + SMARTLIST_FOREACH(circuits_pending_or_conns, circuit_t *, circ, + { + if (circ->marked_for_close) + continue; + tor_assert(circ->state == CIRCUIT_STATE_OR_WAIT); + if (!circ->n_conn && + !memcmp(or_conn->identity_digest, circ->n_conn_id_digest, + DIGEST_LEN)) { + smartlist_add(out, circ); + } + }); +} + +/** Return the number of circuits in state OR_WAIT, waiting for the given + * connection. */ +int +circuit_count_pending_on_or_conn(or_connection_t *or_conn) +{ + int cnt; + smartlist_t *sl = smartlist_create(); + circuit_get_all_pending_on_or_conn(sl, or_conn); + cnt = smartlist_len(sl); + smartlist_free(sl); + log_debug(LD_CIRC,"or_conn to %s, %d pending circs", + or_conn->nickname ? or_conn->nickname : "NULL", cnt); + return cnt; +} + /** Detach from the global circuit list, and deallocate, all * circuits that have been marked for close. */ |