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

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

Tunnels: Make new tunnel selection round-robin

Remove one-second stickiness, as OCMOSJ caching does the job better
http://zzz.i2p/topics/2454
parent 5c1700c2
No related branches found
No related tags found
No related merge requests found
2020-03-24 zzz
* Tunnels: Make new tunnel selection round-robin
2020-03-20 zzz
* Tunnels: FragmentHandler cleanup (ticket #2699)
2020-03-17 zzz
* i2psnark: Hide non-i2p trackers on details page
2020-03-15 zzz
* Ratchet: Stub out ack and ack request blocks
2020-03-01 zzz
* Console:
- Disable browser launch on /configclients when a service
......
......@@ -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();
......
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