public abstract class I2PSessionImpl extends Object implements I2PSession, I2CPMessageReader.I2CPMessageEventListener
Modifier and Type | Class and Description |
---|---|
protected class |
I2PSessionImpl.AvailabilityNotifier
This notifies the client of payload messages.
|
protected static class |
I2PSessionImpl.State |
Modifier and Type | Field and Description |
---|---|
protected I2PSessionImpl.AvailabilityNotifier |
_availabilityNotifier
thread that we tell when new messages are available who then tells us
to fetch them.
|
protected Map<Long,MessagePayloadMessage> |
_availableMessages
map of Long --> MessagePayloadMessage
|
protected int[] |
_bwLimits |
protected Object |
_bwReceivedLock |
protected I2PAppContext |
_context
used to separate things out so we can get rid of singletons
|
protected I2PClientMessageHandlerMap |
_handlerMap |
protected String |
_hostname
hostname of router - will be null if in RouterContext
|
protected LeaseSet |
_leaseSet
currently granted lease set, or null
|
protected Object |
_leaseSetWait
monitor for waiting until a lease set has been granted
|
protected Log |
_log |
protected LinkedBlockingQueue<net.i2p.client.impl.I2PSessionImpl.LookupWaiter> |
_pendingLookups
hashes of lookups we are waiting for
|
protected int |
_portNum
port num to router - will be 0 if in RouterContext
|
protected I2CPMessageProducer |
_producer
class that generates new messages
|
protected I2CPMessageQueue |
_queue
Used for internal connections to the router.
|
protected I2CPMessageReader |
_reader
reader that always searches for messages
|
protected I2PSessionListener |
_sessionListener
who we send events to
|
protected Socket |
_socket
socket for comm
|
protected I2PSessionImpl.State |
_state |
protected Object |
_stateLock |
protected ClientWriterRunner |
_writer
writer message queue
|
protected static int |
CACHE_MAX_SIZE |
static int |
LISTEN_PORT |
protected static String |
PROP_DOMAIN_SOCKET
Use Unix domain socket (or similar) to connect to a router
|
protected static String |
PROP_ENABLE_SSL
SSL interface (only) @since 0.8.3
|
protected static String |
PROP_PW |
protected static String |
PROP_USER |
PORT_ANY, PORT_UNSPECIFIED, PROTO_ANY, PROTO_DATAGRAM, PROTO_DATAGRAM_RAW, 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) |
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[] i)
called by the message handler
|
protected void |
changeState(I2PSessionImpl.State state) |
static void |
clearCache() |
void |
connect()
Connect to the router and establish a session.
|
(package private) void |
dateUpdated(String routerVersion) |
(package private) void |
destLookupFailed(Hash h)
Called by the message handler
on reception of DestReplyMessage
|
(package private) void |
destLookupFailed(long nonce)
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
|
PrivateKey |
getDecryptionKey()
Retrieve the decryption PrivateKey
|
boolean |
getFastReceive() |
(package private) I2PClientMessageHandlerMap |
getHandlerMap()
For Subsessions
|
(package private) LeaseSet |
getLeaseSet() |
Destination |
getMyDestination()
Retrieve the destination of the session
|
(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
|
(package private) SessionId |
getSessionId()
Retrieve the session's ID
|
List<I2PSession> |
getSubsessions() |
boolean |
isClosed()
Has the session been closed (or not yet connected)?
False when open and during transitions.
|
long |
lastActivity() |
Destination |
lookupDest(Hash h)
Blocking.
|
Destination |
lookupDest(Hash h,
long maxWait)
Blocking.
|
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.
|
void |
messageReceived(I2CPMessageReader reader,
I2CPMessage message)
The I2CPMessageEventListener callback.
|
(package private) void |
propogateError(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) |
protected boolean |
reconnect() |
void |
removeSubsession(I2PSession session) |
void |
reportAbuse(int msgId,
int severity)
Report abuse with regards to the given messageId
|
(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 |
setLeaseSet(LeaseSet ls) |
void |
setReduced() |
(package private) void |
setSessionId(SessionId id) |
void |
setSessionListener(I2PSessionListener lsnr)
configure the listener
|
protected boolean |
shouldReconnect() |
protected void |
startVerifyUsage()
Fire up a periodic task to check for unclaimed messages
|
String |
toString() |
protected void |
updateActivity() |
void |
updateOptions(Properties options)
Update the tunnel and bandwidth settings
|
protected void |
verifyOpen()
Throws I2PSessionException if uninitialized, closed or closing.
|
protected void |
waitForDate() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addMuxedSessionListener, addSessionListener, removeListener, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage
protected final Log _log
protected volatile LeaseSet _leaseSet
protected final String _hostname
protected final int _portNum
protected Socket _socket
protected I2CPMessageReader _reader
protected ClientWriterRunner _writer
protected I2CPMessageQueue _queue
protected I2PSessionListener _sessionListener
protected final I2CPMessageProducer _producer
protected Map<Long,MessagePayloadMessage> _availableMessages
protected final LinkedBlockingQueue<net.i2p.client.impl.I2PSessionImpl.LookupWaiter> _pendingLookups
protected final Object _bwReceivedLock
protected volatile int[] _bwLimits
protected final I2PClientMessageHandlerMap _handlerMap
protected final I2PAppContext _context
protected final Object _leaseSetWait
protected I2PSessionImpl.State _state
protected final Object _stateLock
protected I2PSessionImpl.AvailabilityNotifier _availabilityNotifier
protected static final int CACHE_MAX_SIZE
protected static final String PROP_ENABLE_SSL
protected static final String PROP_USER
protected static final String PROP_PW
protected static final String PROP_DOMAIN_SOCKET
public static final int LISTEN_PORT
protected I2PSessionImpl(I2PAppContext context, Properties options, I2PClientMessageHandlerMap handlerMap)
protected I2PSessionImpl(I2PSessionImpl primary, InputStream destKeyStream, Properties options) throws I2PSessionException
I2PSessionException
public I2PSessionImpl(I2PAppContext context, InputStream destKeyStream, Properties options) throws I2PSessionException
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 propertiesI2PSessionException
- if there is a problem loading the private keysvoid dateUpdated(String routerVersion)
routerVersion
- as rcvd in the SetDateMessage, may be null for very old routerspublic I2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException
addSubsession
in interface I2PSession
privateKeyStream
- 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
public void removeSubsession(I2PSession session)
removeSubsession
in interface I2PSession
public List<I2PSession> getSubsessions()
getSubsessions
in interface I2PSession
public void updateOptions(Properties options)
updateOptions
in interface I2PSession
options
- non-nullpublic boolean getFastReceive()
void setLeaseSet(LeaseSet ls)
LeaseSet getLeaseSet()
protected void changeState(I2PSessionImpl.State state)
public void connect() throws I2PSessionException
connect
in interface I2PSession
I2PSessionException
- if there is a configuration error or the router is
not reachableprotected void waitForDate() throws InterruptedException, IOException
InterruptedException
IOException
public byte[] receiveMessage(int msgId) throws I2PSessionException
receiveMessage
in interface I2PSession
msgId
- message to fetchI2PSessionException
public void reportAbuse(int msgId, int severity) throws I2PSessionException
reportAbuse
in interface I2PSession
msgId
- message that was abusive (or -1 for not message related)severity
- how abusiveI2PSessionException
public abstract void receiveStatus(int msgId, long nonce, int status)
public void addNewMessage(MessagePayloadMessage msg)
protected void startVerifyUsage()
public void messageReceived(I2CPMessageReader reader, I2CPMessage message)
messageReceived
in interface I2CPMessageReader.I2CPMessageEventListener
reader
- unusedmessage
- the I2CPMessagepublic void readError(I2CPMessageReader reader, Exception error)
readError
in interface I2CPMessageReader.I2CPMessageEventListener
reader
- unusederror
- non-nullpublic Destination getMyDestination()
getMyDestination
in interface I2PSession
public PrivateKey getDecryptionKey()
getDecryptionKey
in interface I2PSession
public SigningPrivateKey getPrivateKey()
getPrivateKey
in interface I2PSession
I2CPMessageProducer getProducer()
I2PClientMessageHandlerMap getHandlerMap()
I2PAppContext getContext()
Properties getOptions()
SessionId getSessionId()
void setSessionId(SessionId id)
public void setSessionListener(I2PSessionListener lsnr)
setSessionListener
in interface I2PSession
lsnr
- listener to retrieve eventspublic boolean isClosed()
isClosed
in interface I2PSession
protected void verifyOpen() throws I2PSessionException
I2PSessionException
void sendMessage(I2CPMessage message) throws I2PSessionException
I2PSessionException
- if the message is malformed or there is an error writing it outvoid sendMessage_unchecked(I2CPMessage message) throws I2PSessionException
I2PSessionException
- if the message is malformed or there is an error writing it outvoid propogateError(String msg, Throwable error)
error
- non-nullpublic void destroySession()
destroySession
in interface I2PSession
public void destroySession(boolean sendDisconnect)
public void disconnected(I2CPMessageReader reader)
disconnected
in interface I2CPMessageReader.I2CPMessageEventListener
reader
- unusedprotected void disconnect()
protected boolean shouldReconnect()
protected boolean reconnect()
protected String getPrefix()
void destReceived(Destination d)
d
- non-nullvoid destLookupFailed(Hash h)
h
- non-nullvoid destReceived(long nonce, Destination d)
d
- non-nullvoid destLookupFailed(long nonce)
void bwReceived(int[] i)
public static void clearCache()
public Destination lookupDest(Hash h) throws I2PSessionException
lookupDest
in interface I2PSession
I2PSessionException
public Destination lookupDest(Hash h, long maxWait) throws I2PSessionException
lookupDest
in interface I2PSession
maxWait
- msI2PSessionException
public Destination lookupDest(String name) throws I2PSessionException
lookupDest
in interface I2PSession
I2PSessionException
public Destination lookupDest(String name, long maxWait) throws I2PSessionException
lookupDest
in interface I2PSession
maxWait
- msI2PSessionException
public int[] bandwidthLimits() throws I2PSessionException
bandwidthLimits
in interface I2PSession
I2PSessionException
protected void updateActivity()
public long lastActivity()
public void setReduced()