java.lang.Object
net.i2p.router.tunnel.TunnelParticipant
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.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classCallback for defragmented tunnel messages.private classHandle router info lookup completion.private classJob to send a message after router lookup completes.private classJob to handle timeout for router lookup.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HopConfigThe hop configuration of our tunnel.private final RouterContextThe router context.private final FragmentHandlerReassembles the fragmented lease sets.private final InboundMessageDistributorDistributes the messages we relay onward.private final InboundEndpointProcessorProcesses the messages when we are the endpoint.private final LogLogger for the tunnel participant.private RouterInfoThe cached next hop router info.private final SyntheticREDQueueQueue estimating the outbound share used while relaying.private final HopProcessorProcesses the messages for the next hop.(package private) static final intDefault bandwidth per tunnel estimate, about 340 Bps, sized for high bandwidth contexts.private static final longLonger lookup time for the inbound gateway.private static final longTime allowed for a next hop lookup.private static final intSend priority of the messages we relay.Constructor Summary
ModifierConstructorDescriptionTunnelParticipant(RouterContext ctx, HopConfig config, HopProcessor processor) For intermediate tunnel participant (not endpoint).privateTunnelParticipant(RouterContext ctx, HopConfig config, HopProcessor processor, InboundEndpointProcessor inEndProc) Internal constructor shared by all variants.TunnelParticipant(RouterContext ctx, InboundEndpointProcessor inEndProc) For inbound tunnel endpoints.Method Summary
Modifier and TypeMethodDescriptionprivate voidDistribute blame among tunnel peers when message processing fails.voiddispatch(TunnelDataMessage msg, Hash recvFrom) Process an incoming tunnel data message.private static StringformatBandwidth(int bps) Format a bandwidth value in B/s to a human-readable string.intThe number of completed fragmented messages.longWhen the tunnel expires, or -1 if unknown.intThe number of failed fragmented messages.private voidLog a failure to dispatch a tunnel data message.private voidsend(HopConfig config, TunnelDataMessage msg, RouterInfo ri) Forward a tunnel message to the next hop.toString()Description of the participant role and its config.
Field Details
_context
The router context._log
Logger for the tunnel participant._config
The hop configuration of our tunnel._processor
Processes the messages for the next hop._inboundEndpointProcessor
Processes the messages when we are the endpoint._inboundDistributor
Distributes the messages we relay onward._handler
Reassembles the fragmented lease sets._partBWE
Queue estimating the outbound share used while relaying._nextHopCache
The cached next hop router info.MAX_LOOKUP_TIME
private static final long MAX_LOOKUP_TIMETime allowed for a next hop lookup.- See Also:
LONG_MAX_LOOKUP_TIME
private static final long LONG_MAX_LOOKUP_TIMELonger lookup time for the inbound gateway.- See Also:
PRIORITY
private static final int PRIORITYSend priority of the messages we relay.- See Also:
DEFAULT_BW_PER_TUNNEL_ESTIMATE
static final int DEFAULT_BW_PER_TUNNEL_ESTIMATEDefault bandwidth per tunnel estimate, about 340 Bps, sized for high bandwidth contexts.- See Also:
Constructor Details
TunnelParticipant
For intermediate tunnel participant (not endpoint).- Parameters:
ctx- the router context supplying the log and the tunnel poolsconfig- the hop configuration this participant is running, which carries the bandwidth allocation and RED queue settingsprocessor- the hop processor that forwards the reassembled message to the next hop
TunnelParticipant
For inbound tunnel endpoints.- Parameters:
ctx- the router context supplying the log and the tunnel poolsinEndProc- 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 poolsconfig- the hop configuration, null for inbound endpointsprocessor- the hop processor, null for inbound endpointsinEndProc- the inbound endpoint processor, null for intermediate hops
Method Details
formatBandwidth
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
Process an incoming tunnel data message.- Parameters:
msg- the 1024 byte tunnel data message that arrived on this tunnelrecvFrom- the hash of the gateway that delivered the message, used to blame the hop that mangled or dropped it
logDispatchFailure
Log a failure to dispatch a tunnel data message.- Parameters:
msg- the message that could not be dispatched
blameTunnelPeers
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
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 peermsg- the tunnel data message to forwardri- the next hop's router info, null to look it up by hash
toString