java.lang.Object
net.i2p.router.client.ClientMessageEventListener
- All Implemented Interfaces:
I2CPMessageReader.I2CPMessageEventListener
class ClientMessageEventListenerextends Object implements I2CPMessageReader.I2CPMessageEventListener
Receive events from the client and handle them accordingly (updating the runner when necessary).
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumOutcome of validating a client-supplied receive request against the state the router holds for this connection.Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RouterContextThe router context.protected final ClientConnectionRunnerThe client connection runner.Constructor Summary
ConstructorsConstructorDescriptionClientMessageEventListener(RouterContext context, ClientConnectionRunner runner, boolean enforceAuth) Create a new event listener for the given client connection.Method Summary
Modifier and TypeMethodDescription(package private) static ClientMessageEventListener.ReceiveRequestclassifyReceiveBegin(SessionConfig cfg, Payload payload) Validate a ReceiveMessageBeginMessage before any retained payload is read.(package private) static ClientMessageEventListener.ReceiveRequestclassifyReceiveEnd(SessionConfig cfg, Payload payload) Validate a ReceiveMessageEndMessage before the retained payload is released.voiddisconnected(I2CPMessageReader reader) Notify the listener that the stream this reader was reading was closed.protected voidHandle a CreateLeaseSet message.protected voidhandleDestLookup(DestLookupMessage message) Handle a DestLookup message.protected voidDivide router limit by 1.5 for overhead.protected voidhandleHostLookup(HostLookupMessage message) Handle a HostLookup message.voidmessageReceived(I2CPMessageReader reader, I2CPMessage message) Handle an incoming message and dispatch it to the appropriate handler.voidreadError(I2CPMessageReader reader, Exception error) Handle notification that there was an error.protected voidstartCreateSessionJob(SessionConfig config) Override for testing.
Field Details
_context
The router context._runner
The client connection runner.
Constructor Details
ClientMessageEventListener
public ClientMessageEventListener(RouterContext context, ClientConnectionRunner runner, boolean enforceAuth) Create a new event listener for the given client connection.- Parameters:
context- the router contextrunner- the client connection runnerenforceAuth- set false for in-JVM, true for socket access
Method Details
messageReceived
Handle an incoming message and dispatch it to the appropriate handler.- Specified by:
messageReceivedin interfaceI2CPMessageReader.I2CPMessageEventListener- Parameters:
reader- I2CPMessageReader to notifymessage- the I2CPMessage
readError
Handle notification that there was an error.- Specified by:
readErrorin interfaceI2CPMessageReader.I2CPMessageEventListener- Parameters:
reader- I2CPMessageReader to notifyerror- Exception that was thrown, non-null
disconnected
Description copied from interface:I2CPMessageReader.I2CPMessageEventListenerNotify the listener that the stream this reader was reading was closed. For most errors, readError() will be called first, as of 0.9.41.- Specified by:
disconnectedin interfaceI2CPMessageReader.I2CPMessageEventListener- Parameters:
reader- I2CPMessageReader to notify
startCreateSessionJob
Override for testing.- Parameters:
config- the session config
classifyReceiveBegin
static ClientMessageEventListener.ReceiveRequest classifyReceiveBegin(SessionConfig cfg, Payload payload) Validate a ReceiveMessageBeginMessage before any retained payload is read.The router keeps a single payload map per connection, not per session, so a message that names a message id alone is not enough to authorize access. The message must also name a live session on this connection. Session-level validation is the right granularity because every session on a connection must already share one keypair, so sessions of one connection are not mutually untrusted.
- Parameters:
cfg- the session named by the message, or null if there is no such sessionpayload- the retained payload for the message id, or null if none is retained- Returns:
- the request outcome, never null
classifyReceiveEnd
static ClientMessageEventListener.ReceiveRequest classifyReceiveEnd(SessionConfig cfg, Payload payload) Validate a ReceiveMessageEndMessage before the retained payload is released.Uses the same rule as
classifyReceiveBegin(SessionConfig, Payload): the message must name a live session on this connection, and the payload must actually be retained. A message id that is not retained needs no action, so it is reported separately from a rejected session.- Parameters:
cfg- the session named by the message, or null if there is no such sessionpayload- the retained payload for the message id, or null if none is retained- Returns:
- the request outcome, never null
handleCreateLeaseSet
Handle a CreateLeaseSet message. Override for testing.- Parameters:
message- the client request supplying the LeaseSet, its signing keys, and the session it applies to
handleDestLookup
Handle a DestLookup message. Override for testing.- Parameters:
message- the request naming the RouterInfo hash to resolve
handleHostLookup
Handle a HostLookup message. Override for testing.- Parameters:
message- the lookup request supplying the session and request ID
handleGetBWLimits
Divide router limit by 1.5 for overhead. This could someday give a different answer to each client. But it's not enforced anywhere.protected for unit test override.
- Parameters:
message- the client's bandwidth query, which carries no data