TunnelPoolSettings:

- Make dest hash final
 - Ensure allowZeroHop is always true for exploratory
This commit is contained in:
zzz
2013-10-31 21:07:11 +00:00
parent 1d659e4f8a
commit 0010581405
5 changed files with 39 additions and 19 deletions

View File

@@ -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; }

View File

@@ -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; }

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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;