forked from I2P_Developers/i2p.i2p
2007-03-13 zzz
* i2psnark: Make max total uploaders configurable (thanks Amiga4000!)
This commit is contained in:
@ -33,6 +33,7 @@ public class I2PSnarkUtil {
|
|||||||
private I2PSocketManager _manager;
|
private I2PSocketManager _manager;
|
||||||
private boolean _configured;
|
private boolean _configured;
|
||||||
private Set _shitlist;
|
private Set _shitlist;
|
||||||
|
private int _maxUploaders;
|
||||||
|
|
||||||
private I2PSnarkUtil() {
|
private I2PSnarkUtil() {
|
||||||
_context = I2PAppContext.getGlobalContext();
|
_context = I2PAppContext.getGlobalContext();
|
||||||
@ -42,6 +43,7 @@ public class I2PSnarkUtil {
|
|||||||
setI2CPConfig("127.0.0.1", 7654, null);
|
setI2CPConfig("127.0.0.1", 7654, null);
|
||||||
_shitlist = new HashSet(64);
|
_shitlist = new HashSet(64);
|
||||||
_configured = false;
|
_configured = false;
|
||||||
|
_maxUploaders = Snark.MAX_TOTAL_UPLOADERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,12 +74,18 @@ public class I2PSnarkUtil {
|
|||||||
_configured = true;
|
_configured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxUploaders(int limit) {
|
||||||
|
_maxUploaders = limit;
|
||||||
|
_configured = true;
|
||||||
|
}
|
||||||
|
|
||||||
public String getI2CPHost() { return _i2cpHost; }
|
public String getI2CPHost() { return _i2cpHost; }
|
||||||
public int getI2CPPort() { return _i2cpPort; }
|
public int getI2CPPort() { return _i2cpPort; }
|
||||||
public Map getI2CPOptions() { return _opts; }
|
public Map getI2CPOptions() { return _opts; }
|
||||||
public String getEepProxyHost() { return _proxyHost; }
|
public String getEepProxyHost() { return _proxyHost; }
|
||||||
public int getEepProxyPort() { return _proxyPort; }
|
public int getEepProxyPort() { return _proxyPort; }
|
||||||
public boolean getEepProxySet() { return _shouldProxy; }
|
public boolean getEepProxySet() { return _shouldProxy; }
|
||||||
|
public int getMaxUploaders() { return _maxUploaders; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the router, if we aren't already
|
* Connect to the router, if we aren't already
|
||||||
|
@ -755,10 +755,10 @@ public class Snark
|
|||||||
public void torrentComplete(Snark snark);
|
public void torrentComplete(Snark snark);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Maintain a total uploader cap
|
/** Maintain a configurable total uploader cap
|
||||||
** This should be configurable
|
|
||||||
*/
|
*/
|
||||||
private final static int MAX_TOTAL_UPLOADERS = 10;
|
final static int MIN_TOTAL_UPLOADERS = 4;
|
||||||
|
final static int MAX_TOTAL_UPLOADERS = 10;
|
||||||
public static boolean overUploadLimit(int uploaders) {
|
public static boolean overUploadLimit(int uploaders) {
|
||||||
PeerCoordinatorSet coordinators = PeerCoordinatorSet.instance();
|
PeerCoordinatorSet coordinators = PeerCoordinatorSet.instance();
|
||||||
if (coordinators == null || uploaders <= 0)
|
if (coordinators == null || uploaders <= 0)
|
||||||
@ -769,7 +769,8 @@ public class Snark
|
|||||||
if (!c.halted())
|
if (!c.halted())
|
||||||
totalUploaders += c.uploaders;
|
totalUploaders += c.uploaders;
|
||||||
}
|
}
|
||||||
Snark.debug("Total uploaders: " + totalUploaders, Snark.DEBUG);
|
int limit = I2PSnarkUtil.instance().getMaxUploaders();
|
||||||
return totalUploaders > MAX_TOTAL_UPLOADERS;
|
Snark.debug("Total uploaders: " + totalUploaders + " Limit: " + limit, Snark.DEBUG);
|
||||||
|
return totalUploaders > limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
public static final String PROP_I2CP_OPTS = "i2psnark.i2cpOptions";
|
public static final String PROP_I2CP_OPTS = "i2psnark.i2cpOptions";
|
||||||
public static final String PROP_EEP_HOST = "i2psnark.eepHost";
|
public static final String PROP_EEP_HOST = "i2psnark.eepHost";
|
||||||
public static final String PROP_EEP_PORT = "i2psnark.eepPort";
|
public static final String PROP_EEP_PORT = "i2psnark.eepPort";
|
||||||
|
public static final String PROP_UPLOADERS_TOTAL = "i2psnark.uploaders.total";
|
||||||
public static final String PROP_DIR = "i2psnark.dir";
|
public static final String PROP_DIR = "i2psnark.dir";
|
||||||
|
|
||||||
public static final String PROP_AUTO_START = "i2snark.autoStart";
|
public static final String PROP_AUTO_START = "i2snark.autoStart";
|
||||||
@ -99,6 +100,8 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
_config.setProperty(PROP_EEP_HOST, "localhost");
|
_config.setProperty(PROP_EEP_HOST, "localhost");
|
||||||
if (!_config.containsKey(PROP_EEP_PORT))
|
if (!_config.containsKey(PROP_EEP_PORT))
|
||||||
_config.setProperty(PROP_EEP_PORT, "4444");
|
_config.setProperty(PROP_EEP_PORT, "4444");
|
||||||
|
if (!_config.containsKey(PROP_UPLOADERS_TOTAL))
|
||||||
|
_config.setProperty(PROP_UPLOADERS_TOTAL, "" + Snark.MAX_TOTAL_UPLOADERS);
|
||||||
if (!_config.containsKey(PROP_DIR))
|
if (!_config.containsKey(PROP_DIR))
|
||||||
_config.setProperty(PROP_DIR, "i2psnark");
|
_config.setProperty(PROP_DIR, "i2psnark");
|
||||||
if (!_config.containsKey(PROP_AUTO_START))
|
if (!_config.containsKey(PROP_AUTO_START))
|
||||||
@ -129,6 +132,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
int eepPort = getInt(PROP_EEP_PORT, 4444);
|
int eepPort = getInt(PROP_EEP_PORT, 4444);
|
||||||
if (eepHost != null)
|
if (eepHost != null)
|
||||||
I2PSnarkUtil.instance().setProxy(eepHost, eepPort);
|
I2PSnarkUtil.instance().setProxy(eepHost, eepPort);
|
||||||
|
I2PSnarkUtil.instance().setMaxUploaders(getInt(PROP_UPLOADERS_TOTAL, Snark.MAX_TOTAL_UPLOADERS));
|
||||||
getDataDir().mkdirs();
|
getDataDir().mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +148,8 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateConfig(String dataDir, boolean autoStart, String seedPct, String eepHost,
|
public void updateConfig(String dataDir, boolean autoStart, String seedPct, String eepHost,
|
||||||
String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts) {
|
String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
|
||||||
|
String upLimit) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
if (eepHost != null) {
|
if (eepHost != null) {
|
||||||
int port = I2PSnarkUtil.instance().getEepProxyPort();
|
int port = I2PSnarkUtil.instance().getEepProxyPort();
|
||||||
@ -159,6 +164,20 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
addMessage("EepProxy location changed to " + eepHost + ":" + port);
|
addMessage("EepProxy location changed to " + eepHost + ":" + port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (upLimit != null) {
|
||||||
|
int limit = I2PSnarkUtil.instance().getMaxUploaders();
|
||||||
|
try { limit = Integer.parseInt(upLimit); } catch (NumberFormatException nfe) {}
|
||||||
|
if ( limit != I2PSnarkUtil.instance().getEepProxyPort()) {
|
||||||
|
if ( limit >= Snark.MIN_TOTAL_UPLOADERS ) {
|
||||||
|
I2PSnarkUtil.instance().setMaxUploaders(limit);
|
||||||
|
changed = true;
|
||||||
|
_config.setProperty(PROP_UPLOADERS_TOTAL, "" + limit);
|
||||||
|
addMessage("Total uploaders limit changed to " + limit);
|
||||||
|
} else {
|
||||||
|
addMessage("Minimum total uploaders limit is " + Snark.MIN_TOTAL_UPLOADERS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (i2cpHost != null) {
|
if (i2cpHost != null) {
|
||||||
int oldI2CPPort = I2PSnarkUtil.instance().getI2CPPort();
|
int oldI2CPPort = I2PSnarkUtil.instance().getI2CPPort();
|
||||||
String oldI2CPHost = I2PSnarkUtil.instance().getI2CPHost();
|
String oldI2CPHost = I2PSnarkUtil.instance().getI2CPHost();
|
||||||
|
@ -271,7 +271,8 @@ public class I2PSnarkServlet extends HttpServlet {
|
|||||||
String i2cpHost = req.getParameter("i2cpHost");
|
String i2cpHost = req.getParameter("i2cpHost");
|
||||||
String i2cpPort = req.getParameter("i2cpPort");
|
String i2cpPort = req.getParameter("i2cpPort");
|
||||||
String i2cpOpts = req.getParameter("i2cpOpts");
|
String i2cpOpts = req.getParameter("i2cpOpts");
|
||||||
_manager.updateConfig(dataDir, autoStart, seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts);
|
String upLimit = req.getParameter("upLimit");
|
||||||
|
_manager.updateConfig(dataDir, autoStart, seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts, upLimit);
|
||||||
} else if ("Create torrent".equals(action)) {
|
} else if ("Create torrent".equals(action)) {
|
||||||
String baseData = req.getParameter("baseFile");
|
String baseData = req.getParameter("baseFile");
|
||||||
if (baseData != null) {
|
if (baseData != null) {
|
||||||
@ -607,7 +608,7 @@ public class I2PSnarkServlet extends HttpServlet {
|
|||||||
String uri = req.getRequestURI();
|
String uri = req.getRequestURI();
|
||||||
String dataDir = _manager.getDataDir().getAbsolutePath();
|
String dataDir = _manager.getDataDir().getAbsolutePath();
|
||||||
boolean autoStart = _manager.shouldAutoStart();
|
boolean autoStart = _manager.shouldAutoStart();
|
||||||
int seedPct = 0;
|
//int seedPct = 0;
|
||||||
|
|
||||||
out.write("<form action=\"" + uri + "\" method=\"POST\">\n");
|
out.write("<form action=\"" + uri + "\" method=\"POST\">\n");
|
||||||
out.write("<span class=\"snarkConfig\"><hr />\n");
|
out.write("<span class=\"snarkConfig\"><hr />\n");
|
||||||
@ -621,6 +622,7 @@ public class I2PSnarkServlet extends HttpServlet {
|
|||||||
//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");
|
||||||
|
/*
|
||||||
out.write("Seed percentage: <select name=\"seedPct\" disabled=\"true\" >\n\t");
|
out.write("Seed percentage: <select name=\"seedPct\" disabled=\"true\" >\n\t");
|
||||||
if (seedPct <= 0)
|
if (seedPct <= 0)
|
||||||
out.write("<option value=\"0\" selected=\"true\">Unlimited</option>\n\t");
|
out.write("<option value=\"0\" selected=\"true\">Unlimited</option>\n\t");
|
||||||
@ -635,6 +637,9 @@ public class I2PSnarkServlet extends HttpServlet {
|
|||||||
else
|
else
|
||||||
out.write("<option value=\"150\">150%</option>\n\t");
|
out.write("<option value=\"150\">150%</option>\n\t");
|
||||||
out.write("</select><br />\n");
|
out.write("</select><br />\n");
|
||||||
|
*/
|
||||||
|
out.write("Total uploader limit: <input type=\"text\" name=\"upLimit\" value=\""
|
||||||
|
+ I2PSnarkUtil.instance().getMaxUploaders() + "\" size=\"3\" /><br />\n");
|
||||||
|
|
||||||
//out.write("<hr />\n");
|
//out.write("<hr />\n");
|
||||||
out.write("EepProxy host: <input type=\"text\" name=\"eepHost\" value=\""
|
out.write("EepProxy host: <input type=\"text\" name=\"eepHost\" value=\""
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
$Id: history.txt,v 1.558 2007-03-10 03:45:28 zzz Exp $
|
$Id: history.txt,v 1.559 2007-03-12 13:20:01 jrandom Exp $
|
||||||
|
|
||||||
|
2007-03-13 zzz
|
||||||
|
* i2psnark: Make max total uploaders configurable (thanks Amiga4000!)
|
||||||
|
|
||||||
2007-03-12 jrandom
|
2007-03-12 jrandom
|
||||||
* dodge a race on startup (thanks zzz!)
|
* dodge a race on startup (thanks zzz!)
|
||||||
|
@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RouterVersion {
|
public class RouterVersion {
|
||||||
public final static String ID = "$Revision: 1.494 $ $Date: 2007-03-10 03:45:27 $";
|
public final static String ID = "$Revision: 1.495 $ $Date: 2007-03-12 13:19:57 $";
|
||||||
public final static String VERSION = "0.6.1.27";
|
public final static String VERSION = "0.6.1.27";
|
||||||
public final static long BUILD = 8;
|
public final static long BUILD = 9;
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
|
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
|
||||||
System.out.println("Router ID: " + RouterVersion.ID);
|
System.out.println("Router ID: " + RouterVersion.ID);
|
||||||
|
Reference in New Issue
Block a user