Package net.i2p.router.tunnel
Class TunnelDispatcher
java.lang.Object
net.i2p.router.tunnel.TunnelDispatcher
- All Implemented Interfaces:
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
Modifier and TypeClassDescription(package private) static enum
for shouldDropParticipatingMessage() -
Constructor Summary
ConstructorDescriptionCreates a new instance of TunnelDispatcher -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispatch
(TunnelDataMessage msg, Hash recvFrom) We are participating in a tunnel (perhaps we're even the endpoint), so take the message and do what it says.void
We are the inbound tunnel gateway, so encrypt it as necessary and forward it on.void
dispatchOutbound
(I2NPMessage msg, TunnelId outboundTunnel, Hash targetPeer) We are the outbound tunnel gateway (we created it), so wrap up this message with instructions to be forwarded to the targetPeer when it reaches the endpoint.void
dispatchOutbound
(I2NPMessage msg, TunnelId outboundTunnel, TunnelId targetTunnel, Hash targetPeer) We are the outbound tunnel gateway (we created it), so wrap up this message with instructions to be forwarded to the targetTunnel on the targetPeer when it reaches the endpoint.long
what is the date/time on which the last non-locally-created tunnel expires?Get a new random receive tunnel ID that isn't a dup.Get a new random receive tunnel ID that isn't a dup.Get a new random send tunnel ID that isn't a dup.int
static int
boolean
We are the inbound endpoint - we created this tunnelboolean
We are the inbound gateway in this tunnel, and did not create itboolean
We are the outbound gateway - we created this tunnelboolean
We are the outbound endpoint in this tunnel, and did not create itboolean
joinParticipant
(HopConfig cfg) We are a participant in this tunnel, but not as the endpoint or gatewayOnly for console TunnelRenderer.void
No longer participate in the tunnel that someone asked us to be a member ofvoid
We no longer want to participate in this tunnel that we createdvoid
renderStatusHTML
(Writer out) Deprecated.moved to router consolevoid
restart()
Perform a soft restart.boolean
shouldDropParticipatingMessage
(TunnelDispatcher.Location loc, int type, int length) Implement random early discard (RED) to enforce the share bandwidth limit.void
shutdown()
Instruct the service that the router is shutting down and that it should do whatever is necessary to go down gracefully.void
startup()
startupvoid
updateParticipatingStats
(int ms) Generate a current estimate of usage per-participating-tunnel lifetime.
-
Constructor Details
-
TunnelDispatcher
Creates a new instance of TunnelDispatcher
-
-
Method Details
-
joinOutbound
We are the outbound gateway - we created this tunnel- Returns:
- success; false if Tunnel ID is a duplicate
-
joinInbound
We are the inbound endpoint - we created this tunnel- Returns:
- success; false if Tunnel ID is a duplicate
-
joinParticipant
We are a participant in this tunnel, but not as the endpoint or gateway- Returns:
- success; false if Tunnel ID is a duplicate
-
joinOutboundEndpoint
We are the outbound endpoint in this tunnel, and did not create it- Returns:
- success; false if Tunnel ID is a duplicate
-
joinInboundGateway
We are the inbound gateway in this tunnel, and did not create it- Returns:
- success; false if Tunnel ID is a duplicate
-
getParticipatingCount
public int getParticipatingCount() -
getNewOBGWID
Get a new random send tunnel ID that isn't a dup. Note that we do not keep track of IDs for pending builds so this does not fully prevent joinOutbound() from failing later.- Since:
- 0.9.5
-
getNewIBEPID
Get a new random receive tunnel ID that isn't a dup. Not for zero hop tunnels. Note that we do not keep track of IDs for pending builds so this does not fully prevent joinInbound() from failing later.- Since:
- 0.9.5
-
getNewIBZeroHopID
Get a new random receive tunnel ID that isn't a dup. For zero hop tunnels only. Note that we do not keep track of IDs for pending builds so this does not fully prevent joinInbound() from failing later.- Since:
- 0.9.5
-
getLastParticipatingExpiration
public long getLastParticipatingExpiration()what is the date/time on which the last non-locally-created tunnel expires? -
remove
We no longer want to participate in this tunnel that we created -
remove
No longer participate in the tunnel that someone asked us to be a member of -
dispatch
We are participating in a tunnel (perhaps we're even the endpoint), so take the message and do what it says. If there are later hops, that means encrypt a layer and forward it on. If there aren't later hops, how we handle it depends upon whether we created it or not. If we didn't, simply honor the instructions. If we did, unwrap all the layers of encryption and honor those instructions (within reason). -
dispatch
We are the inbound tunnel gateway, so encrypt it as necessary and forward it on. -
dispatchOutbound
We are the outbound tunnel gateway (we created it), so wrap up this message with instructions to be forwarded to the targetPeer when it reaches the endpoint.- Parameters:
msg
- raw message to deliver to the target peeroutboundTunnel
- tunnel to send the message out, or null for directtargetPeer
- peer to receive the message
-
dispatchOutbound
public void dispatchOutbound(I2NPMessage msg, TunnelId outboundTunnel, TunnelId targetTunnel, Hash targetPeer) We are the outbound tunnel gateway (we created it), so wrap up this message with instructions to be forwarded to the targetTunnel on the targetPeer when it reaches the endpoint.- Parameters:
msg
- raw message to deliver to the targetTunnel on the targetPeeroutboundTunnel
- tunnel to send the message outtargetTunnel
- tunnel on the targetPeer to deliver the message to, or null for directtargetPeer
- gateway to the tunnel to receive the message
-
listParticipatingTunnels
Only for console TunnelRenderer.- Returns:
- a copy
-
updateParticipatingStats
public void updateParticipatingStats(int ms) Generate a current estimate of usage per-participating-tunnel lifetime. The router code calls this every 'ms' millisecs. This is better than waiting until the tunnel expires to update the rate, as we want this to be current because it's an important part of the throttle code. Stay a little conservative by taking the counts only for tunnels 1-10m old and computing the average from that. -
shouldDropParticipatingMessage
Implement random early discard (RED) to enforce the share bandwidth limit. For now, this does not enforce the available bandwidth, we leave that to Throttle. This is similar to the code in ../RouterThrottleImpl.java We drop in proportion to how far over the limit we are. Perhaps an exponential function would be better? The drop probability is adjusted for the size of the message. At this stage, participants and IBGWs see a standard 1024 byte message. OBEPs however may see a wide variety of sizes. Network-wise, it's most efficient to drop OBEP messages, because they are unfragmented and we know their size. Therefore we drop the big ones and we drop a single wrapped I2CP message, not a fragment of one or more messages. Also, the OBEP is the earliest identifiable hop in the message's path (a plain participant could be earlier or later, but on average is later)- Parameters:
loc
- message hop locationtype
- I2NP message typelength
- the length of the message
-
startup
public void startup()startup -
shutdown
public void shutdown()Description copied from interface:Service
Instruct the service that the router is shutting down and that it should do whatever is necessary to go down gracefully. It should not depend on other components at this point. This call DOES block. -
restart
public void restart()Description copied from interface:Service
Perform a soft restart. -
renderStatusHTML
Deprecated.moved to router console- Specified by:
renderStatusHTML
in interfaceService
- Throws:
IOException
-