give us more aci-space

svn:r149
This commit is contained in:
Roger Dingledine 2002-12-30 08:51:41 +00:00
parent fbf4ca3ff8
commit 0b717a3e74

View File

@ -96,32 +96,33 @@ void circuit_free_cpath(crypt_path_t **cpath, int cpathlen) {
free(cpath); free(cpath);
} }
/* return 0 if can't get a unique aci. */
aci_t get_unique_aci_by_addr_port(uint32_t addr, uint16_t port, int aci_type) { aci_t get_unique_aci_by_addr_port(uint32_t addr, uint16_t port, int aci_type) {
aci_t test_aci; aci_t test_aci;
connection_t *conn; connection_t *conn;
try_again:
log(LOG_DEBUG,"get_unique_aci_by_addr_port() trying to get a unique aci"); log(LOG_DEBUG,"get_unique_aci_by_addr_port() trying to get a unique aci");
crypto_pseudo_rand(2, (unsigned char *)&test_aci); crypto_pseudo_rand(2, (unsigned char *)&test_aci);
if(aci_type == ACI_TYPE_LOWER) if(aci_type == ACI_TYPE_LOWER && test_aci >= (2<<15))
test_aci &= htons(0x00FF); test_aci -= (2<<15);
if(aci_type == ACI_TYPE_HIGHER) if(aci_type == ACI_TYPE_HIGHER && test_aci < (2<<15))
test_aci &= htons(0xFF00); test_aci += (2<<15);
/* if aci_type == ACI_BOTH, don't filter any of it */ /* if aci_type == ACI_BOTH, don't filter any of it */
if(test_aci == 0) if(test_aci == 0)
return get_unique_aci_by_addr_port(addr, port, aci_type); /* try again */ goto try_again;
conn = connection_exact_get_by_addr_port(addr,port); conn = connection_exact_get_by_addr_port(addr,port);
if(!conn) /* there can't be a conflict -- no connection of that sort yet */ if(!conn) /* there can't be a conflict -- no connection of that sort yet */
return test_aci; return test_aci;
if(circuit_get_by_aci_conn(test_aci, conn)) if(circuit_get_by_aci_conn(test_aci, conn))
return get_unique_aci_by_addr_port(addr, port, aci_type); /* try again */ goto try_again;
return test_aci; return test_aci;
} }
int circuit_init(circuit_t *circ, int aci_type) { int circuit_init(circuit_t *circ, int aci_type) {
@ -150,6 +151,10 @@ int circuit_init(circuit_t *circ, int aci_type) {
gettimeofday(&start,NULL); gettimeofday(&start,NULL);
circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, aci_type); circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, aci_type);
if(!circ->n_aci) {
log(LOG_ERR,"circuit_init(): failed to get unique aci.");
return -1;
}
gettimeofday(&end,NULL); gettimeofday(&end,NULL);