- All Implemented Interfaces:
Serializable, Comparator<Lease>
- Enclosing class:
TunnelPool
LeaseSet.equals(Object) and lease-by-lease equals() always work. The sort method is arbitrary, as far as the equals() tests are concerned, but we use latest expiration first, since we need to sort them by that anyway.Constructor Summary
ConstructorsConstructorDescriptionA stateless comparator: it reads nothing but the two leases, so a bare instance behaves exactly like any other.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
Constructor Details
LeaseComparator
LeaseComparator()A stateless comparator: it reads nothing but the two leases, so a bare instance behaves exactly like any other.
Method Details
compare
Order leases by end time, breaking ties on tunnel identity.Ordering by end time is the point of this comparator: a tunnel set that has not changed has to serialise to the same LeaseSet, or the router republishes identical leases and the floodfill does needless work.
The tie-break is not cosmetic, it is the whole correctness of the LeaseSet. A
TreeSetdiscards any element its comparator calls equal, and end times collide constantly:TunnelPool.computeLeaseEndDate(long, long, long)clamps tonow + maxLeaseMsand floors atnow + 60sfrom a singlenowtaken for the whole build, so every tunnel in a batch that outruns the lease cap lands on the very same instant. Comparing end time alone therefore collapsed a pool of eight tunnels to a one-lease LeaseSet, published as such, and a destination advertised through a single tunnel reads as unreachable to everyone else. Breaking ties on tunnel id and gateway keeps the ordering stable while making the comparator agree withLease.equals(Object), so the set can no longer silently lose leases.- Specified by:
comparein interfaceComparator<Lease>