forked from I2P_Developers/i2p.i2p
- integration of dynamicly configurable startup delay of i2psnark
- i2psnark webfrontent configuration of startup delay - default startup delay 3 minutes - new config variable in i2psnark.config: i2psnark.startupDelay
This commit is contained in:
@@ -53,14 +53,15 @@ public class I2PSnarkUtil {
|
|||||||
private int _maxUpBW;
|
private int _maxUpBW;
|
||||||
private int _maxConnections;
|
private int _maxConnections;
|
||||||
private File _tmpDir;
|
private File _tmpDir;
|
||||||
|
private int _startupDelay;
|
||||||
|
|
||||||
|
public static final int DEFAULT_STARTUP_DELAY = 3;
|
||||||
public static final String PROP_USE_OPENTRACKERS = "i2psnark.useOpentrackers";
|
public static final String PROP_USE_OPENTRACKERS = "i2psnark.useOpentrackers";
|
||||||
public static final boolean DEFAULT_USE_OPENTRACKERS = true;
|
public static final boolean DEFAULT_USE_OPENTRACKERS = true;
|
||||||
public static final String PROP_OPENTRACKERS = "i2psnark.opentrackers";
|
public static final String PROP_OPENTRACKERS = "i2psnark.opentrackers";
|
||||||
public static final String DEFAULT_OPENTRACKERS = "http://tracker.welterde.i2p/a";
|
public static final String DEFAULT_OPENTRACKERS = "http://tracker.welterde.i2p/a";
|
||||||
public static final int DEFAULT_MAX_UP_BW = 8; //KBps
|
public static final int DEFAULT_MAX_UP_BW = 8; //KBps
|
||||||
public static final int MAX_CONNECTIONS = 16; // per torrent
|
public static final int MAX_CONNECTIONS = 16; // per torrent
|
||||||
|
|
||||||
public I2PSnarkUtil(I2PAppContext ctx) {
|
public I2PSnarkUtil(I2PAppContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
_log = _context.logManager().getLog(Snark.class);
|
_log = _context.logManager().getLog(Snark.class);
|
||||||
@@ -72,6 +73,7 @@ public class I2PSnarkUtil {
|
|||||||
_maxUploaders = Snark.MAX_TOTAL_UPLOADERS;
|
_maxUploaders = Snark.MAX_TOTAL_UPLOADERS;
|
||||||
_maxUpBW = DEFAULT_MAX_UP_BW;
|
_maxUpBW = DEFAULT_MAX_UP_BW;
|
||||||
_maxConnections = MAX_CONNECTIONS;
|
_maxConnections = MAX_CONNECTIONS;
|
||||||
|
_startupDelay = DEFAULT_STARTUP_DELAY;
|
||||||
// This is used for both announce replies and .torrent file downloads,
|
// This is used for both announce replies and .torrent file downloads,
|
||||||
// so it must be available even if not connected to I2CP.
|
// so it must be available even if not connected to I2CP.
|
||||||
// so much for multiple instances
|
// so much for multiple instances
|
||||||
@@ -127,6 +129,11 @@ public class I2PSnarkUtil {
|
|||||||
_maxConnections = limit;
|
_maxConnections = limit;
|
||||||
_configured = true;
|
_configured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStartupDelay(int minutes) {
|
||||||
|
_startupDelay = minutes;
|
||||||
|
_configured = true;
|
||||||
|
}
|
||||||
|
|
||||||
public String getI2CPHost() { return _i2cpHost; }
|
public String getI2CPHost() { return _i2cpHost; }
|
||||||
public int getI2CPPort() { return _i2cpPort; }
|
public int getI2CPPort() { return _i2cpPort; }
|
||||||
@@ -137,7 +144,8 @@ public class I2PSnarkUtil {
|
|||||||
public int getMaxUploaders() { return _maxUploaders; }
|
public int getMaxUploaders() { return _maxUploaders; }
|
||||||
public int getMaxUpBW() { return _maxUpBW; }
|
public int getMaxUpBW() { return _maxUpBW; }
|
||||||
public int getMaxConnections() { return _maxConnections; }
|
public int getMaxConnections() { return _maxConnections; }
|
||||||
|
public int getStartupDelay() { return _startupDelay; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the router, if we aren't already
|
* Connect to the router, if we aren't already
|
||||||
*/
|
*/
|
||||||
|
@@ -59,10 +59,11 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
public static final String DEFAULT_AUTO_START = "false";
|
public static final String DEFAULT_AUTO_START = "false";
|
||||||
public static final String PROP_LINK_PREFIX = "i2psnark.linkPrefix";
|
public static final String PROP_LINK_PREFIX = "i2psnark.linkPrefix";
|
||||||
public static final String DEFAULT_LINK_PREFIX = "file:///";
|
public static final String DEFAULT_LINK_PREFIX = "file:///";
|
||||||
|
public static final String PROP_STARTUP_DELAY = "i2psnark.startupDelay";
|
||||||
|
|
||||||
public static final int MIN_UP_BW = 2;
|
public static final int MIN_UP_BW = 2;
|
||||||
public static final int DEFAULT_MAX_UP_BW = 10;
|
public static final int DEFAULT_MAX_UP_BW = 10;
|
||||||
|
public static final int DEFAULT_STARTUP_DELAY = 3;
|
||||||
private SnarkManager() {
|
private SnarkManager() {
|
||||||
_snarks = new HashMap();
|
_snarks = new HashMap();
|
||||||
_addSnarkLock = new Object();
|
_addSnarkLock = new Object();
|
||||||
@@ -124,7 +125,9 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
public String linkPrefix() {
|
public String linkPrefix() {
|
||||||
return _config.getProperty(PROP_LINK_PREFIX, DEFAULT_LINK_PREFIX + getDataDir().getAbsolutePath() + File.separatorChar);
|
return _config.getProperty(PROP_LINK_PREFIX, DEFAULT_LINK_PREFIX + getDataDir().getAbsolutePath() + File.separatorChar);
|
||||||
}
|
}
|
||||||
private int getStartupDelayMinutes() { return 3; }
|
private int getStartupDelayMinutes() {
|
||||||
|
return Integer.valueOf(_config.getProperty(PROP_STARTUP_DELAY)).intValue();
|
||||||
|
}
|
||||||
public File getDataDir() {
|
public File getDataDir() {
|
||||||
String dir = _config.getProperty(PROP_DIR, "i2psnark");
|
String dir = _config.getProperty(PROP_DIR, "i2psnark");
|
||||||
File f = new File(dir);
|
File f = new File(dir);
|
||||||
@@ -167,6 +170,9 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
_config.setProperty(PROP_DIR, "i2psnark");
|
_config.setProperty(PROP_DIR, "i2psnark");
|
||||||
if (!_config.containsKey(PROP_AUTO_START))
|
if (!_config.containsKey(PROP_AUTO_START))
|
||||||
_config.setProperty(PROP_AUTO_START, DEFAULT_AUTO_START);
|
_config.setProperty(PROP_AUTO_START, DEFAULT_AUTO_START);
|
||||||
|
if (!_config.containsKey(PROP_STARTUP_DELAY))
|
||||||
|
_config.setProperty(PROP_STARTUP_DELAY, "" + DEFAULT_STARTUP_DELAY);
|
||||||
|
|
||||||
updateConfig();
|
updateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,6 +210,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
// _util.setProxy(eepHost, eepPort);
|
// _util.setProxy(eepHost, eepPort);
|
||||||
_util.setMaxUploaders(getInt(PROP_UPLOADERS_TOTAL, Snark.MAX_TOTAL_UPLOADERS));
|
_util.setMaxUploaders(getInt(PROP_UPLOADERS_TOTAL, Snark.MAX_TOTAL_UPLOADERS));
|
||||||
_util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
|
_util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
|
||||||
|
_util.setStartupDelay(getInt(PROP_STARTUP_DELAY, DEFAULT_STARTUP_DELAY));
|
||||||
String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS);
|
String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS);
|
||||||
if (ot != null)
|
if (ot != null)
|
||||||
_util.setOpenTrackerString(ot);
|
_util.setOpenTrackerString(ot);
|
||||||
@@ -222,7 +229,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
return defaultVal;
|
return defaultVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateConfig(String dataDir, boolean autoStart, String seedPct, String eepHost,
|
public void updateConfig(String dataDir, boolean autoStart, String startDelay, String seedPct, String eepHost,
|
||||||
String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
|
String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
|
||||||
String upLimit, String upBW, boolean useOpenTrackers, String openTrackers) {
|
String upLimit, String upBW, boolean useOpenTrackers, String openTrackers) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
@@ -268,7 +275,19 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i2cpHost != null) {
|
|
||||||
|
if (startDelay != null){
|
||||||
|
int minutes = _util.getStartupDelay();
|
||||||
|
try { minutes = Integer.parseInt(startDelay); } catch (NumberFormatException nfe) {}
|
||||||
|
if ( minutes != _util.getStartupDelay()) {
|
||||||
|
_util.setStartupDelay(minutes);
|
||||||
|
changed = true;
|
||||||
|
_config.setProperty(PROP_STARTUP_DELAY, "" + minutes);
|
||||||
|
addMessage(_("Startup delay limit changed to {0} minutes", minutes));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (i2cpHost != null) {
|
||||||
int oldI2CPPort = _util.getI2CPPort();
|
int oldI2CPPort = _util.getI2CPPort();
|
||||||
String oldI2CPHost = _util.getI2CPHost();
|
String oldI2CPHost = _util.getI2CPHost();
|
||||||
int port = oldI2CPPort;
|
int port = oldI2CPPort;
|
||||||
|
@@ -451,9 +451,10 @@ public class I2PSnarkServlet extends Default {
|
|||||||
String i2cpOpts = buildI2CPOpts(req);
|
String i2cpOpts = buildI2CPOpts(req);
|
||||||
String upLimit = req.getParameter("upLimit");
|
String upLimit = req.getParameter("upLimit");
|
||||||
String upBW = req.getParameter("upBW");
|
String upBW = req.getParameter("upBW");
|
||||||
|
String startupDel = req.getParameter("startupDelay");
|
||||||
boolean useOpenTrackers = req.getParameter("useOpenTrackers") != null;
|
boolean useOpenTrackers = req.getParameter("useOpenTrackers") != null;
|
||||||
String openTrackers = req.getParameter("openTrackers");
|
String openTrackers = req.getParameter("openTrackers");
|
||||||
_manager.updateConfig(dataDir, autoStart, seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts, upLimit, upBW, useOpenTrackers, openTrackers);
|
_manager.updateConfig(dataDir, autoStart, startupDel, seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts, upLimit, upBW, useOpenTrackers, openTrackers);
|
||||||
} else if ("Create".equals(action)) {
|
} else if ("Create".equals(action)) {
|
||||||
String baseData = req.getParameter("baseFile");
|
String baseData = req.getParameter("baseFile");
|
||||||
if (baseData != null && baseData.trim().length() > 0) {
|
if (baseData != null && baseData.trim().length() > 0) {
|
||||||
@@ -990,6 +991,11 @@ public class I2PSnarkServlet extends Default {
|
|||||||
out.write(_("If checked, automatically start torrents that are added"));
|
out.write(_("If checked, automatically start torrents that are added"));
|
||||||
out.write("\" >");
|
out.write("\" >");
|
||||||
|
|
||||||
|
out.write("<tr><td>");
|
||||||
|
out.write(_("Startup delay"));
|
||||||
|
out.write(": <td><input name=\"startupDelay\" size=\"3\" value=\"" + _manager.util().getStartupDelay() + "\"> minutes <br>\n");
|
||||||
|
|
||||||
|
|
||||||
//Auto add: <input type="checkbox" name="autoAdd" value="true" title="If true, automatically add torrents that are found in the data directory" />
|
//Auto add: <input type="checkbox" name="autoAdd" value="true" title="If true, automatically add torrents that are found in the data directory" />
|
||||||
//Auto stop: <input type="checkbox" name="autoStop" value="true" title="If true, automatically stop torrents that are removed from the data directory" />
|
//Auto stop: <input type="checkbox" name="autoStop" value="true" title="If true, automatically stop torrents that are removed from the data directory" />
|
||||||
//out.write("<br>\n");
|
//out.write("<br>\n");
|
||||||
@@ -1079,6 +1085,7 @@ public class I2PSnarkServlet extends Default {
|
|||||||
out.write(_("I2CP options"));
|
out.write(_("I2CP options"));
|
||||||
out.write(": <td><textarea name=\"i2cpOpts\" cols=\"60\" rows=\"1\" wrap=\"off\" >"
|
out.write(": <td><textarea name=\"i2cpOpts\" cols=\"60\" rows=\"1\" wrap=\"off\" >"
|
||||||
+ opts.toString() + "</textarea><br>\n");
|
+ opts.toString() + "</textarea><br>\n");
|
||||||
|
|
||||||
|
|
||||||
out.write("<tr><td> <td><input type=\"submit\" value=\"");
|
out.write("<tr><td> <td><input type=\"submit\" value=\"");
|
||||||
out.write(_("Save configuration"));
|
out.write(_("Save configuration"));
|
||||||
|
Reference in New Issue
Block a user