## net.i2p.client
Class I2PSessionImpl2

    java.lang.Object
      net.i2p.client.I2PSessionImpl
          net.i2p.client.I2PSessionImpl2

All Implemented Interfaces:
  I2PSession, I2CPMessageReader.I2CPMessageEventListener

Direct Known Subclasses:
  I2PSessionMuxedImpl, I2PSimpleSession

     class I2PSessionImpl2

extends I2PSessionImpl

Thread safe implementation of an I2P session running over TCP.

Author:
  jrandom

Nested Class Summary

Nested classes/interfaces inherited from class net.i2p.client.I2PSessionImpl
`I2PSessionImpl.AvailabilityNotifier, I2PSessionImpl.VerifyUsage`

Field Summary

Fields inherited from class net.i2p.client.I2PSessionImpl
`_availabilityNotifier, _availableMessages, _bwLimits, _bwReceivedLock, _closed, _closing, _context, _handlerMap, _hostname, _log, _opening, _out, _pendingLookups, _portNum, _producer, _queue, _reader, _sessionListener, _socket, _writer, LISTEN_PORT, PROP_ENABLE_SSL`

Fields inherited from interface net.i2p.client.I2PSession
`PORT_ANY, PORT_UNSPECIFIED, PROTO_ANY, PROTO_DATAGRAM, PROTO_STREAMING, PROTO_UNSPECIFIED`

Constructor Summary
`I2PSessionImpl2()` for extension
`I2PSessionImpl2(I2PAppContext ctx, InputStream destKeyStream, Properties options)` Create a new session, reading the Destination, PrivateKey, and SigningPrivateKey from the destKeyStream, and using the specified options to connect to the router

Method Summary
`void` `addMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port)` See I2PSessionMuxedImpl for details
`void` `addSessionListener(I2PSessionListener lsnr, int proto, int port)` See I2PSessionMuxedImpl for details
`void` `destroySession(boolean sendDisconnect)` Tear down the session, and do NOT reconnect.
`protected long` `getTimeout()`
`byte[]` `receiveMessage(int msgId)` pull the unencrypted AND DECOMPRESSED data
`void` `receiveStatus(int msgId, long nonce, int status)` Only call this with nonzero status, i.e.
`protected boolean` `reconnect()` Called whenever we want to reconnect (used only in the superclass).
`void` `removeListener(int proto, int port)` See I2PSessionMuxedImpl for details
`protected boolean` `sendBestEffort(Destination dest, byte[] payload, long expires, int flags)` TODO - Don't need to save MessageState since actuallyWait is false...
`protected boolean` `sendBestEffort(Destination dest, byte[] payload, SessionKey keyUsed, Set tagsSent, long expires)`
`boolean` `sendMessage(Destination dest, byte[] payload)` Send a new message to the given destination, containing the specified payload, returning true if the router feels confident that the message was delivered.
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size)`
`boolean` `sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport)` See I2PSessionMuxedImpl for proto/port details.
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent)` End-to-End Crypto is disabled, tags and keys are ignored.
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, int proto, int fromport, int toport)` See I2PSessionMuxedImpl for proto/port details.
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expires)` End-to-End Crypto is disabled, tags and keys are ignored.
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expire, int proto, int fromport, int toport)` See I2PSessionMuxedImpl for proto/port details.
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expire, int proto, int fromport, int toport, int flags)` See I2PSessionMuxedImpl for proto/port details.
`boolean` `sendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set tagsSent)` End-to-End Crypto is disabled, tags and keys are ignored! Like sendMessage above, except the key used and the tags sent are exposed to the application.
`protected boolean` `sendNoEffort(Destination dest, byte[] payload, long expires)` Same as sendBestEffort(), except we do not expect any MessageStatusMessage responses - not for accepted, or success, or failure.
`protected boolean` `shouldCompress(int size)`

Methods inherited from class net.i2p.client.I2PSessionImpl

