## net.i2p.client
Class I2PSessionImpl2

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

All Implemented Interfaces:
  I2PSession, I2CPMessageReader.I2CPMessageEventListener

     class I2PSessionImpl2

extends I2PSessionImpl

Thread safe implementation of an I2P session running over TCP.

Author:
  jrandom

Field Summary

Fields inherited from class net.i2p.client.I2PSessionImpl
`_context, _handlerMap, _producer, LISTEN_PORT`

Constructor Summary
`I2PSessionImpl2(I2PAppContext ctx, java.io.InputStream destKeyStream, java.util.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` `destroySession(boolean sendDisconnect)`
`protected long` `getTimeout()`
`byte[]` `receiveMessage(int msgId)` pull the unencrypted AND DECOMPRESSED data
`void` `receiveStatus(int msgId, long nonce, int status)`
`protected boolean` `reconnect()` Called whenever we want to reconnect (used only in the superclass).
`boolean` `sendMessage(Destination dest, byte[] payload)` Send the data to the destination.
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size)`
`boolean` `sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, java.util.Set tagsSent)`
`boolean` `sendMessage(Destination dest, byte[] payload, SessionKey keyUsed, java.util.Set tagsSent)` Like sendMessage above, except the key used and the tags sent are exposed to the application.

Methods inherited from class net.i2p.client.I2PSessionImpl
`addNewMessage, connect, createNewTags, dateUpdated, destroySession, disconnect, disconnected, getDecryptionKey, getLeaseSet, getMyDestination, getOptions, getPrefix, getPrivateKey, getProducer, getSessionId, isClosed, messageReceived, propogateError, readError, reportAbuse, sendMessage, setLeaseSet, setSessionId, setSessionListener, shouldReconnect`

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

Constructor Detail

### I2PSessionImpl2

    public I2PSessionImpl2(I2PAppContext ctx,
                           java.io.InputStream destKeyStream,
                           java.util.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

  Throws:
    `I2PSessionException` - if there is a problem loading the private keys or

Method Detail

### getTimeout

    protected long getTimeout()

### destroySession

    public void destroySession(boolean sendDisconnect)

  Overrides:
    `destroySession` in class `I2PSessionImpl`

### sendMessage

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

  Description copied from class: `I2PSessionImpl`
  Send the data to the destination. TODO: this currently always returns true, regardless of whether the message was delivered successfully. make this wait for at least ACCEPTED

  Specified by:
    `sendMessage` in interface `I2PSession`
  Specified by:
    `sendMessage` in class `I2PSessionImpl`
  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,
                               java.util.Set tagsSent)
                        throws I2PSessionException

  Description copied from interface: `I2PSession`
  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).

  Specified by:
    `sendMessage` in interface `I2PSession`
  Specified by:
    `sendMessage` in class `I2PSessionImpl`
  Parameters:
    `dest` - location to send the message
    `payload` - body of the message to be sent (unencrypted)
    `keyUsed` - session key delivered to the destination for association with the tags sent. This is essentially an output parameter - keyUsed.getData() is ignored during this call, but after the call completes, it will be filled with the bytes of the session key delivered. Typically the key delivered is the same one as the key encrypted with, but not always. If this is null then the key data will not be exposed.
    `tagsSent` - set of tags delivered to the peer and associated with the keyUsed. This is also an output parameter - the contents of the set is ignored during the call, but afterwards it contains a set of SessionTag objects that were sent along side the given keyUsed.
  Throws:
    `I2PSessionException`

### sendMessage

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

  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
  Throws:
    `I2PSessionException`

### receiveStatus

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

  Specified by:
    `receiveStatus` in class `I2PSessionImpl`

### 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`