Changeset 9faba9f


Ignore:
Timestamp:
Mar 10, 2012 9:53:29 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
307826c
Parents:
87c04bf
Message:
  • Console: Test if IPv6 addresses will work before instantiating

connectors, so Jetty will still start without them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java

    r87c04bf r9faba9f  
    66import java.io.FilenameFilter;
    77import java.io.IOException;
     8import java.net.InetAddress;
     9import java.net.Inet4Address;
    810import java.security.KeyStore;
    911import java.util.HashMap;
     
    1113import java.util.Map;
    1214import java.util.Properties;
     15import java.util.Set;
    1316import java.util.StringTokenizer;
    1417import java.util.concurrent.Executors;
     
    2528import net.i2p.jetty.I2PLogger;
    2629import net.i2p.router.RouterContext;
     30import net.i2p.util.Addresses;
    2731import net.i2p.util.FileUtil;
    2832import net.i2p.util.I2PAppThread;
     
    292296        try {
    293297            int boundAddresses = 0;
     298            boolean hasIPV6 = Addresses.getAllAddresses().contains("0:0:0:0:0:0:0:0");
    294299
    295300            // add standard listeners
     301            int lport = 0;
    296302            if (_listenPort != null) {
    297                 Integer lport = Integer.parseInt(_listenPort);
     303                try {
     304                    lport = Integer.parseInt(_listenPort);
     305                } catch (NumberFormatException nfe) {}
     306                if (lport <= 0)
     307                    System.err.println("Bad routerconsole port " + _listenPort);
     308            }
     309            if (lport > 0) {
    298310                StringTokenizer tok = new StringTokenizer(_listenHost, " ,");
    299311                while (tok.hasMoreTokens()) {
    300312                    String host = tok.nextToken().trim();
    301313                    try {
     314                        // Test before we add the connector, because Jetty 6 won't start if any of the
     315                        // connectors are bad
     316                        InetAddress test = InetAddress.getByName(host);
     317                        if ((!hasIPV6) && (!(test instanceof Inet4Address)))
     318                            throw new IOException("IPv6 addresses unsupported, you may ignore this warning if the console is still available at http://127.0.0.1:7657");
    302319                        //if (host.indexOf(":") >= 0) // IPV6 - requires patched Jetty 5
    303320                        //    _server.addListener('[' + host + "]:" + _listenPort);
     
    312329                        _server.addConnector(lsnr);
    313330                        boundAddresses++;
    314                     } catch (NumberFormatException nfe) {
    315                         System.err.println("Unable to bind routerconsole to " + host + " port " + _listenPort + ' ' + nfe);
    316331                    } catch (Exception ioe) { // this doesn't seem to work, exceptions don't happen until start() below
    317332                        System.err.println("Unable to bind routerconsole to " + host + " port " + _listenPort + ' ' + ioe);
     
    340355                        // doing it this way means we don't have to escape an IPv6 host with []
    341356                        try {
     357                            // Test before we add the connector, because Jetty 6 won't start if any of the
     358                            // connectors are bad
     359                            InetAddress test = InetAddress.getByName(host);
     360                            if ((!hasIPV6) && (!(test instanceof Inet4Address)))
     361                                throw new IOException("IPv6 addresses unsupported, you may ignore this warning if the console is still available at http://127.0.0.1:7657");
    342362                            // TODO if class not found use SslChannelConnector
    343363                            // Sadly there's no common base class with the ssl methods in it
Note: See TracChangeset for help on using the changeset viewer.