`addNewMessage, bandwidthLimits, bwReceived, connect, dateUpdated, destLookupFailed, destReceived, destroySession, disconnect, disconnected, getDecryptionKey, getLeaseSet, getMyDestination, getOpening, getOptions, getPrefix, getPrivateKey, getProducer, getSessionId, isClosed, lastActivity, loadConfig, lookupDest, lookupDest, messageReceived, propogateError, readError, reportAbuse, sendMessage, setLeaseSet, setOpening, setReduced, setSessionId, setSessionListener, shouldReconnect, toString, updateActivity, updateOptions`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### I2PSessionImpl2

    public I2PSessionImpl2()

  for extension

### I2PSessionImpl2

    public I2PSessionImpl2(I2PAppContext ctx,
                           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

  Parameters:
    `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 or

Method Detail

### getTimeout

    protected long getTimeout()

### destroySession

    public void destroySession(boolean sendDisconnect)

  Description copied from class: `I2PSessionImpl`
  Tear down the session, and do NOT reconnect. Blocks if session has not been fully started.

  Overrides:
    `destroySession` in class `I2PSessionImpl`

### shouldCompress

    protected boolean shouldCompress(int size)

### addSessionListener

    public void addSessionListener(I2PSessionListener lsnr,
                                   int proto,
                                   int port)

  Description copied from interface: `I2PSession`
  See I2PSessionMuxedImpl for details

### addMuxedSessionListener

    public void addMuxedSessionListener(I2PSessionMuxedListener l,
                                        int proto,
                                        int port)

  Description copied from interface: `I2PSession`
  See I2PSessionMuxedImpl for details

### removeListener

    public void removeListener(int proto,
                               int port)

  Description copied from interface: `I2PSession`
  See I2PSessionMuxedImpl for details

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               int proto,
                               int fromport,
                               int toport)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  See I2PSessionMuxedImpl for proto/port details.

  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               int offset,
                               int size,
                               SessionKey keyUsed,
                               Set tagsSent,
                               int proto,
                               int fromport,
                               int toport)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  See I2PSessionMuxedImpl for proto/port details. End-to-End Crypto is disabled, tags and keys are ignored.

    `keyUsed` - UNUSED, IGNORED.
    `tagsSent` - UNUSED, IGNORED.
  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               int offset,
                               int size,
                               SessionKey keyUsed,
                               Set tagsSent,
                               long expire,
                               int proto,
                               int fromport,
                               int toport)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  See I2PSessionMuxedImpl for proto/port details. End-to-End Crypto is disabled, tags and keys are ignored.

    `keyUsed` - UNUSED, IGNORED.
    `tagsSent` - UNUSED, IGNORED.
  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               int offset,
                               int size,
                               SessionKey keyUsed,
                               Set tagsSent,
                               long expire,
                               int proto,
                               int fromport,
                               int toport,
                               int flags)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  See I2PSessionMuxedImpl for proto/port details. End-to-End Crypto is disabled, tags and keys are ignored.

    `keyUsed` - UNUSED, IGNORED.
    `tagsSent` - UNUSED, IGNORED.
  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  Send a new message to the given destination, containing the specified payload, returning true if the router feels confident that the message was delivered.

  Parameters:
    `dest` - location to send the message
    `payload` - body of the message to be sent (unencrypted)
  Returns:
    whether it was accepted by the router for delivery or not
  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               int offset,
                               int size)
                        throws I2PSessionException

  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               SessionKey keyUsed,
                               Set tagsSent)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  End-to-End Crypto is disabled, tags and keys are ignored! Like sendMessage above, except the key used and the tags sent are exposed to the application.

  If some application layer message delivery confirmation is used, rather than i2p's (slow) built in confirmation via guaranteed delivery mode, the application can update the SessionKeyManager, ala:

         SessionKeyManager.getInstance().tagsDelivered(dest.getPublicKey(), keyUsed, tagsSent);

  If an application is using guaranteed delivery mode, this is not useful, but for applications using best effort delivery mode, if they can know with certainty that a message was delivered and can update the SessionKeyManager appropriately, a significant performance boost will occur (subsequent message encryption and decryption will be done via AES and a SessionTag, rather than ElGamal+AES, which is 1000x slower).

  Parameters:
    `keyUsed` - unused - no end-to-end crypto
    `tagsSent` - unused - no end-to-end crypto
    `dest` - location to send the message
    `payload` - body of the message to be sent (unencrypted)
  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               int offset,
                               int size,
                               SessionKey keyUsed,
                               Set tagsSent)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  End-to-End Crypto is disabled, tags and keys are ignored.

  Parameters:
    `keyUsed` - unused - no end-to-end crypto
    `tagsSent` - unused - no end-to-end crypto
  Throws:
    `I2PSessionException`

### sendMessage

    public boolean sendMessage(Destination dest,
                               byte[] payload,
                               int offset,
                               int size,
                               SessionKey keyUsed,
                               Set tagsSent,
                               long expires)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  End-to-End Crypto is disabled, tags and keys are ignored.

  Parameters:
    `keyUsed` - unused - no end-to-end crypto
    `tagsSent` - unused - no end-to-end crypto
  Throws:
    `I2PSessionException`

### receiveMessage

    public byte[] receiveMessage(int msgId)
                          throws I2PSessionException

  pull the unencrypted AND DECOMPRESSED data

  Specified by:
    `receiveMessage` in interface `I2PSession`
  Overrides:
    `receiveMessage` in class `I2PSessionImpl`
  Parameters:
    `msgId` - message to fetch
  Returns:
    unencrypted body of the message, or null if not found
  Throws:
    `I2PSessionException`

### sendBestEffort

    protected boolean sendBestEffort(Destination dest,
                                     byte[] payload,
                                     SessionKey keyUsed,
                                     Set tagsSent,
                                     long expires)
                              throws I2PSessionException

  Parameters:
    `keyUsed` - unused - no end-to-end crypto
    `tagsSent` - unused - no end-to-end crypto
  Throws:
    `I2PSessionException`

### sendBestEffort

    protected boolean sendBestEffort(Destination dest,
                                     byte[] payload,
                                     long expires,
                                     int flags)
                              throws I2PSessionException

  TODO - Don't need to save MessageState since actuallyWait is false... But for now just use sendNoEffort() instead.

  Parameters:
    `flags` - to be passed to the router
  Throws:
    `I2PSessionException`
  Since:
    0.8.4

### sendNoEffort

    protected boolean sendNoEffort(Destination dest,
                                   byte[] payload,
                                   long expires)
                            throws I2PSessionException

  Same as sendBestEffort(), except we do not expect any MessageStatusMessage responses - not for accepted, or success, or failure. So we don't create a MessageState and save it on the _sendingStates HashSet

  Returns:
    true always
  Throws:
    `I2PSessionException`
  Since:
    0.8.1

### receiveStatus

    public void receiveStatus(int msgId,
                              long nonce,
                              int status)

  Only call this with nonzero status, i.e. for outbound messages whose MessageState may be queued on _sendingStates. Even when using sendBestEffort(), this is a waste, because the MessageState is removed from _sendingStates immediately and so the lookup here fails. And iterating through the HashSet instead of having a map is bad too. This is now pretty much avoided since streaming now sets i2cp.messageReliability = none, which forces sendNoEffort() instead of sendBestEffort(), so the router won't send us any MSM's for outbound traffic.

  Specified by:
    `receiveStatus` in class `I2PSessionImpl`
  Parameters:
    `status` - != 0

### reconnect

    protected boolean reconnect()

  Called whenever we want to reconnect (used only in the superclass). We need to override this to clear out the message state

  Overrides:
    `reconnect` in class `I2PSessionImpl`