Class TunnelPool

  • Direct Known Subclasses:
    AliasedTunnelPool

    public class TunnelPool
    extends Object
    A group of tunnels for the router or a particular client, in a single direction. Public only for TunnelRenderer in router console.
    • Field Detail

      • _log

        protected final Log _log
      • _alive

        protected volatile boolean _alive
    • Method Detail

      • startup

        void startup()
        Warning, this may be called more than once (without an intervening shutdown()) if the tunnel is stopped and then restarted by the client manager with the same Destination (i.e. for servers or clients w/ persistent key, or restarting close-on-idle clients)
      • shutdown

        void shutdown()
      • getRateName

        public String getRateName()
        RateStat name for the bandwidth graph
        Returns:
        non-null
        Since:
        0.9.35
      • selectTunnel

        TunnelInfo selectTunnel()
        Pull a random tunnel out of the pool. If there are none available but the pool is configured to allow 0hop tunnels, this builds a fake one and returns it.
        Returns:
        null on failure, but it should always build and return a fallback
      • selectTunnel

        TunnelInfo selectTunnel​(Hash closestTo)
        Return the tunnel from the pool that is XOR-closet to the target. By using this instead of the random selectTunnel(), we force some locality in OBEP-IBGW connections to minimize those connections network-wide. Does not check for backlogged next peer. Does not return an expired tunnel.
        Returns:
        null on failure
        Since:
        0.8.10
      • listTunnels

        public List<TunnelInfo> listTunnels()
        Return a list of tunnels in the pool
        Returns:
        A copy of the list of TunnelInfo objects
      • needFallback

        boolean needFallback()
        Do we really need more fallbacks? Used to prevent a zillion of them. Does not check config, only call if config allows zero hop.
      • getTunnelCount

        int getTunnelCount()
        duplicate of size(), let's pick one
      • isAlive

        public boolean isAlive()
        Is this pool running AND either exploratory, or tracked by the client manager? A pool will be alive but not tracked after the client manager removes it but before all the tunnels have expired.
      • size

        public int size()
        duplicate of getTunnelCount(), let's pick one
      • addTunnel

        void addTunnel​(TunnelInfo info)
        Add to the pool.
      • removeTunnel

        void removeTunnel​(TunnelInfo info)
        Remove from the pool.
      • tunnelFailed

        void tunnelFailed​(TunnelInfo cfg)
        Remove the tunnel and blame all the peers (not necessarily equally). This may be called multiple times from TestJob.
      • tunnelFailed

        void tunnelFailed​(TunnelInfo cfg,
                          Hash blamePeer)
        Remove the tunnel and blame only one peer. This may be called multiple times.
        Since:
        0.8.13
      • refreshLeaseSet

        void refreshLeaseSet()
        noop for outbound and exploratory
      • buildFallback

        boolean buildFallback()
        This will build a fallback (zero-hop) tunnel ONLY if this pool is exploratory, or the settings allow it.
        Returns:
        true if a fallback tunnel is built
      • locked_buildNewLeaseSet

        protected LeaseSet locked_buildNewLeaseSet()
        Build a leaseSet with the required tunnels that aren't about to expire. Caller must synchronize on _tunnels. The returned LeaseSet will be incomplete; it will not have the destination set and will not be signed. Only the leases will be included.
        Returns:
        null on failure
      • getLifetimeProcessed

        public long getLifetimeProcessed()
      • countHowManyToBuild

        int countHowManyToBuild()
        Gather the data to see how many tunnels to build, and then actually compute that value (delegated to the countHowManyToBuild function below)
      • configureNewTunnel

        PooledTunnelCreatorConfig configureNewTunnel()
        This only sets the peers and creation/expiration times in the configuration. For the crypto, see BuildRequestor and BuildMessageGenerator.
        Returns:
        null on failure