java.lang.Object
net.i2p.client.impl.I2PSessionDemultiplexer
All Implemented Interfaces:
I2PSessionListener, I2PSessionMuxedListener

public class I2PSessionDemultiplexerextends Object implements 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.

  • Field Details

  • Constructor Details

    • I2PSessionDemultiplexer

      public I2PSessionDemultiplexer(I2PAppContext ctx)
      Create a new demultiplexer.
      Parameters:
      ctx - supplies the log
  • Method Details

    • messageAvailable

      public void messageAvailable(I2PSession session, int msgId, long size)
      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:
      messageAvailable in interface I2PSessionListener
      Specified by:
      messageAvailable in interface I2PSessionMuxedListener
      Parameters:
      session - session to notify
      msgId - message number available
      size - 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:
      messageAvailable in interface I2PSessionMuxedListener
      Parameters:
      session - session to notify
      msgId - message number available
      size - size of the message payload in bytes
      proto - 1-254 or 0 for unspecified
      fromport - 1-65535 or 0 for unspecified
      toport - 1-65535 or 0 for unspecified
    • protocolNumberToString

      public static String protocolNumberToString(int proto)
      Convert a protocol number to a human-readable string.
      Parameters:
      proto - an I2PSession protocol number, or 0 for any
      Returns:
      human-readable protocol name, or null if unrecognised
    • reportAbuse

      public void reportAbuse(I2PSession session, int severity)
      Description copied from interface: I2PSessionMuxedListener
      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. All registered listeners will be called.

      Unused. Not fully implemented.

      Specified by:
      reportAbuse in interface I2PSessionListener
      Specified by:
      reportAbuse in interface I2PSessionMuxedListener
      Parameters:
      session - session to report abuse to
      severity - how bad the abuse is
    • disconnected

      public void disconnected(I2PSession session)
      Description copied from interface: I2PSessionMuxedListener
      Notify the client that the session has been terminated. All registered listeners will be called.
      Specified by:
      disconnected in interface I2PSessionListener
      Specified by:
      disconnected in interface I2PSessionMuxedListener
      Parameters:
      session - the session that was terminated
    • errorOccurred

      public void errorOccurred(I2PSession session, String message, Throwable error)
      Description copied from interface: I2PSessionMuxedListener
      Notify the client that some error occurred. All registered listeners will be called.
      Specified by:
      errorOccurred in interface I2PSessionListener
      Specified by:
      errorOccurred in interface I2PSessionMuxedListener
      Parameters:
      session - the session that reported the error
      message - a human-readable description of the error
      error - the cause, non-null
    • addListener

      public void addListener(I2PSessionListener l, int proto, int port)
      For those that don't need to hear about the protocol and ports in messageAvailable() (Streaming lib).
      Parameters:
      l - the listener
      proto - the protocol number
      port - the port number
    • addMuxedListener

      public void addMuxedListener(I2PSessionMuxedListener l, int proto, int port)
      For those that do care UDP perhaps.
      Parameters:
      l - the listener
      proto - the protocol number
      port - the port number
    • removeListener

      public void removeListener(int proto, int port)
      Remove a listener for the given protocol and port.
      Parameters:
      proto - the protocol number
      port - the port number
    • findListener

      private I2PSessionMuxedListener findListener(int proto, int port)
      Find the one listener that most specifically matches the request.
      Parameters:
      proto - the protocol number
      port - the port number
      Returns:
      the best-matching listener, or null if none matches
    • getListener

      private I2PSessionMuxedListener getListener(int proto, int port)
      Finds the listener for a protocol and port pair.
      Parameters:
      proto - the protocol number
      port - the port number
      Returns:
      the listener, null if none is registered
    • key

      private static Integer key(int proto, int port)
      Combines a protocol and port into one map key.
      Parameters:
      proto - the protocol number
      port - the port number
      Returns:
      the key