- All Known Implementing Classes:
I2PSocketManagerFull
public interface I2PSocketManager
Centralize the coordination and multiplexing of the local client's streaming. There should be one I2PSocketManager for each I2PSession, and if an application is sending and receiving data through the streaming library using an I2PSocketManager, it should not attempt to call I2PSession's setSessionListener or receive any messages with its .receiveMessage.
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceListener for notification when an I2P session is disconnected.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidRegister a listener to be notified when the I2P session disconnects.addSubsession(InputStream privateKeyStream, Properties opts) For a server, you must call connect() on the returned object.Create a copy of the current options, to be used in a setDefaultOptions() call.buildOptions(Properties opts) Create a modified copy of the current options, to be used in a setDefaultOptions() call.connect(Destination peer) Create a new connected socket (block until the socket is created).connect(Destination peer, I2PSocketOptions options) Create a new connected socket (block until the socket is created).connectToSocket(Destination peer) Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.connectToSocket(Destination peer, int timeout) Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.voidDestroy the socket manager, freeing all the associated resources.longThe current accept timeout.Current options, not a copy, setters may be used to make changes.getName()For logging / diagnostics only.Returns non-null socket.The I2P session associated with this manager.Like getServerSocket but returns a real ServerSocket for easier porting of apps.All subsessions of the primary session.booleanHas the socket manager been destroyed?Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.booleanping(Destination peer, int localPort, int remotePort, long timeoutMs) Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise.byte[]ping(Destination peer, int localPort, int remotePort, long timeoutMs, byte[] payload) Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise.booleanping(Destination peer, long timeoutMs) Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise.voidRemove a disconnection listener.voidremoveSubsession(I2PSession session) Remove a subsession.voidsetAcceptTimeout(long ms) How long should we wait for the client to .accept() a socket before sending back a NACK/Close?voidsetDefaultOptions(I2PSocketOptions options) Update the options on a running socket manager.voidFor logging / diagnostics only.
Method Details
getSession
addSubsession
For a server, you must call connect() on the returned object. Connecting the primary session does NOT connect any subsessions. If the primary session is not connected, connecting a subsession will connect the primary session first.- Parameters:
privateKeyStream- 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:
I2PSessionException- if the router does not support sub-sessions, if a sub-session request is already pending, or if the new session duplicates an existing one by private key
removeSubsession
Remove a subsession.- Parameters:
session- the subsession to remove
getSubsessions
List<I2PSession> getSubsessions()All subsessions of the primary session.- Returns:
- a list of subsessions, non-null, does not include the primary session
setAcceptTimeout
void setAcceptTimeout(long ms) How long should we wait for the client to .accept() a socket before sending back a NACK/Close?- Parameters:
ms- milliseconds to wait, maximum
getAcceptTimeout
long getAcceptTimeout()The current accept timeout.- Returns:
- the accept timeout
setDefaultOptions
Update the options on a running socket manager. Parameters in the I2PSocketOptions interface may be changed directly with the setters; no need to use this method for those. This does NOT update the underlying I2CP or tunnel options; use getSession().updateOptions() for that.- Parameters:
options- as created from a call to buildOptions(properties), non-null
getDefaultOptions
I2PSocketOptions getDefaultOptions()Current options, not a copy, setters may be used to make changes.- Returns:
- the default options
getServerSocket
I2PServerSocket getServerSocket()Returns non-null socket. This method does not throw exceptions, but methods on the returned socket may throw exceptions if the socket or socket manager is closed.- Returns:
- non-null
buildOptions
I2PSocketOptions buildOptions()Create a copy of the current options, to be used in a setDefaultOptions() call.- Returns:
- a copy of the current options
buildOptions
Create a modified copy of the current options, to be used in a setDefaultOptions() call. Defaults in opts are honored: a property absent from opts keeps its current value rather than reverting to the default.- Parameters:
opts- The new options, may be null- Returns:
- a modified copy of the current options
connect
I2PSocket connect(Destination peer, I2PSocketOptions options) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException Create a new connected socket (block until the socket is created).- Parameters:
peer- Destination to connect tooptions- I2P socket options to be used for connecting- Returns:
- new connected socket
- Throws:
ConnectException- if the peer refuses the connectionNoRouteToHostException- if the peer is not found or not reachableInterruptedIOException- if the connection timeoutsI2PException- if there is some other I2P-related problem
connect
I2PSocket connect(Destination peer) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException Create a new connected socket (block until the socket is created).- Parameters:
peer- Destination to connect to- Returns:
- new connected socket
- Throws:
ConnectException- if the peer refuses the connectionNoRouteToHostException- if the peer is not found or not reachableInterruptedIOException- if the connection timeoutsI2PException- if there is some other I2P-related problem
destroySocketManager
void destroySocketManager()Destroy the socket manager, freeing all the associated resources. This method will block untill all the managed sockets are closed. The socket manager CANNOT be reused after this.isDestroyed
boolean isDestroyed()Has the socket manager been destroyed?- Returns:
- true if destroyed
listSockets
ping
Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks. Uses the ports from the default options.- Parameters:
peer- Destination to pingtimeoutMs- timeout in ms, greater than zero- Returns:
- success or failure
- Throws:
IllegalArgumentException- on bad args
ping
Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks. Uses the ports specified.- Parameters:
peer- Destination to pinglocalPort- 0 - 65535remotePort- 0 - 65535timeoutMs- timeout in ms, greater than zero- Returns:
- success or failure
- Throws:
IllegalArgumentException- on bad args
ping
Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks. Uses the ports specified.- Parameters:
peer- Destination to pinglocalPort- 0 - 65535remotePort- 0 - 65535timeoutMs- timeout in ms, greater than zeropayload- to include in the ping- Returns:
- the payload received in the pong, zero-length if none, null on failure or timeout
- Throws:
IllegalArgumentException- on bad args
getName
String getName()For logging / diagnostics only.- Returns:
- the label reported for this manager in logs and console output, as set by setName()
setName
For logging / diagnostics only.- Parameters:
name- the label reported in logs and console output
addDisconnectListener
Register a listener to be notified when the I2P session disconnects.- Parameters:
lsnr- the listener to invoke on session disconnect
removeDisconnectListener
Remove a disconnection listener.- Parameters:
lsnr- the listener previously passed toaddDisconnectListener(I2PSocketManager.DisconnectListener)
getStandardServerSocket
Like getServerSocket but returns a real ServerSocket for easier porting of apps.- Returns:
- a standard ServerSocket
- Throws:
IOException- on I/O error
connectToSocket
Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.- Parameters:
peer- destination to connect to- Returns:
- a connected Socket
- Throws:
IOException- on I/O error
connectToSocket
Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.- Parameters:
peer- destination to connect totimeout- ms if > 0, forces blocking (disables connectDelay)- Returns:
- a connected Socket
- Throws:
IOException- on I/O error