log to stdout when I2P has warmed up

pull/35/head
knaccc 5 years ago
parent 8c310b5df9
commit b9a5baef78

@ -18,7 +18,7 @@ public class Main {
System.exit(1); System.exit(1);
} }
System.out.println("I2P router launched.\n" + System.out.println("I2P router launched. Note that it will take several minutes for I2P to warm up before it is ready.\n" +
"Press Ctrl-C to gracefully shut down the router (or send the SIGINT signal to the process)."); "Press Ctrl-C to gracefully shut down the router (or send the SIGINT signal to the process).");
Properties p = new Properties(); Properties p = new Properties();
@ -38,13 +38,18 @@ public class Main {
+ p.entrySet().stream().map(e->"--"+e.getKey()+"="+e.getValue()).collect(Collectors.joining(" "))); + p.entrySet().stream().map(e->"--"+e.getKey()+"="+e.getValue()).collect(Collectors.joining(" ")));
RouterWrapper routerWrapper = new RouterWrapper(p, ()->{ RouterWrapper routerWrapper = new RouterWrapper(p, ()->{
Main.consoleOut.println("**** A new version of I2P-zero is available at https://github.com/i2p-zero/i2p-zero - Please keep your software up-to-date, as it will enhance your privacy and keep you safe from vulnerabilities"); consoleOut.println("**** A new version of I2P-zero is available at https://github.com/i2p-zero/i2p-zero - Please keep your software up-to-date, as it will enhance your privacy and keep you safe from vulnerabilities");
}); });
routerWrapper.start(()->Main.consoleOut.println("For best performance, please open port " + routerWrapper.routerExternalPort + " on your firewall for incoming UDP and TCP connections. This port has been randomly assigned to you. For privacy reasons, please do not share this port with others.")); routerWrapper.start(()->consoleOut.println("For best performance, please open port " + routerWrapper.routerExternalPort + " on your firewall for incoming UDP and TCP connections. This port has been randomly assigned to you. For privacy reasons, please do not share this port with others."));
Runtime.getRuntime().addShutdownHook(new Thread(()->routerWrapper.stop(true))); Runtime.getRuntime().addShutdownHook(new Thread(()->routerWrapper.stop(true)));
new Thread(()->{
routerWrapper.waitForRouterRunning();
consoleOut.println("I2P router now ready to create tunnels");
}).start();
} }
} }

@ -332,6 +332,9 @@ public class RouterWrapper {
if(router==null) return false; if(router==null) return false;
return router.isRunning(); return router.isRunning();
} }
public void waitForRouterRunning() {
while(!isRouterRunning()) { try { Thread.sleep(100); } catch (InterruptedException e) {} }
}
public RouterContext getRouterContext() { public RouterContext getRouterContext() {
return router.getContext(); return router.getContext();

@ -202,9 +202,6 @@ public class TunnelControl implements Runnable {
} }
}).start(); }).start();
} }
public void waitForRouterRunning() {
while(!routerWrapper.isRouterRunning()) { try { Thread.sleep(100); } catch (InterruptedException e) {} }
}
} }
public static class ClientTunnel extends Tunnel { public static class ClientTunnel extends Tunnel {
@ -220,7 +217,7 @@ public class TunnelControl implements Runnable {
@Override @Override
public Tunnel start() { public Tunnel start() {
new Thread(()->{ new Thread(()->{
waitForRouterRunning(); routerWrapper.waitForRouterRunning();
tunnel = new I2PTunnel(new String[]{"-die", "-nocli", "-e", "config localhost 7654", "-e", "client " + port + " " + dest}); tunnel = new I2PTunnel(new String[]{"-die", "-nocli", "-e", "config localhost 7654", "-e", "client " + port + " " + dest});
}).start(); }).start();
return this; return this;
@ -242,7 +239,7 @@ public class TunnelControl implements Runnable {
@Override @Override
public Tunnel start() { public Tunnel start() {
new Thread(()->{ new Thread(()->{
waitForRouterRunning(); routerWrapper.waitForRouterRunning();
tunnel = new I2PTunnel(new String[]{"-die", "-nocli", "-e", "config localhost 7654", "-e", "httpclient " + port}); tunnel = new I2PTunnel(new String[]{"-die", "-nocli", "-e", "config localhost 7654", "-e", "httpclient " + port});
}).start(); }).start();
return this; return this;
@ -276,7 +273,7 @@ public class TunnelControl implements Runnable {
@Override @Override
public Tunnel start() { public Tunnel start() {
new Thread(() -> { new Thread(() -> {
waitForRouterRunning(); routerWrapper.waitForRouterRunning();
try { try {
String uuid = new BigInteger(128, new Random()).toString(16); String uuid = new BigInteger(128, new Random()).toString(16);
String seckeyPath = tunnelControlTempDir.getAbsolutePath() + File.separator + "seckey." + uuid + ".dat"; String seckeyPath = tunnelControlTempDir.getAbsolutePath() + File.separator + "seckey." + uuid + ".dat";
@ -419,7 +416,7 @@ public class TunnelControl implements Runnable {
@Override @Override
public Tunnel start() { public Tunnel start() {
new Thread(()->{ new Thread(()->{
waitForRouterRunning(); routerWrapper.waitForRouterRunning();
tunnel = new I2PTunnel(new String[]{"-die", "-nocli", "-e", "sockstunnel " + port}); tunnel = new I2PTunnel(new String[]{"-die", "-nocli", "-e", "sockstunnel " + port});
}).start(); }).start();
return this; return this;

Loading…
Cancel
Save