Package net.i2p.client.impl
Class I2PSessionImpl2
- java.lang.Object
- 
- net.i2p.client.impl.I2PSessionImpl
- 
- net.i2p.client.impl.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. Unused directly, see I2PSessionMuxedImpl extension.- Author:
- jrandom
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class net.i2p.client.impl.I2PSessionImplI2PSessionImpl.AvailabilityNotifier, I2PSessionImpl.State
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected boolean_noEffortDon't expect any MSMs from the router for outbound traffic @since 0.8.1protected Map<Long,MessageState>_sendingStatesset of MessageState objects, representing all of the messages in the process of being sentprotected AtomicLong_sendMessageNonce- 
Fields inherited from class net.i2p.client.impl.I2PSessionImpl_availabilityNotifier, _availableMessages, _bwLimits, _bwReceivedLock, _context, _handlerMap, _hostname, _leaseSet, _leaseSetWait, _log, _pendingLookups, _portNum, _producer, _queue, _reader, _sessionListener, _socket, _state, _stateLock, _transientSigningPublicKey, _writer, CACHE_MAX_SIZE, LISTEN_PORT, PROP_DOMAIN_SOCKET
 - 
Fields inherited from interface net.i2p.client.I2PSessionPORT_ANY, PORT_UNSPECIFIED, PROTO_ANY, PROTO_DATAGRAM, PROTO_DATAGRAM_RAW, PROTO_STREAMING, PROTO_UNSPECIFIED
 
- 
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedI2PSessionImpl2(I2PSessionImpl primary, InputStream destKeyStream, Properties options)protectedI2PSessionImpl2(I2PAppContext ctx, InputStream destKeyStream, Properties options)for extension by I2PSessionMuxedImpl Create a new session, reading the Destination, PrivateKey, and SigningPrivateKey from the destKeyStream, and using the specified options to connect to the routerprotectedI2PSessionImpl2(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap)for extension by SimpleSession (no dest)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port)Listen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.voidaddSessionListener(I2PSessionListener lsnr, int proto, int port)Listen on specified protocol and port.voiddestroySession(boolean sendDisconnect)Tear down the session, and do NOT reconnect.protected longgetTimeout()byte[]receiveMessage(int msgId)pull the unencrypted AND DECOMPRESSED datavoidreceiveStatus(int msgId, long nonce, int status)Only call this with nonzero status, i.e.protected booleanreconnect()Called whenever we want to reconnect (used only in the superclass).voidremoveListener(int proto, int port)removes the specified listener (only)protected booleansendBestEffort(Destination dest, byte[] payload, long expires, int flags)TODO - Don't need to save MessageState since actuallyWait is false...protected booleansendBestEffort(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires)booleansendMessage(Destination dest, byte[] payload)unused, see MuxedImpl overridebooleansendMessage(Destination dest, byte[] payload, int offset, int size)Send a new message to the given destination, containing the specified payload, returning true if the router feels confident that the message was delivered.booleansendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport)See I2PSessionMuxedImpl for proto/port details.booleansendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromport, int toport, SendMessageOptions options)See I2PSessionMuxedImpl for proto/port details.longsendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromport, int toport, SendMessageOptions options, SendMessageStatusListener listener)Send a message and request an asynchronous notification of delivery status.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent)End-to-End Crypto is disabled, tags and keys are ignored.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromport, int toport)See I2PSessionMuxedImpl for proto/port details.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires)Unused? see MuxedImpl overridebooleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromport, int toport)See I2PSessionMuxedImpl for proto/port details.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromport, int toport, int flags)See I2PSessionMuxedImpl for proto/port details.booleansendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> 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 booleansendNoEffort(Destination dest, byte[] payload, long expires, int flags)Same as sendBestEffort(), except we do not expect any MessageStatusMessage responses - not for accepted, or success, or failure.protected booleanshouldCompress(int size)protected voidstartVerifyUsage()Fire up a periodic task to check for unclaimed messages- 
Methods inherited from class net.i2p.client.impl.I2PSessionImpladdNewMessage, addSubsession, bandwidthLimits, bwReceived, changeState, clearCache, connect, dateUpdated, destLookupFailed, destLookupFailed, destReceived, destReceived, destroySession, disconnect, disconnected, getContext, getDecryptionKey, getFastReceive, getHandlerMap, getLeaseSet, getMyDestination, getName, getOfflineExpiration, getOfflineSignature, getOptions, getPrefix, getPrivateKey, getProducer, getRouterVersion, getSessionId, getSubsessions, getTransientSigningPublicKey, isClosed, isOffline, lastActivity, lookupDest, lookupDest, lookupDest, lookupDest, lookupDest2, messageReceived, propogateError, readError, removeSubsession, reportAbuse, sendBlindingInfo, sendMessage, sendMessage_unchecked, setLeaseSet, setReduced, setSessionId, setSessionListener, shouldReconnect, supportsLS2, toString, updateActivity, updateOptions, verifyOpen, waitForDate
 
