net.i2p.router.peermanager
Class ProfileOrganizer

java.lang.Object
  extended by net.i2p.router.peermanager.ProfileOrganizer

public class ProfileOrganizer
extends java.lang.Object

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).


Field Summary
static int DEFAULT_MINIMUM_FAST_PEERS
           
static int DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS
           
static java.lang.String PROP_MINIMUM_FAST_PEERS
          Defines the minimum number of 'fast' peers that the organizer should select.
static java.lang.String 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.
 
Constructor Summary
ProfileOrganizer(RouterContext context)
           
 
Method Summary
 PeerProfile addProfile(PeerProfile profile)
          Add the new profile, returning the old value (or null if no profile existed)
 int countActivePeers()
           
 int countFailingPeers()
           
 int countFastPeers()
           
 int countHighCapacityPeers()
           
 int countNotFailingPeers()
           
 int countWellIntegratedPeers()
           
 void exportProfile(Hash profile, java.io.OutputStream out)
           
 double getCapacityThreshold()
           
 double getIntegrationThreshold()
           
protected  int getMaximumFastPeers()
          fixme add config @since 0.7.10
protected  int getMaximumHighCapPeers()
          fixme add config @since 0.7.11
protected  int getMinimumFastPeers()
          Defines the minimum number of 'fast' peers that the organizer should select.
protected  int getMinimumHighCapacityPeers()
          Defines the minimum number of 'fast' peers that the organizer should select.
 PeerProfile getProfile(Hash peer)
          Retrieve the profile for the given peer, if one exists (else null)
 double getSpeedThreshold()
           
 Hash getUs()
           
 boolean isFailing(Hash peer)
           
 boolean isFast(Hash peer)
           
 boolean isHighCapacity(Hash peer)
           
 boolean isSelectable(Hash peer)
           
 boolean isWellIntegrated(Hash peer)
           
static void main(java.lang.String[] args)
          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).
 void reorganize()
          Place peers into the correct tier, as well as expand/contract and even drop profiles according to whatever limits are in place.
 void reorganize(boolean shouldCoalesce)
           
 void selectActiveNotFailingPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches)
          Return a set of Hashes for peers that are both not failing and we're actively talking with.
 void selectAllNotFailingPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches, boolean onlyNotFailing)
          Return a set of Hashes for peers that are not failing.
 java.util.Set<Hash> selectAllPeers()
          Find the hashes for all peers we are actively profiling
 void selectFailingPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches)
          I'm not quite sure why you'd want this...
 void selectFastPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches)
          Return a set of Hashes for peers that are both fast and reliable.
 void selectFastPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches, int mask)
           
 void selectHighCapacityPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches)
          Return a set of Hashes for peers that have a high capacity
 void selectHighCapacityPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches, int mask)
           
 void selectNotFailingPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches)
          Return a set of Hashes for peers that are not failing, preferring ones that we are already talking with
 void selectNotFailingPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches, boolean onlyNotFailing)
           
 void selectNotFailingPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches, boolean onlyNotFailing, int mask)
          Return a set of Hashes for peers that are not failing, preferring ones that we are already talking with
 void selectNotFailingPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches, int mask)
           
 java.util.List<Hash> selectPeersLocallyUnreachable()
          Get the peers the transport layer thinks are unreachable, and add in the peers with the SSU peer testing bug, and peers requiring introducers.
 java.util.List<Hash> selectPeersRecentlyRejecting()
          Get the peers that have recently rejected us for bandwidth recent == last 20s
 void selectWellIntegratedPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches)
          Return a set of Hashes for peers that are well integrated into the network.
 void selectWellIntegratedPeers(int howMany, java.util.Set<Hash> exclude, java.util.Set<Hash> matches, int mask)
           
 void setUs(Hash us)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_MINIMUM_FAST_PEERS

public static final java.lang.String PROP_MINIMUM_FAST_PEERS
Defines the minimum number of 'fast' peers that the organizer should select. See getMinimumFastPeers()

See Also:
Constant Field Values

DEFAULT_MINIMUM_FAST_PEERS

public static final int DEFAULT_MINIMUM_FAST_PEERS
See Also:
Constant Field Values

PROP_MINIMUM_HIGH_CAPACITY_PEERS

public static final java.lang.String 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:
Constant Field Values

DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS

public static final int DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS
See Also:
Constant Field Values
Constructor Detail

ProfileOrganizer

public ProfileOrganizer(RouterContext context)
Method Detail

setUs

public void setUs(Hash us)

getUs

public Hash getUs()

getSpeedThreshold

public double getSpeedThreshold()

getCapacityThreshold

public double getCapacityThreshold()

getIntegrationThreshold

