java.lang.Object
net.i2p.router.tunnel.pool.ExcluderBase
net.i2p.router.tunnel.pool.TunnelPeerSelector.Excluder
- Enclosing class:
TunnelPeerSelector
Excluder that automatically adds peers to the set when they should be excluded.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final longActivity window in ms, computed once per Excluder construction.private booleanWhen true, the no-signal check inTunnelPeerSelector.getExclusionReason(Hash, boolean, boolean, double, long)is skipped, allowing untested peers to be considered for tunnel builds.private final doubleBuild success ratio, fetched once per Excluder construction.private final booleanWhether this selector builds exploratory tunnels.private final booleanWhether this selector builds inbound tunnels.private static final intCap on classified exclusions.Constructor Summary
ConstructorsConstructorDescriptionExcluder(boolean isInbound, boolean isExploratory) Automatically adds selectPeersInTooManyTunnels(), unlessi2np.allowLocal.Excluder(boolean isInbound, boolean isExploratory, double buildSuccess) Automatically adds selectPeersInTooManyTunnels(), unlessi2np.allowLocal.Does not add selectPeersInTooManyTunnels().Does not add selectPeersInTooManyTunnels().Method Summary
Public MethodsModifier and TypeMethodDescriptionbooleanAutomatically check if peer is allowed and add the Hash to the set if not.(package private) StringFormat excluded peers grouped by reason, sorted by hash within each group.(package private) intRelax no-signal exclusions under peer scarcity: remove all peers previously excluded for "no-signal" from the underlying set, and set a flag so future contains() calls skip the no-signal check.Methods inherited from class ExcluderBase
add, addAll, clear, containsAll, equals, getReasonsSummary, hashCode, isEmpty, iterator, recordExclusion, remove, removeAll, retainAll, size, toArray, toArray, toStringModifier and TypeMethodDescriptionbooleanAdd the hash to the underlying set.booleanaddAll(Collection<? extends Hash> c) Add all of the hashes to the underlying set.voidclear()Remove all hashes from the underlying set.booleancontainsAll(Collection<?> c) Whether the underlying set contains all of the given hashes.booleanWhether the underlying set equals the given object.protected StringFormat exclusion summary grouped by reason (counts only, no peer hashes).inthashCode()The hash code of the underlying set.booleanisEmpty()Whether the underlying set is empty.iterator()An iterator over the underlying set.protected voidrecordExclusion(Hash h, String reason) Record why a peer was excluded, for diagnostic logging.booleanRemove the hash from the underlying set.booleanremoveAll(Collection<?> c) Remove all of the given hashes from the underlying set.booleanretainAll(Collection<?> c) Retain only the given hashes in the underlying set.intsize()The number of hashes in the underlying set.Object[]toArray()The hashes of the underlying set as an array.<Hash> Hash[]toArray(Hash[] a) The hashes of the underlying set in the given array.toString()Description of the excluded set and its size.Methods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
spliterator
Field Details
MAX_EXCLUDED_PEERS
private static final int MAX_EXCLUDED_PEERSCap on classified exclusions. Bulk-loaded diversity entries carry no reason and are therefore never evicted; only reasoned entries are bounded, oldest first.- See Also:
_isIn
private final boolean _isInWhether this selector builds inbound tunnels._isExpl
private final boolean _isExplWhether this selector builds exploratory tunnels._buildSuccess
private final double _buildSuccessBuild success ratio, fetched once per Excluder construction._activityWindow
private final long _activityWindowActivity window in ms, computed once per Excluder construction.TunnelPeerSelector.getActivityWindow(RouterContext, double)callscountActivePeers(), which scans every non-failing profile under a read lock; recomputing it per candidate made selection O(candidates × peers). It is constant for one selection._allowNoSignal
private volatile boolean _allowNoSignalWhen true, the no-signal check inTunnelPeerSelector.getExclusionReason(Hash, boolean, boolean, double, long)is skipped, allowing untested peers to be considered for tunnel builds. Set byrelaxNoSignalExclusions()when peer scarcity demands it.
Constructor Details
Excluder
public Excluder(boolean isInbound, boolean isExploratory) Automatically adds selectPeersInTooManyTunnels(), unlessi2np.allowLocal. Fetches the build success ratio once, so the per-peer exclusion checks incontains(Object)never re-read router statistics.- Parameters:
isInbound- true for an inbound poolisExploratory- true for an exploratory pool
Excluder
public Excluder(boolean isInbound, boolean isExploratory, double buildSuccess) Automatically adds selectPeersInTooManyTunnels(), unlessi2np.allowLocal. Uses a build success ratio already fetched by the caller.- Parameters:
isInbound- true for an inbound poolisExploratory- true for an exploratory poolbuildSuccess- the global build success ratio in [0.0, 1.0]
Excluder
Does not add selectPeersInTooManyTunnels(). Makes a copy of toAdd. Fetches the build success ratio once, so the per-peer exclusion checks incontains(Object)never re-read router statistics.- Parameters:
isInbound- true for an inbound poolisExploratory- true for an exploratory pooltoAdd- initial contents, copied
Excluder
Does not add selectPeersInTooManyTunnels(). Makes a copy of toAdd. Uses a build success ratio already fetched by the caller.- Parameters:
isInbound- true for an inbound poolisExploratory- true for an exploratory pooltoAdd- initial contents, copiedbuildSuccess- the global build success ratio in [0.0, 1.0]
Method Details
contains
Description copied from class:ExcluderBaseAutomatically check if peer is allowed and add the Hash to the set if not.- Specified by:
containsin interfaceCollection<Hash>- Specified by:
containsin interfaceSet<Hash>- Specified by:
containsin classExcluderBase- Parameters:
o- a peer hash to look up in the underlying set- Returns:
- true if peer should be excluded
relaxNoSignalExclusions
int relaxNoSignalExclusions()Relax no-signal exclusions under peer scarcity: remove all peers previously excluded for "no-signal" from the underlying set, and set a flag so future contains() calls skip the no-signal check. This allows untested peers to be considered as tunnel candidates when we can't build tunnels due to insufficient proven peers.- Returns:
- number of peers un-excluded
formatByReasonWithPeers
String formatByReasonWithPeers()Format excluded peers grouped by reason, sorted by hash within each group.- Returns:
- multi-line string like "Too many tunnels (128): peer1 peer2..."