net.i2p.router.peermanager

## Class ProfileOrganizer

- java.lang.Object
- - net.i2p.router.peermanager.ProfileOrganizer

-     public class ProfileOrganizer
      extends Object

  Categorizes peers into performance tiers based on historical metrics. Requires periodic reorganize() calls to update peer classifications for optimal tunnel selection.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ProfileOrganizer.Slice` Defines peer selection slicing modes for tier-based peer organization.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ABSOLUTE_MAX_PROFILES`
    `static int` | `DEFAULT_MAX_PROFILES`
    `static int` | `DEFAULT_MINIMUM_FAST_PEERS`
    `static int` | `DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS`
    `static String` | `PROP_MAX_PROFILES`
    `static String` | `PROP_MINIMUM_FAST_PEERS`
    `static String` | `PROP_MINIMUM_HIGH_CAPACITY_PEERS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ProfileOrganizer(RouterContext context)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `PeerProfile` | `addProfile(PeerProfile profile)`
    `(package private) void` | `clearProfiles()`
    `int` | `countActivePeers()`
    `int` | `countActivePeersInLastHour()`
    `int` | `countFastPeers()`
    `int` | `countHighCapacityPeers()`
    `int` | `countNotFailingPeers()`
    `boolean` | `exportProfile(Hash profile, OutputStream out)`
    `double` | `getCapacityThreshold()`
    `double` | `getIntegrationThreshold()`
    `protected int` | `getMaximumFastPeers()`
    `protected int` | `getMaximumHighCapPeers()`
    `protected int` | `getMinimumFastPeers()`
    `protected int` | `getMinimumHighCapacityPeers()`
    `(package private) PeerProfile` | `getOrCreateProfileNonblocking(Hash peer)`
    `PeerProfile` | `getProfile(Hash peer)`
    `PeerProfile` | `getProfileNonblocking(Hash peer)`
    `double` | `getSpeedThreshold()`
    `Hash` | `getUs()`
    `boolean` | `isFast(Hash peer)`
    `boolean` | `isHighCapacity(Hash peer)`
    `boolean` | `isSelectable(Hash peer)`
    `boolean` | `isWellIntegrated(Hash peer)`
    `static void` | `main(String[] args)`
    `boolean` | `peerSendsBadReplies(Hash peer)`
    `void` | `purgeStaleProfileFiles()`
    `(package private) void` | `reorganize()`
    `(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)`
    `void` | `selectActiveNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet)`
    `void` | `selectAllNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, boolean onlyNotFailing)`
    `Set<Hash>` | `selectAllPeers()`
    `void` | `selectFastPeers(int howMany, Set<Hash> exclude, Set<Hash> matches)`
    `void` | `selectFastPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet)`
    `void` | `selectFastPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, SessionKey randomKey, ProfileOrganizer.Slice subTierMode, int mask, MaskedIPSet ipSet)`
    `void` | `selectHighCapacityPeers(int howMany, Set<Hash> exclude, Set<Hash> matches)`
    `void` | `selectHighCapacityPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet)`
    `void` | `selectNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches)`
    `void` | `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)`
    `void` | `selectNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask, MaskedIPSet ipSet)`
    `void` | `setUs(Hash us)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ABSOLUTE_MAX_PROFILES

          public static final int ABSOLUTE_MAX_PROFILES

      See Also:
        Constant Field Values

    - #### DEFAULT_MAX_PROFILES

          public static final int DEFAULT_MAX_PROFILES

    - #### DEFAULT_MINIMUM_FAST_PEERS

          public static final int DEFAULT_MINIMUM_FAST_PEERS

      See Also:
        Constant Field Values

    - #### DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS

          public static final int DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS

      See Also:
        Constant Field Values

    - #### PROP_MAX_PROFILES

          public static final String PROP_MAX_PROFILES

      See Also:
        Constant Field Values

    - #### PROP_MINIMUM_FAST_PEERS

          public static final String PROP_MINIMUM_FAST_PEERS

      See Also:
        Constant Field Values

    - #### PROP_MINIMUM_HIGH_CAPACITY_PEERS

          public static final String PROP_MINIMUM_HIGH_CAPACITY_PEERS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ProfileOrganizer

          public ProfileOrganizer(RouterContext context)

  - ### Method Detail

    - #### addProfile

          public PeerProfile addProfile(PeerProfile profile)

    - #### clearProfiles

          void clearProfiles()

    - #### countActivePeers

          public int countActivePeers()

    - #### countActivePeersInLastHour

          public int countActivePeersInLastHour()

    - #### countFastPeers

          public int countFastPeers()

    - #### countHighCapacityPeers

          public int countHighCapacityPeers()

    - #### countNotFailingPeers

          public int countNotFailingPeers()

    - #### exportProfile

          public boolean exportProfile(Hash profile,
                                       OutputStream out)
                                throws IOException

      Throws:
        `IOException`

    - #### getCapacityThreshold

          public double getCapacityThreshold()

    - #### getIntegrationThreshold

          public double getIntegrationThreshold()

    - #### getMaximumFastPeers

          protected int getMaximumFastPeers()

    - #### getMaximumHighCapPeers

          protected int getMaximumHighCapPeers()

    - #### getMinimumFastPeers

          protected int getMinimumFastPeers()

    - #### getMinimumHighCapacityPeers

          protected int getMinimumHighCapacityPeers()

    - #### getOrCreateProfileNonblocking

          PeerProfile getOrCreateProfileNonblocking(Hash peer)

    - #### getProfile

          public PeerProfile getProfile(Hash peer)

    - #### getProfileNonblocking

          public PeerProfile getProfileNonblocking(Hash peer)

    - #### getSpeedThreshold

          public double getSpeedThreshold()

    - #### getUs

          public Hash getUs()

    - #### isFast

          public boolean isFast(Hash peer)

    - #### isHighCapacity

          public boolean isHighCapacity(Hash peer)

    - #### isSelectable

          public boolean isSelectable(Hash peer)

    - #### isWellIntegrated

          public boolean isWellIntegrated(Hash peer)

    - #### main

          public static void main(String[] args)

    - #### peerSendsBadReplies

          public boolean peerSendsBadReplies(Hash peer)

    - #### purgeStaleProfileFiles

          public void purgeStaleProfileFiles()

    - #### reorganize

          void reorganize()

    - #### reorganize

          void reorganize(boolean shouldCoalesce,
                          boolean shouldDecay)

      Reorganizes peer profiles into performance-based tiers (fast, high-capacity, etc.) and expires stale entries.

      This method:

      - Coalesces and decays stats if requested and uptime conditions are met.
      - Filters out unreachable, inactive, or low-tier peers.
      - Recalculates dynamic thresholds for speed, capacity, and integration.
      - Rebuilds internal tier maps and the global profile ordering.
      - Expires profiles that haven't been active recently to bound memory usage.

      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.

      Parameters:
        `shouldCoalesce` - if `true`, coalesce statistics for active profiles
        `shouldDecay` - if `true` and coalescing is performed, apply decay to historical stats

    - #### selectActiveNotFailingPeers

          public void selectActiveNotFailingPeers(int howMany,
                                                  Set<Hash> exclude,
                                                  Set<Hash> matches)

    - #### selectActiveNotFailingPeers

          public void selectActiveNotFailingPeers(int howMany,
                                                  Set<Hash> exclude,
                                                  Set<Hash> matches,
                                                  int mask,
                                                  MaskedIPSet ipSet)

    - #### selectAllNotFailingPeers

          public void selectAllNotFailingPeers(int howMany,
                                               Set<Hash> exclude,
                                               Set<Hash> matches,
                                               boolean onlyNotFailing)

    - #### selectAllPeers

          public Set<Hash> selectAllPeers()

    - #### selectFastPeers

          public void selectFastPeers(int howMany,
                                      Set<Hash> exclude,
                                      Set<Hash> matches)

    - #### selectFastPeers

          public void selectFastPeers(int howMany,
                                      Set<Hash> exclude,
                                      Set<Hash> matches,
                                      int mask,
                                      MaskedIPSet ipSet)

    - #### selectFastPeers

          public void selectFastPeers(int howMany,
                                      Set<Hash> exclude,
                                      Set<Hash> matches,
                                      SessionKey randomKey,
                                      ProfileOrganizer.Slice subTierMode,
                                      int mask,
                                      MaskedIPSet ipSet)

    - #### selectHighCapacityPeers

          public void selectHighCapacityPeers(int howMany,
                                              Set<Hash> exclude,
                                              Set<Hash> matches)

    - #### selectHighCapacityPeers

          public void selectHighCapacityPeers(int howMany,
                                              Set<Hash> exclude,
                                              Set<Hash> matches,
                                              int mask,
                                              MaskedIPSet ipSet)

    - #### selectNotFailingPeers

          public void selectNotFailingPeers(int howMany,
                                            Set<Hash> exclude,
                                            Set<Hash> matches)

    - #### 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,
                                            MaskedIPSet ipSet)

    - #### selectNotFailingPeers

          public void selectNotFailingPeers(int howMany,
                                            Set<Hash> exclude,
                                            Set<Hash> matches,
                                            int mask,
                                            MaskedIPSet ipSet)

    - #### setUs

          public void setUs(Hash us)