* SSUDemo: configuration fixes, delete RI on exit, log tweaks

This commit is contained in:
zzz
2013-05-18 14:27:11 +00:00
parent be262c6a70
commit 226c7eb8e3

View File

@ -53,8 +53,9 @@ public class SSUDemo {
private static Properties getEnv() { private static Properties getEnv() {
Properties envProps = System.getProperties(); Properties envProps = System.getProperties();
// disable the NTCP transport // disable the NTCP transport and UPnP
envProps.setProperty("i2np.ntcp.enable", "false"); envProps.setProperty("i2np.ntcp.enable", "false");
envProps.setProperty("i2np.upnp.enable", "false");
// we want SNTP synchronization for replay prevention // we want SNTP synchronization for replay prevention
envProps.setProperty("time.disabled", "false"); envProps.setProperty("time.disabled", "false");
// allow 127.0.0.1/10.0.0.1/etc (useful for testing). If this is false, // allow 127.0.0.1/10.0.0.1/etc (useful for testing). If this is false,
@ -64,8 +65,10 @@ public class SSUDemo {
// set, since there has to be someone to detect one's IP off. most don't need // set, since there has to be someone to detect one's IP off. most don't need
// to set these though // to set these though
envProps.setProperty("i2np.udp.host", "127.0.0.1"); envProps.setProperty("i2np.udp.host", "127.0.0.1");
envProps.setProperty("i2np.udp.internalPort", "12000"); // we don't have a context yet to use its random
envProps.setProperty("i2np.udp.port", "12000"); String port = Integer.toString(44000 + (((int) System.currentTimeMillis()) & (16384 - 1)));
envProps.setProperty("i2np.udp.internalPort", port);
envProps.setProperty("i2np.udp.port", port);
// disable I2CP, the netDb, peer testing/profile persistence, and tunnel // disable I2CP, the netDb, peer testing/profile persistence, and tunnel
// creation/management // creation/management
envProps.setProperty("i2p.dummyClientFacade", "true"); envProps.setProperty("i2p.dummyClientFacade", "true");
@ -85,7 +88,17 @@ public class SSUDemo {
// write the logs to ./logs/log-router-*.txt (logger configured with the file // write the logs to ./logs/log-router-*.txt (logger configured with the file
// ./logger.config, or another config file specified as // ./logger.config, or another config file specified as
// -Dlogger.configLocation=blah) // -Dlogger.configLocation=blah)
envProps.setProperty("loggerFilenameOverride", "logs/log-router-@.txt"); // avoid conflicts over log
envProps.setProperty("loggerFilenameOverride", "logs/log-router-" + port + "-@.txt");
System.setProperty("wrapper.logfile", "wrapper-" + port + ".log");
// avoid conflicts over key backup etc. so we don't all use the same keys
envProps.setProperty("router.keyBackupDir", "keyBackup/router-" + port);
envProps.setProperty("router.info.location", "router-" + port + ".info");
envProps.setProperty("router.keys.location", "router-" + port + ".keys");
envProps.setProperty("router.configLocation", "router-" + port + ".config");
envProps.setProperty("router.pingFile", "router-" + port + ".ping");
// avoid conflicts over blockfile
envProps.setProperty("i2p.naming.impl", "net.i2p.client.naming.HostsTxtNamingService");
return envProps; return envProps;
} }
@ -107,6 +120,7 @@ public class SSUDemo {
infoDir.mkdirs(); infoDir.mkdirs();
FileOutputStream fos = null; FileOutputStream fos = null;
File infoFile = new File(infoDir, info.getIdentity().calculateHash().toBase64()); File infoFile = new File(infoDir, info.getIdentity().calculateHash().toBase64());
infoFile.deleteOnExit();
try { try {
fos = new FileOutputStream(infoFile); fos = new FileOutputStream(infoFile);
info.writeBytes(fos); info.writeBytes(fos);
@ -166,7 +180,8 @@ public class SSUDemo {
out.setPriority(100); out.setPriority(100);
out.setTarget(ri); out.setTarget(ri);
FooMessage data = new FooMessage(_us, new byte[] { 0x0, 0x1, 0x2, 0x3 }); FooMessage data = new FooMessage(_us, new byte[] { 0x0, 0x1, 0x2, 0x3 });
System.out.println("SEND: " + Base64.encode(data.getData())); System.out.println("SEND: " + Base64.encode(data.getData()) + " to " +
ri.getIdentity().calculateHash());
out.setMessage(data); out.setMessage(data);
// job fired if we can't contact them, or if it takes too long to get an ACK // job fired if we can't contact them, or if it takes too long to get an ACK
out.setOnFailedSendJob(null); out.setOnFailedSendJob(null);
@ -207,17 +222,19 @@ public class SSUDemo {
private static class FooHandleJob extends JobImpl { private static class FooHandleJob extends JobImpl {
private final I2NPMessage _msg; private final I2NPMessage _msg;
private final Hash _from;
public FooHandleJob(RouterContext ctx, I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) { public FooHandleJob(RouterContext ctx, I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) {
super(ctx); super(ctx);
_msg = receivedMessage; _msg = receivedMessage;
_from = fromHash;
} }
public void runJob() { public void runJob() {
// we know its a FooMessage, since thats the type of message that the handler // we know its a FooMessage, since thats the type of message that the handler
// is registered as // is registered as
FooMessage m = (FooMessage)_msg; FooMessage m = (FooMessage)_msg;
System.out.println("RECV: " + Base64.encode(m.getData())); System.out.println("RECV: " + Base64.encode(m.getData()) + " from " + _from);
} }
public String getName() { return "Handle Foo message"; } public String getName() { return "Handle Foo message"; }
} }