net.i2p.router.tunnel.pool

## Class TunnelPeerSelector

- java.lang.Object
- - net.i2p.router.tunnel.pool.ConnectChecker
  - - net.i2p.router.tunnel.pool.TunnelPeerSelector

- Direct Known Subclasses:
    ClientPeerSelector, ExploratoryPeerSelector

      public abstract class TunnelPeerSelector
      extends ConnectChecker

  Coordinate the selection of peers to go into a tunnel for one particular pool.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `TunnelPeerSelector.Excluder` Excluder that automatically adds peers to the set when they should be excluded.

  - ### Field Summary

    - ### Fields inherited from class net.i2p.router.tunnel.pool.ConnectChecker

      `ANY_V4, ctx, log`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `TunnelPeerSelector(RouterContext context)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `allowAsIBGW(Hash h)` Should we allow as IBGW? This just checks for the "R" capability and IPv4 support.
    `protected boolean` | `allowAsOBEP(Hash h)` Should we allow as OBEP? This just checks for IPv4 support.
    `protected boolean` | `checkTunnel(boolean isInbound, boolean isExploratory, List<Hash> tunnel)` Connectivity check.
    `protected boolean` | `filterSlow(boolean isInbound, boolean isExploratory)` do we want to skip peers that are slow?
    `protected Set<Hash>` | `getClosestHopExclude(boolean isInbound, Set<Hash> toAdd)` Pick peers that we want to avoid for the first OB hop or last IB hop.
    `protected Set<Hash>` | `getExclude(boolean isInbound, boolean isExploratory)` As of 0.9.58, this returns a set populated only by TunnelManager.selectPeersInTooManyTunnels(), for passing to ProfileOrganizer.
    `protected int` | `getLength(TunnelPoolSettings settings)`
    `protected boolean` | `isIPv6Only()` Are we IPv6 only?
    `protected void` | `orderPeers(List<Hash> rv, SessionKey key)` see HashComparator
    `protected List<Hash>` | `selectExplicit(TunnelPoolSettings settings, int length)` For debugging, also possibly for restricted routes.
    `abstract List<Hash>` | `selectPeers(TunnelPoolSettings settings)` Which peers should go into the next tunnel for the given settings?
    `static boolean` | `shouldExclude(RouterContext ctx, RouterInfo peer)` Should the peer be excluded based on its published caps, crypto, and version?
    `protected boolean` | `shouldSelectExplicit(TunnelPoolSettings settings)` For debugging, also possibly for restricted routes? Needs analysis and testing

    - ### Methods inherited from class net.i2p.router.tunnel.pool.ConnectChecker

      `canConnect, canConnect, canConnect, getInboundMask, getOutboundMask, isNTCPDisabled, isSSUDisabled`

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

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

- - ### Constructor Detail

    - #### TunnelPeerSelector

          protected TunnelPeerSelector(RouterContext context)

  - ### Method Detail

    - #### allowAsIBGW

          protected boolean allowAsIBGW(Hash h)

      Should we allow as IBGW? This just checks for the "R" capability and IPv4 support. Will return false for hidden or IPv6-only. This is intended for tunnel candidates, where we already have the RI. Will not force RI lookups. Default true.

    - #### allowAsOBEP

          protected boolean allowAsOBEP(Hash h)

      Should we allow as OBEP? This just checks for IPv4 support. Will return false for IPv6-only. This is intended for tunnel candidates, where we already have the RI. Will not force RI lookups. Default true.

    - #### checkTunnel

          protected boolean checkTunnel(boolean isInbound,
                                        boolean isExploratory,
                                        List<Hash> tunnel)

      Connectivity check. Check that each hop can connect to the next, including us. Check that the OBEP is not IPv6-only, and the IBGW is reachable and not hidden or IPv6-only. Tells the profile manager to blame the hop, and returns false on failure.
      Parameters:
        `tunnel` - ENDPOINT FIRST, GATEWAY LAST!!!!, length 2 or greater
      Returns:
        ok

    - #### filterSlow

          protected boolean filterSlow(boolean isInbound,
                                       boolean isExploratory)

      do we want to skip peers that are slow?
      Returns:
        true unless configured otherwise

    - #### getClosestHopExclude

          protected Set<Hash> getClosestHopExclude(boolean isInbound,
                                                   Set<Hash> toAdd)

      Pick peers that we want to avoid for the first OB hop or last IB hop. There's several cases of importance:
      1. Inbound and we are hidden - Exclude all unless connected. This is taken care of in ClientPeerSelector and TunnelPeerSelector selectPeers(), not here.
      2. We are IPv6-only. Exclude all v4-only peers, unless connected This is taken care of here.
      3. We have NTCP or SSU disabled. Exclude all incompatible peers, unless connected This is taken care of here.
      4. Minimum version check, if we are some brand-new sig type, or are using some new tunnel build method. Not currently used, but this is where to implement the checks if needed. Make sure that ClientPeerSelector and TunnelPeerSelector selectPeers() call this when needed.
      As of 0.9.58, this a set with only toAdd, for use in ProfileOrganizer. The set will be populated via the contains() calls.
      Parameters:
        `isInbound` -
      Returns:
        non-null

    - #### getExclude

          protected Set<Hash> getExclude(boolean isInbound,
                                         boolean isExploratory)

      As of 0.9.58, this returns a set populated only by TunnelManager.selectPeersInTooManyTunnels(), for passing to ProfileOrganizer. The set will be populated via the contains() calls.

    - #### getLength

          protected int getLength(TunnelPoolSettings settings)

      Returns:
        randomized number of hops 0-7, not including ourselves

    - #### isIPv6Only

          protected boolean isIPv6Only()

      Are we IPv6 only?

    - #### orderPeers

          protected void orderPeers(List<Hash> rv,
                                    SessionKey key)

      see HashComparator

    - #### selectExplicit

          protected List<Hash> selectExplicit(TunnelPoolSettings settings,
                                              int length)

      For debugging, also possibly for restricted routes. Needs analysis and testing
      Parameters:
        `settings` - the tunnel pool settings
        `length` - the desired length of the tunnel
      Returns:
        the list of explicit peer hashes for the tunnel

    - #### selectPeers

          public abstract List<Hash> selectPeers(TunnelPoolSettings settings)

      Which peers should go into the next tunnel for the given settings?
      Returns:
        ordered list of Hash objects (one per peer) specifying what order they should appear in a tunnel (ENDPOINT FIRST). This includes the local router in the list. If there are no tunnels or peers to build through, and the settings reject 0 hop tunnels, this will return null.

    - #### shouldExclude

          public static boolean shouldExclude(RouterContext ctx,
                                              RouterInfo peer)

      Should the peer be excluded based on its published caps, crypto, and version?
      Parameters:
        `ctx` - Router context for peer count checks
        `peer` - The peer to evaluate
      Returns:
        true if the peer should be excluded

    - #### shouldSelectExplicit

          protected boolean shouldSelectExplicit(TunnelPoolSettings settings)

      For debugging, also possibly for restricted routes? Needs analysis and testing
      Returns:
        usually false