mirror of
https://github.com/i2p/i2p.plugins.zzzot.git
synced 2024-12-06 19:27:29 +01:00
Add zzzot.config file to set interval
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<!-- make the install xpi2p -->
|
||||
<copy file="scripts/i2ptunnel.config" todir="plugin/" overwrite="true" />
|
||||
<copy file="scripts/plugin.config" todir="plugin/" overwrite="true" />
|
||||
<copy file="scripts/zzzot.config" todir="plugin/" overwrite="true" />
|
||||
<exec executable="echo" osfamily="unix" failonerror="true" output="plugin/plugin.config" append="true">
|
||||
<arg value="version=${release.number}-b${build.number}" />
|
||||
</exec>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# announce interval in seconds
|
||||
# minimum 900 (15 minutes), maximum 21600 (6 hours)
|
||||
interval=1620
|
||||
@@ -32,12 +32,16 @@ public class Torrents extends ConcurrentHashMap<InfoHash, Peers> {
|
||||
private static final int CACHE_SIZE = 2048;
|
||||
private final SDSCache<InfoHash> _hashCache;
|
||||
private final SDSCache<PID> _pidCache;
|
||||
private final Integer _interval;
|
||||
|
||||
|
||||
public Torrents() {
|
||||
/**
|
||||
* @param interval in seconds
|
||||
*/
|
||||
public Torrents(int interval) {
|
||||
super();
|
||||
_hashCache = new SDSCache<InfoHash>(InfoHash.class, InfoHash.LENGTH, CACHE_SIZE);
|
||||
_pidCache = new SDSCache<PID>(PID.class, PID.LENGTH, CACHE_SIZE);
|
||||
_interval = Integer.valueOf(interval);
|
||||
}
|
||||
|
||||
public int countPeers() {
|
||||
@@ -48,6 +52,14 @@ public class Torrents extends ConcurrentHashMap<InfoHash, Peers> {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return in seconds
|
||||
* @since 0.12.0
|
||||
*/
|
||||
public Integer getInterval() {
|
||||
return _interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull from cache or return new
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user