make mesh expiration configurable

This commit is contained in:
Zlatin Balevsky
2019-06-25 08:04:57 +01:00
parent 4fd9fc1991
commit 970f814685
2 changed files with 4 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ class MuWireSettings {
Set<String> watchedDirectories
float downloadSequentialRatio
int hostClearInterval
int meshExpiration
MuWireSettings() {
this(new Properties())
@@ -37,6 +38,7 @@ class MuWireSettings {
shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true"))
downloadSequentialRatio = Float.valueOf(props.getProperty("downloadSequentialRatio","0.8"))
hostClearInterval = Integer.valueOf(props.getProperty("hostClearInterval","60"))
meshExpiration = Integer.valueOf(props.getProperty("meshExpiration","60"))
watchedDirectories = new HashSet<>()
if (props.containsKey("watchedDirectories")) {
@@ -58,6 +60,7 @@ class MuWireSettings {
props.setProperty("shareDownloadedFiles", String.valueOf(shareDownloadedFiles))
props.setProperty("downloadSequentialRatio", String.valueOf(downloadSequentialRatio))
props.setProperty("hostClearInterval", String.valueOf(hostClearInterval))
props.setProperty("meshExpiration", String.valueOf(meshExpiration))
if (!watchedDirectories.isEmpty()) {
String encoded = watchedDirectories.stream().

View File

@@ -17,8 +17,6 @@ import net.i2p.data.Base64
class MeshManager {
private static final int EXPIRATION = 60 * 60 * 1000
private final Map<InfoHash, Mesh> meshes = Collections.synchronizedMap(new HashMap<>())
private final FileManager fileManager
private final File home
@@ -83,7 +81,7 @@ class MeshManager {
JsonSlurper slurper = new JsonSlurper()
meshFile.eachLine {
def json = slurper.parseText(it)
if (now - json.timestamp > EXPIRATION)
if (now - json.timestamp > settings.meshExpiration * 60 * 1000)
return
InfoHash infoHash = new InfoHash(Base64.decode(json.infoHash))
Pieces pieces = new Pieces(json.nPieces, settings.downloadSequentialRatio)