public double getIntegrationThreshold()

getProfile

public PeerProfile getProfile(Hash peer)
Retrieve the profile for the given peer, if one exists (else null)


addProfile

public PeerProfile addProfile(PeerProfile profile)
Add the new profile, returning the old value (or null if no profile existed)


countFastPeers

public int countFastPeers()

countHighCapacityPeers

public int countHighCapacityPeers()

countWellIntegratedPeers

public int countWellIntegratedPeers()

countNotFailingPeers

public int countNotFailingPeers()

countFailingPeers

public int countFailingPeers()

countActivePeers

public int countActivePeers()

isFast

public boolean isFast(Hash peer)

isHighCapacity

public boolean isHighCapacity(Hash peer)

isWellIntegrated

public boolean isWellIntegrated(Hash peer)

isFailing

public boolean isFailing(Hash peer)

peerSendsBadReplies

public 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).


exportProfile

public void exportProfile(Hash profile,
                          java.io.OutputStream out)
                   throws java.io.IOException
Throws:
java.io.IOException

selectFastPeers

public void selectFastPeers(int howMany,
                            java.util.Set<Hash> exclude,
                            java.util.Set<Hash> matches)
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 desired
exclude - set of Hashes for routers that we don't want selected
matches - set to store the return value in

selectFastPeers

public void selectFastPeers(int howMany,
                            java.util.Set<Hash> exclude,
                            java.util.Set<Hash> matches,
                            int mask)

selectHighCapacityPeers

public void selectHighCapacityPeers(int howMany,
                                    java.util.Set<Hash> exclude,
                                    java.util.Set<Hash> matches)
Return a set of Hashes for peers that have a high capacity


selectHighCapacityPeers

public void selectHighCapacityPeers(int howMany,
                                    java.util.Set<Hash> exclude,
                                    java.util.Set<Hash> matches,
                                    int mask)

selectWellIntegratedPeers

public void selectWellIntegratedPeers(int howMany,
                                      java.util.Set<Hash> exclude,
                                      java.util.Set<Hash> matches)
Return a set of Hashes for peers that are well integrated into the network.


selectWellIntegratedPeers

public void selectWellIntegratedPeers(int howMany,
                                      java.util.Set<Hash> exclude,
                                      java.util.Set<Hash> matches,
                                      int mask)

selectNotFailingPeers

public void selectNotFailingPeers(int howMany,
                                  java.util.Set<Hash> exclude,
                                  java.util.Set<Hash> matches)
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,
                                  java.util.Set<Hash> exclude,
                                  java.util.Set<Hash> matches,
                                  int mask)

selectNotFailingPeers

public void selectNotFailingPeers(int howMany,
                                  java.util.Set<Hash> exclude,
                                  java.util.Set<Hash> matches,
                                  boolean onlyNotFailing)

selectNotFailingPeers

public void selectNotFailingPeers(int howMany,
                                  java.util.Set<Hash> exclude,
                                  java.util.Set<Hash> matches,
                                  boolean onlyNotFailing,
                                  int mask)
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 find
exclude - what peers to skip (may be null)
matches - set to store the matches in
onlyNotFailing - if true, don't include any high capacity peers

selectActiveNotFailingPeers

public void selectActiveNotFailingPeers(int howMany,
                                        java.util.Set<Hash> exclude,
                                        java.util.Set<Hash> matches)
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 No mask parameter, to be fixed

selectAllNotFailingPeers

public void selectAllNotFailingPeers(int howMany,
                                     java.util.Set<Hash> exclude,
                                     java.util.Set<Hash> matches,
                                     boolean onlyNotFailing)
Return a set of Hashes for peers that are not failing.


selectFailingPeers

public void selectFailingPeers(int howMany,
                               java.util.Set<Hash> exclude,
                               java.util.Set<Hash> matches)
I'm not quite sure why you'd want this... (other than for failover from the better results)


selectPeersLocallyUnreachable

public java.util.List<Hash> selectPeersLocallyUnreachable()
Get the peers the transport layer thinks are unreachable, and add in the peers with the SSU peer testing bug, and peers requiring introducers.


selectPeersRecentlyRejecting

public java.util.List<Hash> selectPeersRecentlyRejecting()
Get the peers that have recently rejected us for bandwidth recent == last 20s


selectAllPeers

public java.util.Set<Hash> selectAllPeers()
Find the hashes for all peers we are actively profiling


reorganize

public 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

public void reorganize(boolean shouldCoalesce)

isSelectable

public boolean isSelectable(Hash peer)

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 by two 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

public static void main(java.lang.String[] args)
Read in all of the profiles specified and print out their calculated values. Usage:
  ProfileOrganizer [filename]*