public abstract class I2PSessionImpl extends Object implements I2PSession, I2CPMessageReader.I2CPMessageEventListener
| Modifier and Type | Class and Description |
|---|---|
protected class | I2PSessionImpl.AvailabilityNotifierThis notifies the client of payload messages. |
protected static class | I2PSessionImpl.StateSession state enumeration. |
I2PSession.TunnelPair| Modifier and Type | Field and Description |
|---|---|
protected I2PSessionImpl.AvailabilityNotifier | _availabilityNotifierthread that we tell when new messages are available who then tells us
to fetch them. |
protected Map<Long,MessagePayloadMessage> | _availableMessagesmap of Long--> MessagePayloadMessage |
protected int[] | _bwLimitscurrent bandwidth limits |
protected Object | _bwReceivedLocklock for bandwidth limit updates |
protected I2PAppContext | _contextused to separate things out so we can get rid of singletons |
protected I2PClientMessageHandlerMap | _handlerMaphandler map for I2CP message types |
protected String | _hostnamehostname of router - will be null if in RouterContext |
protected LeaseSet | _leaseSetcurrently granted lease set, or null |
protected Object | _leaseSetWaitmonitor for waiting until a lease set has been granted |
protected Log | _loglogger |
protected LinkedBlockingQueue<net.i2p.client.impl.I2PSessionImpl.LookupWaiter> | _pendingLookupshashes of lookups we are waiting for |
protected int | _portNumport num to router - will be 0 if in RouterContext |
protected I2CPMessageProducer | _producerclass that generates new messages |
protected I2CPMessageQueue | _queueUsed for internal connections to the router. |
protected I2CPMessageReader | _readerreader that always searches for messages |
protected I2PSessionListener | _sessionListenerwho we send events to |
protected Socket | _socketsocket for comm |
protected I2PSessionImpl.State | _statecurrent session state |
protected Object | _stateLocklock for state transitions |
protected SigningPublicKey | _transientSigningPublicKeytransient signing public key for offline signatures |
protected Set<TunnelStatusListener> | _tunnelStatusListenerslisteners for tunnel status changes (tunnel failures and removals) |
protected ClientWriterRunner | _writerwriter message queue |
protected static int | CACHE_MAX_SIZEmaximum size of the lookup cache |
(package private) static SessionId | DUMMY_SESSIONDummy session ID for messages before a real session is established |
static int | LISTEN_PORTDefault I2CP listen port |
protected static String | PROP_DOMAIN_SOCKETUse Unix domain socket (or similar) to connect to a router |
PORT_ANY, PORT_UNSPECIFIED, PROTO_ANY, PROTO_DATAGRAM, PROTO_DATAGRAM_RAW, PROTO_DATAGRAM2, PROTO_DATAGRAM3, PROTO_STREAMING, PROTO_UNSPECIFIED| Modifier | Constructor and Description |
|---|---|
| I2PSessionImpl(I2PAppContext context,
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
As of 0.9.19, defaults in options are honored. |
protected | I2PSessionImpl(I2PAppContext context,
Properties options,
I2PClientMessageHandlerMap handlerMap)for extension by SimpleSession (no dest) |
protected | I2PSessionImpl(I2PSessionImpl primary,
InputStream destKeyStream,
Properties options)For extension by SubSession via I2PSessionMuxedImpl and I2PSessionImpl2 |
| Modifier and Type | Method and Description |
|---|---|
void | addNewMessage(MessagePayloadMessage msg)Recieve a payload message and let the app know its available |
I2PSession | addSubsession(InputStream privateKeyStream,
Properties opts)Router must be connected or was connected... |
int[] | bandwidthLimits()Blocking. |
(package private) void | bwReceived(int[] limits)called by the message handler |
protected void | changeState(I2PSessionImpl.State state)Change the session state |
static void | clearCache()Clear the lookup cache |
void | connect()Connect to the router and establish a session. |
(package private) void | dateUpdated(String routerVersion)Update the router version and related feature support flags. |
(package private) void | destLookupFailed(Hash h)Called by the message handler
on reception of DestReplyMessage |
(package private) void | destLookupFailed(long nonce,
int code)Called by the message handler
on reception of HostReplyMessage |
(package private) void | destReceived(Destination d)Called by the message handler
on reception of DestReplyMessage |
(package private) void | destReceived(long nonce,
Destination d)Called by the message handler
on reception of HostReplyMessage |
void | destroySession()Tear down the session, and do NOT reconnect. |
void | destroySession(boolean sendDisconnect)Tear down the session, and do NOT reconnect. |
protected void | disconnect()Will interrupt a connect in progress. |
void | disconnected(I2CPMessageReader reader)The I2CPMessageEventListener callback. |
(package private) I2PAppContext | getContext()For Subsessions |
boolean | getFastReceive()Does this session support fast receive? |
(package private) I2PClientMessageHandlerMap | getHandlerMap()For Subsessions |
(package private) long | getLastLS2SignTime()The published timestamp of the last LS2 we signed |
(package private) LeaseSet | getLeaseSet()Current lease set published by this session. |
Destination | getMyDestination()Retrieve the destination of the session |
protected String | getName()Get the session name for logging |
long | getOfflineExpiration()Java time (ms) or 0 if not initialized or does not have offline keys. |
Signature | getOfflineSignature()Null on error or if not initialized or does not have offline keys. |
(package private) Properties | getOptions()Retrieve the configuration options, filtered. |
protected String | getPrefix()try hard to make a decent identifier as this will appear in error logs |
SigningPrivateKey | getPrivateKey()Retrieve the signing SigningPrivateKey. |
(package private) I2CPMessageProducer | getProducer()Retrieve the helper that generates I2CP messages |
String | getRouterVersion()Always valid in RouterContext. |
(package private) SessionId | getSessionId()Retrieve the session's ID |
List<I2PSession> | getSubsessions()List of subsessions, non-null, does not include the primary session. |
SigningPublicKey | getTransientSigningPublicKey()Null on error or if not initialized or does not have offline keys. |
boolean | isClosed()Has the session been closed (or not yet connected)?
False when open and during transitions. |
boolean | isOffline()Does this session have offline and transient keys? |
long | lastActivity()Time of last session activity in milliseconds. |
Destination | lookupDest(Hash h)Blocking. |
Destination | lookupDest(Hash h,
long maxWait)Blocking. |
LookupResult | lookupDest(Hash h,
long maxWait,
LookupCallback callback)Lookup a Destination by hostname. |
Destination | lookupDest(String name)Ask the router to lookup a Destination by host name. |
Destination | lookupDest(String name,
long maxWait)Ask the router to lookup a Destination by host name. |
LookupResult | lookupDest(String name,
long maxWait,
LookupCallback callback)Lookup a Destination by hash. |
LookupResult | lookupDest2(String name,
long maxWait)Ask the router to lookup a Destination by host name. |
void | messageReceived(I2CPMessageReader reader,
I2CPMessage message)The I2CPMessageEventListener callback. |
(package private) void | propagateError(String msg,
Throwable error)Pass off the error to the listener
Misspelled, oh well. |
void | readError(I2CPMessageReader reader,
Exception error)The I2CPMessageEventListener callback. |
byte[] | receiveMessage(int msgId)Pull the unencrypted data from the message that we've already prefetched and
notified the user that its available. |
abstract void | receiveStatus(int msgId,
long nonce,
int status)Receive a message status update |
protected boolean | reconnect()Attempt to reconnect to the router |
void | removeSubsession(I2PSession session)Remove a subsession. |
void | reportAbuse(int msgId,
int severity)Report abuse with regards to the given messageId |
void | sendBlindingInfo(BlindData bd)Send blinding info to the router. |
(package private) void | sendMessage_unchecked(I2CPMessage message)Deliver an I2CP message to the router. |
(package private) void | sendMessage(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) void | setLastLS2SignTime(long now)The published timestamp of the last LS2 we signed |
(package private) void | setLeaseSet(LeaseSet ls)Lease set published by this session. |
void | setReduced()Mark the session as reduced |
(package private) void | setSessionId(SessionId id)Session ID assigned by the router. |
void | setSessionListener(I2PSessionListener lsnr)configure the listener |
protected boolean | shouldReconnect()Whether the session should attempt reconnection on disconnect. |
protected void | startVerifyUsage()Fire up a periodic task to check for unclaimed messages |
boolean | supportsLS2()Does this session support LS2? |
String | toString() |
protected void | updateActivity()Update the last activity timestamp |
void | updateOptions(Properties options)Update the tunnel and bandwidth settings |
protected void | verifyOpen()Throws I2PSessionException if uninitialized, closed or closing. |
protected void | waitForDate()Wait for a SetDate response from the router. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddMuxedSessionListener, addSessionListener, addTunnelStatusListener, getCurrentTunnelPair, getDecryptionKey, rebuildTunnels, removeListener, removeTunnelStatusListener, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, setCurrentTunnelPair, switchToNewTunnelprotected I2PSessionImpl.AvailabilityNotifier _availabilityNotifier
protected Map<Long,MessagePayloadMessage> _availableMessages
protected volatile int[] _bwLimits
protected final Object _bwReceivedLock
protected final I2PAppContext _context
protected final I2PClientMessageHandlerMap _handlerMap
protected final String _hostname
protected volatile LeaseSet _leaseSet
protected final Object _leaseSetWait
protected final Log _log
protected final LinkedBlockingQueue<net.i2p.client.impl.I2PSessionImpl.LookupWaiter> _pendingLookups
protected final int _portNum
protected final I2CPMessageProducer _producer
protected I2CPMessageQueue _queue
protected volatile I2CPMessageReader _reader
protected volatile I2PSessionListener _sessionListener
protected volatile Socket _socket
protected I2PSessionImpl.State _state
protected final Object _stateLock
protected SigningPublicKey _transientSigningPublicKey
protected final Set<TunnelStatusListener> _tunnelStatusListeners
protected volatile ClientWriterRunner _writer
protected static final int CACHE_MAX_SIZE
static final SessionId DUMMY_SESSION
public static final int LISTEN_PORT
protected static final String PROP_DOMAIN_SOCKET
public I2PSessionImpl(I2PAppContext context, InputStream destKeyStream, Properties options) throws I2PSessionException
context - the I2P app contextdestKeyStream - stream containing the private key data,
format is specified in PrivateKeyFileoptions - set of options to configure the router with, if null will use System propertiesI2PSessionException - if there is a problem loading the private keysprotected I2PSessionImpl(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap)
context - the I2P app contextoptions - session configuration optionshandlerMap - the I2CP message handler mapprotected I2PSessionImpl(I2PSessionImpl primary, InputStream destKeyStream, Properties options) throws I2PSessionException
primary - the primarydestKeyStream - stream containing the private key data,
format is specified in PrivateKeyFileoptions - set of options to configure the router with, if null will use System propertiesI2PSessionExceptionpublic void addNewMessage(MessagePayloadMessage msg)
msg - the payload messagepublic I2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException
addSubsession in interface I2PSessionprivateKeyStream - null for transient, if non-null must have same encryption keys as primary session
and different signing keysopts - subsession options if any, may be nullI2PSessionException - on errorpublic int[] bandwidthLimits()
throws I2PSessionExceptionbandwidthLimits in interface I2PSessionI2PSessionException - on errorvoid bwReceived(int[] limits)
limits - the bandwidth limitsprotected void changeState(I2PSessionImpl.State state)
public static void clearCache()
public void connect()
throws I2PSessionExceptionconnect in interface I2PSessionI2PSessionException - if there is a configuration error or the router is
not reachablevoid dateUpdated(String routerVersion)
routerVersion - as rcvd in the SetDateMessage, may be null for very old routersvoid destLookupFailed(Hash h)
h - non-nullvoid destLookupFailed(long nonce,
int code)nonce - the lookup noncecode - the failure codevoid destReceived(Destination d)
d - non-nullvoid destReceived(long nonce,
Destination d)nonce - the lookup nonced - non-nullpublic void destroySession()
destroySession in interface I2PSessionpublic void destroySession(boolean sendDisconnect)
sendDisconnect - if true, send disconnect message to routerprotected void disconnect()
public void disconnected(I2CPMessageReader reader)
disconnected in interface I2CPMessageReader.I2CPMessageEventListenerreader - unusedI2PAppContext getContext()
public boolean getFastReceive()
I2PClientMessageHandlerMap getHandlerMap()
long getLastLS2SignTime()
LeaseSet getLeaseSet()
public Destination getMyDestination()
getMyDestination in interface I2PSessionprotected String getName()
public long getOfflineExpiration()
getOfflineExpiration in interface I2PSessionpublic Signature getOfflineSignature()
getOfflineSignature in interface I2PSessionProperties getOptions()
protected final String getPrefix()
public SigningPrivateKey getPrivateKey()
getPrivateKey in interface I2PSessionI2CPMessageProducer getProducer()
public String getRouterVersion()
getRouterVersion in interface I2PSessionSessionId getSessionId()
public List<I2PSession> getSubsessions()
getSubsessions in interface I2PSessionpublic SigningPublicKey getTransientSigningPublicKey()
getTransientSigningPublicKey in interface I2PSessionpublic boolean isClosed()
isClosed in interface I2PSessionpublic boolean isOffline()
isOffline in interface I2PSessionpublic long lastActivity()
public Destination lookupDest(Hash h) throws I2PSessionException
lookupDest in interface I2PSessionh - the hash to look upI2PSessionException - on errorpublic Destination lookupDest(Hash h, long maxWait) throws I2PSessionException
lookupDest in interface I2PSessionmaxWait - msh - the hash to look upI2PSessionException - on errorpublic LookupResult lookupDest(Hash h, long maxWait, LookupCallback callback) throws I2PSessionException
lookupDest in interface I2PSessionmaxWait - mscallback - to return the result, non-nullh - the hash to look upI2PSessionException - on errorpublic Destination lookupDest(String name) throws I2PSessionException
lookupDest in interface I2PSessionname - the hostname to look upI2PSessionException - on errorpublic Destination lookupDest(String name, long maxWait) throws I2PSessionException
lookupDest in interface I2PSessionmaxWait - msname - the hostname to look upI2PSessionException - on errorpublic LookupResult lookupDest(String name, long maxWait, LookupCallback callback) throws I2PSessionException
lookupDest in interface I2PSessionmaxWait - mscallback - to return the result, non-nullname - the hostname to look upI2PSessionException - on errorpublic LookupResult lookupDest2(String name, long maxWait) throws I2PSessionException
lookupDest2 in interface I2PSessionmaxWait - msname - the hostname to look upI2PSessionException - on errorpublic void messageReceived(I2CPMessageReader reader, I2CPMessage message)
messageReceived in interface I2CPMessageReader.I2CPMessageEventListenerreader - unusedmessage - the I2CPMessagevoid propagateError(String msg, Throwable error)
msg - the error messageerror - non-nullpublic void readError(I2CPMessageReader reader, Exception error)
readError in interface I2CPMessageReader.I2CPMessageEventListenerreader - unusederror - non-nullpublic byte[] receiveMessage(int msgId)
throws I2PSessionExceptionreceiveMessage in interface I2PSessionmsgId - message to fetchI2PSessionException - on errorpublic abstract void receiveStatus(int msgId,
long nonce,
int status)msgId - the message IDnonce - the noncestatus - the statusprotected boolean reconnect()
public void removeSubsession(I2PSession session)
I2PSessionremoveSubsession in interface I2PSessionsession - the subsession to removepublic void reportAbuse(int msgId,
int severity)
throws I2PSessionExceptionreportAbuse in interface I2PSessionmsgId - message that was abusive (or -1 for not message related)severity - how abusiveI2PSessionException - on errorpublic void sendBlindingInfo(BlindData bd) throws I2PSessionException
I2PSessionsendBlindingInfo in interface I2PSessionbd - the blind dataI2PSessionException - on errorvoid sendMessage_unchecked(I2CPMessage message) throws I2PSessionException
message - the I2CP message to sendI2PSessionException - if the message is malformed or there is an error writing it outvoid sendMessage(I2CPMessage message) throws I2PSessionException
message - the I2CP message to sendI2PSessionException - if the message is malformed or there is an error writing it outvoid setLastLS2SignTime(long now)
now - the timestamp to setvoid setLeaseSet(LeaseSet ls)
public void setReduced()
void setSessionId(SessionId id)
id - the session ID to setpublic void setSessionListener(I2PSessionListener lsnr)
setSessionListener in interface I2PSessionlsnr - listener to retrieve eventsprotected boolean shouldReconnect()
protected void startVerifyUsage()
public boolean supportsLS2()
protected void updateActivity()
public void updateOptions(Properties options)
updateOptions in interface I2PSessionoptions - non-nullprotected void verifyOpen()
throws I2PSessionExceptionI2PSessionException - if not openprotected void waitForDate()
throws InterruptedException,
IOExceptionInterruptedException - if interruptedIOException - on I/O error