Class ProfileOrganizer


  • public class ProfileOrganizer
    extends 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 Detail

      • 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 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). Blocking if a reorganize is happening.
      • getProfileNonblocking

        public PeerProfile getProfileNonblocking​(Hash peer)
        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

        PeerProfile getOrCreateProfileNonblocking​(Hash peer)
        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

        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

        @Deprecated
        public int countWellIntegratedPeers()
        Deprecated.
        use ProfileManager.getPeersByCapability('f').size()
      • 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)
        Deprecated for now, always false
      • clearProfiles

        void clearProfiles()
        Since:
        0.8.8
      • 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).
      • selectFastPeers

        public void selectFastPeers​(int howMany,
                                    Set<Hash> exclude,
                                    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,
                                    Set<Hash> exclude,
                                    Set<Hash> matches,
                                    int mask)
        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
        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 match
      • selectFastPeers

        public void selectFastPeers​(int howMany,
                                    Set<Hash> exclude,
                                    Set<Hash> matches,
                                    SessionKey randomKey,
                                    ProfileOrganizer.Slice subTierMode)
        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
        randomKey - used for deterministic random partitioning into subtiers
        subTierMode - 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
        
      • selectHighCapacityPeers

        public void selectHighCapacityPeers​(int howMany,
                                            Set<Hash> exclude,
                                            Set<Hash> matches)
        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)
        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 match
      • selectWellIntegratedPeers

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

        @Deprecated
        public void selectWellIntegratedPeers​(int howMany,
                                              Set<Hash> exclude,
                                              Set<Hash> matches,
                                              int mask)
        Deprecated.
        unused
        Return a set of Hashes for peers that are well integrated into the network.
        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 match
      • selectNotFailingPeers

        public 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 with
      • selectNotFailingPeers

        public void selectNotFailingPeers​(int howMany,
                                          Set<Hash> exclude,
                                          Set<Hash> matches,
                                          int mask)
        Parameters:
        mask - ignored, should call locked_selectPeers, to be fixed
      • selectNotFailingPeers

        public void selectNotFailingPeers​(int howMany,
                                          Set<Hash> exclude,
                                          Set<Hash> matches,
                                          boolean onlyNotFailing)
      • selectNotFailingPeers

        public void selectNotFailingPeers​(int howMany,
                                          Set<Hash> exclude,
                                          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
        mask - ignored, should call locked_selectPeers, to be fixed
      • selectActiveNotFailingPeers

        public 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. 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 No mask parameter, to be fixed
      • 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.
      • selectFailingPeers

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

        public List<Hash> selectPeersLocallyUnreachable()
        Get the peers the transport layer thinks are unreachable, and peers requiring introducers.
      • selectPeersRecentlyRejecting

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

        public Set<Hash> 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

        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 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​(String[] args)
        Read in all of the profiles specified and print out their calculated values. Usage:
          ProfileOrganizer [filename]*