forked from I2P_Developers/i2p.i2p
API: Fix some client-side APIs to honor defaults in Properties;
add javadocs to specify where we do and don't (ticket #1491)
This commit is contained in:
@@ -540,6 +540,8 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
* This DOES update a running TunnelTask, but NOT the session.
|
||||
* A more efficient runClientOptions().
|
||||
*
|
||||
* Defaults in opts properties are not recommended, they may or may not be honored.
|
||||
*
|
||||
* @param opts non-null
|
||||
* @since 0.9.1
|
||||
*/
|
||||
|
@@ -113,6 +113,8 @@ public class TunnelController implements Logging {
|
||||
* the prefix should be used (and, in turn, that prefix should be stripped off
|
||||
* before being interpreted by this controller)
|
||||
*
|
||||
* Defaults in config properties are not recommended, they may or may not be honored.
|
||||
*
|
||||
* @param config original key=value mapping non-null
|
||||
* @param prefix beginning of key values that are relevant to this tunnel
|
||||
*/
|
||||
@@ -121,6 +123,7 @@ public class TunnelController implements Logging {
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults in config properties are not recommended, they may or may not be honored.
|
||||
*
|
||||
* @param config original key=value mapping non-null
|
||||
* @param prefix beginning of key values that are relevant to this tunnel
|
||||
@@ -506,6 +509,7 @@ public class TunnelController implements Logging {
|
||||
|
||||
/**
|
||||
* These are the ones stored with a prefix of "option."
|
||||
* Defaults in config properties are not honored.
|
||||
*
|
||||
* @return keys with the "option." prefix stripped, non-null
|
||||
* @since 0.9.1 Much better than getClientOptions()
|
||||
|
@@ -73,6 +73,9 @@ public interface I2PSocketManager {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param opts The new options, may be null
|
||||
*/
|
||||
public I2PSocketOptions buildOptions(Properties opts);
|
||||
|
@@ -49,6 +49,7 @@ public class I2PSocketManagerFactory {
|
||||
* I2CP router on the local machine on the default port (7654).
|
||||
*
|
||||
* Blocks for a long time while the router builds tunnels.
|
||||
* The nonblocking createDisconnectedManager() is preferred.
|
||||
*
|
||||
* @return the newly created socket manager, or null if there were errors
|
||||
*/
|
||||
@@ -61,6 +62,7 @@ public class I2PSocketManagerFactory {
|
||||
* I2CP router on the local machine on the default port (7654).
|
||||
*
|
||||
* Blocks for a long time while the router builds tunnels.
|
||||
* The nonblocking createDisconnectedManager() is preferred.
|
||||
*
|
||||
* @param opts Streaming and I2CP options, may be null
|
||||
* @return the newly created socket manager, or null if there were errors
|
||||
@@ -74,6 +76,7 @@ public class I2PSocketManagerFactory {
|
||||
* I2CP router on the specified host and port.
|
||||
*
|
||||
* Blocks for a long time while the router builds tunnels.
|
||||
* The nonblocking createDisconnectedManager() is preferred.
|
||||
*
|
||||
* @param host I2CP host null to use default, ignored if in router context
|
||||
* @param port I2CP port <= 0 to use default, ignored if in router context
|
||||
@@ -88,6 +91,7 @@ public class I2PSocketManagerFactory {
|
||||
* I2CP router on the given machine reachable through the given port.
|
||||
*
|
||||
* Blocks for a long time while the router builds tunnels.
|
||||
* The nonblocking createDisconnectedManager() is preferred.
|
||||
*
|
||||
* @param i2cpHost I2CP host null to use default, ignored if in router context
|
||||
* @param i2cpPort I2CP port <= 0 to use default, ignored if in router context
|
||||
@@ -115,6 +119,7 @@ public class I2PSocketManagerFactory {
|
||||
* stream and connected to the default I2CP host and port.
|
||||
*
|
||||
* Blocks for a long time while the router builds tunnels.
|
||||
* The nonblocking createDisconnectedManager() is preferred.
|
||||
*
|
||||
* @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
|
||||
* or null for a transient destination. Caller must close.
|
||||
@@ -129,6 +134,7 @@ public class I2PSocketManagerFactory {
|
||||
* stream and connected to the default I2CP host and port.
|
||||
*
|
||||
* Blocks for a long time while the router builds tunnels.
|
||||
* The nonblocking createDisconnectedManager() is preferred.
|
||||
*
|
||||
* @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
|
||||
* or null for a transient destination. Caller must close.
|
||||
@@ -145,6 +151,7 @@ public class I2PSocketManagerFactory {
|
||||
* port.
|
||||
*
|
||||
* Blocks for a long time while the router builds tunnels.
|
||||
* The nonblocking createDisconnectedManager() is preferred.
|
||||
*
|
||||
* @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
|
||||
* or null for a transient destination. Caller must close.
|
||||
@@ -220,11 +227,11 @@ public class I2PSocketManagerFactory {
|
||||
Properties syscopy = (Properties) System.getProperties().clone();
|
||||
for (Map.Entry<Object, Object> e : syscopy.entrySet()) {
|
||||
String name = (String) e.getKey();
|
||||
if (!opts.containsKey(name))
|
||||
if (opts.getProperty(name) != null)
|
||||
opts.setProperty(name, (String) e.getValue());
|
||||
}
|
||||
// as of 0.8.1 (I2CP default is BestEffort)
|
||||
if (!opts.containsKey(I2PClient.PROP_RELIABILITY))
|
||||
if (opts.getProperty(I2PClient.PROP_RELIABILITY) == null)
|
||||
opts.setProperty(I2PClient.PROP_RELIABILITY, I2PClient.PROP_RELIABILITY_NONE);
|
||||
|
||||
if (i2cpHost != null)
|
||||
|
@@ -264,6 +264,9 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
/**
|
||||
* Sets max buffer size, connect timeout, read timeout, and write timeout
|
||||
* from properties. Does not set local port or remote port.
|
||||
*
|
||||
* As of 0.9.19, defaults in opts are honored.
|
||||
*
|
||||
* @param opts may be null
|
||||
*/
|
||||
public ConnectionOptions(Properties opts) {
|
||||
@@ -388,66 +391,68 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
|
||||
/**
|
||||
* Note: NOT part of the interface
|
||||
*
|
||||
* As of 0.9.19, defaults in opts are honored.
|
||||
*/
|
||||
@Override
|
||||
public void setProperties(Properties opts) {
|
||||
super.setProperties(opts);
|
||||
if (opts == null) return;
|
||||
if (opts.containsKey(PROP_MAX_WINDOW_SIZE))
|
||||
if (opts.getProperty(PROP_MAX_WINDOW_SIZE) != null)
|
||||
setMaxWindowSize(getInt(opts, PROP_MAX_WINDOW_SIZE, Connection.MAX_WINDOW_SIZE));
|
||||
if (opts.containsKey(PROP_CONNECT_DELAY))
|
||||
if (opts.getProperty(PROP_CONNECT_DELAY) != null)
|
||||
setConnectDelay(getInt(opts, PROP_CONNECT_DELAY, -1));
|
||||
if (opts.containsKey(PROP_PROFILE))
|
||||
if (opts.getProperty(PROP_PROFILE) != null)
|
||||
setProfile(getInt(opts, PROP_PROFILE, PROFILE_BULK));
|
||||
if (opts.containsKey(PROP_MAX_MESSAGE_SIZE))
|
||||
if (opts.getProperty(PROP_MAX_MESSAGE_SIZE) != null)
|
||||
setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, Packet.MAX_PAYLOAD_SIZE));
|
||||
if (opts.containsKey(PROP_INITIAL_RECEIVE_WINDOW))
|
||||
if (opts.getProperty(PROP_INITIAL_RECEIVE_WINDOW) != null)
|
||||
setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1));
|
||||
if (opts.containsKey(PROP_INITIAL_RESEND_DELAY))
|
||||
if (opts.getProperty(PROP_INITIAL_RESEND_DELAY) != null)
|
||||
setResendDelay(getInt(opts, PROP_INITIAL_RESEND_DELAY, 1000));
|
||||
if (opts.containsKey(PROP_INITIAL_ACK_DELAY))
|
||||
if (opts.getProperty(PROP_INITIAL_ACK_DELAY) != null)
|
||||
setSendAckDelay(getInt(opts, PROP_INITIAL_ACK_DELAY, DEFAULT_INITIAL_ACK_DELAY));
|
||||
if (opts.containsKey(PROP_INITIAL_WINDOW_SIZE))
|
||||
if (opts.getProperty(PROP_INITIAL_WINDOW_SIZE) != null)
|
||||
setWindowSize(getInt(opts, PROP_INITIAL_WINDOW_SIZE, INITIAL_WINDOW_SIZE));
|
||||
if (opts.containsKey(PROP_MAX_RESENDS))
|
||||
if (opts.getProperty(PROP_MAX_RESENDS) != null)
|
||||
setMaxResends(getInt(opts, PROP_MAX_RESENDS, DEFAULT_MAX_SENDS));
|
||||
// handled in super()
|
||||
//if (opts.containsKey(PROP_WRITE_TIMEOUT))
|
||||
//if (opts.getProperty(PROP_WRITE_TIMEOUT))
|
||||
// setWriteTimeout(getInt(opts, PROP_WRITE_TIMEOUT, -1));
|
||||
if (opts.containsKey(PROP_INACTIVITY_TIMEOUT))
|
||||
if (opts.getProperty(PROP_INACTIVITY_TIMEOUT) != null)
|
||||
setInactivityTimeout(getInt(opts, PROP_INACTIVITY_TIMEOUT, DEFAULT_INACTIVITY_TIMEOUT));
|
||||
if (opts.containsKey(PROP_INACTIVITY_ACTION))
|
||||
if (opts.getProperty(PROP_INACTIVITY_ACTION) != null)
|
||||
setInactivityAction(getInt(opts, PROP_INACTIVITY_ACTION, DEFAULT_INACTIVITY_ACTION));
|
||||
setInboundBufferSize(getMaxMessageSize() * (Connection.MAX_WINDOW_SIZE + 2));
|
||||
if (opts.contains(PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR))
|
||||
if (opts.getProperty(PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR) != null)
|
||||
setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR,
|
||||
DEFAULT_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR));
|
||||
if (opts.contains(PROP_SLOW_START_GROWTH_RATE_FACTOR))
|
||||
if (opts.getProperty(PROP_SLOW_START_GROWTH_RATE_FACTOR) != null)
|
||||
setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR,
|
||||
DEFAULT_SLOW_START_GROWTH_RATE_FACTOR));
|
||||
if (opts.containsKey(PROP_CONNECT_TIMEOUT))
|
||||
if (opts.getProperty(PROP_CONNECT_TIMEOUT) != null)
|
||||
// overrides default in super()
|
||||
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DEFAULT_CONNECT_TIMEOUT));
|
||||
if (opts.containsKey(PROP_ANSWER_PINGS))
|
||||
if (opts.getProperty(PROP_ANSWER_PINGS) != null)
|
||||
setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
|
||||
if (opts.containsKey(PROP_ENFORCE_PROTO))
|
||||
if (opts.getProperty(PROP_ENFORCE_PROTO) != null)
|
||||
setEnforceProtocol(getBool(opts, PROP_ENFORCE_PROTO, DEFAULT_ENFORCE_PROTO));
|
||||
if (opts.containsKey(PROP_DISABLE_REJ_LOG))
|
||||
if (opts.getProperty(PROP_DISABLE_REJ_LOG) != null)
|
||||
setDisableRejectLogging(getBool(opts, PROP_DISABLE_REJ_LOG, false));
|
||||
initLists(opts);
|
||||
if (opts.containsKey(PROP_MAX_CONNS_MIN))
|
||||
if (opts.getProperty(PROP_MAX_CONNS_MIN) != null)
|
||||
_maxConnsPerMinute = getInt(opts, PROP_MAX_CONNS_MIN, 0);
|
||||
if (opts.containsKey(PROP_MAX_CONNS_HOUR))
|
||||
if (opts.getProperty(PROP_MAX_CONNS_HOUR) != null)
|
||||
_maxConnsPerHour = getInt(opts, PROP_MAX_CONNS_HOUR, 0);
|
||||
if (opts.containsKey(PROP_MAX_CONNS_DAY))
|
||||
if (opts.getProperty(PROP_MAX_CONNS_DAY) != null)
|
||||
_maxConnsPerDay = getInt(opts, PROP_MAX_CONNS_DAY, 0);
|
||||
if (opts.containsKey(PROP_MAX_TOTAL_CONNS_MIN))
|
||||
if (opts.getProperty(PROP_MAX_TOTAL_CONNS_MIN) != null)
|
||||
_maxTotalConnsPerMinute = getInt(opts, PROP_MAX_TOTAL_CONNS_MIN, 0);
|
||||
if (opts.containsKey(PROP_MAX_TOTAL_CONNS_HOUR))
|
||||
if (opts.getProperty(PROP_MAX_TOTAL_CONNS_HOUR) != null)
|
||||
_maxTotalConnsPerHour = getInt(opts, PROP_MAX_TOTAL_CONNS_HOUR, 0);
|
||||
if (opts.containsKey(PROP_MAX_TOTAL_CONNS_DAY))
|
||||
if (opts.getProperty(PROP_MAX_TOTAL_CONNS_DAY) != null)
|
||||
_maxTotalConnsPerDay = getInt(opts, PROP_MAX_TOTAL_CONNS_DAY, 0);
|
||||
if (opts.containsKey(PROP_MAX_STREAMS))
|
||||
if (opts.getProperty(PROP_MAX_STREAMS) != null)
|
||||
_maxConns = getInt(opts, PROP_MAX_STREAMS, 0);
|
||||
|
||||
_rto = getInt(opts, PROP_INITIAL_RTO, INITIAL_RTO);
|
||||
|
@@ -102,6 +102,9 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param opts The new options, may be null
|
||||
*/
|
||||
public I2PSocketOptions buildOptions(Properties opts) {
|
||||
@@ -216,6 +219,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
* 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.
|
||||
*
|
||||
* @param options as created from a call to buildOptions(properties), non-null
|
||||
*/
|
||||
public void setDefaultOptions(I2PSocketOptions options) {
|
||||
|
@@ -47,6 +47,9 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
/**
|
||||
* Sets max buffer size, connect timeout, read timeout, and write timeout
|
||||
* from properties. Does not set local port or remote port.
|
||||
*
|
||||
* As of 0.9.19, defaults in opts are honored.
|
||||
*
|
||||
* @param opts may be null
|
||||
*/
|
||||
public I2PSocketOptionsImpl(Properties opts) {
|
||||
@@ -56,17 +59,20 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
/**
|
||||
* Sets max buffer size, connect timeout, read timeout, and write timeout
|
||||
* from properties. Does not set local port or remote port.
|
||||
*
|
||||
* As of 0.9.19, defaults in opts are honored.
|
||||
*
|
||||
* @param opts may be null
|
||||
*/
|
||||
public void setProperties(Properties opts) {
|
||||
if (opts == null) return;
|
||||
if (opts.containsKey(PROP_BUFFER_SIZE))
|
||||
if (opts.getProperty(PROP_BUFFER_SIZE) != null)
|
||||
_maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
|
||||
if (opts.containsKey(PROP_CONNECT_TIMEOUT))
|
||||
if (opts.getProperty(PROP_CONNECT_TIMEOUT) != null)
|
||||
_connectTimeout = getInt(opts, PROP_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
|
||||
if (opts.containsKey(PROP_READ_TIMEOUT))
|
||||
if (opts.getProperty(PROP_READ_TIMEOUT) != null)
|
||||
_readTimeout = getInt(opts, PROP_READ_TIMEOUT, -1);
|
||||
if (opts.containsKey(PROP_WRITE_TIMEOUT))
|
||||
if (opts.getProperty(PROP_WRITE_TIMEOUT) != null)
|
||||
_writeTimeout = getInt(opts, PROP_WRITE_TIMEOUT, DEFAULT_WRITE_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -95,6 +101,9 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not part of the API, not for external use.
|
||||
*/
|
||||
public static double getDouble(Properties opts, String name, double defaultVal) {
|
||||
if (opts == null) return defaultVal;
|
||||
String val = opts.getProperty(name);
|
||||
|
Reference in New Issue
Block a user