All Implemented Interfaces:
I2PSession, I2CPMessageReader.I2CPMessageEventListener
Direct Known Subclasses:
SubSession

class I2PSessionMuxedImplextends I2PSessionImpl2
I2PSession with protocol and ports

Streaming lib has been modified to send I2PSession.PROTO_STREAMING but still receives all. It sends with fromPort and toPort = 0, and receives on all ports.

No datagram apps have been modified yet.

Therefore the compatibility situation is as follows:

Compatibility: old streaming -> new streaming: sends proto anything, rcvs proto anything new streaming -> old streaming: sends PROTO_STREAMING, ignores rcvd proto old datagram -> new datagram: sends proto anything, rcvs proto anything new datagram -> old datagram: sends PROTO_DATAGRAM, ignores rcvd proto In all the above cases, streaming and datagram receive traffic for the other protocol, same as before.

old datagram -> new muxed: doesn't work because the old sends proto 0 but the udp side of the mux registers with PROTO_DATAGRAM, so the datagrams go to the streaming side, same as before. old streaming -> new muxed: works

Typical Usage: Streaming + datagrams: I2PSocketManager sockMgr = getSocketManager(); I2PSession session = sockMgr.getSession(); session.addMuxedSessionListener(myI2PSessionMuxedListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); or session.addSessionListener(myI2PSessionListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); session.sendMessage(dest, payload, I2PSession.PROTO_DATAGRAM, fromPort, toPort);

Datagrams only, with multiple ports: I2PClient client = I2PClientFactory.createClient(I2PAppContext); ... I2PSession session = client.createSession(...); session.addMuxedSessionListener(myI2PSessionMuxedListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); or session.addSessionListener(myI2PSessionListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); session.sendMessage(dest, payload, I2PSession.PROTO_DATAGRAM, fromPort, toPort);

