public class ProfileOrganizer extends Object
| Modifier and Type | Class and Description |
|---|---|
static class | ProfileOrganizer.SliceDefines peer selection slicing modes for tier-based peer organization. |
| Modifier and Type | Field and Description |
|---|---|
static int | _defaultMaxFastPeers_defaultMaxFastPeers. |
static int | _defaultMaxHighCapPeers_defaultMaxHighCapPeers. |
static int | _defaultMaxProfiles_defaultMaxProfiles. |
static int | _defaultMinFastPeers_defaultMinFastPeers. |
static int | _defaultMinHighCapPeers_defaultMinHighCapPeers. |
static int | ABSOLUTE_MAX_PROFILESABSOLUTE_MAX_PROFILES. |
static double | ATTACK_THRESHOLDThreshold below which the network is considered under attack |
static int | DEFAULT_MAX_ROUTERINFO_AGE_HOURSDEFAULT_MAX_ROUTERINFO_AGE_HOURS. |
static int | DEFAULT_MINIMUM_HIGH_CAPACITY_PEERSDEFAULT_MINIMUM_HIGH_CAPACITY_PEERS. |
static int | MIN_MAX_PROFILESMIN_MAX_PROFILES. |
static String | PROP_MAX_PROFILESPROP_MAX_PROFILES. |
static String | PROP_MAX_ROUTERINFO_AGE_HOURSPROP_MAX_ROUTERINFO_AGE_HOURS. |
static String | PROP_MAXIMUM_FAST_PEERSPROP_MAXIMUM_FAST_PEERS. |
static String | PROP_MAXIMUM_HIGH_CAPACITY_PEERSPROP_MAXIMUM_HIGH_CAPACITY_PEERS. |
static String | PROP_MINIMUM_FAST_PEERSPROP_MINIMUM_FAST_PEERS. |
static String | PROP_MINIMUM_HIGH_CAPACITY_PEERSPROP_MINIMUM_HIGH_CAPACITY_PEERS. |
| Constructor and Description |
|---|
ProfileOrganizer(RouterContext context)Creates a profile organizer with empty tier maps and registers
performance tracking statistics for peer classification. |
| Modifier and Type | Method and Description |
|---|---|
PeerProfile | addProfile(PeerProfile profile)Insert a fully-constructed profile into the organizer. |
(package private) void | clearProfiles()Remove all profiles and clear all tier maps. |
int | countActivePeers()Count peers with any send or hear activity in the last 4 hours. |
int | countActivePeersInLastHour()Count peers with activity (send, receive, or failure) within the last hour. |
int | countFastPeers()Number of peers classified as fast tier. |
int | countHighCapacityPeers()Number of peers classified as high-capacity tier. |
int | countNotFailingPeers()Total number of peer profiles in memory (all tiers). |
void | demoteIfCongested(Hash peer)Immediately demote a peer from fast/high-cap tiers if it has a congestion cap (D/E). |
void | demoteIfHighLatency(Hash peer)Immediately demote a peer from fast/high-cap tiers if its capacityBonus is -30
(UI shows ✖ for high latency). |
(package private) void | demoteIfHighRTT(Hash peer,
long responseTimeMs)Immediately demote a peer from fast/high-cap tiers if its tunnel test RTT
exceeds the low-latency threshold (timeout * 2), matching the PeerTestJob metric. |
void | demoteIfNoTunnel(Hash peer)Immediately demote a peer from fast/high-cap tiers if it has G cap (no tunnels). |
void | demoteIfStale(Hash peer)Immediately demote a peer from fast/high-cap tiers if its RouterInfo is stale
and it has no recent proof of life (fails isSelectable). |
void | demoteIfUnreachable(Hash peer)Immediately demote a peer from fast/high-cap tiers when our transport
connection to it failed during tunnel build (first hop unreachable). |
(package private) void | evictProfilesNotInNetdb()Evict profiles for peers no longer in the network database. |
boolean | exportProfile(Hash profile,
OutputStream out)Write a peer profile to the given output stream for persistence. |
double | getCapacityThreshold()Current minimum capacity value for the high-capacity peer tier. |
static int | getDefaultMaxFastPeers() |
static int | getDefaultMaxHighCapPeers() |
static int | getDefaultMaxProfilesValue() |
static int | getDefaultMinFastPeers() |
double | getIntegrationThreshold()Current minimum integration value for the well-integrated peer tier. |
protected int | getMaximumFastPeers() |
protected int | getMaximumHighCapPeers() |
static int | getMinHighCapacityPeers() |
protected int | getMinimumFastPeers() |
protected int | getMinimumHighCapacityPeers() |
(package private) PeerProfile | getOrCreateProfileNonblocking(Hash peer)Retrieve an existing profile or create a new one, without blocking on contention. |
PeerProfile | getProfile(Hash peer)Retrieve the profile for a peer, or null if unknown. |
PeerProfile | getProfileNonblocking(Hash peer)Retrieve the profile for a peer without blocking. |
double | getSpeedThreshold()Current minimum speed value for the fast peer tier. |
double | getTunnelBuildSuccess() |
Hash | getUs()Self-exclusion hash for this router instance. |
(package private) boolean | isExcludedFromProfiling(Hash peer)Check if a peer should be excluded from profiling. |
boolean | isFast(Hash peer)Check whether a peer is classified in the fast tier. |
boolean | isHighCapacity(Hash peer)Check whether a peer is classified in the high-capacity tier. |
(package private) boolean | isLowBandwidthTier(Hash peer)Check if a peer is in a low bandwidth tier (K, L, M, or Unknown). |
boolean | isLowBuildSuccess() |
boolean | isSelectable(Hash peer) |
boolean | isWellIntegrated(Hash peer)Check whether a peer is classified in the well-integrated tier. |
static void | main(String[] args)main. |
boolean | peerSendsBadReplies(Hash peer)Check whether a peer sends an excessive rate of invalid or failed
netDb lookup replies (potential misbehavior indicator). |
void | purgeStaleProfileFiles()purgeStaleProfileFiles. |
(package private) void | reorganize()Run a standard reorganize round without coalescing or decay. |
(package private) void | reorganize(boolean shouldCoalesce,
boolean shouldDecay)Reorganizes peer profiles into performance-based tiers (fast, high-capacity, etc.) and expires stale entries. |
void | selectActiveNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)Select from currently connected (established) not-failing peers. |
void | selectActiveNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)Select from currently connected peers with IP-subnet diversity. |
void | selectAllNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing)Select from all not-failing peers randomly, falling through to general
peers if the not-failing set is insufficient. |
Set<Hash> | selectAllPeers()Gather the union of all peers from fast, high-capacity, and not-failing tiers. |
void | selectFastPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)Select up to howMany fast-tier peers, filling shortfalls from high-capacity. |
void | selectFastPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)Select fast-tier peers with IP-subnet diversity constraints. |
void | selectFastPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
SessionKey randomKey,
ProfileOrganizer.Slice subTierMode,
int mask,
MaskedIPSet ipSet)Select fast-tier peers deterministically sliced by a random key. |
void | selectHighBandwidthPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)Select up to howMany peers from O/P/X bandwidth tiers (high shared bandwidth)
that are not failing. |
void | selectHighBandwidthPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing,
int mask,
MaskedIPSet ipSet)Select high-bandwidth peers with tier-exclusion and IP-subnet diversity. |
void | selectHighCapacityPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)Select high-capacity peers, filling shortfalls from not-failing peers. |
void | selectHighCapacityPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)Select high-capacity peers with IP-subnet diversity. |
void | selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)Select from not-failing peers, excluding high-capacity tier if requested. |
void | selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing)Select from not-failing peers, optionally excluding the high-capacity tier. |
void | selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing,
int mask,
MaskedIPSet ipSet)Full-parameter select from not-failing peers. |
void | selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)Select from not-failing peers with IP-subnet diversity. |
static void | setDefaultMaxFastPeers(int val) |
static void | setDefaultMaxHighCapPeers(int val) |
static void | setDefaultMaxProfiles(int val) |
static void | setDefaultMinFastPeers(int val) |
static void | setMinHighCapacityPeers(int val) |
void | setUs(Hash us)Set the local router hash for self-exclusion from peer selection. |
void | writeProfile(PeerProfile profile)writeProfile. |
public static volatile int _defaultMaxFastPeers
public static volatile int _defaultMaxHighCapPeers
public static volatile int _defaultMaxProfiles
public static volatile int _defaultMinFastPeers
public static volatile int _defaultMinHighCapPeers
public static final int ABSOLUTE_MAX_PROFILES
public static final double ATTACK_THRESHOLD
public static final int DEFAULT_MAX_ROUTERINFO_AGE_HOURS
public static final int DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS
public static final int MIN_MAX_PROFILES
public static final String PROP_MAX_PROFILES
public static final String PROP_MAX_ROUTERINFO_AGE_HOURS
public static final String PROP_MAXIMUM_FAST_PEERS
public static final String PROP_MAXIMUM_HIGH_CAPACITY_PEERS
public static final String PROP_MINIMUM_FAST_PEERS
public static final String PROP_MINIMUM_HIGH_CAPACITY_PEERS
public ProfileOrganizer(RouterContext context)
context - the router context providing config, stats, and log accesspublic PeerProfile addProfile(PeerProfile profile)
profile - the profile to addvoid clearProfiles()
public int countActivePeers()
public int countActivePeersInLastHour()
public int countFastPeers()
public int countHighCapacityPeers()
public int countNotFailingPeers()
public void demoteIfCongested(Hash peer)
public void demoteIfHighLatency(Hash peer)
void demoteIfHighRTT(Hash peer, long responseTimeMs)
public void demoteIfNoTunnel(Hash peer)
public void demoteIfStale(Hash peer)
public void demoteIfUnreachable(Hash peer)
void evictProfilesNotInNetdb()
public boolean exportProfile(Hash profile, OutputStream out) throws IOException
profile - the router hash identifying the profile to exportout - the destination stream for the serialized profileIOException - on write errorspublic double getCapacityThreshold()
public static int getDefaultMaxFastPeers()
public static int getDefaultMaxHighCapPeers()
public static int getDefaultMaxProfilesValue()
public static int getDefaultMinFastPeers()
public double getIntegrationThreshold()
protected int getMaximumFastPeers()
protected int getMaximumHighCapPeers()
public static int getMinHighCapacityPeers()
protected int getMinimumFastPeers()
protected int getMinimumHighCapacityPeers()
PeerProfile getOrCreateProfileNonblocking(Hash peer)
peer - the router hash to look up or create a profile forpublic PeerProfile getProfile(Hash peer)
peer - the router hash to look uppublic PeerProfile getProfileNonblocking(Hash peer)
peer - the router hash to look uppublic double getSpeedThreshold()
public double getTunnelBuildSuccess()
public Hash getUs()
boolean isExcludedFromProfiling(Hash peer)
public boolean isFast(Hash peer)
peer - the router hash to checkpublic boolean isHighCapacity(Hash peer)
peer - the router hash to checkboolean isLowBandwidthTier(Hash peer)
public boolean isLowBuildSuccess()
public boolean isSelectable(Hash peer)
public boolean isWellIntegrated(Hash peer)
peer - the router hash to checkpublic static void main(String[] args)
public boolean peerSendsBadReplies(Hash peer)
peer - the router hash to checkpublic void purgeStaleProfileFiles()
void reorganize()
void reorganize(boolean shouldCoalesce,
boolean shouldDecay)This method:
Memory Safety: To prevent unbounded memory growth (e.g., OOM after 8+ hours), this method ensures that expired profiles are removed from all data structures—even if the full reorganization is skipped due to lock contention. A best-effort expiration pass runs outside the write lock to mitigate leaks during high contention.
shouldCoalesce - if true, coalesce statistics for active profilesshouldDecay - if true and coalescing is performed, apply decay to historical statspublic void selectActiveNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashespublic void selectActiveNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesmask - bitmask length for /n diversity restriction (0 to disable)ipSet - mutable set tracking already-selected subnetspublic void selectAllNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesonlyNotFailing - if true, exclude peers already in high-capacity tierpublic Set<Hash> selectAllPeers()
public void selectFastPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashespublic void selectFastPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesmask - bitmask length for /n diversity restriction (0 to disable)ipSet - mutable set tracking already-selected subnetspublic void selectFastPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
SessionKey randomKey,
ProfileOrganizer.Slice subTierMode,
int mask,
MaskedIPSet ipSet)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesrandomKey - key for deterministic sub-tier assignmentsubTierMode - slicing mode (SLICE_ALL to skip slicing)mask - bitmask length for /n diversity restriction (0 to disable)ipSet - mutable set tracking already-selected subnetspublic void selectHighBandwidthPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashespublic void selectHighBandwidthPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing,
int mask,
MaskedIPSet ipSet)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesonlyNotFailing - if true, exclude peers already in high-capacity tiermask - bitmask length for /n diversity restriction (0 to disable)ipSet - mutable set tracking already-selected subnetspublic void selectHighCapacityPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashespublic void selectHighCapacityPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesmask - bitmask length for /n diversity restriction (0 to disable)ipSet - mutable set tracking already-selected subnetspublic void selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashespublic void selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesonlyNotFailing - if true, exclude peers already in high-capacity tierpublic void selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
boolean onlyNotFailing,
int mask,
MaskedIPSet ipSet)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesonlyNotFailing - if true, exclude peers already in high-capacity tiermask - bitmask length for /n diversity restriction (0 to disable)ipSet - mutable set tracking already-selected subnetspublic void selectNotFailingPeers(int howMany,
Set<Hash> exclude,
Set<Hash> matches,
int mask,
MaskedIPSet ipSet)howMany - target number of peersexclude - peers to exclude (may be null)matches - output set populated with selected peer hashesmask - bitmask length for /n diversity restriction (0 to disable)ipSet - mutable set tracking already-selected subnetspublic static void setDefaultMaxFastPeers(int val)
public static void setDefaultMaxHighCapPeers(int val)
public static void setDefaultMaxProfiles(int val)
public static void setDefaultMinFastPeers(int val)
public static void setMinHighCapacityPeers(int val)
public void setUs(Hash us)
public void writeProfile(PeerProfile profile)