* Tunnels: Don't get stuck only building tunnels for an empty pool (ticket #1300)

This commit is contained in:
zzz
2014-06-13 13:40:52 +00:00
parent 2a269ff1a9
commit 95fd0291e3
3 changed files with 28 additions and 6 deletions

View File

@@ -1,3 +1,9 @@
2014-06-13 zzz
* i2psnark: Fix NPE when fetching invalid torrent (ticket #1307)
* Transports: Disallow Carrier Grade NAT (RFC 6598) addresses
* Tunnels: Don't get stuck only building tunnels
for an empty pool (ticket #1300)
2014-06-10 zzz 2014-06-10 zzz
* i2psnark: Fix decoding of negative numbers (ticket #1307) * i2psnark: Fix decoding of negative numbers (ticket #1307)
* NewsFetcher: Only treat correct status codes as success * NewsFetcher: Only treat correct status codes as success

View File

@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 6; public final static long BUILD = 7;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";

View File

@@ -339,8 +339,15 @@ class BuildExecutor implements Runnable {
if ( (allowed > 0) && (!wanted.isEmpty()) ) { if ( (allowed > 0) && (!wanted.isEmpty()) ) {
if (wanted.size() > 1) { if (wanted.size() > 1) {
Collections.shuffle(wanted, _context.random()); Collections.shuffle(wanted, _context.random());
// We generally prioritize pools with no tunnels,
// but sometimes (particularly at startup), the paired tunnel endpoint
// can start dropping the build messages... or hit connection limits,
// or be broken in other ways. So we allow other pools to go
// to the front of the line sometimes, to prevent being "locked up"
// for several minutes.
boolean preferEmpty = _context.random().nextInt(4) != 0;
try { try {
Collections.sort(wanted, new TunnelPoolComparator()); Collections.sort(wanted, new TunnelPoolComparator(preferEmpty));
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
// Java 7 TimSort - see info in TunnelPoolComparator // Java 7 TimSort - see info in TunnelPoolComparator
continue; continue;
@@ -430,15 +437,24 @@ class BuildExecutor implements Runnable {
* during the sort. This will cause Java 7 sort to throw an IAE. * during the sort. This will cause Java 7 sort to throw an IAE.
*/ */
private static class TunnelPoolComparator implements Comparator<TunnelPool> { private static class TunnelPoolComparator implements Comparator<TunnelPool> {
private final boolean _preferEmpty;
public TunnelPoolComparator(boolean preferEmptyPools) {
_preferEmpty = preferEmptyPools;
}
public int compare(TunnelPool tpl, TunnelPool tpr) { public int compare(TunnelPool tpl, TunnelPool tpr) {
if (tpl.getSettings().isExploratory() && !tpr.getSettings().isExploratory()) if (tpl.getSettings().isExploratory() && !tpr.getSettings().isExploratory())
return -1; return -1;
if (tpr.getSettings().isExploratory() && !tpl.getSettings().isExploratory()) if (tpr.getSettings().isExploratory() && !tpl.getSettings().isExploratory())
return 1; return 1;
if (tpl.getTunnelCount() <= 0 && tpr.getTunnelCount() > 0) if (_preferEmpty) {
return -1; if (tpl.getTunnelCount() <= 0 && tpr.getTunnelCount() > 0)
if (tpr.getTunnelCount() <= 0 && tpl.getTunnelCount() > 0) return -1;
return 1; if (tpr.getTunnelCount() <= 0 && tpl.getTunnelCount() > 0)
return 1;
}
return 0; return 0;
} }
} }