Make sequential ACI selection logic handle HIGHER/LOWER

svn:r466
This commit is contained in:
Nick Mathewson 2003-09-16 20:13:43 +00:00
parent 4dddac706d
commit 3f3f8921f6
2 changed files with 14 additions and 7 deletions

View File

@ -123,17 +123,23 @@ static aci_t get_unique_aci_by_addr_port(uint32_t addr, uint16_t port, int aci_t
connection_t *conn; connection_t *conn;
#ifdef SEQUENTIAL_ACI #ifdef SEQUENTIAL_ACI
/* Right now, this is the only used aci_type. XXX The others should uint16_t high_bit;
be removed. */ high_bit = (aci_type == ACI_TYPE_HIGHER) ? 1<<15 : 0;
assert(aci_type == ACI_TYPE_BOTH);
conn = connection_exact_get_by_addr_port(addr,port); conn = connection_exact_get_by_addr_port(addr,port);
if (!conn) if (!conn)
return 1; /* No connection exists; conflict is impossible. */ return 1; /* No connection exists; conflict is impossible. */
do { do {
test_aci = conn->next_aci++; /* This can wrap around to 0; that's okay. */ /* Sequentially iterate over test_aci=1...1<<15-1 until we find an
if (test_aci == 0) * aci such that (high_bit|test_aci) is not already used. */
continue; test_aci = conn->next_aci++;
if (test_aci == 0 || test_aci >= 1<<15) {
test_aci = 1;
conn->next_aci = 2;
}
test_aci |= high_bit;
} while(circuit_get_by_aci_conn(test_aci, conn)); } while(circuit_get_by_aci_conn(test_aci, conn));
return test_aci;
#else #else
try_again: try_again:
log_fn(LOG_DEBUG,"trying to get a unique aci"); log_fn(LOG_DEBUG,"trying to get a unique aci");

View File

@ -330,7 +330,8 @@ struct connection_t {
char nonce[8]; char nonce[8];
#endif #endif
#ifdef SEQUENTIAL_ACI #ifdef SEQUENTIAL_ACI
uint16_t next_aci; /* Which ACI do we try to use next on this connection? */ uint16_t next_aci; /* Which ACI do we try to use next on this connection?
* This is always in the range 0..1<<15-1.*/
#endif #endif
/* Used only by edge connections: */ /* Used only by edge connections: */