check if the console is up before continuing

This commit is contained in:
idk
2022-03-25 18:47:48 -04:00
parent 714ef026f3
commit 4ce272765f
2 changed files with 21 additions and 0 deletions

View File

@ -5,6 +5,7 @@
* On restart to update, will detect if a router requires admin rights to install
and will ask the user to authorize the update. In user-mode, no prompt will ever
be seen.
* Updates to the Firefox profiles to improve compatibility with more Firefoxes
2022-02-10 idk
* This release fixes automatic update using Bittorrent within the I2P network

View File

@ -1,6 +1,8 @@
package net.i2p.router;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.*;
import net.i2p.crypto.*;
@ -49,6 +51,12 @@ public class WinLauncher {
System.out.println("\t" + System.getProperty("i2p.dir.base") + "\n\t" + System.getProperty("i2p.dir.config")
+ "\n\t" + System.getProperty("router.pid"));
// do a quick check to see of port 7657 is already occupied
if (i2pIsRunning()) {
System.err.println("I2P is already running");
System.exit(0);
}
// wupp.i2pRouter = new Router(System.getProperties());
System.out.println("Router is configured");
@ -61,6 +69,18 @@ public class WinLauncher {
RouterLaunch.main(args);
}
private static boolean i2pIsRunning() {
// check if there's something listening on port 7657
try {
InetAddress localhost = InetAddress.getLocalHost();
Socket s = new Socket(localhost, 7657);
s.close();
return true;
} catch (IOException e) {
return false;
}
}
private static final Runnable REGISTER_UPP = () -> {
// first wait for the RouterContext to appear