- All Implemented Interfaces:
I2PSocketManager
This is what I2PSocketManagerFactory.createManager() returns. Direct instantiation by others is deprecated.
Nested Class Summary
Nested classes/interfaces inherited from interface I2PSocketManager
I2PSocketManager.DisconnectListenerModifier and TypeInterfaceDescriptionstatic interfaceListener for notification when an I2P session is disconnected.Field Summary
FieldsModifier and TypeFieldDescription(package private) static PcapWriterThe PCAP writer.(package private) static final StringThe PCAP property.Constructor Summary
ConstructorsConstructorDescriptionI2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name, IncomingConnectionFilter connectionFilter) This is whatI2PSocketManagerFactory.createManager()returns.Method Summary
Modifier and TypeMethodDescriptionvoidAdd a disconnect listener.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.voidDestroy the socket manager, freeing all the associated resources.longAccept timeout in milliseconds.static intNumber of accept worker threads, dynamically adjustable by the Tuner.Connection manager for this socket manager.static intDefault inactivity timeout.static intDefault initial ACK delay.Returns the current default options.static intDefault passive flush delay.static intInitial retransmission timeout.static intInitial window size.static intMaximum inbound buffer cap.static intThe operator-tunable ceiling for the Tuner's stream-cap override.static intThe Tuner's reactive cap on concurrent streams; 0 = not armed (each manager uses its own configuredmaxConcurrentStreams).static intMax SYN queue size, dynamically adjustable by the Tuner.getName()For logging / diagnostics only.static intThe Tuner-managed default for inbound packet receive workers; 0 = no override (each manager uses its configured value or the core count).static intScale factor applied to a sampled recent round-trip time when computing the adaptive SYN accept-queue timeout under tunnel stress.Returns non-null socket.The I2P session for this socket manager.Like getServerSocket but returns a real ServerSocket for easier porting of apps.Subsession list, not including the primary session.static intFraction (percent) of recent SYN-queue entries that must expire un-accepted before the adaptive timeout clamp is armed, in addition to low tunnel build success.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.booleanping(Destination peer, I2PSession session, int localPort, int remotePort, long timeoutMs) Ping the specified peer through a specific subsession, returning true if they replied to the ping within the timeout specified, false otherwise.byte[]ping(Destination peer, I2PSession session, int localPort, int remotePort, long timeoutMs, byte[] payload) Ping the specified peer through a specific subsession, returning true if they replied to the ping within the timeout specified, false otherwise.The accept() call.voidRemove a disconnect listener.voidremoveSubsession(I2PSession session) Remove the subsession.static voidresizeReceiveWorkers(int val) Apply a new receive-worker default and resize every live dispatcher to match, so existing managers (not just ones created afterwards) follow the Tuner.voidsetAcceptTimeout(long ms) Set the accept timeout in milliseconds.static voidsetAcceptWorkerThreads(int val) Number of accept worker threads, dynamically adjustable by the Tuner.static voidsetDefaultInactivityTimeout(int val) Default inactivity timeout.static voidsetDefaultInitialAckDelay(int val) Default initial ACK delay.voidsetDefaultOptions(I2PSession session, I2PSocketOptions options) Update the options on a running subsession.voidsetDefaultOptions(I2PSocketOptions options) Update the options on a running socket manager.static voidsetDefaultPassiveFlushDelay(int val) Default passive flush delay.static voidsetInitialRTO(int val) Initial retransmission timeout.static voidsetInitialWindowSize(int val) Initial window size.static voidsetMaxInboundBuffer(int val) Maximum inbound buffer cap.static voidsetMaxMaxConcurrentStreams(int val) Set the operator-tunable ceiling for the Tuner's stream-cap override.static voidsetMaxStreamsOverride(int val) Arm or clear the Tuner's reactive stream-cap override.static voidsetMaxSYNQueueSize(int val) Max SYN queue size, dynamically adjustable by the Tuner.voidFor logging / diagnostics only.static voidsetReceiveWorkerThreads(int val) Set the Tuner-managed default for inbound packet receive workers.static voidsetRttSynTimeoutScale(int val) Multiplier applied to recent RTT when sizing the adaptive SYN timeout.static voidsetSynExprExpireThresh(int val) Fraction of recent SYNs that must expire un-accepted to arm the clamp.
Field Details
pcapWriter
The PCAP writer.PROP_PCAP
Constructor Details
I2PSocketManagerFull
public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name, IncomingConnectionFilter connectionFilter) This is whatI2PSocketManagerFactory.createManager()returns. Direct instantiation by others is deprecated.- Parameters:
context- non-nullsession- non-nullopts- may be nullname- non-nullconnectionFilter- the filter for incoming connections, may be null
Method Details
buildOptions
Create a copy of the current options, to be used in a setDefaultOptions() call.- Specified by:
buildOptionsin interfaceI2PSocketManager- Returns:
- a copy of the current default 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.
- Specified by:
buildOptionsin interfaceI2PSocketManager- Parameters:
opts- The new options, may be null- Returns:
- a new options object with the specified modifications
getSession
The I2P session for this socket manager.- Specified by:
getSessionin 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:
addSubsessionin 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- 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 the subsession.- Specified by:
removeSubsessionin interfaceI2PSocketManager- Parameters:
session- the subsession to remove
getSubsessions
Subsession list, not including the primary session.- Specified by:
getSubsessionsin interfaceI2PSocketManager- Returns:
- a list of subsessions, non-null, does not include the primary session
getConnectionManager
Connection manager for this socket manager.- Returns:
- the connection manager
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, never null
- Throws:
I2PException- if session is closedRouterRestartException- (extends I2PException) if the router is apparently restartingConnectException- if the I2PServerSocket is closed, or if interruptedSocketTimeoutException- 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.
- Specified by:
pingin interfaceI2PSocketManager- Parameters:
peer- Destination to pingtimeoutMs- timeout in ms, greater than zero- Returns:
- true on success, false on failure
- Throws:
IllegalArgumentException- if timeoutMs is not greater than zero
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.
- Specified by:
pingin interfaceI2PSocketManager- Parameters:
peer- Destination to pinglocalPort- 0 - 65535remotePort- 0 - 65535timeoutMs- timeout in ms, greater than zero- Returns:
- success or failure
- Throws:
IllegalArgumentException- if ports or timeout are invalid
ping
public boolean ping(Destination peer, I2PSession session, int localPort, int remotePort, long timeoutMs) Ping the specified peer through a specific subsession, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks.- Parameters:
peer- Destination to pingsession- the subsession to uselocalPort- 0 - 65535remotePort- 0 - 65535timeoutMs- timeout in ms, greater than zero- Returns:
- success or failure
- Throws:
IllegalArgumentException- if ports or timeout are invalid
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.
- Specified by:
pingin 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- if ports or timeout are invalid
ping
public byte[] ping(Destination peer, I2PSession session, int localPort, int remotePort, long timeoutMs, byte[] payload) Ping the specified peer through a specific subsession, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks.- Parameters:
peer- Destination to pingsession- the subsession to uselocalPort- 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- if ports or timeout are invalid
setAcceptTimeout
public void setAcceptTimeout(long ms) Set the accept timeout in milliseconds.- Specified by:
setAcceptTimeoutin interfaceI2PSocketManager- Parameters:
ms- the accept timeout in milliseconds
getAcceptTimeout
public long getAcceptTimeout()Accept timeout in milliseconds.- Specified by:
getAcceptTimeoutin interfaceI2PSocketManager- Returns:
- the accept timeout in milliseconds
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.- Specified by:
setDefaultOptionsin interfaceI2PSocketManager- Parameters:
options- as created from a call to buildOptions(properties), non-null
setDefaultOptions
Update the options on a running subsession. 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.- Parameters:
session- the subsession to updateoptions- as created from a call to buildOptions(properties), non-null
getDefaultOptions
Returns the current default options. This does NOT update the underlying I2CP or tunnel options; use getSession().updateOptions() for that.- Specified by:
getDefaultOptionsin interfaceI2PSocketManager- Returns:
- the default options
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:
getServerSocketin 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:
getStandardServerSocketin interfaceI2PSocketManager- Returns:
- the standard server socket
- Throws:
IOException- on I/O error
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:
connectin 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:
connectin 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:
connectToSocketin interfaceI2PSocketManager- 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.- Specified by:
connectToSocketin interfaceI2PSocketManager- Parameters:
peer- destination to connect totimeout- ms if > 0, forces blocking (disables connectDelay)- Returns:
- a connected Socket
- Throws:
IOException- on I/O error
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:
destroySocketManagerin interfaceI2PSocketManager
isDestroyed
public boolean isDestroyed()Has the socket manager been destroyed?- Specified by:
isDestroyedin interfaceI2PSocketManager- Returns:
- true once destroySocketManager() has completed; the flag is set at the start of that method, so it also guards against a second destroy
listSockets
Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.- Specified by:
listSocketsin interfaceI2PSocketManager- Returns:
- set of currently connected I2PSockets
getName
For logging / diagnostics only.- Specified by:
getNamein interfaceI2PSocketManager- Returns:
- the name this manager was constructed with, suffixed with a sequence number that distinguishes concurrent managers
setName
For logging / diagnostics only.- Specified by:
setNamein interfaceI2PSocketManager- Parameters:
name- the label reported in logs and console output
addDisconnectListener
Add a disconnect listener.- Specified by:
addDisconnectListenerin interfaceI2PSocketManager- Parameters:
lsnr- the disconnect listener to add
removeDisconnectListener
Remove a disconnect listener.- Specified by:
removeDisconnectListenerin interfaceI2PSocketManager- Parameters:
lsnr- the disconnect listener to remove
getInitialWindowSize
public static int getInitialWindowSize()Initial window size.- Returns:
- the initial window size
setInitialWindowSize
public static void setInitialWindowSize(int val) Initial window size.- Parameters:
val- the new initial window size
getInitialRTO
public static int getInitialRTO()Initial retransmission timeout.- Returns:
- the initial retransmission timeout
setInitialRTO
public static void setInitialRTO(int val) Initial retransmission timeout.- Parameters:
val- the new initial retransmission timeout
getDefaultInitialAckDelay
public static int getDefaultInitialAckDelay()Default initial ACK delay.- Returns:
- the default initial ACK delay
setDefaultInitialAckDelay
public static void setDefaultInitialAckDelay(int val) Default initial ACK delay.- Parameters:
val- the new default initial ACK delay
getDefaultPassiveFlushDelay
public static int getDefaultPassiveFlushDelay()Default passive flush delay.- Returns:
- the default passive flush delay
setDefaultPassiveFlushDelay
public static void setDefaultPassiveFlushDelay(int val) Default passive flush delay.- Parameters:
val- the new default passive flush delay
getDefaultInactivityTimeout
public static int getDefaultInactivityTimeout()Default inactivity timeout.- Returns:
- the default inactivity timeout
setDefaultInactivityTimeout
public static void setDefaultInactivityTimeout(int val) Default inactivity timeout.- Parameters:
val- the new default inactivity timeout
getMaxInboundBuffer
public static int getMaxInboundBuffer()Maximum inbound buffer cap.- Returns:
- the maximum inbound buffer cap (bytes)
setMaxInboundBuffer
public static void setMaxInboundBuffer(int val) Maximum inbound buffer cap.- Parameters:
val- the new maximum inbound buffer cap (bytes)
getMaxStreamsOverride
public static int getMaxStreamsOverride()The Tuner's reactive cap on concurrent streams; 0 = not armed (each manager uses its own configuredmaxConcurrentStreams).- Returns:
- the current override, or 0 if disabled
setMaxStreamsOverride
public static void setMaxStreamsOverride(int val) Arm or clear the Tuner's reactive stream-cap override. Clamped to[0, maxMaxConcurrentStreams]; a manager enforcesmin(config, override).- Parameters:
val- the new override cap, or 0 to disable
getReceiveWorkerThreads
public static int getReceiveWorkerThreads()The Tuner-managed default for inbound packet receive workers; 0 = no override (each manager uses its configured value or the core count).- Returns:
- the current default worker count, or 0 if disabled
setReceiveWorkerThreads
public static void setReceiveWorkerThreads(int val) Set the Tuner-managed default for inbound packet receive workers. Clamped to[0, 8]; 0 disables the override.- Parameters:
val- the new default worker count, or 0 to disable
resizeReceiveWorkers
public static void resizeReceiveWorkers(int val) Apply a new receive-worker default and resize every live dispatcher to match, so existing managers (not just ones created afterwards) follow the Tuner. The resize drains each dispatcher's shard queues before rebuilding, so per-connection ordering and the never-drop guarantee are preserved.- Parameters:
val- the new worker count, clamped to[1, 8]; 0 only updates the default for future managers
getMaxMaxConcurrentStreams
public static int getMaxMaxConcurrentStreams()The operator-tunable ceiling for the Tuner's stream-cap override. Reads fromi2p.streaming.maxMaxConcurrentStreamsinrouter.config.- Returns:
- the current ceiling
setMaxMaxConcurrentStreams
public static void setMaxMaxConcurrentStreams(int val) Set the operator-tunable ceiling for the Tuner's stream-cap override.- Parameters:
val- the new ceiling, clamped to [64, 8192]
getMaxSYNQueueSize
public static int getMaxSYNQueueSize()Max SYN queue size, dynamically adjustable by the Tuner.- Returns:
- the current max SYN queue size
setMaxSYNQueueSize
public static void setMaxSYNQueueSize(int val) Max SYN queue size, dynamically adjustable by the Tuner.- Parameters:
val- the new max SYN queue size
getRttSynTimeoutScale
public static int getRttSynTimeoutScale()Scale factor applied to a sampled recent round-trip time when computing the adaptive SYN accept-queue timeout under tunnel stress. A slow-but-alive fabric (high RTT) must keep a longer window than a fast one so that SYNs aren't expired before the handshake completes. Dynamically adjustable by the Tuner.0 (the unset default) selects
ConnectionHandler.SYN_RTT_SCALE_DEFAULT(4), so the RTT-aware floor stays active out of the box.- Returns:
- the RTT scale factor, or 0 for the built-in default
setRttSynTimeoutScale
public static void setRttSynTimeoutScale(int val) Multiplier applied to recent RTT when sizing the adaptive SYN timeout.- Parameters:
val- the new scale factor; 0 or a negative value selects the built-in default (4)
getSynExprExpireThresh
public static int getSynExprExpireThresh()Fraction (percent) of recent SYN-queue entries that must expire un-accepted before the adaptive timeout clamp is armed, in addition to low tunnel build success. Requiring positive stall evidence keeps a slow-but-alive server from being punished by its own latency. Dynamically adjustable by the Tuner.- Returns:
- the expire-rate threshold as a percent [0,100], 100 disables the clamp
setSynExprExpireThresh
public static void setSynExprExpireThresh(int val) Fraction of recent SYNs that must expire un-accepted to arm the clamp.- Parameters:
val- the new threshold percent; 100 disables the clamp entirely
getAcceptWorkerThreads
public static int getAcceptWorkerThreads()Number of accept worker threads, dynamically adjustable by the Tuner.- Returns:
- the current number of accept worker threads
setAcceptWorkerThreads
public static void setAcceptWorkerThreads(int val) Number of accept worker threads, dynamically adjustable by the Tuner.- Parameters:
val- the new number of accept worker threads (clamped to [0, 16])