java.lang.Object
net.i2p.router.tunnel.TunnelParticipant

class TunnelParticipantextends Object
Participates in a tunnel at an intermediate hop (not gateway or endpoint). Handles message dispatching, bandwidth throttling, fragment reassembly, and next-hop routing.

Optimized for hosting many tunnels efficiently.

  • Field Details

    • _context

      private final RouterContext _context
      The router context.
    • _log

      private final Log _log
      Logger for the tunnel participant.
    • _config

      private final HopConfig _config
      The hop configuration of our tunnel.
    • _processor

      private final HopProcessor _processor
      Processes the messages for the next hop.
    • _inboundEndpointProcessor

      private final InboundEndpointProcessor _inboundEndpointProcessor
      Processes the messages when we are the endpoint.
    • _inboundDistributor

      private final InboundMessageDistributor _inboundDistributor
      Distributes the messages we relay onward.
    • _handler

      private final FragmentHandler _handler
      Reassembles the fragmented lease sets.
    • _partBWE

      private final SyntheticREDQueue _partBWE
      Queue estimating the outbound share used while relaying.
    • _nextHopCache

      private volatile RouterInfo _nextHopCache
      The cached next hop router info.
    • MAX_LOOKUP_TIME

      private static final long MAX_LOOKUP_TIME
      Time allowed for a next hop lookup.
      See Also:
    • LONG_MAX_LOOKUP_TIME

      private static final long LONG_MAX_LOOKUP_TIME
      Longer lookup time for the inbound gateway.
      See Also:
    • PRIORITY

      private static final int PRIORITY
      Send priority of the messages we relay.
      See Also:
    • DEFAULT_BW_PER_TUNNEL_ESTIMATE

      static final int DEFAULT_BW_PER_TUNNEL_ESTIMATE
      Default bandwidth per tunnel estimate, about 340 Bps, sized for high bandwidth contexts.
      See Also:
  • Constructor Details

    • TunnelParticipant

      public TunnelParticipant(RouterContext ctx, HopConfig config, HopProcessor processor)
      For intermediate tunnel participant (not endpoint).
      Parameters:
      ctx - the router context supplying the log and the tunnel pools
      config - the hop configuration this participant is running, which carries the bandwidth allocation and RED queue settings
      processor - the hop processor that forwards the reassembled message to the next hop
    • TunnelParticipant

      public TunnelParticipant(RouterContext ctx, InboundEndpointProcessor inEndProc)
      For inbound tunnel endpoints.
      Parameters:
      ctx - the router context supplying the log and the tunnel pools
      inEndProc - the processor that reassembles and decrypts inbound tunnel messages and delivers them to this endpoint's destination
    • TunnelParticipant

      private TunnelParticipant(RouterContext ctx, HopConfig config, HopProcessor processor, InboundEndpointProcessor inEndProc)
      Internal constructor shared by all variants.
      Parameters:
      ctx - the router context supplying the log and the tunnel pools
      config - the hop configuration, null for inbound endpoints
      processor - the hop processor, null for inbound endpoints
      inEndProc - the inbound endpoint processor, null for intermediate hops
  • Method Details

    • formatBandwidth

      private static String formatBandwidth(int bps)
      Format a bandwidth value in B/s to a human-readable string.
      Parameters:
      bps - the bandwidth in bytes per second
      Returns:
      the value with a B/s, KB/s, MB/s or GB/s unit chosen by magnitude
    • dispatch

      public void dispatch(TunnelDataMessage msg, Hash recvFrom)
      Process an incoming tunnel data message.
      Parameters:
      msg - the 1024 byte tunnel data message that arrived on this tunnel
      recvFrom - the hash of the gateway that delivered the message, used to blame the hop that mangled or dropped it
    • logDispatchFailure

      private void logDispatchFailure(TunnelDataMessage msg)
      Log a failure to dispatch a tunnel data message.
      Parameters:
      msg - the message that could not be dispatched
    • blameTunnelPeers

      private void blameTunnelPeers(TunnelCreatorConfig cfg)
      Distribute blame among tunnel peers when message processing fails.
      Parameters:
      cfg - the config of the tunnel whose peers are blamed
    • getCompleteCount

      public int getCompleteCount()
      The number of completed fragmented messages.
      Returns:
      the complete count
    • getFailedCount

      public int getFailedCount()
      The number of failed fragmented messages.
      Returns:
      the failed count
    • getExpiration

      public long getExpiration()
      When the tunnel expires, or -1 if unknown.
      Returns:
      tunnel expiration time, or -1 if unknown
    • send

      private void send(HopConfig config, TunnelDataMessage msg, RouterInfo ri)
      Forward a tunnel message to the next hop. Resets the expiration to 20s from now, and drops the message instead of forwarding it once it is more than 75s past its original expiration.
      Parameters:
      config - the next hop's config, used for the send-to peer
      msg - the tunnel data message to forward
      ri - the next hop's router info, null to look it up by hash
    • toString

      public String toString()
      Description of the participant role and its config.
      Overrides:
      toString in class Object