Package net.i2p.router.peermanager
Class ProfileOrganizer
java.lang.Object
net.i2p.router.peermanager.ProfileOrganizer
Keep the peer profiles organized according to the tiered model. This does not
actively update anything - the reorganize() method should be called periodically
to recalculate thresholds and move profiles into the appropriate tiers, and addProfile()
should be used to add new profiles (placing them into the appropriate groupings).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Replaces integer subTierMode argument, for clarity -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final String
Defines the minimum number of 'fast' peers that the organizer should select.static final String
Defines the minimum number of 'high capacity' peers that the organizer should select when using the mean - if less than this many are available, select the capacity by the median. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddProfile
(PeerProfile profile) Add the new profile, returning the old value (or null if no profile existed)(package private) void
int
int
int
int
int
int
Deprecated.use ProfileManager.getPeersByCapability('f').size()boolean
exportProfile
(Hash profile, OutputStream out) double
double
protected int
fixme add config @since 0.7.10protected int
fixme add config @since 0.7.11protected int
Defines the minimum number of 'fast' peers that the organizer should select.protected int
Defines the minimum number of 'fast' peers that the organizer should select.(package private) PeerProfile
Retrieve the profile for the given peer, if one exists.getProfile
(Hash peer) Retrieve the profile for the given peer, if one exists (else null).getProfileNonblocking
(Hash peer) Retrieve the profile for the given peer, if one exists (else null).double
getUs()
boolean
Deprecated for now, always falseboolean
boolean
isHighCapacity
(Hash peer) boolean
isSelectable
(Hash peer) boolean
isWellIntegrated
(Hash peer) static void
Read in all of the profiles specified and print out their calculated values.boolean
peerSendsBadReplies
(Hash peer) Does the given peer send us bad replies - either invalid store messages (expired, corrupt, etc) or unreachable replies (pointing towards routers that don't exist).(package private) void
Place peers into the correct tier, as well as expand/contract and even drop profiles according to whatever limits are in place.(package private) void
reorganize
(boolean shouldCoalesce, boolean shouldDecay) void
selectActiveNotFailingPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches) Return a set of Hashes for peers that are both not failing and we're actively talking with.void
selectActiveNotFailingPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are both not failing and we're actively talking with.void
selectAllNotFailingPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, boolean onlyNotFailing) Return a set of Hashes for peers that are not failing.Find the hashes for all peers we are actively profilingvoid
selectFastPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches) Return a set of Hashes for peers that are both fast and reliable.void
selectFastPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are both fast and reliable.void
selectFastPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, SessionKey randomKey, ProfileOrganizer.Slice subTierMode, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are both fast and reliable.void
selectHighCapacityPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches) Return a set of Hashes for peers that have a high capacityvoid
selectHighCapacityPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) void
selectNotFailingPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches) Return a set of Hashes for peers that are not failing, preferring ones that we are already talking withvoid
selectNotFailingPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, boolean onlyNotFailing) void
selectNotFailingPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, boolean onlyNotFailing, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are not failing, preferring ones that we are already talking withvoid
selectNotFailingPeers
(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) Get the peers the transport layer thinks are unreachable, and peers requiring introducers.Get the peers that have recently rejected us for bandwidth recent == last 20svoid
-
Field Details
-
PROP_MINIMUM_FAST_PEERS
Defines the minimum number of 'fast' peers that the organizer should select. SeegetMinimumFastPeers()
- See Also:
-
DEFAULT_MINIMUM_FAST_PEERS
public static final int DEFAULT_MINIMUM_FAST_PEERS- See Also:
-
PROP_MINIMUM_HIGH_CAPACITY_PEERS
Defines the minimum number of 'high capacity' peers that the organizer should select when using the mean - if less than this many are available, select the capacity by the median.- See Also:
-
DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS
public static final int DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS- See Also:
-
-
Constructor Details
-
ProfileOrganizer
-
-
Method Details
-
setUs
-
getUs
-
getSpeedThreshold
public double getSpeedThreshold() -
getCapacityThreshold
public double getCapacityThreshold() -
getIntegrationThreshold
public double getIntegrationThreshold() -
getProfile
Retrieve the profile for the given peer, if one exists (else null). Blocking if a reorganize is happening. -
getProfileNonblocking
Retrieve the profile for the given peer, if one exists (else null). Non-blocking. Returns null if a reorganize is happening.- Since:
- 0.8.12
-
getOrCreateProfileNonblocking
Retrieve the profile for the given peer, if one exists. If it does not exist and it can get the lock, it will create and return a new profile. Non-blocking. Returns null if a reorganize is happening.- Since:
- 0.9.47
-
addProfile
Add the new profile, returning the old value (or null if no profile existed) -
countFastPeers
public int countFastPeers() -
countHighCapacityPeers
public int countHighCapacityPeers() -
countWellIntegratedPeers
Deprecated.use ProfileManager.getPeersByCapability('f').size() -
countNotFailingPeers
public int countNotFailingPeers() -
countFailingPeers
public int countFailingPeers() -
countActivePeers
public int countActivePeers() -
isFast
-
isHighCapacity
-
isWellIntegrated
-
isFailing
Deprecated for now, always false -
clearProfiles
void clearProfiles()- Since:
- 0.8.8
-
peerSendsBadReplies
Does the given peer send us bad replies - either invalid store messages (expired, corrupt, etc) or unreachable replies (pointing towards routers that don't exist). -
exportProfile
- Returns:
- true if successful, false if not found
- Throws:
IOException
-
selectFastPeers
Return a set of Hashes for peers that are both fast and reliable. If an insufficient number of peers are both fast and reliable, fall back onto high capacity peers, and if that doesn't contain sufficient peers, fall back onto not failing peers, and even THAT doesn't have sufficient peers, fall back onto failing peers.- Parameters:
howMany
- how many peers are desiredexclude
- set of Hashes for routers that we don't want selectedmatches
- set to store the return value in
-
selectFastPeers
public void selectFastPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are both fast and reliable. If an insufficient number of peers are both fast and reliable, fall back onto high capacity peers, and if that doesn't contain sufficient peers, fall back onto not failing peers, and even THAT doesn't have sufficient peers, fall back onto failing peers.- Parameters:
howMany
- how many peers are desiredexclude
- set of Hashes for routers that we don't want selectedmatches
- set to store the return value inmask
- 0-4 Number of bytes to match to determine if peers in the same IP range should not be in the same tunnel. 0 = disable check; 1 = /8; 2 = /16; 3 = /24; 4 = exact IP matchipSet
- in/out param, use for multiple calls, may be null only if mask is 0- Since:
- 0.9.53 added ipSet param
-
selectFastPeers
public void selectFastPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, SessionKey randomKey, ProfileOrganizer.Slice subTierMode, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are both fast and reliable. If an insufficient number of peers are both fast and reliable, fall back onto high capacity peers, and if that doesn't contain sufficient peers, fall back onto not failing peers, and even THAT doesn't have sufficient peers, fall back onto failing peers.- Parameters:
howMany
- how many peers are desiredexclude
- set of Hashes for routers that we don't want selectedmatches
- set to store the return value inrandomKey
- used for deterministic random partitioning into subtierssubTierMode
- 0 or 2-7:0: no partitioning, use entire tier 2: return only from group 0 or 1 3: return only from group 2 or 3 4: return only from group 0 5: return only from group 1 6: return only from group 2 7: return only from group 3
mask
- 0-4ipSet
- in/out param, use for multiple calls, may be null only if mask is 0- Since:
- 0.9.53 added mask and ipSet params
-
selectHighCapacityPeers
Return a set of Hashes for peers that have a high capacity -
selectHighCapacityPeers
public void selectHighCapacityPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) - Parameters:
mask
- 0-4 Number of bytes to match to determine if peers in the same IP range should not be in the same tunnel. 0 = disable check; 1 = /8; 2 = /16; 3 = /24; 4 = exact IP matchipSet
- in/out param, use for multiple calls, may be null only if mask is 0- Since:
- 0.9.53 added ipSet param
-
selectNotFailingPeers
Return a set of Hashes for peers that are not failing, preferring ones that we are already talking with -
selectNotFailingPeers
public void selectNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) - Parameters:
mask
- ignored, should call locked_selectPeers, to be fixedipSet
- ignored, should call locked_selectPeers, to be fixed- Since:
- 0.9.53 added ipSet param
-
selectNotFailingPeers
-
selectNotFailingPeers
public void selectNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, boolean onlyNotFailing, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are not failing, preferring ones that we are already talking with- Parameters:
howMany
- how many peers to findexclude
- what peers to skip (may be null)matches
- set to store the matches inonlyNotFailing
- if true, don't include any high capacity peersmask
- ignored, should call locked_selectPeers, to be fixedipSet
- ignored, should call locked_selectPeers, to be fixed- Since:
- 0.9.53 added ipSet param
-
selectActiveNotFailingPeers
Return a set of Hashes for peers that are both not failing and we're actively talking with. We use commSystem().isEstablished(), not profile.getIsActive(), as the NTCP idle time is now shorter than the 5 minute getIsActive() threshold, and we're using this to try and limit connections. Caution, this does NOT cascade further to non-connected peers, so it should only be used when there is a good number of connected peers.- Parameters:
exclude
- non-null, WARNING - side effect, all not-connected peers are added
-
selectActiveNotFailingPeers
public void selectActiveNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet) Return a set of Hashes for peers that are both not failing and we're actively talking with. We use commSystem().isEstablished(), not profile.getIsActive(), as the NTCP idle time is now shorter than the 5 minute getIsActive() threshold, and we're using this to try and limit connections. Caution, this does NOT cascade further to non-connected peers, so it should only be used when there is a good number of connected peers.- Parameters:
exclude
- non-null, WARNING - side effect, all not-connected peers are addedmask
- 0-4 Number of bytes to match to determine if peers in the same IP range should not be in the same tunnel. 0 = disable check; 1 = /8; 2 = /16; 3 = /24; 4 = exact IP matchipSet
- may be null only if mask is 0- Since:
- 0.9.53
-
selectAllNotFailingPeers
public void selectAllNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, boolean onlyNotFailing) Return a set of Hashes for peers that are not failing. -
selectPeersLocallyUnreachable
Get the peers the transport layer thinks are unreachable, and peers requiring introducers. -
selectPeersRecentlyRejecting
Get the peers that have recently rejected us for bandwidth recent == last 20s -
selectAllPeers
Find the hashes for all peers we are actively profiling -
reorganize
void reorganize()Place peers into the correct tier, as well as expand/contract and even drop profiles according to whatever limits are in place. Peer profiles are not coalesced during this method, but the averages are recalculated. -
reorganize
void reorganize(boolean shouldCoalesce, boolean shouldDecay) -
isSelectable
-
getMinimumFastPeers
protected int getMinimumFastPeers()Defines the minimum number of 'fast' peers that the organizer should select. If the profile calculators derive a threshold that does not select at least this many peers, the threshold will be overridden to make sure this many peers are in the fast+reliable group. This parameter should help deal with a lack of diversity in the tunnels created when some peers are particularly fast. Increase default for every local destination, up to a max.- Returns:
- minimum number of peers to be placed in the 'fast' group
-
getMaximumFastPeers
protected int getMaximumFastPeers()fixme add config @since 0.7.10 -
getMaximumHighCapPeers
protected int getMaximumHighCapPeers()fixme add config @since 0.7.11 -
getMinimumHighCapacityPeers
protected int getMinimumHighCapacityPeers()Defines the minimum number of 'fast' peers that the organizer should select. If the profile calculators derive a threshold that does not select at least this many peers, the threshold will be overridden to make sure this many peers are in the fast+reliable group. This parameter should help deal with a lack of diversity in the tunnels created when some peers are particularly fast.- Returns:
- minimum number of peers to be placed in the 'fast' group
-
main
Read in all of the profiles specified and print out their calculated values. Usage:ProfileOrganizer [filename]*
-