- 
 
- 
- 
- 
Field Detail- 
_sendingStatesprotected final Map<Long,MessageState> _sendingStates set of MessageState objects, representing all of the messages in the process of being sent
 - 
_sendMessageNonceprotected final AtomicLong _sendMessageNonce 
 - 
_noEffortprotected boolean _noEffort Don't expect any MSMs from the router for outbound traffic @since 0.8.1
 
- 
 - 
Constructor Detail- 
I2PSessionImpl2protected I2PSessionImpl2(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap) for extension by SimpleSession (no dest)
 - 
I2PSessionImpl2protected I2PSessionImpl2(I2PAppContext ctx, InputStream destKeyStream, Properties options) throws I2PSessionException for extension by I2PSessionMuxedImpl Create a new session, reading the Destination, PrivateKey, and SigningPrivateKey from the destKeyStream, and using the specified options to connect to the router- Parameters:
- 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
 
 - 
I2PSessionImpl2protected I2PSessionImpl2(I2PSessionImpl primary, InputStream destKeyStream, Properties options) throws I2PSessionException - Throws:
- I2PSessionException
 
 
- 
 - 
Method Detail- 
startVerifyUsageprotected void startVerifyUsage() Fire up a periodic task to check for unclaimed messages- Overrides:
- startVerifyUsagein class- I2PSessionImpl
- Since:
- 0.9.14
 
 - 
getTimeoutprotected long getTimeout() 
 - 
destroySessionpublic void destroySession(boolean sendDisconnect) Description copied from class:I2PSessionImplTear down the session, and do NOT reconnect. Will interrupt an open in progress. Calls sessionlistener.disconnected()- Overrides:
- destroySessionin class- I2PSessionImpl
 
 - 
shouldCompressprotected boolean shouldCompress(int size) 
 - 
addSessionListenerpublic void addSessionListener(I2PSessionListener lsnr, int proto, int port) Description copied from interface:I2PSessionListen 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.- 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
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
 
 - 
addMuxedSessionListenerpublic void addMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port) Description copied from interface:I2PSessionListen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.- proto- 1-254 or PROTO_ANY (0) for all; 255 disallowed
- port- 1-65535 or PORT_ANY (0) for all
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
 
 - 
