I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 00105814 authored by zzz's avatar zzz
Browse files

TunnelPoolSettings:

 - Make dest hash final
 - Ensure allowZeroHop is always true for exploratory
parent 1d659e4f
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,8 @@ package net.i2p.router; ...@@ -11,6 +11,8 @@ package net.i2p.router;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import net.i2p.data.Hash;
/** /**
* Wrap up the client settings specifying their tunnel criteria * Wrap up the client settings specifying their tunnel criteria
* *
...@@ -19,9 +21,9 @@ public class ClientTunnelSettings { ...@@ -19,9 +21,9 @@ public class ClientTunnelSettings {
private final TunnelPoolSettings _inboundSettings; private final TunnelPoolSettings _inboundSettings;
private final TunnelPoolSettings _outboundSettings; private final TunnelPoolSettings _outboundSettings;
public ClientTunnelSettings() { public ClientTunnelSettings(Hash dest) {
_inboundSettings = new TunnelPoolSettings(false, true); _inboundSettings = new TunnelPoolSettings(dest, false, true);
_outboundSettings = new TunnelPoolSettings(false, false); _outboundSettings = new TunnelPoolSettings(dest, false, false);
} }
public TunnelPoolSettings getInboundSettings() { return _inboundSettings; } public TunnelPoolSettings getInboundSettings() { return _inboundSettings; }
......
...@@ -13,7 +13,7 @@ import net.i2p.util.SystemVersion; ...@@ -13,7 +13,7 @@ import net.i2p.util.SystemVersion;
* *
*/ */
public class TunnelPoolSettings { public class TunnelPoolSettings {
private Hash _destination; private final Hash _destination;
private String _destinationNickname; private String _destinationNickname;
private int _quantity; private int _quantity;
private int _backupQuantity; private int _backupQuantity;
...@@ -46,6 +46,7 @@ public class TunnelPoolSettings { ...@@ -46,6 +46,7 @@ public class TunnelPoolSettings {
public static final String PROP_DURATION = "duration"; public static final String PROP_DURATION = "duration";
public static final String PROP_LENGTH = "length"; public static final String PROP_LENGTH = "length";
public static final String PROP_LENGTH_VARIANCE = "lengthVariance"; public static final String PROP_LENGTH_VARIANCE = "lengthVariance";
/** don't trust this, always true */
public static final String PROP_ALLOW_ZERO_HOP = "allowZeroHop"; public static final String PROP_ALLOW_ZERO_HOP = "allowZeroHop";
public static final String PROP_IP_RESTRICTION = "IPRestriction"; public static final String PROP_IP_RESTRICTION = "IPRestriction";
public static final String PROP_PRIORITY = "priority"; public static final String PROP_PRIORITY = "priority";
...@@ -63,7 +64,8 @@ public class TunnelPoolSettings { ...@@ -63,7 +64,8 @@ public class TunnelPoolSettings {
private static final int MAX_PRIORITY = 25; private static final int MAX_PRIORITY = 25;
private static final int EXPLORATORY_PRIORITY = 30; private static final int EXPLORATORY_PRIORITY = 30;
public TunnelPoolSettings(boolean isExploratory, boolean isInbound) { public TunnelPoolSettings(Hash dest, boolean isExploratory, boolean isInbound) {
_destination = dest;
_isExploratory = isExploratory; _isExploratory = isExploratory;
_isInbound = isInbound; _isInbound = isInbound;
_quantity = DEFAULT_QUANTITY; _quantity = DEFAULT_QUANTITY;
...@@ -73,7 +75,10 @@ public class TunnelPoolSettings { ...@@ -73,7 +75,10 @@ public class TunnelPoolSettings {
_length = DEFAULT_LENGTH; _length = DEFAULT_LENGTH;
_lengthVariance = DEFAULT_LENGTH_VARIANCE; _lengthVariance = DEFAULT_LENGTH_VARIANCE;
_lengthOverride = -1; _lengthOverride = -1;
_allowZeroHop = DEFAULT_ALLOW_ZERO_HOP; if (isExploratory)
_allowZeroHop = true;
else
_allowZeroHop = DEFAULT_ALLOW_ZERO_HOP;
_IPRestriction = DEFAULT_IP_RESTRICTION; _IPRestriction = DEFAULT_IP_RESTRICTION;
_unknownOptions = new Properties(); _unknownOptions = new Properties();
_randomKey = generateRandomKey(); _randomKey = generateRandomKey();
...@@ -114,9 +119,22 @@ public class TunnelPoolSettings { ...@@ -114,9 +119,22 @@ public class TunnelPoolSettings {
*/ */
public void setLength(int length) { _length = length; } public void setLength(int length) { _length = length; }
/** if there are no tunnels to build with, will this pool allow 0 hop tunnels? */ /**
* If there are no tunnels to build with, will this pool allow 0 hop tunnels?
* Always true for exploratory.
* Generally true for client, but should probably be ignored...
* use getLength() + getLengthVariance() > 0 instead.
*/
public boolean getAllowZeroHop() { return _allowZeroHop; } public boolean getAllowZeroHop() { return _allowZeroHop; }
public void setAllowZeroHop(boolean ok) { _allowZeroHop = ok; }
/**
* If there are no tunnels to build with, will this pool allow 0 hop tunnels?
* No effect on exploratory (always true)
*/
public void setAllowZeroHop(boolean ok) {
if (!_isExploratory)
_allowZeroHop = ok;
}
/** /**
* how should the length be varied. if negative, this randomly skews from * how should the length be varied. if negative, this randomly skews from
...@@ -153,7 +171,6 @@ public class TunnelPoolSettings { ...@@ -153,7 +171,6 @@ public class TunnelPoolSettings {
/** what destination is this a tunnel for (or null if none) */ /** what destination is this a tunnel for (or null if none) */
public Hash getDestination() { return _destination; } public Hash getDestination() { return _destination; }
public void setDestination(Hash dest) { _destination = dest; }
/** random key used for peer ordering */ /** random key used for peer ordering */
public Hash getRandomKey() { return _randomKey; } public Hash getRandomKey() { return _randomKey; }
......
...@@ -11,6 +11,7 @@ package net.i2p.router.client; ...@@ -11,6 +11,7 @@ package net.i2p.router.client;
import java.util.Properties; import java.util.Properties;
import net.i2p.CoreVersion; import net.i2p.CoreVersion;
import net.i2p.data.Hash;
import net.i2p.data.Payload; import net.i2p.data.Payload;
import net.i2p.data.i2cp.BandwidthLimitsMessage; import net.i2p.data.i2cp.BandwidthLimitsMessage;
import net.i2p.data.i2cp.CreateLeaseSetMessage; import net.i2p.data.i2cp.CreateLeaseSetMessage;
...@@ -324,13 +325,14 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi ...@@ -324,13 +325,14 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
return; return;
} }
_runner.getConfig().getOptions().putAll(message.getSessionConfig().getOptions()); _runner.getConfig().getOptions().putAll(message.getSessionConfig().getOptions());
ClientTunnelSettings settings = new ClientTunnelSettings(); Hash dest = _runner.getConfig().getDestination().calculateHash();
ClientTunnelSettings settings = new ClientTunnelSettings(dest);
Properties props = new Properties(); Properties props = new Properties();
props.putAll(_runner.getConfig().getOptions()); props.putAll(_runner.getConfig().getOptions());
settings.readFromProperties(props); settings.readFromProperties(props);
_context.tunnelManager().setInboundSettings(_runner.getConfig().getDestination().calculateHash(), _context.tunnelManager().setInboundSettings(dest,
settings.getInboundSettings()); settings.getInboundSettings());
_context.tunnelManager().setOutboundSettings(_runner.getConfig().getDestination().calculateHash(), _context.tunnelManager().setOutboundSettings(dest,
settings.getOutboundSettings()); settings.getOutboundSettings());
sendStatusMessage(SessionStatusMessage.STATUS_UPDATED); sendStatusMessage(SessionStatusMessage.STATUS_UPDATED);
} }
......
...@@ -10,6 +10,7 @@ package net.i2p.router.client; ...@@ -10,6 +10,7 @@ package net.i2p.router.client;
import java.util.Properties; import java.util.Properties;
import net.i2p.data.Hash;
import net.i2p.data.i2cp.SessionConfig; import net.i2p.data.i2cp.SessionConfig;
import net.i2p.router.ClientTunnelSettings; import net.i2p.router.ClientTunnelSettings;
import net.i2p.router.JobImpl; import net.i2p.router.JobImpl;
...@@ -43,9 +44,10 @@ class CreateSessionJob extends JobImpl { ...@@ -43,9 +44,10 @@ class CreateSessionJob extends JobImpl {
_log.error("No session config on runner " + _runner); _log.error("No session config on runner " + _runner);
return; return;
} }
Hash dest = cfg.getDestination().calculateHash();
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Requesting lease set for destination " + cfg.getDestination().calculateHash().toBase64()); _log.info("Requesting lease set for destination " + dest);
ClientTunnelSettings settings = new ClientTunnelSettings(); ClientTunnelSettings settings = new ClientTunnelSettings(dest);
Properties props = new Properties(); Properties props = new Properties();
// We're NOT going to force all clients to use the router's defaults, since that may be // We're NOT going to force all clients to use the router's defaults, since that may be
......
...@@ -63,9 +63,9 @@ public class TunnelPoolManager implements TunnelManagerFacade { ...@@ -63,9 +63,9 @@ public class TunnelPoolManager implements TunnelManagerFacade {
_clientPeerSelector = new ClientPeerSelector(ctx); _clientPeerSelector = new ClientPeerSelector(ctx);
ExploratoryPeerSelector selector = new ExploratoryPeerSelector(_context); ExploratoryPeerSelector selector = new ExploratoryPeerSelector(_context);
TunnelPoolSettings inboundSettings = new TunnelPoolSettings(true, true); TunnelPoolSettings inboundSettings = new TunnelPoolSettings(null, true, true);
_inboundExploratory = new TunnelPool(_context, this, inboundSettings, selector); _inboundExploratory = new TunnelPool(_context, this, inboundSettings, selector);
TunnelPoolSettings outboundSettings = new TunnelPoolSettings(true, false); TunnelPoolSettings outboundSettings = new TunnelPoolSettings(null, true, false);
_outboundExploratory = new TunnelPool(_context, this, outboundSettings, selector); _outboundExploratory = new TunnelPool(_context, this, outboundSettings, selector);
// threads will be started in startup() // threads will be started in startup()
...@@ -377,7 +377,6 @@ public class TunnelPoolManager implements TunnelManagerFacade { ...@@ -377,7 +377,6 @@ public class TunnelPoolManager implements TunnelManagerFacade {
private static void setSettings(Map<Hash, TunnelPool> pools, Hash client, TunnelPoolSettings settings) { private static void setSettings(Map<Hash, TunnelPool> pools, Hash client, TunnelPoolSettings settings) {
TunnelPool pool = pools.get(client); TunnelPool pool = pools.get(client);
if (pool != null) { if (pool != null) {
settings.setDestination(client); // prevent spoofing or unset dest
pool.setSettings(settings); pool.setSettings(settings);
} }
} }
...@@ -397,8 +396,6 @@ public class TunnelPoolManager implements TunnelManagerFacade { ...@@ -397,8 +396,6 @@ public class TunnelPoolManager implements TunnelManagerFacade {
Hash dest = client.calculateHash(); Hash dest = client.calculateHash();
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Building tunnels for the client " + dest + ": " + settings); _log.debug("Building tunnels for the client " + dest + ": " + settings);
settings.getInboundSettings().setDestination(dest);
settings.getOutboundSettings().setDestination(dest);
TunnelPool inbound = null; TunnelPool inbound = null;
TunnelPool outbound = null; TunnelPool outbound = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment