implement forgetting of hopeless hosts after some time
This commit is contained in:
@ -50,7 +50,7 @@ class MuWireSettings {
|
||||
File chatWelcomeFile
|
||||
Set<String> watchedDirectories
|
||||
float downloadSequentialRatio
|
||||
int hostClearInterval, hostHopelessInterval, hostRejectInterval
|
||||
int hostClearInterval, hostHopelessInterval, hostRejectInterval, hostHopelessPurgeInterval
|
||||
int meshExpiration
|
||||
int speedSmoothSeconds
|
||||
boolean embeddedRouter
|
||||
@ -88,6 +88,7 @@ class MuWireSettings {
|
||||
hostClearInterval = Integer.valueOf(props.getProperty("hostClearInterval","15"))
|
||||
hostHopelessInterval = Integer.valueOf(props.getProperty("hostHopelessInterval", "1440"))
|
||||
hostRejectInterval = Integer.valueOf(props.getProperty("hostRejectInterval", "1"))
|
||||
hostHopelessPurgeInterval = Integer.valueOf(props.getProperty("hostHopelessPurgeInterval","2880"))
|
||||
meshExpiration = Integer.valueOf(props.getProperty("meshExpiration","60"))
|
||||
embeddedRouter = Boolean.valueOf(props.getProperty("embeddedRouter","false"))
|
||||
plugin = Boolean.valueOf(props.getProperty("plugin","false"))
|
||||
@ -158,6 +159,7 @@ class MuWireSettings {
|
||||
props.setProperty("hostClearInterval", String.valueOf(hostClearInterval))
|
||||
props.setProperty("hostHopelessInterval", String.valueOf(hostHopelessInterval))
|
||||
props.setProperty("hostRejectInterval", String.valueOf(hostRejectInterval))
|
||||
props.setProperty("hostHopelessPurgeInterval", String.valueOf(hostHopelessPurgeInterval))
|
||||
props.setProperty("meshExpiration", String.valueOf(meshExpiration))
|
||||
props.setProperty("embeddedRouter", String.valueOf(embeddedRouter))
|
||||
props.setProperty("plugin", String.valueOf(plugin))
|
||||
|
@ -7,17 +7,19 @@ class Host {
|
||||
private static final int MAX_FAILURES = 3
|
||||
|
||||
final Destination destination
|
||||
private final int clearInterval, hopelessInterval, rejectionInterval
|
||||
private final int clearInterval, hopelessInterval, rejectionInterval, purgeInterval
|
||||
int failures,successes
|
||||
long lastAttempt
|
||||
long lastSuccessfulAttempt
|
||||
long lastRejection
|
||||
|
||||
public Host(Destination destination, int clearInterval, int hopelessInterval, int rejectionInterval) {
|
||||
public Host(Destination destination, int clearInterval, int hopelessInterval, int rejectionInterval,
|
||||
int purgeInterval) {
|
||||
this.destination = destination
|
||||
this.clearInterval = clearInterval
|
||||
this.hopelessInterval = hopelessInterval
|
||||
this.rejectionInterval = rejectionInterval
|
||||
this.purgeInterval = purgeInterval
|
||||
}
|
||||
|
||||
private void connectSuccessful() {
|
||||
@ -67,4 +69,9 @@ class Host {
|
||||
synchronized boolean isRecentlyRejected(final long now) {
|
||||
now - lastRejection < (rejectionInterval * 60 * 1000)
|
||||
}
|
||||
|
||||
synchronized boolean shouldBeForgotten(final long now) {
|
||||
isHopeless(now) &&
|
||||
now - lastAttempt > (purgeInterval * 60 * 1000)
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,8 @@ class HostCache extends Service {
|
||||
hosts.get(e.destination).clearFailures()
|
||||
return
|
||||
}
|
||||
Host host = new Host(e.destination, settings.hostClearInterval, settings.hostHopelessInterval, settings.hostRejectInterval)
|
||||
Host host = new Host(e.destination, settings.hostClearInterval, settings.hostHopelessInterval,
|
||||
settings.hostRejectInterval, settings.hostHopelessPurgeInterval)
|
||||
if (allowHost(host)) {
|
||||
hosts.put(e.destination, host)
|
||||
}
|
||||
@ -64,7 +65,8 @@ class HostCache extends Service {
|
||||
Destination dest = e.endpoint.destination
|
||||
Host host = hosts.get(dest)
|
||||
if (host == null) {
|
||||
host = new Host(dest, settings.hostClearInterval, settings.hostHopelessInterval, settings.hostRejectInterval)
|
||||
host = new Host(dest, settings.hostClearInterval, settings.hostHopelessInterval,
|
||||
settings.hostRejectInterval, settings.hostHopelessPurgeInterval)
|
||||
hosts.put(dest, host)
|
||||
}
|
||||
|
||||
@ -130,7 +132,8 @@ class HostCache extends Service {
|
||||
storage.eachLine {
|
||||
def entry = slurper.parseText(it)
|
||||
Destination dest = new Destination(entry.destination)
|
||||
Host host = new Host(dest, settings.hostClearInterval, settings.hostHopelessInterval, settings.hostRejectInterval)
|
||||
Host host = new Host(dest, settings.hostClearInterval, settings.hostHopelessInterval,
|
||||
settings.hostRejectInterval, settings.hostHopelessPurgeInterval)
|
||||
host.failures = Integer.valueOf(String.valueOf(entry.failures))
|
||||
host.successes = Integer.valueOf(String.valueOf(entry.successes))
|
||||
if (entry.lastAttempt != null)
|
||||
@ -163,8 +166,9 @@ class HostCache extends Service {
|
||||
}
|
||||
|
||||
private void save() {
|
||||
storage.delete()
|
||||
final long now = System.currentTimeMillis()
|
||||
hosts.keySet().removeAll { hosts[it].shouldBeForgotten(now) }
|
||||
storage.delete()
|
||||
storage.withPrintWriter { writer ->
|
||||
hosts.each { dest, host ->
|
||||
if (allowHost(host) && !host.isHopeless(now)) {
|
||||
|
@ -75,6 +75,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
|
||||
@ -97,6 +98,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
|
||||
@ -114,6 +116,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
|
||||
@ -136,6 +139,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
@ -160,6 +164,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 100 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
@ -182,6 +187,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
@ -211,6 +217,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
@ -246,6 +253,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
@ -266,6 +274,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
@ -301,6 +310,7 @@ class HostCacheTest {
|
||||
settingsMock.ignore.getHostClearInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessInterval { 0 }
|
||||
settingsMock.ignore.getHostRejectInterval { 0 }
|
||||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
def rv = cache.getHosts(5)
|
||||
|
Reference in New Issue
Block a user