aboutsummaryrefslogtreecommitdiff
path: root/src/or/circuitbuild.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-04-23 12:39:01 -0400
committerNick Mathewson <nickm@torproject.org>2014-04-23 12:39:01 -0400
commita770b74501a3faf6483c40735b70adae6fb95187 (patch)
tree0fcb8430ca965cef50a0b3b1ebaab648d0fefe69 /src/or/circuitbuild.c
parent985deaaaf7b7397857e02206e89392e0ee101077 (diff)
downloadtor-a770b74501a3faf6483c40735b70adae6fb95187.tar
tor-a770b74501a3faf6483c40735b70adae6fb95187.tar.gz
Improvements to #11553 fix based on review
Use a per-channel ratelim_t to control the rate at which we report failures for each channel. Explain why I picked N=32. Never return a zero circID. Thanks to Andrea and to cypherpunks.
Diffstat (limited to 'src/or/circuitbuild.c')
-rw-r--r--src/or/circuitbuild.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 7b852ff5c..8d6aad605 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -102,6 +102,12 @@ channel_connect_for_circuit(const tor_addr_t *addr, uint16_t port,
static circid_t
get_unique_circ_id_by_chan(channel_t *chan)
{
+/* This number is chosen somewhat arbitrarily; see comment below for more
+ * info. When the space is 80% full, it gives a one-in-a-million failure
+ * chance; when the space is 90% full, it gives a one-in-850 chance; and when
+ * the space is 95% full, it gives a one-in-26 failure chance. That seems
+ * okay, though you could make a case IMO for anything between N=32 and
+ * N=256. */
#define MAX_CIRCID_ATTEMPTS 64
circid_t test_circ_id;
@@ -137,19 +143,20 @@ get_unique_circ_id_by_chan(channel_t *chan)
* whole circuit ID space every time we extend a circuit, which is
* not so great either.
*/
- if (! chan->warned_circ_ids_exhausted) {
- chan->warned_circ_ids_exhausted = 1;
- log_warn(LD_CIRC,"No unused circIDs found on channel %s wide "
+ log_fn_ratelim(&chan->last_warned_circ_ids_exhausted, LOG_WARN,
+ LD_CIRC,"No unused circIDs found on channel %s wide "
"circID support, with %u inbound and %u outbound circuits. "
"Failing a circuit.",
chan->wide_circ_ids ? "with" : "without",
chan->num_p_circuits, chan->num_n_circuits);
- }
return 0;
}
- crypto_rand((char*) &test_circ_id, sizeof(test_circ_id));
- test_circ_id &= mask;
+ do {
+ crypto_rand((char*) &test_circ_id, sizeof(test_circ_id));
+ test_circ_id &= mask;
+ } while (test_circ_id == 0);
+
test_circ_id |= high_bit;
} while (circuit_id_in_use_on_channel(test_circ_id, chan));
return test_circ_id;