net.i2p.router.tunnel

## Class TunnelDispatcher

- java.lang.Object
- - net.i2p.router.tunnel.TunnelDispatcher

- All Implemented Interfaces:
    Service

      public class TunnelDispatcher
      extends Object
      implements Service

  Handle the actual processing and forwarding of messages through the various tunnels.

        For each type of tunnel, it creates a chain of handlers, as follows:

        Following tunnels are created by us:

          Outbound Gateway > 0 hops:
             PumpedTunnelGateway
               BatchedRouterPreprocessor -> OutboundSender -> OutboundReceiver -> OutNetMessagePool

          Outbound zero-hop Gateway+Endpoint:
             TunnelGatewayZeroHop
               OutboundMessageDistributor -> OutNetMessagePool

          Inbound Endpoint > 0 hops:
             TunnelParticipant
              RouterFragmentHandler ->  InboundEndpointProcessor -> InboundMessageDistributor -> InNetMessagePool

          Inbound zero-hop Gateway+Endpoint:
             TunnelGatewayZeroHop
               InboundMessageDistributor -> InNetMessagePool

        Following tunnels are NOT created by us:

          Participant (not gateway or endpoint)
             TunnelParticipant
               HopProcessor -> OutNetMessagePool

          Outbound Endpoint > 0 hops:
             OutboundTunnelEndpoint
               RouterFragmentHandler -> HopProcessor -> OutboundMessageDistributor -> OutNetMessagePool

          Inbound Gateway > 0 hops:
             ThrottledPumpedTunnelGateway
               BatchedRouterPreprocessor -> InboundSender -> InboundGatewayReceiver -> OutNetMessagePool

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TunnelDispatcher.Location` Location in the tunnel for RED logic

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TunnelDispatcher(RouterContext ctx)` Creates a new instance of TunnelDispatcher

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `dispatch(TunnelDataMessage msg, Hash recvFrom)` Dispatch a TunnelDataMessage to the appropriate participant or endpoint
    `void` | `dispatch(TunnelGatewayMessage msg)` Dispatch a TunnelGatewayMessage to the appropriate gateway
    `void` | `dispatchOutbound(I2NPMessage msg, TunnelId outboundTunnel, Hash targetPeer)` Dispatch an outbound message through a tunnel
    `void` | `dispatchOutbound(I2NPMessage msg, TunnelId outboundTunnel, TunnelId targetTunnel, Hash targetPeer)`
    `int` | `getAllocatedBW()` Get the total bandwidth allocated for participating tunnels
    `long` | `getLastParticipatingExpiration()` Returns the timestamp of the last participating tunnel expiration.
    `(package private) int` | `getMaxPerTunnelBandwidth(TunnelDispatcher.Location loc)` Get the max bandwidth per tunnel
    `TunnelId` | `getNewIBEPID()` Get a new random receive tunnel ID that isn't a duplicate
    `TunnelId` | `getNewIBZeroHopID()` Get a new random receive tunnel ID that isn't a duplicate (zero hop)
    `TunnelId` | `getNewOBGWID()` Get a new random send tunnel ID that isn't a duplicate
    `int` | `getParticipatingCount()` Get the number of participating tunnels
    `static int` | `getShareBandwidth(RouterContext ctx)` Get the current bandwidth share in KBps
    `boolean` | `hasOutboundGateway(TunnelId tid)`
    `boolean` | `joinInbound(TunnelCreatorConfig cfg)` We are the inbound endpoint - we created this tunnel
    `boolean` | `joinInboundGateway(HopConfig cfg)` We are the inbound gateway in this tunnel, and did not create it
    `boolean` | `joinOutbound(PooledTunnelCreatorConfig cfg)` We are the outbound gateway - we created this tunnel
    `boolean` | `joinOutboundEndpoint(HopConfig cfg)` We are the outbound endpoint in this tunnel, and did not create it
    `boolean` | `joinParticipant(HopConfig cfg)` We are a participant in this tunnel, but not as the endpoint or gateway
    `List<HopConfig>` | `listParticipatingTunnels()` Get a list of participating tunnels (for console display)
    `void` | `remove(HopConfig cfg)` Remove a tunnel we're participating in
    `void` | `remove(TunnelCreatorConfig cfg)` Remove a tunnel we created
    `void` | `renderStatusHTML(Writer out)` Deprecated.
    `void` | `restart()` Restart the TunnelDispatcher
    `(package private) boolean` | `shouldDropParticipatingMessage(TunnelDispatcher.Location loc, int type, int length, SyntheticREDQueue bwe)` Implement RED (Random Early Discard) to enforce bandwidth limits
    `void` | `shutdown()` Shut down TunnelDispatcher
    `void` | `startup()` Start up the TunnelDispatcher
    `void` | `updateParticipatingStats(int ms)` Update stats for participating tunnels

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

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

