summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-11-26 00:53:51 +0000
committerNick Mathewson <nickm@torproject.org>2005-11-26 00:53:51 +0000
commit31d5d96739f367e054619fda1266bf7d281b931e (patch)
tree8c8612f2968b4b4d44eefe2749cd02ce7785f35c /src/or/connection.c
parent72cb64406a5b0d64a27340ced604b99019067c36 (diff)
downloadtor-31d5d96739f367e054619fda1266bf7d281b931e.tar.gz
tor-31d5d96739f367e054619fda1266bf7d281b931e.zip
Cut down a common call to circuit_get_by_conn by about half.
svn:r5459
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 333df458e8..9ef723e91b 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -1582,7 +1582,7 @@ connection_get_by_type_addr_port_purpose(int type, uint32_t addr, uint16_t port,
connection_t *
connection_get_by_identity_digest(const char *digest)
{
- int i, n, newer;
+ int i, n, newer, best_has_circ=0, conn_has_circ;
connection_t *conn, *best=NULL;
connection_t **carray;
@@ -1595,6 +1595,7 @@ connection_get_by_identity_digest(const char *digest)
continue;
if (!best) {
best = conn; /* whatever it is, it's better than nothing. */
+ best_has_circ = (circuit_get_by_conn(best) != NULL);
continue;
}
if (best->state == OR_CONN_STATE_OPEN &&
@@ -1603,10 +1604,13 @@ connection_get_by_identity_digest(const char *digest)
newer = best->timestamp_created < conn->timestamp_created;
if (conn->is_obsolete && (!best->is_obsolete || !newer))
continue; /* we have something, and it's better than this. */
- if (circuit_get_by_conn(best) && !circuit_get_by_conn(conn))
+ conn_has_circ = (circuit_get_by_conn(conn) != NULL);
+ if (best_has_circ && !conn_has_circ)
continue; /* prefer conns with circuits on them */
- if (newer)
+ if (newer) {
best = conn; /* lastly, prefer newer conns */
+ best_has_circ = conn_has_circ;
+ }
}
return best;
}