load latest verified hosts on hostcache startup

auto-update
Zlatin Balevsky 2022-02-10 13:15:11 +00:00
parent 0dc569c0ae
commit 92f30aeab7
No known key found for this signature in database
GPG Key ID: A72832072D525E41
3 changed files with 42 additions and 1 deletions

View File

@ -21,7 +21,6 @@
|---|---|---|---|
|"Edit File Details" frame|N/A|GUI|High|
|Right-click resync from watched folders table|N/A|GUI|Medium|
|Persist known hosts|N/A|HostCache, infrastructure|High|
|Fix reproducible build on Windows| N/A| Build scripts | Low|
|Option to disable saving of search tabs| N/A | GUI | Medium |
|Progress bar while collection preview is generated | 70 | GUI | Low |

View File

@ -73,6 +73,7 @@ public class HostCache {
File unverified = new File("unverified")
verified.mkdir()
unverified.mkdir()
hostPool.load(verified)
timer.schedule({hostPool.serialize(verified, unverified)} as TimerTask, 10000, 60 * 60 * 1000)
session.addMuxedSessionListener(new Listener(hostPool: hostPool, toReturn: 3, crawler: crawler),

View File

@ -1,10 +1,15 @@
package com.muwire.hostcache
import groovy.json.JsonSlurper
import groovy.util.logging.Log
import net.i2p.data.Destination
import java.text.SimpleDateFormat
import java.util.stream.Collectors
import groovy.json.JsonOutput
@Log
class HostPool {
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMdd-HH")
@ -102,4 +107,40 @@ class HostPool {
}
}
}
synchronized void load(File path) {
File [] serialized = path.listFiles(new FileFilter() {
@Override
boolean accept(File pathname) {
return pathname.length() > 0
}
})
if (serialized == null || serialized.length == 0) {
log.info("couldn't find any files to load from.")
return
}
Arrays.sort(serialized, new Comparator<File>() {
@Override
int compare(File o1, File o2) {
return Long.compare(o2.lastModified(), o1.lastModified())
}
})
File toLoad = serialized[0]
log.info("loading from $toLoad")
int loaded = 0
def slurper = new JsonSlurper()
toLoad.eachLine {
def parsed = slurper.parseText(it)
def host = new Host()
host.destination = new Destination(parsed.destination)
host.verifyTime = parsed.verifyTime
host.leafSlots = parsed.leafSlots
host.peerSlots = parsed.peerSlots
host.verificationFailures = parsed.verificationFailures
addUnverified(host)
loaded++
}
log.info("loaded ${unverified.size()}/$loaded hosts")
}
}