- - ### Constructor Detail

    - #### TunnelDispatcher

          public TunnelDispatcher(RouterContext ctx)

      Creates a new instance of TunnelDispatcher

  - ### Method Detail

    - #### dispatch

          public void dispatch(TunnelDataMessage msg,
                               Hash recvFrom)

      Dispatch a TunnelDataMessage to the appropriate participant or endpoint

    - #### dispatch

          public void dispatch(TunnelGatewayMessage msg)

      Dispatch a TunnelGatewayMessage to the appropriate gateway

    - #### dispatchOutbound

          public void dispatchOutbound(I2NPMessage msg,
                                       TunnelId outboundTunnel,
                                       Hash targetPeer)

      Dispatch an outbound message through a tunnel

    - #### dispatchOutbound

          public void dispatchOutbound(I2NPMessage msg,
                                       TunnelId outboundTunnel,
                                       TunnelId targetTunnel,
                                       Hash targetPeer)

    - #### getAllocatedBW

          public int getAllocatedBW()

      Get the total bandwidth allocated for participating tunnels

    - #### getLastParticipatingExpiration

          public long getLastParticipatingExpiration()

      Returns the timestamp of the last participating tunnel expiration.

    - #### getMaxPerTunnelBandwidth

          int getMaxPerTunnelBandwidth(TunnelDispatcher.Location loc)

      Get the max bandwidth per tunnel

    - #### getNewIBEPID

          public TunnelId getNewIBEPID()

      Get a new random receive tunnel ID that isn't a duplicate

    - #### getNewIBZeroHopID

          public TunnelId getNewIBZeroHopID()

      Get a new random receive tunnel ID that isn't a duplicate (zero hop)

    - #### getNewOBGWID

          public TunnelId getNewOBGWID()

      Get a new random send tunnel ID that isn't a duplicate

    - #### getParticipatingCount

          public int getParticipatingCount()

      Get the number of participating tunnels

    - #### getShareBandwidth

          public static int getShareBandwidth(RouterContext ctx)

      Get the current bandwidth share in KBps

    - #### hasOutboundGateway

          public boolean hasOutboundGateway(TunnelId tid)

      Returns:
        true if we currently have an outbound gateway for the given TunnelId. This helps callers determine if a tunnel is ready for outbound dispatch.

    - #### joinInbound

          public boolean joinInbound(TunnelCreatorConfig cfg)

      We are the inbound endpoint - we created this tunnel
      Returns:
        true if successful, false if tunnel ID is a duplicate

    - #### joinInboundGateway

          public boolean joinInboundGateway(HopConfig cfg)

      We are the inbound gateway in this tunnel, and did not create it
      Returns:
        true if successful, false if tunnel ID is a duplicate

    - #### joinOutbound

          public boolean joinOutbound(PooledTunnelCreatorConfig cfg)

      We are the outbound gateway - we created this tunnel
      Returns:
        true if successful, false if tunnel ID is a duplicate

    - #### joinOutboundEndpoint

          public boolean joinOutboundEndpoint(HopConfig cfg)

      We are the outbound endpoint in this tunnel, and did not create it
      Returns:
        true if successful, false if tunnel ID is a duplicate

    - #### joinParticipant

          public boolean joinParticipant(HopConfig cfg)

      We are a participant in this tunnel, but not as the endpoint or gateway
      Returns:
        true if successful, false if tunnel ID is a duplicate

    - #### listParticipatingTunnels

          public List<HopConfig> listParticipatingTunnels()

      Get a list of participating tunnels (for console display)

    - #### remove

          public void remove(HopConfig cfg)

      Remove a tunnel we're participating in

    - #### remove

          public void remove(TunnelCreatorConfig cfg)

      Remove a tunnel we created

    - #### renderStatusHTML

          @Deprecated
          public void renderStatusHTML(Writer out)
                                            throws IOException

      Deprecated.
      Render status HTML (deprecated)
      Specified by:
        `renderStatusHTML` in interface `Service`
      Throws:
        `IOException`

    - #### restart

          public void restart()

      Restart the TunnelDispatcher
      Specified by:
        `restart` in interface `Service`

    - #### shouldDropParticipatingMessage

          boolean shouldDropParticipatingMessage(TunnelDispatcher.Location loc,
                                                 int type,
                                                 int length,
                                                 SyntheticREDQueue bwe)

      Implement RED (Random Early Discard) to enforce bandwidth limits

    - #### shutdown

          public void shutdown()

      Shut down TunnelDispatcher
      Specified by:
        `shutdown` in interface `Service`

    - #### startup

          public void startup()

      Start up the TunnelDispatcher
      Specified by:
        `startup` in interface `Service`

    - #### updateParticipatingStats

          public void updateParticipatingStats(int ms)

      Update stats for participating tunnels