java.lang.Object
net.i2p.client.impl.I2PSessionImpl
All Implemented Interfaces:
I2PSession, I2CPMessageReader.I2CPMessageEventListener
Direct Known Subclasses:
I2PSessionImpl2

public abstract class I2PSessionImplextends Object implements I2PSession, I2CPMessageReader.I2CPMessageEventListener
Implementation of an I2P session running over TCP. This class is NOT thread safe - only one thread should send messages at any given time

Public only for clearCache(). Except for methods defined in I2PSession and I2CPMessageEventListener, not maintained as a public API, not for external use. Use I2PClientFactory to get an I2PClient and then createSession().

  • Field Details

    • _log

      protected final Log _log
      Logger for this session.
    • _myDestination

      private final Destination _myDestination
      Our destination.
    • _privateKey

      private PrivateKey _privateKey
      Private key for decryption.
    • _signingPrivateKey

      private SigningPrivateKey _signingPrivateKey
      Private key for signing.
    • _options

      private final Properties _options
      Configuration options.
    • _sessionId

      private volatile SessionId _sessionId
      This session's ID.
    • _leaseSet

      protected volatile LeaseSet _leaseSet
      Currently granted lease set, or null.
    • _offlineExpiration

      private long _offlineExpiration
      When the offline lease set expires.
    • _offlineSignature

      private Signature _offlineSignature
      Signature for the offline lease set.
    • _transientSigningPublicKey

      protected SigningPublicKey _transientSigningPublicKey
      Transient signing public key for offline signatures.
    • _lastLS2SignTime

      private AtomicLong _lastLS2SignTime
      When the lease set was last signed for LS2.
    • _subsessions

      private final List<SubSession> _subsessions
      The registered subsessions.
    • _subsessionMap

      private final ConcurrentHashMap<SessionId, SubSession> _subsessionMap
      The established subsessions by id.
    • _subsessionLock

      private final Object _subsessionLock
      Lock guarding the subsession lists.
    • MIN_SUBSESSION_VERSION

      private static final String MIN_SUBSESSION_VERSION
      Router version that first supported subsessions.
      See Also:
    • _routerSupportsSubsessions

      private volatile boolean _routerSupportsSubsessions
      Whether the router supports subsessions.
    • _hostname

      protected final String _hostname
      Hostname of router - will be null if in RouterContext.
    • _portNum

      protected final int _portNum
      Port number of router - will be 0 if in RouterContext.
    • _socket

      protected volatile Socket _socket
      Socket for communication.
    • _reader

      protected volatile I2CPMessageReader _reader
      Reader that always searches for messages.
    • _writer

      protected volatile ClientWriterRunner _writer
      Writer message queue.
    • _queue

      protected I2CPMessageQueue _queue
      Used for internal connections to the router. If this is set, _socket and _writer will be null.
    • _sessionListener

      protected volatile I2PSessionListener _sessionListener
      Where session events are sent.
    • _producer

      protected final I2CPMessageProducer _producer
      Class that generates new messages.
    • _availableMessages

      protected Map<Long, MessagePayloadMessage> _availableMessages
      Map of Long--> MessagePayloadMessage.
    • _pendingLookups

      protected final LinkedBlockingQueue<I2PSessionImpl.LookupWaiter> _pendingLookups
      Hashes of lookups we are waiting for.
    • _lookupID

      private final AtomicInteger _lookupID
      Counter handing out lookup ids.
    • _bwReceivedLock

      protected final Object _bwReceivedLock
      Lock for bandwidth limit updates.
    • _bwLimits

      protected volatile int[] _bwLimits
      Current bandwidth limits.
    • _routerVersion

      private volatile String _routerVersion
      The router's version string.
    • _shortHash

      private volatile String _shortHash
      Short hash of the local destination.
    • _handlerMap

      protected final I2PClientMessageHandlerMap _handlerMap
      Handler map for I2CP message types.
    • _context

      protected final I2PAppContext _context
      App context, kept separate so we can get rid of singletons.
    • _leaseSetWait

      protected final Object _leaseSetWait
      Monitor for waiting until a lease set has been granted.
    • _errorMessage

      private String _errorMessage
      The message describing the last session error.
    • _errorCause

      private Throwable _errorCause
      Why the session failed, if it did.
    • STATES_CLOSED

      private static final Set<I2PSessionImpl.State> STATES_CLOSED
      States counted as closed.
    • STATES_OPENING

      private static final Set<I2PSessionImpl.State> STATES_OPENING
      States counted as opening.
    • STATES_CLOSED_OR_OPENING

      private static final Set<I2PSessionImpl.State> STATES_CLOSED_OR_OPENING
      States counted as closed or opening.
    • STATES_CLOSED_OR_CLOSING

      private static final Set<I2PSessionImpl.State> STATES_CLOSED_OR_CLOSING
      States counted as closed or closing.
    • _state

      protected I2PSessionImpl.State _state
      Current session state.
    • _stateLock

      protected final Object _stateLock
      Lock for state transitions.
    • _availabilityNotifier

      protected I2PSessionImpl.AvailabilityNotifier _availabilityNotifier
      Thread that we tell when new messages are available, who then tells us to fetch them. The point of this is so that the fetch doesn't block the reading of other messages (in turn, potentially leading to deadlock).
    • _lastActivity

      private AtomicLong _lastActivity
      When the session last sent or received.
    • _isReduced

      private volatile boolean _isReduced
      Whether the session is in reduced functionality mode.
    • _fastReceive

      private final boolean _fastReceive
      Whether fast receive was requested.
    • _routerSupportsFastReceive

      private volatile boolean _routerSupportsFastReceive
      Whether the router supports fast receive.
    • _routerSupportsHostLookup

      private volatile boolean _routerSupportsHostLookup
      Whether the router supports host lookups.
    • _routerSupportsLS2

      private volatile boolean _routerSupportsLS2
      Whether the router supports LS2.
    • _routerSupportsBlindingInfo

      private volatile boolean _routerSupportsBlindingInfo
      Whether the router returns blinding info.
    • _tunnelStatusListeners

      protected final Set<TunnelStatusListener> _tunnelStatusListeners
      Listeners for tunnel status changes (tunnel failures and removals).
    • CACHE_MAX_SIZE

      protected static final int CACHE_MAX_SIZE
      Maximum size of the lookup cache.
    • _lookupCache

      private static final Map<Object, Destination> _lookupCache
      Cache of Destination lookups, keyed by a Hash or a String.

      Since 0.9.11 the key may be a String as well as a Hash.

    • MIN_HOST_LOOKUP_VERSION

      private static final String MIN_HOST_LOOKUP_VERSION
      Router version that first supported host lookups.
      See Also:
    • LOOKUP_FAILURE

      private static final LookupResult LOOKUP_FAILURE
      Cached failure result for lookups.
    • PROP_DOMAIN_SOCKET

      protected static final String PROP_DOMAIN_SOCKET
      Use Unix domain socket (or similar) to connect to a router.
      See Also:
    • VERIFY_USAGE_TIME

      private static final long VERIFY_USAGE_TIME
      Usage quota checks run every 1 minute.
      See Also:
    • MAX_SEND_WAIT

      private static final long MAX_SEND_WAIT
      The wait for send capacity is at most 10 seconds.
      See Also:
    • MIN_FAST_VERSION

      private static final String MIN_FAST_VERSION
      Router version that first supported fast receive.
      See Also:
    • MIN_LS2_VERSION

      private static final String MIN_LS2_VERSION
      Router version that first supported LS2.
      See Also:
    • MIN_BLINDINFO_VERSION

      private static final String MIN_BLINDINFO_VERSION
      Router version that first returned blinding info.
      See Also:
    • LISTEN_PORT

      public static final int LISTEN_PORT
      Default I2CP listen port.
      See Also:
    • BUF_SIZE

      private static final int BUF_SIZE
      Receive buffer size.
    • DUMMY_SESSION

      static final SessionId DUMMY_SESSION
      Dummy session ID for messages before a real session is established.
    • MAX_RECONNECT_DELAY

      private static final int MAX_RECONNECT_DELAY
      The wait between reconnect tries tops out at 320 seconds.
      See Also:
    • BASE_RECONNECT_DELAY

      private static final int BASE_RECONNECT_DELAY
      The first reconnect try waits 10 seconds.
      See Also:
  • Constructor Details

    • I2PSessionImpl

      protected I2PSessionImpl(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap)
      For extension by SimpleSession (no dest).
      Parameters:
      context - the I2P app context
      options - session configuration options
      handlerMap - the I2CP message handler map
    • I2PSessionImpl

      protected I2PSessionImpl(I2PSessionImpl primary, InputStream destKeyStream, Properties options) throws I2PSessionException
      For extension by SubSession via I2PSessionMuxedImpl and I2PSessionImpl2.
      Parameters:
      primary - the muxed session sharing this session's context, handlers and producer
      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 the destination key stream cannot be read or is not in the expected format
    • I2PSessionImpl

      private I2PSessionImpl(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap, I2CPMessageProducer producer, boolean hasDest)
      Basic setup of the session's final fields.
      Parameters:
      context - the app context
      options - the session options
      handlerMap - the map of the message handlers
      producer - the I2CP message producer
      hasDest - true if a destination was supplied
    • I2PSessionImpl

      public I2PSessionImpl(I2PAppContext context, InputStream destKeyStream, Properties options) throws I2PSessionException
      Create a new session, reading the Destination, PrivateKey, and SigningPrivateKey from the destKeyStream, and using the specified options to connect to the router

      As of 0.9.19, defaults in options are honored.

      This does NOT validate consistency of the destKeyStream, e.g. pubkey/privkey match or valid offline sig. The router does that.

      Parameters:
      context - the I2P app context
      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

    • dateUpdated

      void dateUpdated(String routerVersion)
      Update the router version and related feature support flags.
      Parameters:
      routerVersion - as rcvd in the SetDateMessage, may be null for very old routers
    • addSubsession

      public I2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException
      Router must be connected or was connected... for now.
      Specified by:
      addSubsession in interface I2PSession
      Parameters:
      privateKeyStream - 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:
      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)
      No-op, this session has no subsessions.
      Specified by:
      removeSubsession in interface I2PSession
      Parameters:
      session - the subsession to remove
    • getSubsessions

      public List<I2PSession> getSubsessions()
      List of subsessions, non-null, does not include the primary session.
      Specified by:
      getSubsessions in interface I2PSession
      Returns:
      the subsessions, in registration order
    • loadConfig

      private final Properties loadConfig(Properties opts)
      Parse the config for anything we know about. Also fill in the authorization properties if missing.
      Parameters:
      opts - the caller-supplied session options, copied and augmented
      Returns:
      the configuration properties
    • getTunnelBuildTimeout

      private int getTunnelBuildTimeout()
      Minutes to wait for the first lease set during connect, from the session options if set there, else from the router options, else the 1 hour default.
      Returns:
      minutes, at least 1
    • getTunnelBuildTimeout

      static int getTunnelBuildTimeout(String sessionValue, String contextValue)
      Parse the tunnel build timeout, shared with the instance method and tests. Invalid or non-positive values fall back to the 1 hour default.
      Parameters:
      sessionValue - per-session option value, or null
      contextValue - router option value, or null
      Returns:
      minutes, at least 1
    • getHost

      private String getHost()
      I2CP host from the config.
      Returns:
      configured host name, or a placeholder for logging if not applicable
    • getPort

      private int getPort()
      I2CP port from the config.
      Returns:
      configured port, 0 if not applicable, or LISTEN_PORT if unparseable
    • filter

      private Properties filter(Properties options)
      Save some memory, don't pass along the pointless properties. As of 0.9.19, defaults from options will be promoted to real values in rv.
      Parameters:
      options - the properties to filter, system and disallowed streaming keys are dropped
      Returns:
      a new Properties without defaults
    • isAllowedStreamingProperty

      private boolean isAllowedStreamingProperty(String key)
      Check if a streaming property should be allowed through the filter. These are known-good streaming options that should be passed to the router.
      Parameters:
      key - the property key
      Returns:
      true if the property should be allowed
    • updateOptions

      public void updateOptions(Properties options)
      Update the tunnel and bandwidth settings.
      Specified by:
      updateOptions in interface I2PSession
      Parameters:
      options - non-null
    • getFastReceive

      public boolean getFastReceive()
      Does this session support fast receive?
      Returns:
      true if fast receive is supported
    • supportsLS2

      public boolean supportsLS2()
      Does this session support LS2?
      Returns:
      true if LS2 is supported
    • setLeaseSet

      void setLeaseSet(LeaseSet ls)
      Lease set published by this session.
      Parameters:
      ls - the lease set to publish, or null to withdraw the current one
    • getLeaseSet

      public LeaseSet getLeaseSet()
      Current lease set published by this session. Each lease in the lease set corresponds to one inbound tunnel allocated to this session by the router, so the lease count is the number of active inbound tunnels for this destination.
      Returns:
      the current lease set, or null if not yet published
    • changeState

      protected void changeState(I2PSessionImpl.State state)
      Change the session state.
      Parameters:
      state - the new state to move to, waking any waiter blocked on a state change
    • readDestination

      private void readDestination(InputStream destKeyStream) throws DataFormatException, IOException
      Load up the destKeyFile for our Destination, PrivateKey, and SigningPrivateKey. As of 0.9.38, loads the offline data also. See PrivateKeyFile.

      This does NOT validate consistency of the destKeyStream, e.g. pubkey/privkey match or valid offline sig. The router does that.

      Parameters:
      destKeyStream - the stream to read the Destination, PrivateKey and SigningPrivateKey from
      Throws:
      DataFormatException - if the file is in the wrong format or keys are invalid
      IOException - if there is a problem reading the file
    • isOffline

      public boolean isOffline()
      Does this session have offline and transient keys?
      Specified by:
      isOffline in interface I2PSession
      Returns:
      true if the session was created from an offline-signed destination
    • getOfflineExpiration

      public long getOfflineExpiration()
      Java time (ms) or 0 if not initialized or does not have offline keys.
      Specified by:
      getOfflineExpiration in interface I2PSession
      Returns:
      the expiry time, or 0 when unavailable
    • getOfflineSignature

      public Signature getOfflineSignature()
      Null on error or if not initialized or does not have offline keys.
      Specified by:
      getOfflineSignature in interface I2PSession
      Returns:
      the signature, or null when unavailable
    • getTransientSigningPublicKey

      public SigningPublicKey getTransientSigningPublicKey()
      Null on error or if not initialized or does not have offline keys.
      Specified by:
      getTransientSigningPublicKey in interface I2PSession
      Returns:
      the signature, or null when unavailable
    • 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 primary session will not automatically connect subsessions. Connecting a subsession will automatically connect the primary session if not previously connected.

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

      protected void waitForDate() throws InterruptedException, IOException
      Wait for a SetDate response from the router.
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting
      IOException - on I/O error
    • receiveMessage

      public byte[] receiveMessage(int msgId) throws I2PSessionException
      Pull the unencrypted data from the message that we've already prefetched and notified the user that its available.
      Specified by:
      receiveMessage in interface I2PSession
      Parameters:
      msgId - message to fetch
      Returns:
      the data, or null on error
      Throws:
      I2PSessionException - declared but never thrown; failures return null instead
    • discardMessage

      public void discardMessage(int msgId)
      Throw away the received message, we don't want it. Use instead of receiveMessage(int) to avoid gunzip overhead.
      Specified by:
      discardMessage in interface I2PSession
      Parameters:
      msgId - message whose payload should be dropped rather than returned
    • reportAbuse

      public void reportAbuse(int msgId, int severity) throws I2PSessionException
      Report abuse with regards to the given messageId.
      Specified by:
      reportAbuse in interface I2PSession
      Parameters:
      msgId - message that was abusive (or -1 for not message related)
      severity - abuse rating from 1 (mildest) to 100 (worst)
      Throws:
      I2PSessionException - if the session is not open or closed
    • receiveStatus

      public abstract void receiveStatus(int msgId, long nonce, int status)
      Receive a message status update.
      Parameters:
      msgId - the message ID
      nonce - router-assigned value identifying the request the update belongs to
      status - the MessageStatusMessage.STATUS_ code for the send outcome
    • addNewMessage

      public void addNewMessage(MessagePayloadMessage msg)
      Receive a payload message and let the app know its available.
      Parameters:
      msg - the payload message
    • startVerifyUsage

      protected void startVerifyUsage()
      Fire up a periodic task to check for unclaimed messages.
    • messageReceived

      public void messageReceived(I2CPMessageReader reader, I2CPMessage message)
      The I2CPMessageEventListener callback. Receive notification of some I2CP message and handle it if possible.

      We route the message based on message type AND session ID.

      The following types never contain a session ID and are not routable to a subsession: BandwidthLimitsMessage, DestReplyMessage

      The following types may not contain a valid session ID even when intended for a subsession, so we must take special care: SessionStatusMessage.

      Specified by:
      messageReceived in interface I2CPMessageReader.I2CPMessageEventListener
      Parameters:
      reader - ignored, the session already holds its own connection
      message - the I2CPMessage
    • readError

      public void readError(I2CPMessageReader reader, Exception error)
      The I2CPMessageEventListener callback. Receive notification of an error reading the I2CP stream. As of 0.9.41, does NOT call sessionlistener.disconnected(I2CPMessageReader), the I2CPMessageReader will call disconnected() also.
      Specified by:
      readError in interface I2CPMessageReader.I2CPMessageEventListener
      Parameters:
      reader - ignored, only the error is used
      error - non-null
    • getMyDestination

      public Destination getMyDestination()
      Retrieve the destination of the session.
      Specified by:
      getMyDestination in interface I2PSession
      Returns:
      the my destination
    • getPrivateKey

      public SigningPrivateKey getPrivateKey()
      Retrieve the signing SigningPrivateKey. As of 0.9.38, this will be the transient key if offline signed.
      Specified by:
      getPrivateKey in interface I2PSession
      Returns:
      the private key
    • getProducer

      I2CPMessageProducer getProducer()
      Retrieve the helper that generates I2CP messages.
      Returns:
      the I2CP message producer
    • getHandlerMap

      For Subsessions.
      Returns:
      the I2CP message handler map
    • getContext

      I2PAppContext getContext()
      For Subsessions.
      Returns:
      the I2P app context
    • getOptions

      public Properties getOptions()
      Retrieve the configuration options, filtered. All defaults passed in via constructor have been promoted to the primary map. Reflects updates applied via updateOptions(Properties), including router-side reconfiguration, so the effective tunnel quantity settings for this session may be read from the returned properties.
      Returns:
      non-null, if instantiated with null options, this will be the System properties.
    • getSessionId

      SessionId getSessionId()
      Retrieve the session's ID.
      Returns:
      null if unset
    • setSessionId

      void setSessionId(SessionId id)
      Session ID assigned by the router.
      Parameters:
      id - the session ID to set
    • getLastLS2SignTime

      long getLastLS2SignTime()
      The published timestamp of the last LS2 we signed.
      Returns:
      0 if never
    • setLastLS2SignTime

      void setLastLS2SignTime(long now)
      The published timestamp of the last LS2 we signed.
      Parameters:
      now - the timestamp to set
    • setSessionListener

      public void setSessionListener(I2PSessionListener lsnr)
      Configure the listener.
      Specified by:
      setSessionListener in interface I2PSession
      Parameters:
      lsnr - listener to retrieve events
    • isClosed

      public boolean isClosed()
      Has the session been closed (or not yet connected)? False when open and during transitions. Synchronized.
      Specified by:
      isClosed in interface I2PSession
      Returns:
      true if the session is closed or not yet connected
    • verifyOpen

      protected void verifyOpen() throws I2PSessionException
      Throws I2PSessionException if uninitialized, closed or closing. Blocks if opening.
      Throws:
      I2PSessionException - if not open
    • sendMessage

      void sendMessage(I2CPMessage message) throws I2PSessionException
      Deliver an I2CP message to the router As of 0.9.3, may block for several seconds if the write queue to the router is full.
      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.
      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. Calls sessionlistener.errorOccurred().
      Parameters:
      msg - the error message
      error - non-null
    • destroySession

      public void destroySession()
      Tear down the session, and do NOT reconnect.

      Blocks if session has not been fully started.

      Specified by:
      destroySession in interface I2PSession
    • destroySession

      public void destroySession(boolean sendDisconnect)
      Tear down the session, and do NOT reconnect.

      Will interrupt an open in progress. Calls sessionlistener.disconnected().

      Parameters:
      sendDisconnect - if true, send disconnect message to router
    • closeSocket

      private void closeSocket()
      Close the socket carefully.
    • locked_closeSocket

      private void locked_closeSocket()
      Close the socket carefully. Caller must change state.
    • disconnected

      public void disconnected(I2CPMessageReader reader)
      The I2CPMessageEventListener callback. Receive notification that the I2CP connection was disconnected. Calls sessionlistener.disconnected().
      Specified by:
      disconnected in interface I2CPMessageReader.I2CPMessageEventListener
      Parameters:
      reader - ignored, the session tracks its own connection
    • disconnect

      protected void disconnect()
      Will interrupt a connect in progress. Calls sessionlistener.disconnected().
    • shouldReconnect

      protected boolean shouldReconnect()
      Whether the session should attempt reconnection on disconnect.
      Returns:
      true if the session should attempt to reconnect
    • reconnect

      protected boolean reconnect()
      Attempt to reconnect to the router.
      Returns:
      true if reconnected successfully
    • getPrefix

      protected final String getPrefix()
      Try hard to make a decent identifier as this will appear in error logs.
      Returns:
      the prefix string
    • getName

      protected String getName()
      Session name for logging.
      Returns:
      the session name
    • getName

      private void getName(StringBuilder buf)
      Append the session name for log messages.
      Parameters:
      buf - the buffer the nickname, or the class name if none is set, is appended to
    • destReceived

      void destReceived(Destination d)
      Called by the message handler on reception of DestReplyMessage.
      Parameters:
      d - non-null
    • destLookupFailed

      void destLookupFailed(Hash h)
      Called by the message handler on reception of DestReplyMessage.
      Parameters:
      h - non-null
    • clearPendingLookups

      private void clearPendingLookups()
      Clear out all pending lookups and bw limit requests.
    • destReceived

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

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

      void bwReceived(int[] limits)
      Called by the message handler.
      Parameters:
      limits - the bandwidth limits
    • clearCache

      public static void clearCache()
      Clear the lookup cache.
    • 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 only in I2PSimpleSession. Multiple outstanding lookups are now allowed.
      Specified by:
      lookupDest in interface I2PSession
      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
      Blocking. Waits a max of 10 seconds by default.
      Specified by:
      lookupDest in interface I2PSession
      Parameters:
      h - the hash to look up
      maxWait - milliseconds to wait for the router's reply before giving up
      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
      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
      Parameters:
      name - the hostname to look up
      maxWait - milliseconds to wait for the router's reply before giving up
      Returns:
      null on failure
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • lookupDest2

      public LookupResult lookupDest2(String name, long maxWait) throws I2PSessionException
      Ask the router to lookup a Destination by host name. Blocking. See above for details. Same as lookupDest(Hash) but with a failure code in the return value.
      Specified by:
      lookupDest2 in interface I2PSession
      Parameters:
      name - the hostname to look up
      maxWait - milliseconds to wait for the router's reply before giving up
      Returns:
      non-null
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • x_lookupDest

      private I2PSessionImpl.LookupWaiter x_lookupDest(String name, long maxWait) throws I2PSessionException
      Ask the router to lookup a Destination by host name. Blocking. See above for details.
      Parameters:
      name - the hostname to look up
      maxWait - milliseconds to wait for the router's reply before giving up
      Returns:
      null on failure
      Throws:
      I2PSessionException - if the thread is interrupted while waiting for the router's reply
    • lookupDest

      public LookupResult lookupDest(Hash h, long maxWait, LookupCallback callback) throws I2PSessionException
      Lookup a Destination by hostname. Non-blocking. If the result is cached or there is an immediate failure, the result code will be something other than RESULT_DEFERRED, and the callback will NOT be called.
      Specified by:
      lookupDest in interface I2PSession
      Parameters:
      h - the hash to look up
      maxWait - milliseconds to wait for the router's reply before giving up
      callback - to return the result, non-null
      Returns:
      non-null. If result code is RESULT_DEFERRED, callback will be called later
      Throws:
      I2PSessionException - if the router predates 0.9.11 and has no HostLookup
    • lookupDest

      public LookupResult lookupDest(String name, long maxWait, LookupCallback callback) throws I2PSessionException
      Lookup a Destination by hash. Non-blocking. If the result is cached or there is an immediate failure, the result code will be something other than RESULT_DEFERRED, and the callback will NOT be called.
      Specified by:
      lookupDest in interface I2PSession
      Parameters:
      name - the hostname to look up
      maxWait - milliseconds to wait for the router's reply before giving up
      callback - to return the result, non-null
      Returns:
      non-null. If result code is RESULT_DEFERRED, callback will be called later
      Throws:
      I2PSessionException - if the router predates 0.9.11 and has no HostLookup
    • bandwidthLimits

      public int[] bandwidthLimits() throws I2PSessionException
      Blocking. Waits a max of 5 seconds. But shouldn't take long. Implemented in 0.8.3 in I2PSessionImpl; previously was available only in I2PSimpleSession. Multiple outstanding lookups are now allowed.
      Specified by:
      bandwidthLimits in interface I2PSession
      Returns:
      null on failure
      Throws:
      I2PSessionException - if the calling thread is interrupted while waiting
    • sendBlindingInfo

      public void sendBlindingInfo(BlindData bd) throws I2PSessionException
      Send blinding info to a peer.
      Specified by:
      sendBlindingInfo in interface I2PSession
      Parameters:
      bd - the blind data
      Throws:
      I2PSessionException - if the router predates 0.9.43 and has no BlindingInfo
    • getRouterVersion

      public String getRouterVersion()
      Always valid in RouterContext. Returns null if not yet connected in I2PAppContext.
      Specified by:
      getRouterVersion in interface I2PSession
      Returns:
      null if unknown
    • updateActivity

      protected void updateActivity()
      Update the last activity timestamp.
    • lastActivity

      public long lastActivity()
      Time of last session activity in milliseconds.
      Returns:
      the last activity timestamp
    • setReduced

      public void setReduced()
      Mark the session as reduced.
    • startIdleMonitor

      private void startIdleMonitor()
      Starts the thread that closes idle sessions.
    • toString

      public String toString()
      Overrides:
      toString in class Object