- All Implemented Interfaces:
I2PSession, I2CPMessageReader.I2CPMessageEventListener
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.
Nested Class Summary
Nested classes/interfaces inherited from class I2PSessionMuxedImpl
I2PSessionMuxedImpl.MuxedAvailabilityNotifierModifier and TypeClassDescriptionprotected classMuxedAvailabilityNotifier Extends AvailabilityNotifier.Nested classes/interfaces inherited from class I2PSessionImpl
I2PSessionImpl.AvailabilityNotifier, I2PSessionImpl.StateModifier and TypeClassDescriptionprotected classThis notifies the client of payload messages.protected static enumSession state enumeration.Nested classes/interfaces inherited from interface I2PSession
I2PSession.TunnelPairModifier and TypeInterfaceDescriptionstatic classSimple holder for tunnel pair information.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PSessionMuxedImplThe session this one shares its connection with.Fields inherited from class I2PSessionImpl2
_noEffort, _sendingStates, _sendMessageNonceModifier and TypeFieldDescriptionprotected booleanDon't expect any MSMs from the router for outbound traffic.protected final Map<Long, MessageState> One MessageState object per message in the process of being sent.protected final AtomicLongSource of the per-message replay nonces sent to the router.Fields inherited from class I2PSessionImpl
_availabilityNotifier, _availableMessages, _bwLimits, _bwReceivedLock, _context, _handlerMap, _hostname, _leaseSet, _leaseSetWait, _log, _pendingLookups, _portNum, _producer, _queue, _reader, _sessionListener, _socket, _state, _stateLock, _transientSigningPublicKey, _tunnelStatusListeners, _writer, CACHE_MAX_SIZE, DUMMY_SESSION, LISTEN_PORT, PROP_DOMAIN_SOCKETModifier and TypeFieldDescriptionprotected I2PSessionImpl.AvailabilityNotifierThread that we tell when new messages are available, who then tells us to fetch them.protected Map<Long, MessagePayloadMessage> Map of Long--> MessagePayloadMessage.protected int[]Current bandwidth limits.protected final ObjectLock for bandwidth limit updates.protected final I2PAppContextApp context, kept separate so we can get rid of singletons.protected final I2PClientMessageHandlerMapHandler map for I2CP message types.protected final StringHostname of router - will be null if in RouterContext.protected LeaseSetCurrently granted lease set, or null.protected final ObjectMonitor for waiting until a lease set has been granted.protected final LogLogger for this session.protected final LinkedBlockingQueue<I2PSessionImpl.LookupWaiter> Hashes of lookups we are waiting for.protected final intPort number of router - will be 0 if in RouterContext.protected final I2CPMessageProducerClass that generates new messages.protected I2CPMessageQueueUsed for internal connections to the router.protected I2CPMessageReaderReader that always searches for messages.protected I2PSessionListenerWhere session events are sent.protected SocketSocket for communication.protected I2PSessionImpl.StateCurrent session state.protected final ObjectLock for state transitions.protected SigningPublicKeyTransient signing public key for offline signatures.protected final Set<TunnelStatusListener> Listeners for tunnel status changes (tunnel failures and removals).protected ClientWriterRunnerWriter message queue.protected static final intMaximum size of the lookup cache.(package private) static final SessionIdDummy session ID for messages before a real session is established.static final intDefault I2CP listen port.protected static final StringUse Unix domain socket (or similar) to connect to a router.Fields inherited from interface I2PSession
PORT_ANY, PORT_UNSPECIFIED, PROTO_ANY, PROTO_DATAGRAM, PROTO_DATAGRAM_RAW, PROTO_DATAGRAM2, PROTO_DATAGRAM3, PROTO_STREAMING, PROTO_UNSPECIFIEDModifier and TypeFieldDescriptionstatic final intAny port.static final intUnspecified port.static final intAny protocol.static final intA repliable and signed datagram.static final intA raw (unsigned, unrepliable) datagram.static final intA repliable and signed datagram.static final intA repliable but unsigned datagram.static final intStreaming protocol.static final intUnspecified protocol.Constructor Summary
ConstructorsConstructorDescriptionSubSession(I2PSession primary, InputStream destKeyStream, Properties options) Must be a I2PSessionMuxedImpl.Method Summary
Public MethodsModifier and TypeMethodDescriptionaddSubsession(InputStream destKeyStream, Properties opts) Unsupported in a subsession.int[]This won't be called, as the reply does not contain a session ID, so it won't be routed back to us.(package private) voidbwReceived(int[] i) Called by the message handler.voidconnect()Connect to the router and establish a session.(package private) voiddestLookupFailed(long nonce, int code) Called by the message handler on reception of HostReplyMessage.(package private) voidCalled by the message handler on reception of DestReplyMessage(package private) voiddestReceived(long nonce, Destination d) Called by the message handler on reception of HostReplyMessage.(package private) voidCalled by the message handler on reception of DestReplyMessagevoidTear down the session, and do NOT reconnect.protected voidWill interrupt a connect in progress.Options the primary session was created with.Unsupported in a subsession.booleanisClosed()Has the session been closed (or not yet connected)? False when open and during transitions.longTime of last session activity in milliseconds.lookupDest(String name) Ask the router to lookup a Destination by host name.lookupDest(String name, long maxWait) Ask the router to lookup a Destination by host name.lookupDest(Hash h) Blocking.lookupDest(Hash h, long maxWait) Looks up a Destination, blocking up to the given wait for the answer.(package private) voidpropagateError(String msg, Throwable error) Pass off the error to the listener Misspelled, oh well.protected booleanReconnect the I2CP session.voidremoveSubsession(I2PSession session) Unsupported in a subsession.(package private) voidsendMessage(I2CPMessage message) Deliver an I2CP message to the router May block for several seconds if the write queue to the router is full.(package private) voidsendMessage_unchecked(I2CPMessage message) Deliver an I2CP message to the router.voidMark the session as reduced.protected voidUpdate the last activity timestamp.voidupdateOptions(Properties options) Does nothing for now.Methods inherited from class I2PSessionMuxedImpl
addMuxedSessionListener, addNewMessage, addSessionListener, removeListener, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, setSessionListenerModifier and TypeMethodDescriptionvoidaddMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port) Listen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.voidStore a received payload message and notify the client that it is available, including the protocol and ports it arrived on.voidaddSessionListener(I2PSessionListener lsnr, int proto, int port) Listen on specified protocol and port.voidremoveListener(int proto, int port) Remove the specified listener (only).booleansendMessage(Destination dest, byte[] payload) Send an I2CP message, with the protocol and ports unset.booleansendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) Send an I2CP message.booleansendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options) See SendMessageOptions for option 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, int proto, int fromport, int toport) Send a message with session key and tags.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) Send a message with session key and tags.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort) Send a message with protocol and port information.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort, int flags) Send a message with protocol, port, and flags.voidListen on all protocols and ports.Methods inherited from class I2PSessionImpl2
addTunnelStatusListener, destroySession, getCurrentTunnelPair, getTimeout, notifyPoolShuttingDown, notifyTunnelFailed, notifyTunnelRemoved, rebuildTunnels, receiveMessage, receiveStatus, removeTunnelStatusListener, sendBestEffort, sendBestEffort, sendMessage, sendMessage, sendMessage, sendNoEffort, setCurrentTunnelPair, shouldCompress, startVerifyUsage, switchToNewTunnelModifier and TypeMethodDescriptionvoidRegister a tunnel status listener.voiddestroySession(boolean sendDisconnect) Destroy the I2P session, after clearing the message send states.Return the current tunnel pair.protected longWait this long for the router to accept a sent message, in ms.protected voidnotifyPoolShuttingDown(String poolName, boolean isInbound) Notify all tunnel status listeners of pool shutdown.protected voidnotifyTunnelFailed(String poolName, boolean isInbound) Notify all tunnel status listeners of a tunnel failure.protected voidNotify all tunnel status listeners of a tunnel removal.voidRebuild the tunnel set.byte[]receiveMessage(int msgId) Receive a message from the router, decompressing it unless it was sent uncompressed.voidreceiveStatus(int msgId, long nonce, int status) Only call this with nonzero status, i.e.voidRemove a tunnel status listener.protected booleansendBestEffort(Destination dest, byte[] payload, long expires, int flags) Send a best-effort message with the given flags.protected booleansendBestEffort(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) Send a message with best effort delivery.booleansendMessage(Destination dest, byte[] payload, int offset, int size) Send an I2CP message.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent) Send a message with session key and tags.booleansendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent) Send a message with session key and tags.protected booleansendNoEffort(Destination dest, byte[] payload, long expires, int flags) Same asI2PSessionImpl2.sendBestEffort(Destination, byte[], SessionKey, Set, long), except we do not expect any MessageStatusMessage responses - not for accepted, or success, or failure.voidCurrent tunnel pair in use.protected booleanshouldCompress(int size) Return whether compression should be used.protected voidFire up a periodic task to check for unclaimed messages.booleanSwitch to the new tunnel set.Methods inherited from class I2PSessionImpl
changeState, clearCache, dateUpdated, discardMessage, disconnected, getContext, getFastReceive, getHandlerMap, getLastLS2SignTime, getLeaseSet, getMyDestination, getName, getOfflineExpiration, getOfflineSignature, getOptions, getPrefix, getPrivateKey, getProducer, getRouterVersion, getSessionId, getTransientSigningPublicKey, getTunnelBuildTimeout, isOffline, lookupDest, lookupDest, lookupDest2, messageReceived, readError, reportAbuse, sendBlindingInfo, setLastLS2SignTime, setLeaseSet, setSessionId, shouldReconnect, supportsLS2, toString, verifyOpen, waitForDateModifier and TypeMethodDescriptionprotected voidchangeState(I2PSessionImpl.State state) Change the session state.static voidClear the lookup cache.(package private) voiddateUpdated(String routerVersion) Update the router version and related feature support flags.voiddiscardMessage(int msgId) Throw away the received message, we don't want it.voiddisconnected(I2CPMessageReader reader) The I2CPMessageEventListener callback.(package private) I2PAppContextFor Subsessions.booleanDoes this session support fast receive?(package private) I2PClientMessageHandlerMapFor Subsessions.(package private) longThe published timestamp of the last LS2 we signed.Current lease set published by this session.Retrieve the destination of the session.protected StringgetName()Session name for logging.longJava time (ms) or 0 if not initialized or does not have offline keys.Null on error or if not initialized or does not have offline keys.Retrieve the configuration options, filtered.protected final StringTry hard to make a decent identifier as this will appear in error logs.Retrieve the signing SigningPrivateKey.(package private) I2CPMessageProducerRetrieve the helper that generates I2CP messages.Always valid in RouterContext.(package private) SessionIdRetrieve the session's ID.Null on error or if not initialized or does not have offline keys.(package private) static intgetTunnelBuildTimeout(String sessionValue, String contextValue) Parse the tunnel build timeout, shared with the instance method and tests.booleanDoes this session have offline and transient keys?lookupDest(String name, long maxWait, LookupCallback callback) Lookup a Destination by hash.lookupDest(Hash h, long maxWait, LookupCallback callback) Lookup a Destination by hostname.lookupDest2(String name, long maxWait) Ask the router to lookup a Destination by host name.voidmessageReceived(I2CPMessageReader reader, I2CPMessage message) The I2CPMessageEventListener callback.voidreadError(I2CPMessageReader reader, Exception error) The I2CPMessageEventListener callback.voidreportAbuse(int msgId, int severity) Report abuse with regards to the given messageId.voidSend blinding info to a peer.(package private) voidsetLastLS2SignTime(long now) The published timestamp of the last LS2 we signed.(package private) voidsetLeaseSet(LeaseSet ls) Lease set published by this session.(package private) voidSession ID assigned by the router.protected booleanWhether the session should attempt reconnection on disconnect.booleanDoes this session support LS2?toString()protected voidThrows I2PSessionException if uninitialized, closed or closing.protected voidWait for a SetDate response from the router.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface I2PSession
getDecryptionKeyModifier and TypeMethodDescriptionRetrieve the decryption PrivateKey associated with the Destination.
Field Details
_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 I2PSessionMuxedImpldestKeyStream- location from which to read keysoptions- 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:
addSubsessionin interfaceI2PSession- Overrides:
addSubsessionin classI2PSessionImpl- Parameters:
destKeyStream- null for transient, if non-null must have same encryption keys as primary sessionopts- subsession options if any, may be null- Returns:
- a new subsession, non-null
- Throws:
UnsupportedOperationException- always, as a subsession cannot hold subsessionsI2PSessionException- if the router does not support sub-sessions, or a sub-session request is pending or the same key was already added
removeSubsession
Unsupported in a subsession. Does nothing.- Specified by:
removeSubsessionin interfaceI2PSession- Overrides:
removeSubsessionin classI2PSessionImpl- Parameters:
session- the subsession to remove
getSubsessions
Unsupported in a subsession.- Specified by:
getSubsessionsin interfaceI2PSession- Overrides:
getSubsessionsin classI2PSessionImpl- Returns:
- empty list always
updateOptions
Does nothing for now.- Specified by:
updateOptionsin interfaceI2PSession- Overrides:
updateOptionsin classI2PSessionImpl- Parameters:
options- non-null
getPrimaryOptions
Options the primary session was created with.- Returns:
- the primary session's options, never null
connect
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:
connectin interfaceI2PSession- Overrides:
connectin classI2PSessionImpl- 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:
isClosedin interfaceI2PSession- Overrides:
isClosedin classI2PSessionImpl- Returns:
- true if this subsession or its primary has been closed
sendMessage
Deliver an I2CP message to the router May block for several seconds if the write queue to the router is full.- Overrides:
sendMessagein classI2PSessionImpl- Parameters:
message- the I2CP message to send- Throws:
I2PSessionException- if the message is malformed or there is an error writing it out
sendMessage_unchecked
Deliver an I2CP message to the router. Does NOT check state. Call only fromconnect()or other methods that need to send messages when not in OPEN state.- Overrides:
sendMessage_uncheckedin classI2PSessionImpl- Parameters:
message- the I2CP message to send- Throws:
I2PSessionException- if the message is malformed or there is an error writing it out
propagateError
Pass off the error to the listener Misspelled, oh well.- Overrides:
propagateErrorin classI2PSessionImpl- Parameters:
msg- the error messageerror- 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:
destroySessionin interfaceI2PSession- Overrides:
destroySessionin classI2PSessionImpl
disconnect
protected void disconnect()Will interrupt a connect in progress.- Overrides:
disconnectin classI2PSessionImpl
reconnect
protected boolean reconnect()Description copied from class:I2PSessionImpl2Reconnect the I2CP session. Called by the superclass whenever it wants to reconnect; overridden to also clear out the message state.- Overrides:
reconnectin classI2PSessionImpl2- Returns:
- whether the session was reconnected
destReceived
Called by the message handler on reception of DestReplyMessageThis will never happen, as the dest reply message does not contain a session ID.
- Overrides:
destReceivedin classI2PSessionImpl- Parameters:
d- non-null
destLookupFailed
Called by the message handler on reception of DestReplyMessageThis will never happen, as the dest reply message does not contain a session ID.
- Overrides:
destLookupFailedin classI2PSessionImpl- Parameters:
h- non-null
destReceived
Called by the message handler on reception of HostReplyMessage.- Overrides:
destReceivedin classI2PSessionImpl- Parameters:
nonce- the lookup nonced- non-null
destLookupFailed
void destLookupFailed(long nonce, int code) Called by the message handler on reception of HostReplyMessage.- Overrides:
destLookupFailedin classI2PSessionImpl- Parameters:
nonce- the lookup noncecode- 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:
bwReceivedin classI2PSessionImpl- Parameters:
i- the bandwidth limits
lookupDest
Blocking. Waits a max of 10 seconds by default. See lookupDest with maxWait parameter to change. Implemented in 0.8.3 inI2PSessionImpl; previously was availableI2PSimpleSessioneSession. Multiple outstanding lookups are now allowed.- Specified by:
lookupDestin interfaceI2PSession- Overrides:
lookupDestin classI2PSessionImpl- Parameters:
h- the hash to look up- Returns:
- null on failure
- Throws:
I2PSessionException- if the calling thread is interrupted while waiting
lookupDest
Looks up a Destination, blocking up to the given wait for the answer.- Specified by:
lookupDestin interfaceI2PSession- Overrides:
lookupDestin classI2PSessionImpl- Parameters:
h- the hash to look upmaxWait- the maximum time to wait, in milliseconds- Returns:
- null on failure
- Throws:
I2PSessionException- if the calling thread is interrupted while waiting
lookupDest
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:
lookupDestin interfaceI2PSession- Overrides:
lookupDestin classI2PSessionImpl- 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
Ask the router to lookup a Destination by host name. Blocking. See above for details.- Specified by:
lookupDestin interfaceI2PSession- Overrides:
lookupDestin classI2PSessionImpl- Parameters:
name- the hostname to look upmaxWait- the maximum time to wait, in milliseconds- Returns:
- null on failure
- Throws:
I2PSessionException- if the calling thread is interrupted while waiting
bandwidthLimits
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:
bandwidthLimitsin interfaceI2PSession- Overrides:
bandwidthLimitsin classI2PSessionImpl- Returns:
- null on failure
- Throws:
I2PSessionException- if the calling thread is interrupted while waiting
updateActivity
protected void updateActivity()Description copied from class:I2PSessionImplUpdate the last activity timestamp.- Overrides:
updateActivityin classI2PSessionImpl
lastActivity
public long lastActivity()Description copied from class:I2PSessionImplTime of last session activity in milliseconds.- Overrides:
lastActivityin classI2PSessionImpl- Returns:
- the last activity timestamp
setReduced
public void setReduced()Description copied from class:I2PSessionImplMark the session as reduced.- Overrides:
setReducedin classI2PSessionImpl