Our connection_or_get_by_identity_digest() was slightly wrong. If best

didn't have any circuits on it, but conn had circuits, we would not make
conn our new best unless it was also newer.  Also, restructure the code
a bit to maybe make it clearer.


svn:r6012
This commit is contained in:
Peter Palfrader 2006-02-14 00:08:19 +00:00
parent cfcb1b1afd
commit 761da5b97f

View File

@ -394,12 +394,22 @@ connection_or_get_by_identity_digest(const char *digest)
conn->state != OR_CONN_STATE_OPEN) conn->state != OR_CONN_STATE_OPEN)
continue; /* avoid non-open conns if we can */ continue; /* avoid non-open conns if we can */
newer = best->timestamp_created < conn->timestamp_created; 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 (!best->is_obsolete && conn->is_obsolete)
if (best->n_circuits && !conn->n_circuits) continue; /* We never prefer obsolete over non-obsolete connections. */
continue; /* prefer conns with circuits on them */
if (newer) /* If both are obsolete we prefer the newer: */
best = conn; /* lastly, prefer newer conns */ if ((best->is_obsolete && conn->is_obsolete && newer) ||
/* We prefer non-obsolete connections */
(best->is_obsolete && !conn->is_obsolete) ||
/* If both have circuits we prefer the newer: */
(best->n_circuits && conn->n_circuits && newer) ||
/* If neither has circuits we prefer the newer: */
(!best->n_circuits && !conn->n_circuits && newer) ||
/* We prefer connections with circuits: */
(!best->n_circuits && conn->n_circuits)) {
best = conn;
};
} }
return best; return best;
} }