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