- Use servlet path everywhere, so the war can be renamed

- Use servlet path as base for config file and data directory names,
    so we may have multiple instances running together
  - Don't override service(), use doGet() and doPost() instead
This commit is contained in:
zzz
2013-01-23 22:44:52 +00:00
parent 4ba8f02f59
commit 18e369bcf4
5 changed files with 125 additions and 56 deletions

View File

@@ -49,6 +49,7 @@ import org.klomp.snark.dht.KRPC;
public class I2PSnarkUtil {
private final I2PAppContext _context;
private final Log _log;
private final String _baseName;
private boolean _shouldProxy;
private String _proxyHost;
@@ -82,8 +83,17 @@ public class I2PSnarkUtil {
public static final boolean DEFAULT_USE_DHT = true;
public I2PSnarkUtil(I2PAppContext ctx) {
this(ctx, "i2psnark");
}
/**
* @param baseName generally "i2psnark"
* @since Jetty 7
*/
public I2PSnarkUtil(I2PAppContext ctx, String baseName) {
_context = ctx;
_log = _context.logManager().getLog(Snark.class);
_baseName = baseName;
_opts = new HashMap();
//setProxy("127.0.0.1", 4444);
setI2CPConfig("127.0.0.1", 7654, null);
@@ -99,7 +109,7 @@ public class I2PSnarkUtil {
// This is used for both announce replies and .torrent file downloads,
// so it must be available even if not connected to I2CP.
// so much for multiple instances
_tmpDir = new SecureDirectory(ctx.getTempDir(), "i2psnark");
_tmpDir = new SecureDirectory(ctx.getTempDir(), baseName);
FileUtil.rmdir(_tmpDir, false);
_tmpDir.mkdirs();
}
@@ -253,7 +263,7 @@ public class I2PSnarkUtil {
_connecting = false;
}
if (_shouldUseDHT && _manager != null && _dht == null)
_dht = new KRPC(_context, _manager.getSession());
_dht = new KRPC(_context, _baseName, _manager.getSession());
return (_manager != null);
}
@@ -588,7 +598,7 @@ public class I2PSnarkUtil {
public synchronized void setUseDHT(boolean yes) {
_shouldUseDHT = yes;
if (yes && _manager != null && _dht == null) {
_dht = new KRPC(_context, _manager.getSession());
_dht = new KRPC(_context, _baseName, _manager.getSession());
} else if (!yes && _dht != null) {
_dht.stop();
_dht = null;