mirror of https://github.com/zlatinb/muwire
log hostcache stats
parent
ad5b00fc90
commit
4740e8b4f5
|
@ -64,6 +64,9 @@ public class HostCache {
|
|||
Timer timer = new Timer("timer", true)
|
||||
timer.schedule({hostPool.age()} as TimerTask, 1000,1000)
|
||||
timer.schedule({crawler.startCrawl()} as TimerTask, 10000, 10000)
|
||||
File verified = new File("verified.json")
|
||||
File unverified = new File("unverified.json")
|
||||
timer.schedule({hostPool.serialize(verified, unverified)} as TimerTask, 10000, 60 * 60 * 1000)
|
||||
|
||||
session.addMuxedSessionListener(new Listener(hostPool: hostPool, toReturn: 2, crawler: crawler),
|
||||
I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY)
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.muwire.hostcache
|
|||
|
||||
import java.util.stream.Collectors
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
|
||||
class HostPool {
|
||||
|
||||
final def maxFailures
|
||||
|
@ -74,4 +76,25 @@ class HostPool {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void serialize(File verifiedFile, File unverifiedFile) {
|
||||
write(verifiedFile, verified.values())
|
||||
write(unverifiedFile, unverified.values())
|
||||
}
|
||||
|
||||
private void write(File target, Collection hosts) {
|
||||
JsonOutput jsonOutput = new JsonOutput()
|
||||
target.withPrintWriter { writer ->
|
||||
hosts.each {
|
||||
def json = [:]
|
||||
json.destination = it.destination.toBase64()
|
||||
json.verifyTime = it.verifyTime
|
||||
json.leafSlots = it.leafSlots
|
||||
json.peerSlots = it.peerSlots
|
||||
json.verificationFailures = it.verificationFailures
|
||||
def str = jsonOutput.toJson(json)
|
||||
writer.println(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue