summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-09-16 20:13:43 +0000
committerNick Mathewson <nickm@torproject.org>2003-09-16 20:13:43 +0000
commit3f3f8921f6b7695292592e346bbea24f73a6c941 (patch)
tree7a6024025a6c127a6f5a674e38c2e922d41620cd
parent4dddac706d5f47fcacebdd9693b974460100e8d3 (diff)
downloadtor-3f3f8921f6b7695292592e346bbea24f73a6c941.tar.gz
tor-3f3f8921f6b7695292592e346bbea24f73a6c941.zip
Make sequential ACI selection logic handle HIGHER/LOWER
svn:r466
-rw-r--r--src/or/circuit.c18
-rw-r--r--src/or/or.h3
2 files changed, 14 insertions, 7 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index ceafed6caf..dbaf7c59c4 100644
--- a/src/or/circuit.c
+++ b/src/or/circuit.c
@@ -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;
#ifdef SEQUENTIAL_ACI
- /* Right now, this is the only used aci_type. XXX The others should
- be removed. */
- assert(aci_type == ACI_TYPE_BOTH);
+ uint16_t high_bit;
+ high_bit = (aci_type == ACI_TYPE_HIGHER) ? 1<<15 : 0;
conn = connection_exact_get_by_addr_port(addr,port);
if (!conn)
return 1; /* No connection exists; conflict is impossible. */
+
do {
- test_aci = conn->next_aci++; /* This can wrap around to 0; that's okay. */
- if (test_aci == 0)
- continue;
+ /* Sequentially iterate over test_aci=1...1<<15-1 until we find an
+ * aci such that (high_bit|test_aci) is not already used. */
+ 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));
+ return test_aci;
#else
try_again:
log_fn(LOG_DEBUG,"trying to get a unique aci");
diff --git a/src/or/or.h b/src/or/or.h
index d9f7cbc089..2bea073025 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -330,7 +330,8 @@ struct connection_t {
char nonce[8];
#endif
#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
/* Used only by edge connections: */