java.lang.Object
net.i2p.router.tunnel.TunnelGateway
- Direct Known Subclasses:
PumpedTunnelGateway, TunnelGatewayZeroHop
Serve as the gatekeeper for a tunnel, accepting messages, coalescing and/or fragmenting them before wrapping them up for tunnel delivery. The flow here. is:
- add an I2NPMessage (and a target tunnel/router, if necessary)
- that message is queued up into a TunnelGateway.Pending and offered to the assigned QueuePreprocessor.
- that QueuePreprocessor may then take off any of the TunnelGateway.Pending messages or instruct the TunnelGateway to offer it the messages again in a short while (in an attempt to coalesce them).
- when the QueueProcessor accepts a TunnelGateway.Pending, it preprocesses it into fragments, forwarding each preprocessed fragment group through the Sender.
- the Sender then encrypts the preprocessed data and delivers it to the Receiver.
- the Receiver now has the encrypted message and may do with it as it pleases (e.g. wrap it as necessary and enqueue it onto the OutNetMessagePool, or if debugging, verify that it can be decrypted properly)
Unused directly - see PumpedTunnelGateway, ThrottledPumpedTunnelGateway, and TunnelGatewayZeroHop overrides.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classDelayed flush timer event.static interfaceInterface for preprocessing queued tunnel messages.static interfaceInterface for receiving encrypted tunnel data.static interfaceInterface for sending preprocessed tunnel data.Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RouterContextThe router context.protected final TunnelGateway.DelayedFlushThe delayed flush timer.protected longThe last flush time.protected final LogThe log instance.protected intThe messages sent count.protected final TunnelGateway.QueuePreprocessorThe queue preprocessor.protected final List<PendingGatewayMessage> The message queue.protected final TunnelGateway.ReceiverThe message receiver, consuming encrypted messages for forwarding.protected final TunnelGateway.SenderThe message sender, encrypting and forwarding preprocessed messages.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTunnelGateway(RouterContext context, TunnelGateway.QueuePreprocessor preprocessor, TunnelGateway.Sender sender, TunnelGateway.Receiver receiver) Creates a new TunnelGateway.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanadd(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) Add a message to be sent down the tunnel, either sending it now (perhaps coalesced with other pending messages) or after a brief pause (_flushFrequency).booleanadd(TunnelGatewayMessage msg) Add a message to be sent down the tunnel, where we are the inbound gateway.intThe number of messages sent.
Field Details
_context
The router context._log
The log instance._queue
The message queue._preprocessor
The queue preprocessor._sender
The message sender, encrypting and forwarding preprocessed messages._receiver
The message receiver, consuming encrypted messages for forwarding._lastFlush
protected long _lastFlushThe last flush time._delayedFlush
The delayed flush timer._messagesSent
protected int _messagesSentThe messages sent count.
Constructor Details
TunnelGateway
protected TunnelGateway(RouterContext context, TunnelGateway.QueuePreprocessor preprocessor, TunnelGateway.Sender sender, TunnelGateway.Receiver receiver) Creates a new TunnelGateway.- Parameters:
context- the router contextpreprocessor- this pulls Pending messages off a list, builds some full preprocessed messages, and pumps those into the sendersender- this takes a preprocessed message, encrypts it, and sends it to the receiverreceiver- this receives the encrypted message and forwards it off to the first hop
Method Details
add
Add a message to be sent down the tunnel, where we are the inbound gateway.- Parameters:
msg- message received to be sent through the tunnel- Returns:
- true if the message was accepted, false if dropped
add
Add a message to be sent down the tunnel, either sending it now (perhaps coalesced with other pending messages) or after a brief pause (_flushFrequency). If it is queued up past its expiration, it is silently dropped.UNUSED - see overrides.
- Parameters:
msg- message to be sent through the tunneltoRouter- router to send to after the endpoint (or null for endpoint processing)toTunnel- tunnel to send to after the endpoint (or null for endpoint or router processing)- Returns:
- true if the message was accepted, false if dropped
getMessagesSent
public int getMessagesSent()The number of messages sent.- Returns:
- the number of messages sent