java.lang.Object
net.i2p.client.impl.I2PSessionDemultiplexer
- All Implemented Interfaces:
I2PSessionListener, I2PSessionMuxedListener
Implement multiplexing with a 1-byte 'protocol' and a two-byte 'port'. Listeners register with either
addListener(I2PSessionListener, int, int) or addMuxedListener(), depending on whether they want to hear about the protocol, from port, and to port for every received message.messageAvailable(I2PSession, int, long) only calls one listener, not all that apply. The others call all listeners.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classFor listeners that don't care about proto and ports.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<Integer, I2PSessionMuxedListener> Muxed listeners, by protocol and port.private final LogLogger for this class.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidaddListener(I2PSessionListener l, int proto, int port) For those that don't need to hear about the protocol and ports in messageAvailable() (Streaming lib).voidaddMuxedListener(I2PSessionMuxedListener l, int proto, int port) For those that do care UDP perhaps.voiddisconnected(I2PSession session) Notify the client that the session has been terminated.voiderrorOccurred(I2PSession session, String message, Throwable error) Notify the client that some error occurred.private I2PSessionMuxedListenerfindListener(int proto, int port) Find the one listener that most specifically matches the request.private I2PSessionMuxedListenergetListener(int proto, int port) Finds the listener for a protocol and port pair.private static Integerkey(int proto, int port) Combines a protocol and port into one map key.voidmessageAvailable(I2PSession session, int msgId, long size) Intentional no-op.voidmessageAvailable(I2PSession session, int msgId, long size, int proto, int fromport, int toport) Notify the best-matching listener for the protocol and port.static StringprotocolNumberToString(int proto) Convert a protocol number to a human-readable string.voidremoveListener(int proto, int port) Remove a listener for the given protocol and port.voidreportAbuse(I2PSession session, int severity) Instruct the client that the session specified seems to be under attack and that the client may wish to move its destination to another router.
Field Details
_log
Logger for this class._listeners
Muxed listeners, by protocol and port.
Constructor Details
I2PSessionDemultiplexer
Create a new demultiplexer.- Parameters:
ctx- supplies the log
Method Details
messageAvailable
Intentional no-op. Notifications reach a registered listener through the four-argument overload below, which knows the protocol and ports to match on. A muxed session never calls this one, because its availability notifier is the MuxedAvailabilityNotifier.- Specified by:
messageAvailablein interfaceI2PSessionListener- Specified by:
messageAvailablein interfaceI2PSessionMuxedListener- Parameters:
session- session to notifymsgId- message number availablesize- size of the message payload in bytes
messageAvailable
public void messageAvailable(I2PSession session, int msgId, long size, int proto, int fromport, int toport) Notify the best-matching listener for the protocol and port.- Specified by:
messageAvailablein interfaceI2PSessionMuxedListener- Parameters:
session- session to notifymsgId- message number availablesize- size of the message payload in bytesproto- 1-254 or 0 for unspecifiedfromport- 1-65535 or 0 for unspecifiedtoport- 1-65535 or 0 for unspecified
protocolNumberToString
Convert a protocol number to a human-readable string.- Parameters:
proto- anI2PSessionprotocol number, or 0 for any- Returns:
- human-readable protocol name, or null if unrecognised
reportAbuse
Description copied from interface:I2PSessionMuxedListenerInstruct the client that the session specified seems to be under attack and that the client may wish to move its destination to another router. All registered listeners will be called.Unused. Not fully implemented.
- Specified by:
reportAbusein interfaceI2PSessionListener- Specified by:
reportAbusein interfaceI2PSessionMuxedListener- Parameters:
session- session to report abuse toseverity- how bad the abuse is
disconnected
Description copied from interface:I2PSessionMuxedListenerNotify the client that the session has been terminated. All registered listeners will be called.- Specified by:
disconnectedin interfaceI2PSessionListener- Specified by:
disconnectedin interfaceI2PSessionMuxedListener- Parameters:
session- the session that was terminated
errorOccurred
Description copied from interface:I2PSessionMuxedListenerNotify the client that some error occurred. All registered listeners will be called.- Specified by:
errorOccurredin interfaceI2PSessionListener- Specified by:
errorOccurredin interfaceI2PSessionMuxedListener- Parameters:
session- the session that reported the errormessage- a human-readable description of the errorerror- the cause, non-null
addListener
For those that don't need to hear about the protocol and ports in messageAvailable() (Streaming lib).- Parameters:
l- the listenerproto- the protocol numberport- the port number
addMuxedListener
For those that do care UDP perhaps.- Parameters:
l- the listenerproto- the protocol numberport- the port number
removeListener
public void removeListener(int proto, int port) Remove a listener for the given protocol and port.- Parameters:
proto- the protocol numberport- the port number
findListener
Find the one listener that most specifically matches the request.- Parameters:
proto- the protocol numberport- the port number- Returns:
- the best-matching listener, or null if none matches
getListener
Finds the listener for a protocol and port pair.- Parameters:
proto- the protocol numberport- the port number- Returns:
- the listener, null if none is registered
key
Combines a protocol and port into one map key.- Parameters:
proto- the protocol numberport- the port number- Returns:
- the key