Consolidate I2CP property definitions

This commit is contained in:
zzz
2019-11-13 18:06:35 +00:00
parent 65b3cdbb12
commit b8ed77da9a
8 changed files with 52 additions and 51 deletions

View File

@ -64,6 +64,13 @@ public interface I2PClient {
*/
public final static String PROP_FAST_RECEIVE = "i2cp.fastReceive";
/** @since 0.9.44, was protected in I2PSessionImpl */
public static final String PROP_ENABLE_SSL = "i2cp.SSL";
/** @since 0.9.44, was protected in I2PSessionImpl */
public static final String PROP_USER = "i2cp.username";
/** @since 0.9.44, was protected in I2PSessionImpl */
public static final String PROP_PW = "i2cp.password";
/**
* 7654
* @since 0.9.38

View File

@ -66,7 +66,7 @@ class I2CPMessageProducer {
"i2cp.closeIdleTime", "i2cp.closeOnIdle", "i2cp.encryptLeaseSet",
"i2cp.gzip", "i2cp.leaseSetKey", "i2cp.leaseSetPrivateKey",
"i2cp.leaseSetSigningPrivateKey", "i2cp.reduceIdleTime", "i2cp.reduceOnIdle",
I2PSessionImpl.PROP_ENABLE_SSL, I2PClient.PROP_TCP_HOST, I2PClient.PROP_TCP_PORT,
I2PClient.PROP_ENABLE_SSL, I2PClient.PROP_TCP_HOST, I2PClient.PROP_TCP_PORT,
// long and shouldn't be passed through
"i2p.reseedURL"
};

View File

@ -211,11 +211,6 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
private static final Map<Object, Destination> _lookupCache = new LHMCache<Object, Destination>(CACHE_MAX_SIZE);
private static final String MIN_HOST_LOOKUP_VERSION = "0.9.11";
/** SSL interface (only) @since 0.8.3 */
protected static final String PROP_ENABLE_SSL = "i2cp.SSL";
protected static final String PROP_USER = "i2cp.username";
protected static final String PROP_PW = "i2cp.password";
/**
* Use Unix domain socket (or similar) to connect to a router
* @since 0.9.14
@ -431,12 +426,12 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
// auto-add auth if required, not set in the options, and we are not in the same JVM
if ((!_context.isRouterContext()) &&
_context.getBooleanProperty("i2cp.auth") &&
((!opts.containsKey(PROP_USER)) || (!opts.containsKey(PROP_PW)))) {
String configUser = _context.getProperty(PROP_USER);
String configPW = _context.getProperty(PROP_PW);
((!opts.containsKey(I2PClient.PROP_USER)) || (!opts.containsKey(I2PClient.PROP_PW)))) {
String configUser = _context.getProperty(I2PClient.PROP_USER);
String configPW = _context.getProperty(I2PClient.PROP_PW);
if (configUser != null && configPW != null) {
options.setProperty(PROP_USER, configUser);
options.setProperty(PROP_PW, configPW);
options.setProperty(I2PClient.PROP_USER, configUser);
options.setProperty(I2PClient.PROP_PW, configPW);
}
}
if (options.getProperty(I2PClient.PROP_FAST_RECEIVE) == null)
@ -748,7 +743,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
} catch (InvocationTargetException e) {
throw new I2PSessionException("Cannot load DomainSocketFactory", e);
}
} else if (Boolean.parseBoolean(_options.getProperty(PROP_ENABLE_SSL))) {
} else if (Boolean.parseBoolean(_options.getProperty(I2PClient.PROP_ENABLE_SSL))) {
try {
I2PSSLSocketFactory fact = new I2PSSLSocketFactory(_context, false, "certificates/i2cp");
_socket = fact.createSocket(_hostname, _portNum);
@ -776,12 +771,12 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
_reader.startReading();
if (_log.shouldLog(Log.DEBUG)) _log.debug(getPrefix() + "Before getDate");
Properties auth = null;
if ((!_context.isRouterContext()) && _options.containsKey(PROP_USER) && _options.containsKey(PROP_PW)) {
if ((!_context.isRouterContext()) && _options.containsKey(I2PClient.PROP_USER) && _options.containsKey(I2PClient.PROP_PW)) {
// Only supported by routers 0.9.11 or higher, but we don't know the version yet.
// Auth will also be sent in the SessionConfig.
auth = new OrderedProperties();
auth.setProperty(PROP_USER, _options.getProperty(PROP_USER));
auth.setProperty(PROP_PW, _options.getProperty(PROP_PW));
auth.setProperty(I2PClient.PROP_USER, _options.getProperty(I2PClient.PROP_USER));
auth.setProperty(I2PClient.PROP_PW, _options.getProperty(I2PClient.PROP_PW));
}
sendMessage_unchecked(new GetDateMessage(CoreVersion.VERSION, auth));
waitForDate();

View File

@ -80,7 +80,7 @@ public class I2PSimpleSession extends I2PSessionImpl2 {
_reader = new QueuedI2CPMessageReader(_queue, this);
_reader.startReading();
} else {
if (Boolean.parseBoolean(getOptions().getProperty(PROP_ENABLE_SSL))) {
if (Boolean.parseBoolean(getOptions().getProperty(I2PClient.PROP_ENABLE_SSL))) {
try {
I2PSSLSocketFactory fact = new I2PSSLSocketFactory(_context, false, "certificates/i2cp");
_socket = fact.createSocket(_hostname, _portNum);
@ -110,19 +110,19 @@ public class I2PSimpleSession extends I2PSessionImpl2 {
// Auth was not enforced on a simple session until 0.9.11
// We will get disconnected for router version < 0.9.11 since it doesn't
// support the AuthMessage
if ((!opts.containsKey(PROP_USER)) && (!opts.containsKey(PROP_PW))) {
if ((!opts.containsKey(I2PClient.PROP_USER)) && (!opts.containsKey(I2PClient.PROP_PW))) {
// auto-add auth if not set in the options
String configUser = _context.getProperty(PROP_USER);
String configPW = _context.getProperty(PROP_PW);
String configUser = _context.getProperty(I2PClient.PROP_USER);
String configPW = _context.getProperty(I2PClient.PROP_PW);
if (configUser != null && configPW != null) {
opts.setProperty(PROP_USER, configUser);
opts.setProperty(PROP_PW, configPW);
opts.setProperty(I2PClient.PROP_USER, configUser);
opts.setProperty(I2PClient.PROP_PW, configPW);
}
}
if (opts.containsKey(PROP_USER) && opts.containsKey(PROP_PW)) {
if (opts.containsKey(I2PClient.PROP_USER) && opts.containsKey(I2PClient.PROP_PW)) {
Properties auth = new OrderedProperties();
auth.setProperty(PROP_USER, opts.getProperty(PROP_USER));
auth.setProperty(PROP_PW, opts.getProperty(PROP_PW));
auth.setProperty(I2PClient.PROP_USER, opts.getProperty(I2PClient.PROP_USER));
auth.setProperty(I2PClient.PROP_PW, opts.getProperty(I2PClient.PROP_PW));
sendMessage_unchecked(new GetDateMessage(CoreVersion.VERSION, auth));
} else {
// we must now send a GetDate even in SimpleSession, or we won't know

View File

@ -34,9 +34,6 @@ import net.i2p.data.Hash;
class LookupDest {
private static final long DEFAULT_TIMEOUT = 15*1000;
private static final String PROP_ENABLE_SSL = "i2cp.SSL";
private static final String PROP_USER = "i2cp.username";
private static final String PROP_PW = "i2cp.password";
protected LookupDest(I2PAppContext context) {}
@ -110,15 +107,15 @@ class LookupDest {
s = ctx.getProperty(I2PClient.PROP_TCP_PORT);
if (s != null)
opts.put(I2PClient.PROP_TCP_PORT, s);
s = ctx.getProperty(PROP_ENABLE_SSL);
s = ctx.getProperty(I2PClient.PROP_ENABLE_SSL);
if (s != null)
opts.put(PROP_ENABLE_SSL, s);
s = ctx.getProperty(PROP_USER);
opts.put(I2PClient.PROP_ENABLE_SSL, s);
s = ctx.getProperty(I2PClient.PROP_USER);
if (s != null)
opts.put(PROP_USER, s);
s = ctx.getProperty(PROP_PW);
opts.put(I2PClient.PROP_USER, s);
s = ctx.getProperty(I2PClient.PROP_PW);
if (s != null)
opts.put(PROP_PW, s);
opts.put(I2PClient.PROP_PW, s);
}
return opts;
}