diff --git a/router/java/src/net/i2p/router/ClientTunnelSettings.java b/router/java/src/net/i2p/router/ClientTunnelSettings.java index 13a0b888064d04a7f13d17b957e945dacdc4f63c..ac8139ebe0750ac56e434e682a87704c475e6646 100644 --- a/router/java/src/net/i2p/router/ClientTunnelSettings.java +++ b/router/java/src/net/i2p/router/ClientTunnelSettings.java @@ -11,6 +11,8 @@ package net.i2p.router; import java.util.Iterator; import java.util.Properties; +import net.i2p.data.Hash; + /** * Wrap up the client settings specifying their tunnel criteria * @@ -19,9 +21,9 @@ public class ClientTunnelSettings { private final TunnelPoolSettings _inboundSettings; private final TunnelPoolSettings _outboundSettings; - public ClientTunnelSettings() { - _inboundSettings = new TunnelPoolSettings(false, true); - _outboundSettings = new TunnelPoolSettings(false, false); + public ClientTunnelSettings(Hash dest) { + _inboundSettings = new TunnelPoolSettings(dest, false, true); + _outboundSettings = new TunnelPoolSettings(dest, false, false); } public TunnelPoolSettings getInboundSettings() { return _inboundSettings; } diff --git a/router/java/src/net/i2p/router/TunnelPoolSettings.java b/router/java/src/net/i2p/router/TunnelPoolSettings.java index 03461c11c07a8cf22bbd0f5c42c0b736e624e9fb..34f345ec747207180cfeb3ab67127efea084b8ab 100644 --- a/router/java/src/net/i2p/router/TunnelPoolSettings.java +++ b/router/java/src/net/i2p/router/TunnelPoolSettings.java @@ -13,7 +13,7 @@ import net.i2p.util.SystemVersion; * */ public class TunnelPoolSettings { - private Hash _destination; + private final Hash _destination; private String _destinationNickname; private int _quantity; private int _backupQuantity; @@ -46,6 +46,7 @@ public class TunnelPoolSettings { public static final String PROP_DURATION = "duration"; public static final String PROP_LENGTH = "length"; 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_IP_RESTRICTION = "IPRestriction"; public static final String PROP_PRIORITY = "priority"; @@ -63,7 +64,8 @@ public class TunnelPoolSettings { private static final int MAX_PRIORITY = 25; 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; _isInbound = isInbound; _quantity = DEFAULT_QUANTITY; @@ -73,7 +75,10 @@ public class TunnelPoolSettings { _length = DEFAULT_LENGTH; _lengthVariance = DEFAULT_LENGTH_VARIANCE; _lengthOverride = -1; - _allowZeroHop = DEFAULT_ALLOW_ZERO_HOP; + if (isExploratory) + _allowZeroHop = true; + else + _allowZeroHop = DEFAULT_ALLOW_ZERO_HOP; _IPRestriction = DEFAULT_IP_RESTRICTION; _unknownOptions = new Properties(); _randomKey = generateRandomKey(); @@ -114,9 +119,22 @@ public class TunnelPoolSettings { */ 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 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 @@ -153,7 +171,6 @@ public class TunnelPoolSettings { /** what destination is this a tunnel for (or null if none) */ public Hash getDestination() { return _destination; } - public void setDestination(Hash dest) { _destination = dest; } /** random key used for peer ordering */ public Hash getRandomKey() { return _randomKey; } diff --git a/router/java/src/net/i2p/router/client/ClientMessageEventListener.java b/router/java/src/net/i2p/router/client/ClientMessageEventListener.java index 4107de39bee0f385501bb0aef66c070b158ad02a..4c6b5dd41185637dc13ec0af0d4bedb1c6a04329 100644 --- a/router/java/src/net/i2p/router/client/ClientMessageEventListener.java +++ b/router/java/src/net/i2p/router/client/ClientMessageEventListener.java @@ -11,6 +11,7 @@ package net.i2p.router.client; import java.util.Properties; import net.i2p.CoreVersion; +import net.i2p.data.Hash; import net.i2p.data.Payload; import net.i2p.data.i2cp.BandwidthLimitsMessage; import net.i2p.data.i2cp.CreateLeaseSetMessage; @@ -324,13 +325,14 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi return; } _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(); props.putAll(_runner.getConfig().getOptions()); settings.readFromProperties(props); - _context.tunnelManager().setInboundSettings(_runner.getConfig().getDestination().calculateHash(), + _context.tunnelManager().setInboundSettings(dest, settings.getInboundSettings()); - _context.tunnelManager().setOutboundSettings(_runner.getConfig().getDestination().calculateHash(), + _context.tunnelManager().setOutboundSettings(dest, settings.getOutboundSettings()); sendStatusMessage(SessionStatusMessage.STATUS_UPDATED); } diff --git a/router/java/src/net/i2p/router/client/CreateSessionJob.java b/router/java/src/net/i2p/router/client/CreateSessionJob.java index 5b0c103b122b663e351f37791a3c1947d7ab563b..af01a496cb71af4ab4510239ae7d41bb7af0d302 100644 --- a/router/java/src/net/i2p/router/client/CreateSessionJob.java +++ b/router/java/src/net/i2p/router/client/CreateSessionJob.java @@ -10,6 +10,7 @@ package net.i2p.router.client; import java.util.Properties; +import net.i2p.data.Hash; import net.i2p.data.i2cp.SessionConfig; import net.i2p.router.ClientTunnelSettings; import net.i2p.router.JobImpl; @@ -43,9 +44,10 @@ class CreateSessionJob extends JobImpl { _log.error("No session config on runner " + _runner); return; } + Hash dest = cfg.getDestination().calculateHash(); if (_log.shouldLog(Log.INFO)) - _log.info("Requesting lease set for destination " + cfg.getDestination().calculateHash().toBase64()); - ClientTunnelSettings settings = new ClientTunnelSettings(); + _log.info("Requesting lease set for destination " + dest); + ClientTunnelSettings settings = new ClientTunnelSettings(dest); Properties props = new Properties(); // We're NOT going to force all clients to use the router's defaults, since that may be diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java index f57fff8cbc8a45c1c9699a367e4ea2f961d925ec..f97dbead1bc0b23353d2e9235dc0d8b2266ff8f8 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java @@ -63,9 +63,9 @@ public class TunnelPoolManager implements TunnelManagerFacade { _clientPeerSelector = new ClientPeerSelector(ctx); 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); - TunnelPoolSettings outboundSettings = new TunnelPoolSettings(true, false); + TunnelPoolSettings outboundSettings = new TunnelPoolSettings(null, true, false); _outboundExploratory = new TunnelPool(_context, this, outboundSettings, selector); // threads will be started in startup() @@ -377,7 +377,6 @@ public class TunnelPoolManager implements TunnelManagerFacade { private static void setSettings(Map<Hash, TunnelPool> pools, Hash client, TunnelPoolSettings settings) { TunnelPool pool = pools.get(client); if (pool != null) { - settings.setDestination(client); // prevent spoofing or unset dest pool.setSettings(settings); } } @@ -397,8 +396,6 @@ public class TunnelPoolManager implements TunnelManagerFacade { Hash dest = client.calculateHash(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Building tunnels for the client " + dest + ": " + settings); - settings.getInboundSettings().setDestination(dest); - settings.getOutboundSettings().setDestination(dest); TunnelPool inbound = null; TunnelPool outbound = null;