- All Implemented Interfaces:
I2PSession, I2CPMessageReader.I2CPMessageEventListener
- Direct Known Subclasses:
I2PSessionMuxedImpl, I2PSimpleSession
Unused directly, see I2PSessionMuxedImpl extension.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classCheck for expired message states, without wastefully setting a timer for each message.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 I2PSession.TunnelPairThe tunnels carrying this session now.protected 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.private static MethodReflected accessor for the tunnel manager.private static final intDon't bother if really small.private static final longHow often expired leases are dropped - every 63 seconds.private static final longMax # seconds to wait for confirmation of the message send.private static final booleanShould we gzip each payload prior to sending it?private static final booleanWhether the router may send compressed lease sets.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
ConstructorsModifierConstructorDescriptionprotectedI2PSessionImpl2(I2PSessionImpl primary, InputStream destKeyStream, Properties options) For extension bySubSessionvia I2PSessionMuxedImplprotectedI2PSessionImpl2(I2PAppContext ctx, InputStream destKeyStream, Properties options) For extension by I2PSessionMuxedImplprotectedI2PSessionImpl2(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap) For extension by SimpleSession (no dest).Method Summary
Modifier and TypeMethodDescriptionvoidaddMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port) Register a muxed session listener.voidaddSessionListener(I2PSessionListener lsnr, int proto, int port) Register a session listener.voidRegister a tunnel status listener.private voidClear all pending message states.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.private ObjectCached reflection access toRouterContext.tunnelManager().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.protected booleanReconnect the I2CP session.voidremoveListener(int proto, int port) Remove a registered listener.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) Unused, see MuxedImpl override.booleansendMessage(Destination dest, byte[] payload, int offset, int size) Send an I2CP message.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) Send an I2CP message.longsendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromport, int toport, SendMessageOptions options, SendMessageStatusListener listener) 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, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromport, int toport) Send an I2CP message.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) Unused? See the MuxedImpl override.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromport, int toport) Send an I2CP message.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromport, int toport, int flags) Send an I2CP message.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 assendBestEffort(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
addNewMessage, addSubsession, bandwidthLimits, bwReceived, changeState, clearCache, connect, dateUpdated, destLookupFailed, destLookupFailed, destReceived, destReceived, destroySession, discardMessage, disconnect, disconnected, getContext, getFastReceive, getHandlerMap, getLastLS2SignTime, getLeaseSet, getMyDestination, getName, getOfflineExpiration, getOfflineSignature, getOptions, getPrefix, getPrivateKey, getProducer, getRouterVersion, getSessionId, getSubsessions, getTransientSigningPublicKey, getTunnelBuildTimeout, isClosed, isOffline, lastActivity, lookupDest, lookupDest, lookupDest, lookupDest, lookupDest, lookupDest, lookupDest2, messageReceived, propagateError, readError, removeSubsession, reportAbuse, sendBlindingInfo, sendMessage, sendMessage_unchecked, setLastLS2SignTime, setLeaseSet, setReduced, setSessionId, setSessionListener, shouldReconnect, supportsLS2, toString, updateActivity, updateOptions, verifyOpen, waitForDateModifier and TypeMethodDescriptionvoidReceive a payload message and let the app know its available.addSubsession(InputStream privateKeyStream, Properties opts) Router must be connected or was connected...int[]Blocking.(package private) voidbwReceived(int[] limits) Called by the message handler.protected voidchangeState(I2PSessionImpl.State state) Change the session state.static voidClear the lookup cache.voidconnect()Connect to the router and establish a session.(package private) voiddateUpdated(String routerVersion) Update the router version and related feature support flags.(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 DestReplyMessage.voidTear down the session, and do NOT reconnect.voiddiscardMessage(int msgId) Throw away the received message, we don't want it.protected voidWill interrupt a connect in progress.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.List of subsessions, non-null, does not include the primary session.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.booleanisClosed()Has the session been closed (or not yet connected)? False when open and during transitions.booleanDoes this session have offline and transient keys?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(String name, long maxWait, LookupCallback callback) Lookup a Destination by hash.lookupDest(Hash h) Blocking.lookupDest(Hash h, long maxWait) Blocking.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.(package private) voidpropagateError(String msg, Throwable error) Pass off the error to the listener Misspelled, oh well.voidreadError(I2CPMessageReader reader, Exception error) The I2CPMessageEventListener callback.voidremoveSubsession(I2PSession session) No-op, this session has no subsessions.voidreportAbuse(int msgId, int severity) Report abuse with regards to the given messageId.voidSend blinding info to a peer.(package private) voidsendMessage(I2CPMessage message) 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.(package private) voidsendMessage_unchecked(I2CPMessage message) Deliver an I2CP message to the router.(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.voidMark the session as reduced.(package private) voidSession ID assigned by the router.voidConfigure the listener.protected booleanWhether the session should attempt reconnection on disconnect.booleanDoes this session support LS2?toString()protected voidUpdate the last activity timestamp.voidupdateOptions(Properties options) Update the tunnel and bandwidth settings.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
_sendingStates
One MessageState object per message in the process of being sent._sendMessageNonce
Source of the per-message replay nonces sent to the router.SEND_TIMEOUT
private static final long SEND_TIMEOUTMax # seconds to wait for confirmation of the message send.- See Also:
SHOULD_COMPRESS
private static final boolean SHOULD_COMPRESSShould we gzip each payload prior to sending it?- See Also:
SHOULD_DECOMPRESS
private static final boolean SHOULD_DECOMPRESSWhether the router may send compressed lease sets.- See Also:
_noEffort
protected boolean _noEffortDon't expect any MSMs from the router for outbound traffic.REMOVE_EXPIRED_TIME
private static final long REMOVE_EXPIRED_TIMEHow often expired leases are dropped - every 63 seconds.- See Also:
_tunnelManagerMethod
Reflected accessor for the tunnel manager.DONT_COMPRESS_SIZE
private static final int DONT_COMPRESS_SIZEDon't bother if really small. Three 66-byte messages will fit in one tunnel message. Four messages don't fit no matter how small. So below 66 it isn't worth it. See ConnectionOptions.java in the streaming lib for similar calculations.Since we still have to pass it through gzip -0 the CPU savings is trivial but it's the best we can do for now. See below.
i2cp.gzipdefaults to SHOULD_COMPRESS = true.Perhaps the http server (which does its own compression) and P2P apps (with generally uncompressible data) should set to false.
- See Also:
_currentTunnelPair
The tunnels carrying this session now.
Constructor Details
I2PSessionImpl2
protected I2PSessionImpl2(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap) For extension by SimpleSession (no dest).- Parameters:
context- the app context whose router client the session sends throughoptions- router connection options, or null to use the System propertieshandlerMap- the map the session registers its incoming-message handlers in
I2PSessionImpl2
protected I2PSessionImpl2(I2PAppContext ctx, InputStream destKeyStream, Properties options) throws I2PSessionException For extension by I2PSessionMuxedImplCreate a new session, reading the Destination, PrivateKey, and SigningPrivateKey from the destKeyStream, and using the specified options to connect to the router.
- Parameters:
ctx- the app context whose router client the session sends throughdestKeyStream- stream containing the private key data, format is specified inPrivateKeyFileoptions- 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
I2PSessionImpl2
protected I2PSessionImpl2(I2PSessionImpl primary, InputStream destKeyStream, Properties options) throws I2PSessionException For extension bySubSessionvia I2PSessionMuxedImplCreate a new session, reading the Destination, PrivateKey, and SigningPrivateKey from the destKeyStream, and using the specified options to connect to the router.
- Parameters:
primary- the muxed session whose context, handlers and producer are shareddestKeyStream- stream containing the private key data, format is specified inPrivateKeyFileoptions- 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 parsed
Method Details
startVerifyUsage
protected void startVerifyUsage()Fire up a periodic task to check for unclaimed messages.- Overrides:
startVerifyUsagein classI2PSessionImpl
getTimeout
protected long getTimeout()Wait this long for the router to accept a sent message, in ms.- Returns:
- milliseconds to wait for the router to accept the message
destroySession
public void destroySession(boolean sendDisconnect) Destroy the I2P session, after clearing the message send states.- Overrides:
destroySessionin classI2PSessionImpl- Parameters:
sendDisconnect- if true, send a disconnect message to the router
shouldCompress
protected boolean shouldCompress(int size) Return whether compression should be used.- Parameters:
size- the uncompressed message size in bytes, compared to 66- Returns:
- true if the message should be compressed before sending
addSessionListener
Register a session listener. Not supported by this implementation - use I2PSessionMuxedImpl, which demultiplexes by protocol and port.- Parameters:
lsnr- the listenerproto- ignored - this implementation registers no listenersport- ignored - this implementation registers no listeners- Throws:
UnsupportedOperationException- always, as listeners are unsupported here
addMuxedSessionListener
Register a muxed session listener. Not supported by this implementation - use I2PSessionMuxedImpl.- Parameters:
l- the listenerproto- ignored - this implementation registers no listenersport- ignored - this implementation registers no listeners- Throws:
UnsupportedOperationException- always, as listeners are unsupported here
removeListener
public void removeListener(int proto, int port) Remove a registered listener. Not supported by this implementation - nothing is ever registered here.- Parameters:
proto- ignored - nothing is ever registered hereport- ignored - nothing is ever registered here- Throws:
UnsupportedOperationException- always, as no listener is ever registered
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) throws I2PSessionException Send an I2CP message. Not supported by this implementation - use I2PSessionMuxedImpl.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)proto- 1-254, or 0 for unset; 255 disallowedfromport- source port, 1-65535 or 0 for unsettoport- destination port, 1-65535 or 0 for unset- Returns:
- false always
- Throws:
UnsupportedOperationException- always, as muxed sends are unsupported hereI2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromport, int toport) throws I2PSessionException Send an I2CP message. Not supported by this implementation - use I2PSessionMuxedImpl.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- UNUSED, IGNORED, as end-to-end crypto is disabledtagsSent- UNUSED, IGNORED, as end-to-end crypto is disabledproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromport- 1-65535 or 0 for unsettoport- 1-65535 or 0 for unset- Returns:
- false always
- Throws:
UnsupportedOperationException- always, as muxed sends are unsupported hereI2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public 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 Send an I2CP message. Not supported by this implementation - use I2PSessionMuxedImpl.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- UNUSED, IGNORED, as end-to-end crypto is disabledtagsSent- UNUSED, IGNORED, as end-to-end crypto is disabledexpire- absolute expiration timestamp, NOT interval from nowproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromport- 1-65535 or 0 for unsettoport- 1-65535 or 0 for unset- Returns:
- false always
- Throws:
UnsupportedOperationException- always, as muxed sends are unsupported hereI2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public 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 Send an I2CP message. Not supported by this implementation - use I2PSessionMuxedImpl.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- UNUSED, IGNORED, as end-to-end crypto is disabledtagsSent- UNUSED, IGNORED, as end-to-end crypto is disabledexpire- absolute expiration timestamp, NOT interval from nowproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromport- 1-65535 or 0 for unsettoport- 1-65535 or 0 for unsetflags- packedSendMessageOptionsbits to send with the message- Returns:
- false always
- Throws:
UnsupportedOperationException- always, as muxed sends are unsupported hereI2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromport, int toport, SendMessageOptions options) throws I2PSessionException Send an I2CP message. Not supported by this implementation - use I2PSessionMuxedImpl.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromport- 1-65535 or 0 for unsettoport- 1-65535 or 0 for unsetoptions- to be passed to the router- Returns:
- false always
- Throws:
UnsupportedOperationException- always, as muxed sends are unsupported hereI2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public long sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromport, int toport, SendMessageOptions options, SendMessageStatusListener listener) throws I2PSessionException Send an I2CP message. Not supported by this implementation - use I2PSessionMuxedImpl.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromport- 1-65535 or 0 for unsettoport- 1-65535 or 0 for unsetoptions- to be passed to the routerlistener- for delivery status notification- Returns:
- -1 always
- Throws:
UnsupportedOperationException- always, as muxed sends are unsupported hereI2PSessionException- on all errors
sendMessage
Unused, see MuxedImpl override.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)- Returns:
- whether it was accepted by the router for delivery or not
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size) throws I2PSessionException Send an I2CP message. No end-to-end crypto is done, so any key or tags are ignored; this delegates to the no-effort/best-effort send below.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to send- Returns:
- whether the router accepted the message for delivery
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent) throws I2PSessionException Send a message with session key and tags.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)keyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end crypto- Returns:
- whether the router accepted the message for delivery
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent) throws I2PSessionException Send a message with session key and tags.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end crypto- Returns:
- whether the router accepted the message for delivery
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) throws I2PSessionException Unused? See the MuxedImpl override.- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end cryptoexpires- absolute expiration timestamp, NOT interval from now- Returns:
- whether the router accepted the message for delivery
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
receiveMessage
Receive a message from the router, decompressing it unless it was sent uncompressed.- Specified by:
receiveMessagein interfaceI2PSession- Overrides:
receiveMessagein classI2PSessionImpl- Parameters:
msgId- the message ID- Returns:
- the data, or null on error
- Throws:
I2PSessionException- declared but never thrown; failures return null instead
sendBestEffort
protected boolean sendBestEffort(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) throws I2PSessionException Send a message with best effort delivery.- Parameters:
dest- the remote destination to send topayload- the message bytes to deliverkeyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end cryptoexpires- expiration time in ms since the epoch, 0 for the router default- Returns:
- whether the router accepted the message for delivery
- Throws:
I2PSessionException- if the wait for the router's status update is interrupted
sendBestEffort
protected boolean sendBestEffort(Destination dest, byte[] payload, long expires, int flags) throws I2PSessionException Send a best-effort message with the given flags.- Parameters:
dest- the remote destination to send topayload- the message bytes to deliverexpires- expiration time in ms since the epoch, 0 for the router defaultflags- to be passed to the router- Returns:
- whether the router accepted the message for delivery
- Throws:
I2PSessionException- if the wait for the router's status update is interrupted
sendNoEffort
protected boolean sendNoEffort(Destination dest, byte[] payload, long expires, int flags) throws I2PSessionException Same assendBestEffort(Destination, byte[], SessionKey, Set, long), 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.- Parameters:
dest- the remote destination to send topayload- the message bytesexpires- expiration time in ms since the epoch, 0 for the router defaultflags- to be passed to the router- Returns:
- true always
- Throws:
I2PSessionException- if the router rejects the send
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.
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 classI2PSessionImpl- Parameters:
msgId- the message IDnonce- the nonce identifying the sendstatus- != 0
reconnect
protected boolean reconnect()Reconnect the I2CP session. Called by the superclass whenever it wants to reconnect; overridden to also clear out the message state.- Overrides:
reconnectin classI2PSessionImpl- Returns:
- whether the session was reconnected
clearStates
private void clearStates()Clear all pending message states.getTunnelManager
Cached reflection access toRouterContext.tunnelManager(). Method is looked up once and reused to avoid repeated getMethod() overhead.- Returns:
- the tunnel manager
addTunnelStatusListener
Register a tunnel status listener. In a router context the listener is also registered with the TunnelPoolManager, if there is one.- Parameters:
lsnr- the listener
removeTunnelStatusListener
Remove a tunnel status listener.- Parameters:
lsnr- the listener
switchToNewTunnel
public boolean switchToNewTunnel()Switch to the new tunnel set. Not supported by this implementation.- Returns:
- false always
setCurrentTunnelPair
Current tunnel pair in use.- Parameters:
pair- the tunnel pair in use
getCurrentTunnelPair
Return the current tunnel pair.- Returns:
- the current tunnel pair, or null if none
rebuildTunnels
public void rebuildTunnels()Rebuild the tunnel set.notifyTunnelFailed
Notify all tunnel status listeners of a tunnel failure.- Parameters:
poolName- the pool the failed tunnel belonged toisInbound- true if the tunnel was an inbound one
notifyTunnelRemoved
Notify all tunnel status listeners of a tunnel removal.- Parameters:
event- identifies the removed tunnel, its pool, direction and the reason
notifyPoolShuttingDown
Notify all tunnel status listeners of pool shutdown.- Parameters:
poolName- the pool being shut downisInbound- true if the pool builds inbound tunnels