diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-07-06 17:08:24 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-07-19 01:58:45 -0400 |
commit | 773bfaf91ebe1ef80f37d473714a11f962e753fb (patch) | |
tree | 0c115b831f478d641b051d7be0cae8e5c5216c8b /src/common/util.c | |
parent | 1d3c8c1f74e9f80317a70c3b7d9372dee87dd373 (diff) | |
download | tor-773bfaf91ebe1ef80f37d473714a11f962e753fb.tar.gz tor-773bfaf91ebe1ef80f37d473714a11f962e753fb.zip |
Implement stream isolation
This is the meat of proposal 171: we change circuit_is_acceptable()
to require that the connection is compatible with every connection
that has been linked to the circuit; we update circuit_is_better to
prefer attaching streams to circuits in the way that decreases the
circuits' usefulness the least; and we update link_apconn_to_circ()
to do the appropriate bookkeeping.
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index b95ee3a612..bf0bbe0603 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -412,6 +412,32 @@ round_uint64_to_next_multiple_of(uint64_t number, uint64_t divisor) return number; } +/** Return the number of bits set in <b>v</b>. */ +int +n_bits_set_u8(uint8_t v) +{ + static const int nybble_table[] = { + 0, /* 0000 */ + 1, /* 0001 */ + 1, /* 0010 */ + 2, /* 0011 */ + 1, /* 0100 */ + 2, /* 0101 */ + 2, /* 0110 */ + 3, /* 0111 */ + 1, /* 1000 */ + 2, /* 1001 */ + 2, /* 1010 */ + 3, /* 1011 */ + 2, /* 1100 */ + 3, /* 1101 */ + 3, /* 1110 */ + 4, /* 1111 */ + }; + + return nybble_table[v & 15] + nybble_table[v>>4]; +} + /* ===== * String manipulation * ===== */ |