Compare commits

..

5 Commits

7 changed files with 32 additions and 16 deletions

View File

@@ -35,7 +35,7 @@ class Cli {
Core core
try {
core = new Core(props, home, "0.4.12")
core = new Core(props, home, "0.4.13")
} catch (Exception bad) {
bad.printStackTrace(System.out)
println "Failed to initialize core, exiting"

View File

@@ -53,7 +53,7 @@ class CliDownloader {
Core core
try {
core = new Core(props, home, "0.4.12")
core = new Core(props, home, "0.4.13")
} catch (Exception bad) {
bad.printStackTrace(System.out)
println "Failed to initialize core, exiting"

View File

@@ -361,7 +361,7 @@ public class Core {
}
}
Core core = new Core(props, home, "0.4.12")
Core core = new Core(props, home, "0.4.13")
core.startServices()
// ... at the end, sleep or execute script

View File

@@ -24,7 +24,7 @@ class MuWireSettings {
boolean shareDownloadedFiles
Set<String> watchedDirectories
float downloadSequentialRatio
int hostClearInterval
int hostClearInterval, hostHopelessInterval
int meshExpiration
boolean embeddedRouter
int inBw, outBw
@@ -50,7 +50,8 @@ class MuWireSettings {
updateType = props.getProperty("updateType","jar")
shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true"))
downloadSequentialRatio = Float.valueOf(props.getProperty("downloadSequentialRatio","0.8"))
hostClearInterval = Integer.valueOf(props.getProperty("hostClearInterval","60"))
hostClearInterval = Integer.valueOf(props.getProperty("hostClearInterval","15"))
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))

View File

@@ -7,19 +7,22 @@ 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() {
failures = 0
successes++
lastAttempt = System.currentTimeMillis()
lastSuccessfulAttempt = lastAttempt
}
synchronized void onFailure() {
@@ -41,6 +44,12 @@ class Host {
}
synchronized void canTryAgain() {
System.currentTimeMillis() - lastAttempt > (clearInterval * 60 * 1000)
lastSuccessfulAttempt > 0 &&
System.currentTimeMillis() - lastAttempt > (clearInterval * 60 * 1000)
}
synchronized void isHopeless() {
isFailed() &&
System.currentTimeMillis() - lastSuccessfulAttempt > (hopelessInterval * 60 * 1000)
}
}

View File

@@ -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)
}
@@ -82,6 +82,10 @@ class HostCache extends Service {
List<Destination> getHosts(int n) {
List<Destination> rv = new ArrayList<>(hosts.keySet())
rv.retainAll {allowHost(hosts[it])}
rv.removeAll {
def h = hosts[it];
h.isFailed() && !h.canTryAgain()
}
if (rv.size() <= n)
return rv
Collections.shuffle(rv)
@@ -106,12 +110,14 @@ 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)
host.lastAttempt = entry.lastAttempt
if (allowHost(host))
if (entry.lastSuccessfulAttempt != null)
host.lastSuccessfulAttempt = entry.lastSuccessfulAttempt
if (allowHost(host))
hosts.put(dest, host)
}
}
@@ -120,8 +126,6 @@ class HostCache extends Service {
}
private boolean allowHost(Host host) {
if (host.isFailed() && !host.canTryAgain())
return false
if (host.destination == myself)
return false
TrustLevel trust = trustService.getLevel(host.destination)
@@ -140,12 +144,13 @@ class HostCache extends Service {
storage.delete()
storage.withPrintWriter { writer ->
hosts.each { dest, host ->
if (allowHost(host)) {
if (allowHost(host) && !host.isHopeless()) {
def map = [:]
map.destination = dest.toBase64()
map.failures = host.failures
map.successes = host.successes
map.lastAttempt = host.lastAttempt
map.lastSuccessfulAttempt = host.lastSuccessfulAttempt
def json = JsonOutput.toJson(map)
writer.println json
}

View File

@@ -1,5 +1,5 @@
group = com.muwire
version = 0.4.12
version = 0.4.13
groovyVersion = 2.4.15
slf4jVersion = 1.7.25
spockVersion = 1.1-groovy-2.4