java.lang.Object
net.i2p.router.tunnel.pool.TunnelPeerSelector.HashComparator
- All Implemented Interfaces:
Serializable, Comparator<Hash>
- Enclosing class:
TunnelPeerSelector
private static class TunnelPeerSelector.HashComparatorextends Object implements Comparator<Hash>, Serializable
Implement a deterministic comparison that cannot be predicted by others. A naive implementation (using the distance from a random key) allows an attacker who runs two routers with hashes far apart to maximize his chances of those two routers being at opposite ends of a tunnel.
Previous Previous: d(l, h) - d(r, h)
Previous: d((H(l+h), h) - d(H(r+h), h)
Now: SipHash using h to generate the SipHash keys then siphash(l) - siphash(r).
Field Summary
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDerives the SipHash sort keys from a session key, holding no state of its own.Method Summary
All MethodsMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparator
equals, max, min, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Field Details
k0
private final long k0First seed for the deterministic peer shuffle.k1
private final long k1Second seed for the deterministic peer shuffle.
Constructor Details
HashComparator
Derives the SipHash sort keys from a session key, holding no state of its own.- Parameters:
k- container for sort keys, not used as a Hash
Method Details
compare
Compare the two hashes by SipHash distance.- Specified by:
comparein interfaceComparator<Hash>