removeListenerpublic void removeListener(int proto, int port)Description copied from interface:I2PSessionremoves the specified listener (only)- Throws:
- UnsupportedOperationException- always, use MuxedImpl
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) throws I2PSessionException Description copied from interface:I2PSessionSee I2PSessionMuxedImpl for proto/port details.- Returns:
- success
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
- I2PSessionException
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromport, int toport) throws I2PSessionException Description copied from interface:I2PSessionSee I2PSessionMuxedImpl for proto/port details. End-to-End Crypto is disabled, tags and keys are ignored.- keyUsed- UNUSED, IGNORED.
- tagsSent- UNUSED, IGNORED.
- 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:
- success
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
- I2PSessionException
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromport, int toport) throws I2PSessionException Description copied from interface:I2PSessionSee I2PSessionMuxedImpl for proto/port details. End-to-End Crypto is disabled, tags and keys are ignored.- keyUsed- UNUSED, IGNORED.
- tagsSent- UNUSED, IGNORED.
- expire- 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:
- success
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
- I2PSessionException
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromport, int toport, int flags) throws I2PSessionException Description copied from interface:I2PSessionSee I2PSessionMuxedImpl for proto/port details. End-to-End Crypto is disabled, tags and keys are ignored.- keyUsed- UNUSED, IGNORED.
- tagsSent- UNUSED, IGNORED.
- expire- 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:
- success
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
- I2PSessionException
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromport, int toport, SendMessageOptions options) throws I2PSessionException Description copied from interface:I2PSessionSee I2PSessionMuxedImpl for proto/port details. See SendMessageOptions for option details.- 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:
- success
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
- I2PSessionException
 
 - 
sendMessagepublic long sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromport, int toport, SendMessageOptions options, SendMessageStatusListener listener) throws I2PSessionException Description copied from interface:I2PSessionSend a message and request an asynchronous notification of delivery status. Notifications will be delivered at least up to the expiration specified in the options, or 60 seconds if not specified. See I2PSessionMuxedImpl for proto/port details. See SendMessageOptions for option details.- 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:
- the message ID to be used for later notification to the listener
- Throws:
- UnsupportedOperationException- always, use MuxedImpl
- I2PSessionException- on all errors
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload) throws I2PSessionException unused, see MuxedImpl override- 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
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int offset, int size) throws I2PSessionException Description copied from interface:I2PSessionSend a new message to the given destination, containing the specified payload, returning true if the router feels confident that the message was delivered. WARNING: It is recommended that you use a method that specifies the protocol and ports.- Parameters:
- dest- location to send the message
- payload- body of the message to be sent (unencrypted)
- Returns:
- success
- Throws:
- I2PSessionException
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent) throws I2PSessionException Description copied from interface:I2PSessionEnd-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)
- Returns:
- success
- Throws:
- I2PSessionException
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent) throws I2PSessionException Description copied from interface:I2PSessionEnd-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
- Returns:
- success
- Throws:
- I2PSessionException
 
 - 
sendMessagepublic boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) throws I2PSessionException Unused? see MuxedImpl override- Parameters:
- keyUsed- unused - no end-to-end crypto
- tagsSent- unused - no end-to-end crypto
- expires- absolute expiration timestamp, NOT interval from now
- Returns:
- success
- Throws:
- I2PSessionException
 
 - 
receiveMessagepublic byte[] receiveMessage(int msgId) throws I2PSessionExceptionpull the unencrypted AND DECOMPRESSED data- Specified by:
- receiveMessagein interface- I2PSession
- Overrides:
- receiveMessagein class- I2PSessionImpl
- Parameters:
- msgId- message to fetch
- Returns:
- unencrypted body of the message, or null if not found
- Throws:
- I2PSessionException
 
 - 
sendBestEffortprotected boolean sendBestEffort(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) throws I2PSessionException - Parameters:
- keyUsed- unused - no end-to-end crypto
- tagsSent- unused - no end-to-end crypto
- Throws:
- I2PSessionException
 
 - 
sendBestEffortprotected 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
 
 - 
sendNoEffortprotected boolean sendNoEffort(Destination dest, byte[] payload, long expires, int flags) 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
 
 - 
receiveStatuspublic 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. 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:
- receiveStatusin class- I2PSessionImpl
- Parameters:
- status- != 0
 
 - 
reconnectprotected 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:
- reconnectin class- I2PSessionImpl
 
 
- 
 
-