- All Implemented Interfaces:
I2PSocketOptions
- Direct Known Subclasses:
ConnectionOptions
I2PSocketManager.buildOptions() to get one of these.Field Summary
Modifier and TypeFieldDescriptionprivate longHow long a connect may wait, in ms.private intThe local port of the socket.private intLargest send or receive buffer allowed, in bytes.private longHow long a read may wait, in ms.private intThe remote port of the socket.private longHow long a write may wait, in ms.static final intDefault max buffer size.static final intDefault base connect timeout in ms (30 seconds).static final intDefault read timeout in ms; -1 means block forever.static final intDefault write timeout in ms; -1 means never time out.Fields inherited from interface I2PSocketOptions
PROFILE_BULK, PROFILE_INTERACTIVE, PROP_BUFFER_SIZE, PROP_CONNECT_TIMEOUT, PROP_MAX_CONNECT_TIMEOUT, PROP_PROFILE, PROP_READ_TIMEOUT, PROP_WRITE_TIMEOUTModifier and TypeFieldDescriptionstatic final intProfile for bulk transfers (normal downloads/uploads).static final intProfile for interactive traffic (latency-sensitive, e.g.static final StringHow much data will we accept that hasn't been written out yet.static final StringBase time to wait for the ACK from a SYN, in milliseconds, before any adaptive scaling is applied.static final StringAbsolute cap on the time an outbound connect will wait for a SYN ACK, in milliseconds.static final StringIf set, the profile used to prioritize packets on the network.static final StringHow long to block on read.static final StringHow long to block on write/flush.Constructor Summary
ConstructorsConstructorDescriptionMax buffer size, connect timeout, read timeout, and write timeout from System properties.Max buffer size, connect timeout, read timeout, and write timeout from properties.Initializes from System properties then copies over all options.Method Summary
Modifier and TypeMethodDescriptionlongBase time to wait for the ACK from a SYN, in milliseconds.(package private) static doublegetDouble(Properties opts, String name, double defaultVal) Not part of the API, not for external use.protected static intgetInt(Properties opts, String name, int defaultVal) Parse an integer property value, with a default on failure.intThe local port.intHow much data will we accept that hasn't been written out yet.intgetPort()The remote port.longWhat is the longest we'll block on the input stream while waiting for more data.longWhat is the longest we'll block on the output stream while waiting for the data to flush.protected voidinit(Properties opts) Max buffer size, connect timeout, read timeout, and write timeout from properties.voidsetConnectTimeout(long ms) Define how long we will wait for the ACK from a SYN, in milliseconds.voidsetLocalPort(int port) The local port.voidsetMaxBufferSize(int numBytes) How much data will we accept that hasn't been written out yet.voidsetPort(int port) The remote port.voidsetProperties(Properties opts) Max buffer size, connect timeout, read timeout, and write timeout from properties.voidsetReadTimeout(long ms) What is the longest we'll block on the input stream while waiting for more data.voidsetWriteTimeout(long ms) What is the longest we'll block on the output stream while waiting for the data to flush.
Field Details
_connectTimeout
private long _connectTimeoutHow long a connect may wait, in ms._readTimeout
private long _readTimeoutHow long a read may wait, in ms._writeTimeout
private long _writeTimeoutHow long a write may wait, in ms._maxBufferSize
private int _maxBufferSizeLargest send or receive buffer allowed, in bytes._localPort
private int _localPortThe local port of the socket._remotePort
private int _remotePortThe remote port of the socket.DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault max buffer size. Platform-dependent: a slow system, or one reporting less than 512 MB of memory, gets 512 KB, everything else 1 MB (see the sizing below).DEFAULT_READ_TIMEOUT
public static final int DEFAULT_READ_TIMEOUTDefault read timeout in ms; -1 means block forever.- See Also:
DEFAULT_WRITE_TIMEOUT
public static final int DEFAULT_WRITE_TIMEOUTDefault write timeout in ms; -1 means never time out.- See Also:
DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUTDefault base connect timeout in ms (30 seconds). This is the pre-scaling window only: the effective window is scaled by the connect timeout multiplier and capped at the absolute max connect timeout (75 seconds by default), so a caller setting a longer value still waits no longer than the cap.- See Also:
Constructor Details
I2PSocketOptionsImpl
public I2PSocketOptionsImpl()Max buffer size, connect timeout, read timeout, and write timeout from System properties. Does not set local port or remote port.I2PSocketOptionsImpl
Initializes from System properties then copies over all options.- Parameters:
opts- may be null
I2PSocketOptionsImpl
Max buffer size, connect timeout, read timeout, and write timeout from properties. Does not set local port or remote port.A property absent from opts, or one that does not parse as an integer, falls back to the corresponding default.
- Parameters:
opts- may be null
Method Details
setProperties
Max buffer size, connect timeout, read timeout, and write timeout from properties. Does not set local port or remote port.Only the properties present in opts are applied. Anything absent from opts keeps the value this object already has, so a partial opts overrides only what it names.
- Parameters:
opts- may be null
init
Max buffer size, connect timeout, read timeout, and write timeout from properties. Does not set local port or remote port.- Parameters:
opts- options properties to read the four settings from
getInt
Parse an integer property value, with a default on failure.- Parameters:
opts- properties to read from, null yields the defaultname- the property name to look updefaultVal- returned when the property is absent or not an integer- Returns:
- the parsed integer, or defaultVal when absent or unparseable
getDouble
Not part of the API, not for external use.- Parameters:
opts- properties to read from, null yields the defaultname- the property name to look updefaultVal- returned when the property is absent or not a number- Returns:
- the parsed property value, or defaultVal if it cannot be parsed
getConnectTimeout
public long getConnectTimeout()Base time to wait for the ACK from a SYN, in milliseconds.The stored value is un-scaled; the effective connect window adds the connect delay on the delayed-SYN path, is scaled by the connect timeout multiplier, and is capped at the absolute max connect timeout, so a stored value above that cap waits no longer than the cap.
Default 30 seconds.
- Specified by:
getConnectTimeoutin interfaceI2PSocketOptions- Returns:
- milliseconds to wait, or a non-positive value for no connect timeout, i.e. the handshake is not given up on a timer
setConnectTimeout
public void setConnectTimeout(long ms) Define how long we will wait for the ACK from a SYN, in milliseconds.The value is stored un-scaled; see
getConnectTimeout().Default 30 seconds.
- Specified by:
setConnectTimeoutin interfaceI2PSocketOptions- Parameters:
ms- timeout in ms, <= 0 for no connect timeout
getReadTimeout
public long getReadTimeout()What is the longest we'll block on the input stream while waiting for more data. If this value is exceeded, the read() throws SocketTimeoutException.WARNING: Default -1 (unlimited), which is probably not what you want.
- Specified by:
getReadTimeoutin interfaceI2PSocketOptions- Returns:
- timeout in ms, 0 for nonblocking, -1 for forever
setReadTimeout
public void setReadTimeout(long ms) What is the longest we'll block on the input stream while waiting for more data. If this value is exceeded, the read() throws SocketTimeoutException.WARNING: Default -1 (unlimited), which is probably not what you want.
- Specified by:
setReadTimeoutin interfaceI2PSocketOptions- Parameters:
ms- timeout in ms, 0 for nonblocking, -1 for forever
getMaxBufferSize
public int getMaxBufferSize()How much data will we accept that hasn't been written out yet. After this amount has been exceeded, subsequent .write calls will block until either some data is removed or the connection is closed. If this is less than or equal to zero, there is no limit (warning: can eat ram)Default is
DEFAULT_BUFFER_SIZE, which is platform-dependent.- Specified by:
getMaxBufferSizein interfaceI2PSocketOptions- Returns:
- buffer size limit, in bytes
setMaxBufferSize
public void setMaxBufferSize(int numBytes) How much data will we accept that hasn't been written out yet. After this amount has been exceeded, subsequent .write calls will block until either some data is removed or the connection is closed. If this is less than or equal to zero, there is no limit (warning: can eat ram)Default is
DEFAULT_BUFFER_SIZE, which is platform-dependent.- Specified by:
setMaxBufferSizein interfaceI2PSocketOptions- Parameters:
numBytes- How much data will we accept that hasn't been written out yet.
getWriteTimeout
public long getWriteTimeout()What is the longest we'll block on the output stream while waiting for the data to flush. If this value is exceeded, the write() throws InterruptedIOException. If this is less than or equal to zero, there is no timeout.Default -1 (unlimited).
- Specified by:
getWriteTimeoutin interfaceI2PSocketOptions- Returns:
- the write timeout
setWriteTimeout
public void setWriteTimeout(long ms) What is the longest we'll block on the output stream while waiting for the data to flush. If this value is exceeded, the write() throws InterruptedIOException. If this is less than or equal to zero, there is no timeout.Default -1 (unlimited).
- Specified by:
setWriteTimeoutin interfaceI2PSocketOptions- Parameters:
ms- wait time to block on the output stream while waiting for the data to flush.
getPort
public int getPort()The remote port.- Specified by:
getPortin interfaceI2PSocketOptions- Returns:
- Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
setPort
public void setPort(int port) The remote port.- Specified by:
setPortin interfaceI2PSocketOptions- Parameters:
port- 0 - 65535- Throws:
IllegalArgumentException- if port is outside 0 - 65535
getLocalPort
public int getLocalPort()The local port.- Specified by:
getLocalPortin interfaceI2PSocketOptions- Returns:
- Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
setLocalPort
public void setLocalPort(int port) The local port. Zero (default) means you will receive traffic on all ports. Nonzero means you will get traffic ONLY for that port, use with care, as most applications do not specify a remote port.- Specified by:
setLocalPortin interfaceI2PSocketOptions- Parameters:
port- 0 - 65535- Throws:
IllegalArgumentException- if port is outside 0 - 65535