Multiple streaming ports: Needs some streaming lib hacking.

  • Field Details

    • _demultiplexer

      private final I2PSessionDemultiplexer _demultiplexer
      The demultiplexer delivering the messages.
    • PROTO_BYTE

      private static final int PROTO_BYTE
      OS byte in gzip header.
      See Also:
    • FROMPORT_BYTES

      private static final int FROMPORT_BYTES
      Upper two bytes of MTIME in gzip header.
      See Also:
    • TOPORT_BYTES

      private static final int TOPORT_BYTES
      Lower two bytes of MTIME in gzip header.
      See Also:
  • Constructor Details

    • I2PSessionMuxedImpl

      public I2PSessionMuxedImpl(I2PAppContext ctx, InputStream destKeyStream, Properties options) throws I2PSessionException
      Create a new muxed session.
      Parameters:
      ctx - the application context whose router is to be used
      destKeyStream - stream containing the private key data, format is specified in PrivateKeyFile
      options - set of options to configure the router with, if null will use System properties
      Throws:
      I2PSessionException - if there is a problem loading the private keys
    • I2PSessionMuxedImpl

      protected I2PSessionMuxedImpl(I2PSessionImpl primary, InputStream destKeyStream, Properties options) throws I2PSessionException
      For extension by SubSession.
      Parameters:
      primary - the SubSession this one multiplexes alongside, or null
      destKeyStream - stream containing the private key data, format is specified in PrivateKeyFile
      options - set of options to configure the router with, if null will use System properties
      Throws:
      I2PSessionException - if there is a problem loading the private keys
  • Method Details

    • setSessionListener

      public void setSessionListener(I2PSessionListener lsnr)
      Listen on all protocols and ports.
      Specified by:
      setSessionListener in interface I2PSession
      Overrides:
      setSessionListener in class I2PSessionImpl
      Parameters:
      lsnr - listener to retrieve events
    • addSessionListener

      public void addSessionListener(I2PSessionListener lsnr, int proto, int port)
      Listen on specified protocol and port.

      An existing listener with the same proto and port is replaced. Only the listener with the best match is called back for each message.

      Specified by:
      addSessionListener in interface I2PSession
      Overrides:
      addSessionListener in class I2PSessionImpl2
      Parameters:
      lsnr - the listener to add
      proto - 1-254 or PROTO_ANY (0) for all; recommended: I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
      port - 1-65535 or PORT_ANY (0) for all
    • addMuxedSessionListener

      public void addMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port)
      Listen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.
      Specified by:
      addMuxedSessionListener in interface I2PSession
      Overrides:
      addMuxedSessionListener in class I2PSessionImpl2
      Parameters:
      l - the listener to add
      proto - 1-254 or PROTO_ANY (0) for all; 255 disallowed
      port - 1-65535 or PORT_ANY (0) for all
    • removeListener

      public void removeListener(int proto, int port)
      Remove the specified listener (only).
      Specified by:
      removeListener in interface I2PSession
      Overrides:
      removeListener in class I2PSessionImpl2
      Parameters:
      proto - the protocol the listener was added for
      port - the port the listener was added for
    • sendMessage

      public boolean sendMessage(Destination dest, byte[] payload) throws I2PSessionException
      Send an I2CP message, with the protocol and ports unset.
      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      Returns:
      true if the router accepted the message, false if it was refused
      Throws:
      I2PSessionException - if the session is not open or closed, or the write queue stays full
    • sendMessage

      public boolean sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) throws I2PSessionException
      Send an I2CP message.
      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      proto - 1-254, or 0 for unset; 255 disallowed
      fromport - source port, 1-65535 or 0 for unset
      toport - destination port, 1-65535 or 0 for unset
      Returns:
      true if the router accepted the message, false if it was refused
      Throws:
      I2PSessionException - if the session is not open or closed, or the write queue stays full
    • sendMessage

      public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) throws I2PSessionException
      Send a message with session key and tags.
      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      offset - offset into the payload
      size - number of bytes to send
      keyUsed - unused - no end-to-end crypto
      tagsSent - unused - no end-to-end crypto
      expires - absolute expiration timestamp, NOT interval from now
      Returns:
      true unless the router reported a failed send status
      Throws:
      I2PSessionException - if the session is not open or closed, or the write queue stays full
    • sendMessage

      public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromport, int toport) throws I2PSessionException
      Send a message with session key and tags.
      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      offset - offset into the payload
      size - number of bytes to send
      keyUsed - unused - no end-to-end crypto
      tagsSent - unused - no end-to-end crypto
      proto - 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
      fromport - 1-65535 or 0 for unset
      toport - 1-65535 or 0 for unset
      Returns:
      true unless the router reported a failed send status
      Throws:
      I2PSessionException - if the session is not open or closed, or the write queue stays full
    • sendMessage

      public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort) throws I2PSessionException
      Send a message with protocol and port information.
      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      offset - offset into the payload
      size - number of bytes to send
      keyUsed - unused - no end-to-end crypto
      tagsSent - unused - no end-to-end crypto
      expires - absolute expiration timestamp, NOT interval from now
      proto - 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
      fromPort - 1-65535 or 0 for unset
      toPort - 1-65535 or 0 for unset
      Returns:
      true unless the router reported a failed send status
      Throws:
      I2PSessionException - if the session is not open or closed, or the write queue stays full
    • sendMessage

      public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort, int flags) throws I2PSessionException
      Send a message with protocol, port, and flags.
      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      offset - offset into the payload
      size - number of bytes to send
      keyUsed - unused - no end-to-end crypto
      tagsSent - unused - no end-to-end crypto
      expires - absolute expiration timestamp, NOT interval from now
      proto - 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
      fromPort - 1-65535 or 0 for unset
      toPort - 1-65535 or 0 for unset
      flags - to be passed to the router
      Returns:
      true unless the router reported a failed send status
      Throws:
      I2PSessionException - if the session is not open or closed, or the write queue stays full
    • sendMessage

      public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options) throws I2PSessionException
      See SendMessageOptions for option details.

      Always uses sendNoEffort for now.

      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      offset - offset into the payload
      size - number of bytes to send
      proto - 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
      fromPort - 1-65535 or 0 for unset
      toPort - 1-65535 or 0 for unset
      options - to be passed to the router
      Returns:
      true always
      Throws:
      I2PSessionException - if the session is not open or closed, or the write queue stays full
    • sendMessage

      public long sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options, SendMessageStatusListener listener) throws I2PSessionException
      Send a message and request an asynchronous notification of delivery status.

      See I2PSessionMuxedImpl for proto/port details. See SendMessageOptions for option details.

      Specified by:
      sendMessage in interface I2PSession
      Overrides:
      sendMessage in class I2PSessionImpl2
      Parameters:
      dest - location to send the message
      payload - body of the message to be sent (unencrypted)
      offset - offset into the payload
      size - number of bytes to send
      proto - 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
      fromPort - 1-65535 or 0 for unset
      toPort - 1-65535 or 0 for unset
      options - to be passed to the router
      listener - for delivery status notification
      Returns:
      the message ID to be used for later notification to the listener
      Throws:
      I2PSessionException - on all errors
    • prepPayload

      private byte[] prepPayload(byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions.GzipOption gzo) throws I2PSessionException
      Prepare the payload for sending.
      Parameters:
      payload - the message data to wrap
      offset - start of the message data within payload
      size - number of message bytes to take from offset
      proto - protocol written to the gzip OS byte, 1-254 or 0 for unset
      fromPort - source port written to the MTIME field, 1-65535 or 0 for unset
      toPort - destination port written to the MTIME field, 1-65535 or 0 for unset
      gzo - gzip selection; DEFAULT compresses by size heuristic, GZIP_ON forces compression
      Returns:
      gzip compressed payload, ready to send
      Throws:
      I2PSessionException - if the session is not open
    • sendNoEffort

      private void sendNoEffort(Destination dest, byte[] payload, SendMessageOptions options) throws I2PSessionException
      Send a message without expecting a response.
      Parameters:
      dest - the destination to deliver the message to
      payload - the already-prepared message data
      options - delivery options, expiration and flags applied to the message
      Throws:
      I2PSessionException - if the message cannot be queued to the router, e.g. the write queue is full or the session closed
    • addNewMessage

      public void addNewMessage(MessagePayloadMessage msg)
      Store a received payload message and notify the client that it is available, including the protocol and ports it arrived on.
      Overrides:
      addNewMessage in class I2PSessionImpl
      Parameters:
      msg - the received payload, whose data must be at least 10 bytes for the gzip header
    • getProto

      private static int getProto(MessagePayloadMessage msg)
      Non-muxed sets the OS byte to 0xff.
      Parameters:
      msg - the received payload message to read the header from
      Returns:
      the protocol 0-254, or PROTO_UNSPECIFIED when the OS byte is 0xff
    • getFromPort

      private static int getFromPort(MessagePayloadMessage msg)
      Non-muxed sets the MTIME bytes to 0.
      Parameters:
      msg - the received payload message to read the header from
      Returns:
      the source port 0-65535 from the upper two MTIME bytes, 0 if unset
    • getToPort

      private static int getToPort(MessagePayloadMessage msg)
      Non-muxed sets the MTIME bytes to 0.
      Parameters:
      msg - the received payload message to read the header from
      Returns:
      the destination port 0-65535 from the lower two MTIME bytes, 0 if unset
    • getByte

      private static int getByte(MessagePayloadMessage msg, int i)
      Reads one payload byte of the message.
      Parameters:
      msg - the message to read
      i - the index of the byte
      Returns:
      the payload byte
    • setProto

      private static void setProto(byte[] payload, int p)
      Sets the protocol byte of the payload.
      Parameters:
      payload - the payload to change
      p - the protocol to set
    • setFromPort

      private static void setFromPort(byte[] payload, int p)
      Sets the from port of the payload.
      Parameters:
      payload - the payload to change
      p - the port to set
    • setToPort

      private static void setToPort(byte[] payload, int p)
      Sets the to port of the payload.
      Parameters:
      payload - the payload to change
      p - the port to set