From 7b58e8a88aadec578da7148523ee66c7b4c05f0b Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 29 Sep 2019 18:43:39 +0100 Subject: [PATCH] separate setting for the interval after which a host is considered hopeless --- core/src/main/groovy/com/muwire/core/MuWireSettings.groovy | 4 +++- core/src/main/groovy/com/muwire/core/hostcache/Host.groovy | 7 ++++--- .../main/groovy/com/muwire/core/hostcache/HostCache.groovy | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index 91f65091..5705bcb3 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -24,7 +24,7 @@ class MuWireSettings { boolean shareDownloadedFiles Set watchedDirectories float downloadSequentialRatio - int hostClearInterval + int hostClearInterval, hostHopelessInterval int meshExpiration boolean embeddedRouter int inBw, outBw @@ -51,6 +51,7 @@ class MuWireSettings { shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true")) downloadSequentialRatio = Float.valueOf(props.getProperty("downloadSequentialRatio","0.8")) hostClearInterval = Integer.valueOf(props.getProperty("hostClearInterval","60")) + hostHopelessInterval = Integer.valueOf(props.getProperty("hostHopelessInterval", "1440")) meshExpiration = Integer.valueOf(props.getProperty("meshExpiration","60")) embeddedRouter = Boolean.valueOf(props.getProperty("embeddedRouter","false")) inBw = Integer.valueOf(props.getProperty("inBw","256")) @@ -86,6 +87,7 @@ class MuWireSettings { props.setProperty("shareDownloadedFiles", String.valueOf(shareDownloadedFiles)) props.setProperty("downloadSequentialRatio", String.valueOf(downloadSequentialRatio)) props.setProperty("hostClearInterval", String.valueOf(hostClearInterval)) + props.setProperty("hostHopelessInterval", String.valueOf(hostHopelessInterval)) props.setProperty("meshExpiration", String.valueOf(meshExpiration)) props.setProperty("embeddedRouter", String.valueOf(embeddedRouter)) props.setProperty("inBw", String.valueOf(inBw)) diff --git a/core/src/main/groovy/com/muwire/core/hostcache/Host.groovy b/core/src/main/groovy/com/muwire/core/hostcache/Host.groovy index effaef28..1278bc43 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/Host.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/Host.groovy @@ -7,14 +7,15 @@ class Host { private static final int MAX_FAILURES = 3 final Destination destination - private final int clearInterval + private final int clearInterval, hopelessInterval int failures,successes long lastAttempt long lastSuccessfulAttempt - public Host(Destination destination, int clearInterval) { + public Host(Destination destination, int clearInterval, int hopelessInterval) { this.destination = destination this.clearInterval = clearInterval + this.hopelessInterval = hopelessInterval } synchronized void onConnect() { @@ -49,6 +50,6 @@ class Host { synchronized void isHopeless() { isFailed() && - System.currentTimeMillis() - lastSuccessfulAttempt > (clearInterval * 24 * 60 * 1000) + System.currentTimeMillis() - lastSuccessfulAttempt > (hopelessInterval * 60 * 1000) } } diff --git a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy index 1c35aa85..ce3c99e7 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy @@ -52,7 +52,7 @@ class HostCache extends Service { hosts.get(e.destination).clearFailures() return } - Host host = new Host(e.destination, settings.hostClearInterval) + Host host = new Host(e.destination, settings.hostClearInterval, settings.hostHopelessInterval) if (allowHost(host)) { hosts.put(e.destination, host) } @@ -64,7 +64,7 @@ class HostCache extends Service { Destination dest = e.endpoint.destination Host host = hosts.get(dest) if (host == null) { - host = new Host(dest, settings.hostClearInterval) + host = new Host(dest, settings.hostClearInterval, settings.hostHopelessInterval) hosts.put(dest, host) } @@ -110,7 +110,7 @@ class HostCache extends Service { storage.eachLine { def entry = slurper.parseText(it) Destination dest = new Destination(entry.destination) - Host host = new Host(dest, settings.hostClearInterval) + Host host = new Host(dest, settings.hostClearInterval, settings.hostHopelessInterval) host.failures = Integer.valueOf(String.valueOf(entry.failures)) host.successes = Integer.valueOf(String.valueOf(entry.successes)) if (entry.lastAttempt != null)