diff --git a/CHANGES.txt b/CHANGES.txt index 675236e..5ea5f85 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ Stop cleaner when plugin stops Move to the ClientApp interface, remove all static refs Attempt to fix crash after update + Add zzzot.config file to set interval 0.11.0 2014-11-11 diff --git a/build.xml b/build.xml index daaa8af..7171c12 100644 --- a/build.xml +++ b/build.xml @@ -50,6 +50,7 @@ + diff --git a/scripts/zzzot.config b/scripts/zzzot.config new file mode 100644 index 0000000..af8e7a4 --- /dev/null +++ b/scripts/zzzot.config @@ -0,0 +1,3 @@ +# announce interval in seconds +# minimum 900 (15 minutes), maximum 21600 (6 hours) +interval=1620 diff --git a/src/java/net/i2p/zzzot/Torrents.java b/src/java/net/i2p/zzzot/Torrents.java index e45b903..99d1056 100644 --- a/src/java/net/i2p/zzzot/Torrents.java +++ b/src/java/net/i2p/zzzot/Torrents.java @@ -32,12 +32,16 @@ public class Torrents extends ConcurrentHashMap { private static final int CACHE_SIZE = 2048; private final SDSCache _hashCache; private final SDSCache _pidCache; + private final Integer _interval; - - public Torrents() { + /** + * @param interval in seconds + */ + public Torrents(int interval) { super(); _hashCache = new SDSCache(InfoHash.class, InfoHash.LENGTH, CACHE_SIZE); _pidCache = new SDSCache(PID.class, PID.LENGTH, CACHE_SIZE); + _interval = Integer.valueOf(interval); } public int countPeers() { @@ -48,6 +52,14 @@ public class Torrents extends ConcurrentHashMap { return rv; } + /** + * @return in seconds + * @since 0.12.0 + */ + public Integer getInterval() { + return _interval; + } + /** * Pull from cache or return new * diff --git a/src/java/net/i2p/zzzot/ZzzOT.java b/src/java/net/i2p/zzzot/ZzzOT.java index 98267df..aeb58c1 100644 --- a/src/java/net/i2p/zzzot/ZzzOT.java +++ b/src/java/net/i2p/zzzot/ZzzOT.java @@ -17,6 +17,7 @@ package net.i2p.zzzot; */ import java.util.Iterator; +import java.util.Properties; import net.i2p.I2PAppContext; import net.i2p.util.SimpleTimer2; @@ -28,12 +29,28 @@ class ZzzOT { private final Torrents _torrents; private final Cleaner _cleaner; + private final long EXPIRE_TIME; + private static final String PROP_INTERVAL = "interval"; private static final long CLEAN_TIME = 4*60*1000; - private static final long EXPIRE_TIME = 60*60*1000; + private static final int DEFAULT_INTERVAL = 27*60; + private static final int MIN_INTERVAL = 15*60; + private static final int MAX_INTERVAL = 6*60*60; - ZzzOT(I2PAppContext ctx) { - _torrents = new Torrents(); + ZzzOT(I2PAppContext ctx, Properties p) { + String intv = p.getProperty(PROP_INTERVAL); + int interval = DEFAULT_INTERVAL; + if (intv != null) { + try { + interval = Integer.parseInt(intv); + if (interval < MIN_INTERVAL) + interval = MIN_INTERVAL; + else if (interval > MAX_INTERVAL) + interval = MAX_INTERVAL; + } catch (NumberFormatException nfe) {} + } + _torrents = new Torrents(interval); + EXPIRE_TIME = 1000 * (interval + interval / 2); _cleaner = new Cleaner(ctx); } diff --git a/src/java/net/i2p/zzzot/ZzzOTController.java b/src/java/net/i2p/zzzot/ZzzOTController.java index c595ac9..0c1c1d4 100644 --- a/src/java/net/i2p/zzzot/ZzzOTController.java +++ b/src/java/net/i2p/zzzot/ZzzOTController.java @@ -68,6 +68,7 @@ public class ZzzOTController implements ClientApp { private ClientAppState _state = UNINITIALIZED; private static final String NAME = "ZzzOT"; + private static final String CONFIG_FILE = "zzzot.config"; private static final String BACKUP_SUFFIX = ".jetty6"; private static final String[] xmlFiles = { "jetty.xml", "contexts/base-context.xml", "contexts/cgi-context.xml", @@ -81,7 +82,16 @@ public class ZzzOTController implements ClientApp { _log = ctx.logManager().getLog(ZzzOTController.class); _mgr = mgr; _args = args; - _zzzot = new ZzzOT(ctx); + File cfile = new File(_context.getAppDir(), "plugins/zzzot/" + CONFIG_FILE); + Properties props = new Properties(); + if (cfile.exists()) { + try { + DataHelper.loadProps(props, cfile); + } catch (IOException ioe) { + _log.error("Failed loading zzzot config from " + cfile, ioe); + } + } + _zzzot = new ZzzOT(ctx, props); _state = INITIALIZED; } diff --git a/src/jsp/announce.jsp b/src/jsp/announce.jsp index 24a75a6..cdfbdec 100644 --- a/src/jsp/announce.jsp +++ b/src/jsp/announce.jsp @@ -27,7 +27,6 @@ */ // would be nice to make these configurable final int MAX_RESPONSES = 25; - final int INTERVAL = 27*60; final boolean ALLOW_IP_MISMATCH = false; final boolean ALLOW_COMPACT_RESPONSE = true; @@ -185,7 +184,7 @@ Peers peers = torrents.get(ih); if (matchIP && peers != null) peers.remove(pid); - m.put("interval", Integer.valueOf(INTERVAL)); + m.put("interval", torrents.getInterval()); } else { Peers peers = torrents.get(ih); if (peers == null) { @@ -210,7 +209,7 @@ if (matchIP) p.setLeft(left); - m.put("interval", Integer.valueOf(INTERVAL)); + m.put("interval", torrents.getInterval()); int size = peers.size(); int seeds = peers.countSeeds(); m.put("complete", Integer.valueOf(seeds));