forked from I2P_Developers/i2p.i2p
Tunnels: Make new tunnel selection round-robin
Remove one-second stickiness, as OCMOSJ caching does the job better http://zzz.i2p/topics/2454
This commit is contained in:
@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 3;
|
||||
public final static long BUILD = 4;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
|
@ -40,8 +40,7 @@ public class TunnelPool {
|
||||
private final TunnelPoolManager _manager;
|
||||
protected volatile boolean _alive;
|
||||
private long _lifetimeProcessed;
|
||||
private TunnelInfo _lastSelected;
|
||||
private long _lastSelectionPeriod;
|
||||
private int _lastSelectedIdx;
|
||||
private final int _expireSkew;
|
||||
private long _started;
|
||||
private long _lastRateUpdate;
|
||||
@ -124,8 +123,6 @@ public class TunnelPool {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn(toString() + ": Shutdown called");
|
||||
_alive = false;
|
||||
_lastSelectionPeriod = 0;
|
||||
_lastSelected = null;
|
||||
_context.statManager().removeRateStat(_rateName);
|
||||
synchronized (_inProgress) {
|
||||
_inProgress.clear();
|
||||
@ -152,20 +149,6 @@ public class TunnelPool {
|
||||
_settings.readFromProperties(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* when selecting tunnels, stick with the same one for a brief
|
||||
* period to allow batching if we can.
|
||||
*/
|
||||
private long curPeriod() {
|
||||
long period = _context.clock().now();
|
||||
long ms = period % 1000;
|
||||
if (ms > 500)
|
||||
period = period - ms + 500;
|
||||
else
|
||||
period = period - ms;
|
||||
return period;
|
||||
}
|
||||
|
||||
private long getLifetime() { return System.currentTimeMillis() - _started; }
|
||||
|
||||
/**
|
||||
@ -180,33 +163,24 @@ public class TunnelPool {
|
||||
private TunnelInfo selectTunnel(boolean allowRecurseOnFail) {
|
||||
boolean avoidZeroHop = !_settings.getAllowZeroHop();
|
||||
|
||||
long period = curPeriod();
|
||||
synchronized (_tunnels) {
|
||||
if (_lastSelectionPeriod == period) {
|
||||
if ( (_lastSelected != null) &&
|
||||
(_lastSelected.getExpiration() > period) &&
|
||||
(_tunnels.contains(_lastSelected)) )
|
||||
return _lastSelected;
|
||||
}
|
||||
_lastSelectionPeriod = period;
|
||||
_lastSelected = null;
|
||||
|
||||
if (_tunnels.isEmpty()) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn(toString() + ": No tunnels to select from");
|
||||
} else {
|
||||
Collections.shuffle(_tunnels, _context.random());
|
||||
|
||||
// if there are nonzero hop tunnels and the zero hop tunnels are fallbacks,
|
||||
// avoid the zero hop tunnels
|
||||
TunnelInfo backloggedTunnel = null;
|
||||
if (avoidZeroHop) {
|
||||
for (int i = 0; i < _tunnels.size(); i++) {
|
||||
TunnelInfo info = _tunnels.get(i);
|
||||
_lastSelectedIdx++;
|
||||
if (_lastSelectedIdx >= _tunnels.size())
|
||||
_lastSelectedIdx = 0;
|
||||
TunnelInfo info = _tunnels.get(_lastSelectedIdx);
|
||||
if ( (info.getLength() > 1) && (info.getExpiration() > _context.clock().now()) ) {
|
||||
// avoid outbound tunnels where the 1st hop is backlogged
|
||||
if (_settings.isInbound() || !_context.commSystem().isBacklogged(info.getPeer(1))) {
|
||||
_lastSelected = info;
|
||||
return info;
|
||||
} else {
|
||||
backloggedTunnel = info;
|
||||
@ -229,7 +203,6 @@ public class TunnelPool {
|
||||
if (_settings.isInbound() || info.getLength() <= 1 ||
|
||||
!_context.commSystem().isBacklogged(info.getPeer(1))) {
|
||||
//_log.debug("Selecting tunnel: " + info + " - " + _tunnels);
|
||||
_lastSelected = info;
|
||||
return info;
|
||||
} else {
|
||||
backloggedTunnel = info;
|
||||
@ -505,10 +478,6 @@ public class TunnelPool {
|
||||
if (_settings.isInbound() && !_settings.isExploratory())
|
||||
ls = locked_buildNewLeaseSet();
|
||||
remaining = _tunnels.size();
|
||||
if (_lastSelected == info) {
|
||||
_lastSelected = null;
|
||||
_lastSelectionPeriod = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_manager.getExecutor().repoll();
|
||||
@ -573,10 +542,6 @@ public class TunnelPool {
|
||||
return;
|
||||
if (_settings.isInbound() && !_settings.isExploratory())
|
||||
ls = locked_buildNewLeaseSet();
|
||||
if (_lastSelected == cfg) {
|
||||
_lastSelected = null;
|
||||
_lastSelectionPeriod = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_manager.tunnelFailed();
|
||||
|
Reference in New Issue
Block a user