Package net.i2p.client.streaming.impl
Class I2PSocketManagerFull
java.lang.Object
net.i2p.client.streaming.impl.I2PSocketManagerFull
- All Implemented Interfaces:
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
This is what I2PSocketManagerFactory.createManager() returns.
Direct instantiation by others is deprecated.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.i2p.client.streaming.I2PSocketManager
I2PSocketManager.DisconnectListener
-
Field Summary
Modifier and TypeFieldDescription(package private) static PcapWriter
(package private) static final String
-
Constructor Summary
ConstructorDescriptionDeprecated.use 4-arg constructorI2PSocketManagerFull
(I2PAppContext context, I2PSession session, Properties opts, String name, IncomingConnectionFilter connectionFilter) This is what I2PSocketManagerFactory.createManager() returns. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.connect
(Destination peer, I2PSocketOptions options) Create a new connected socket.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.void
Destroy the socket manager, freeing all the associated resources.long
Current options, not a copy, setters may be used to make changes.getName()
For logging / diagnostics onlyReturns non-null socket.Like getServerSocket but returns a real ServerSocket for easier porting of apps.void
init
(I2PAppContext context, I2PSession session, Properties opts, String name) Deprecated.use 4-arg constructorboolean
Has the socket manager been destroyed?Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.boolean
ping
(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.boolean
ping
(Destination peer, long timeoutMs) Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise.The accept() call.void
void
removeSubsession
(I2PSession session) Remove the subsessionvoid
setAcceptTimeout
(long ms) How long should we wait for the client to .accept() a socket before sending back a NACK/Close?void
setDefaultOptions
(I2PSocketOptions options) Update the options on a running socket manager.void
For logging / diagnostics only
-
Field Details
-
pcapWriter
-
PROP_PCAP
- See Also:
-
-
Constructor Details
-
I2PSocketManagerFull
Deprecated.use 4-arg constructor- Throws:
UnsupportedOperationException
- always
-
I2PSocketManagerFull
public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name, IncomingConnectionFilter connectionFilter) This is what I2PSocketManagerFactory.createManager() returns. Direct instantiation by others is deprecated.- Parameters:
context
- non-nullsession
- non-nullopts
- may be nullname
- non-null
-
-
Method Details
-
init
@Deprecated public void init(I2PAppContext context, I2PSession session, Properties opts, String name) Deprecated.use 4-arg constructorDescription copied from interface:I2PSocketManager
Deprecated - Factory will initialize.- Specified by:
init
in interfaceI2PSocketManager
- Throws:
UnsupportedOperationException
- always
-
buildOptions
Create a copy of the current options, to be used in a setDefaultOptions() call.- Specified by:
buildOptions
in interfaceI2PSocketManager
-
buildOptions
Create a modified copy of the current options, to be used in a setDefaultOptions() call. As of 0.9.19, defaults in opts are honored.- Specified by:
buildOptions
in interfaceI2PSocketManager
- Parameters:
opts
- The new options, may be null
-
getSession
- Specified by:
getSession
in interfaceI2PSocketManager
- Returns:
- the session, non-null
-
addSubsession
public I2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException 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.- Specified by:
addSubsession
in interfaceI2PSocketManager
- Parameters:
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 null- Returns:
- a new subsession, non-null
- Throws:
I2PSessionException
- Since:
- 0.9.21
-
removeSubsession
Remove the subsession- Specified by:
removeSubsession
in interfaceI2PSocketManager
- Since:
- 0.9.21
-
getSubsessions
- Specified by:
getSubsessions
in interfaceI2PSocketManager
- Returns:
- a list of subsessions, non-null, does not include the primary session
- Since:
- 0.9.21
-
getConnectionManager
-
receiveSocket
The accept() call. This only listens on the primary session. There is no way to get incoming connections on a subsession.- Returns:
- connected I2PSocket, or null through 0.9.16, non-null as of 0.9.17
- Throws:
I2PException
- if session is closedRouterRestartException
- (extends I2PException) if the router is apparently restarting, since 0.9.34ConnectException
- (since 0.9.17; I2PServerSocket interface always declared it)SocketTimeoutException
- if a timeout was previously set with setSoTimeout and the timeout has been reached.
-
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. TODO There is no way to ping on a subsession.- Specified by:
ping
in interfaceI2PSocketManager
- Parameters:
peer
-timeoutMs
- timeout in ms, greater than zero- Returns:
- true on success, false on failure
- Throws:
IllegalArgumentException
-
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. TODO There is no way to ping on a subsession.- Specified by:
ping
in interfaceI2PSocketManager
- Parameters:
peer
- Destination to pinglocalPort
- 0 - 65535remotePort
- 0 - 65535timeoutMs
- timeout in ms, greater than zero- Returns:
- success or failure
- Throws:
IllegalArgumentException
- Since:
- 0.9.12
-
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. TODO There is no way to ping on a subsession.- Specified by:
ping
in interfaceI2PSocketManager
- 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
- Since:
- 0.9.18
-
setAcceptTimeout
public void setAcceptTimeout(long ms) How long should we wait for the client to .accept() a socket before sending back a NACK/Close?- Specified by:
setAcceptTimeout
in interfaceI2PSocketManager
- Parameters:
ms
- milliseconds to wait, maximum
-
getAcceptTimeout
public long getAcceptTimeout()- Specified by:
getAcceptTimeout
in interfaceI2PSocketManager
-
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. TODO There is no way to update the options on a subsession.- Specified by:
setDefaultOptions
in interfaceI2PSocketManager
- Parameters:
options
- as created from a call to buildOptions(properties), non-null
-
getDefaultOptions
Current options, not a copy, setters may be used to make changes. TODO There is no facility to specify the session.- Specified by:
getDefaultOptions
in interfaceI2PSocketManager
-
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. This only listens on the primary session. There is no way to get incoming connections on a subsession.- Specified by:
getServerSocket
in interfaceI2PSocketManager
- Returns:
- non-null
-
getStandardServerSocket
Like getServerSocket but returns a real ServerSocket for easier porting of apps. This only listens on the primary session. There is no way to get incoming connections on a subsession.- Specified by:
getStandardServerSocket
in interfaceI2PSocketManager
- Throws:
IOException
- Since:
- 0.8.4
-
connect
public I2PSocket connect(Destination peer, I2PSocketOptions options) throws I2PException, NoRouteToHostException Create a new connected socket. Blocks until the socket is created, unless the connectDelay option (i2p.streaming.connectDelay) is set and greater than zero. If so this will return immediately, and the client may quickly write initial data to the socket and this data will be bundled in the SYN packet.- Specified by:
connect
in interfaceI2PSocketManager
- Parameters:
peer
- Destination to connect tooptions
- I2P socket options to be used for connecting, may be null- Returns:
- I2PSocket if successful
- Throws:
NoRouteToHostException
- if the peer is not found or not reachableI2PException
- if there is some other I2P-related problem
-
connect
Create a new connected socket. Blocks until the socket is created, unless the connectDelay option (i2p.streaming.connectDelay) is set and greater than zero in the default options. If so this will return immediately, and the client may quickly write initial data to the socket and this data will be bundled in the SYN packet.- Specified by:
connect
in interfaceI2PSocketManager
- Parameters:
peer
- Destination to connect to- Returns:
- I2PSocket if successful
- Throws:
NoRouteToHostException
- if the peer is not found or not reachableI2PException
- if there is some other I2P-related problem
-
connectToSocket
Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.- Specified by:
connectToSocket
in interfaceI2PSocketManager
- Throws:
IOException
- Since:
- 0.8.4
-
connectToSocket
Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.- Specified by:
connectToSocket
in interfaceI2PSocketManager
- Parameters:
timeout
- ms if > 0, forces blocking (disables connectDelay)- Throws:
IOException
- Since:
- 0.8.4
-
destroySocketManager
public void destroySocketManager()Destroy the socket manager, freeing all the associated resources. This method will block until all the managed sockets are closed. CANNOT be restarted.- Specified by:
destroySocketManager
in interfaceI2PSocketManager
-
isDestroyed
public boolean isDestroyed()Has the socket manager been destroyed?- Specified by:
isDestroyed
in interfaceI2PSocketManager
- Since:
- 0.9.9
-
listSockets
Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.- Specified by:
listSockets
in interfaceI2PSocketManager
- Returns:
- set of currently connected I2PSockets
-
getName
For logging / diagnostics only- Specified by:
getName
in interfaceI2PSocketManager
-
setName
For logging / diagnostics only- Specified by:
setName
in interfaceI2PSocketManager
-
addDisconnectListener
- Specified by:
addDisconnectListener
in interfaceI2PSocketManager
-
removeDisconnectListener
- Specified by:
removeDisconnectListener
in interfaceI2PSocketManager
-