All Implemented Interfaces:
I2PSession, I2CPMessageReader.I2CPMessageEventListener

class SubSessionextends I2PSessionMuxedImpl
An additional session using another session's connection.

A subsession uses the same connection to the router as the primary session, but has a different Destination. It uses the same tunnels as the primary but has its own leaseset. It must use the same encryption keys as the primary so that garlic encryption/decryption works.

The message handler map and message producer are reused from primary.

Does NOT reuse the session listener ????

While the I2CP protocol, in theory, allows for fully independent sessions over the same I2CP connection, this is not currently supported by the router.

  • Field Details

    • _primary

      private final I2PSessionMuxedImpl _primary
      The session this one shares its connection with.
  • Constructor Details

    • SubSession

      public SubSession(I2PSession primary, InputStream destKeyStream, Properties options) throws I2PSessionException
      Must be a I2PSessionMuxedImpl.
      Parameters:
      primary - must be a I2PSessionMuxedImpl
      destKeyStream - location from which to read keys
      options - session options passed through to the parent session, null to use the System properties
      Throws:
      I2PSessionException - if the generated signing key is identical to the primary session's
  • Method Details

    • addSubsession

      public I2PSession addSubsession(InputStream destKeyStream, Properties opts) throws I2PSessionException
      Unsupported in a subsession.
      Specified by:
      addSubsession in interface I2PSession
      Overrides:
      addSubsession in class I2PSessionImpl
      Parameters:
      destKeyStream - null for transient, if non-null must have same encryption keys as primary session
      opts - subsession options if any, may be null
      Returns:
      a new subsession, non-null
      Throws:
      UnsupportedOperationException - always, as a subsession cannot hold subsessions
      I2PSessionException - if the router does not support sub-sessions, or a sub-session request is pending or the same key was already added
    • removeSubsession

      public void removeSubsession(I2PSession session)
      Unsupported in a subsession. Does nothing.
      Specified by:
      removeSubsession in interface I2PSession
      Overrides:
      removeSubsession in class I2PSessionImpl
      Parameters:
      session - the subsession to remove
    • getSubsessions

      public List<I2PSession> getSubsessions()
      Unsupported in a subsession.
      Specified by:
      getSubsessions in interface I2PSession
      Overrides:
      getSubsessions in class I2PSessionImpl
      Returns:
      empty list always
    • updateOptions

      public void updateOptions(Properties options)
      Does nothing for now.
      Specified by:
      updateOptions in interface I2PSession
      Overrides:
      updateOptions in class I2PSessionImpl
      Parameters:
      options - non-null
    • getPrimaryOptions

      public Properties getPrimaryOptions()
      Options the primary session was created with.
      Returns:
      the primary session's options, never null
    • connect

      public void connect() throws I2PSessionException
      Connect to the router and establish a session. This call blocks until a session is granted.

      Should be threadsafe, other threads will block until complete. Disconnect / destroy from another thread may be called simultaneously and will (should?) interrupt the connect.

      Connecting a subsession will automatically connect the primary session if not previously connected.

      Specified by:
      connect in interface I2PSession
      Overrides:
      connect in class I2PSessionImpl
      Throws:
      I2PSessionException - if there is a configuration error or the router is not reachable
    • isClosed

      public boolean isClosed()
      Has the session been closed (or not yet connected)? False when open and during transitions.
      Specified by:
      isClosed in interface I2PSession
      Overrides:
      isClosed in class I2PSessionImpl
      Returns:
      true if this subsession or its primary has been closed
    • sendMessage

      void sendMessage(I2CPMessage message) throws I2PSessionException
      Deliver an I2CP message to the router May block for several seconds if the write queue to the router is full.
      Overrides:
      sendMessage in class I2PSessionImpl
      Parameters:
      message - the I2CP message to send
      Throws:
      I2PSessionException - if the message is malformed or there is an error writing it out
    • sendMessage_unchecked

      void sendMessage_unchecked(I2CPMessage message) throws I2PSessionException
      Deliver an I2CP message to the router. Does NOT check state. Call only from connect() or other methods that need to send messages when not in OPEN state.
      Overrides:
      sendMessage_unchecked in class I2PSessionImpl
      Parameters:
      message - the I2CP message to send
      Throws:
      I2PSessionException - if the message is malformed or there is an error writing it out
    • propagateError

      void propagateError(String msg, Throwable error)
      Pass off the error to the listener Misspelled, oh well.
      Overrides:
      propagateError in class I2PSessionImpl
      Parameters:
      msg - the error message
      error - non-null
    • destroySession

      public void destroySession()
      Tear down the session, and do NOT reconnect. As of 0.9.67, this does NOT destroy the primary session.

      Blocks if session has not been fully started.

      Specified by:
      destroySession in interface I2PSession
      Overrides:
      destroySession in class I2PSessionImpl
    • disconnect

      protected void disconnect()
      Will interrupt a connect in progress.
      Overrides:
      disconnect in class I2PSessionImpl
    • reconnect

      protected boolean reconnect()
      Description copied from class: I2PSessionImpl2
      Reconnect the I2CP session. Called by the superclass whenever it wants to reconnect; overridden to also clear out the message state.
      Overrides:
      reconnect in class I2PSessionImpl2
      Returns:
      whether the session was reconnected
    • destReceived

      void destReceived(Destination d)
      Called by the message handler on reception of DestReplyMessage

      This will never happen, as the dest reply message does not contain a session ID.

      Overrides:
      destReceived in class I2PSessionImpl
      Parameters:
      d - non-null
    • destLookupFailed

      void destLookupFailed(Hash h)
      Called by the message handler on reception of DestReplyMessage

      This will never happen, as the dest reply message does not contain a session ID.

      Overrides:
      destLookupFailed in class I2PSessionImpl
      Parameters:
      h - non-null
    • destReceived

      void destReceived(long nonce, Destination d)
      Called by the message handler on reception of HostReplyMessage.
      Overrides:
      destReceived in class I2PSessionImpl
      Parameters:
      nonce - the lookup nonce
      d - non-null
    • destLookupFailed

      void destLookupFailed(long nonce, int code)
      Called by the message handler on reception of HostReplyMessage.
      Overrides:
      destLookupFailed in class I2PSessionImpl
      Parameters:
      nonce - the lookup nonce
      code - the failure code
    • bwReceived

      void bwReceived(int[] i)
      Called by the message handler. This will never happen, as the bw limits message does not contain a session ID.
      Overrides:
      bwReceived in class I2PSessionImpl
      Parameters:
      i - the bandwidth limits
    • lookupDest

      public Destination lookupDest(Hash h) throws I2PSessionException
      Blocking. Waits a max of 10 seconds by default. See lookupDest with maxWait parameter to change. Implemented in 0.8.3 in I2PSessionImpl; previously was available I2PSimpleSessioneSession. Multiple outstanding lookups are now allowed.
      Specified by:
      lookupDest in interface I2PSession
      Overrides:
      lookupDest in class I2PSessionImpl
      Parameters:
      h - the hash to look up
      Returns:
      null on failure
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • lookupDest

      public Destination lookupDest(Hash h, long maxWait) throws I2PSessionException
      Looks up a Destination, blocking up to the given wait for the answer.
      Specified by:
      lookupDest in interface I2PSession
      Overrides:
      lookupDest in class I2PSessionImpl
      Parameters:
      h - the hash to look up
      maxWait - the maximum time to wait, in milliseconds
      Returns:
      null on failure
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • lookupDest

      public Destination lookupDest(String name) throws I2PSessionException
      Ask the router to lookup a Destination by host name. Blocking. Waits a max of 10 seconds by default.

      This only makes sense for a b32 hostname, OR outside router context. Inside router context, just query the naming service. Outside router context, this does NOT query the context naming service. Do that first if you expect a local addressbook.

      This will log a warning for non-b32 in router context.

      See interface for suggested implementation.

      Requires router side to be 0.9.11 or higher. If the router is older, this will return null immediately.

      Specified by:
      lookupDest in interface I2PSession
      Overrides:
      lookupDest in class I2PSessionImpl
      Parameters:
      name - the hostname to look up
      Returns:
      the Destination, or null on failure
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • lookupDest

      public Destination lookupDest(String name, long maxWait) throws I2PSessionException
      Ask the router to lookup a Destination by host name. Blocking. See above for details.
      Specified by:
      lookupDest in interface I2PSession
      Overrides:
      lookupDest in class I2PSessionImpl
      Parameters:
      name - the hostname to look up
      maxWait - the maximum time to wait, in milliseconds
      Returns:
      null on failure
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • bandwidthLimits

      public int[] bandwidthLimits() throws I2PSessionException
      This won't be called, as the reply does not contain a session ID, so it won't be routed back to us.
      Specified by:
      bandwidthLimits in interface I2PSession
      Overrides:
      bandwidthLimits in class I2PSessionImpl
      Returns:
      null on failure
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • updateActivity

      protected void updateActivity()
      Description copied from class: I2PSessionImpl
      Update the last activity timestamp.
      Overrides:
      updateActivity in class I2PSessionImpl
    • lastActivity

      public long lastActivity()
      Description copied from class: I2PSessionImpl
      Time of last session activity in milliseconds.
      Overrides:
      lastActivity in class I2PSessionImpl
      Returns:
      the last activity timestamp
    • setReduced

      public void setReduced()
      Description copied from class: I2PSessionImpl
      Mark the session as reduced.
      Overrides:
      setReduced in class I2PSessionImpl