be more careful on startup
This commit is contained in:
@ -76,7 +76,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
|||||||
if (addr != null)
|
if (addr != null)
|
||||||
addresses.add(addr);
|
addresses.add(addr);
|
||||||
|
|
||||||
addresses.addAll(_manager.getAddresses());
|
if (_manager != null)
|
||||||
|
addresses.addAll(_manager.getAddresses());
|
||||||
|
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info("Creating addresses: " + addresses);
|
_log.info("Creating addresses: " + addresses);
|
||||||
|
@ -63,10 +63,11 @@ class TCPListener {
|
|||||||
_handlers = new ArrayList(CONCURRENT_HANDLERS);
|
_handlers = new ArrayList(CONCURRENT_HANDLERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make sure we are listening on the transport's getMyAddress() */
|
/** Make sure we are listening per the transport's config */
|
||||||
public void startListening() {
|
public void startListening() {
|
||||||
TCPAddress addr = _transport.getMyAddress();
|
TCPAddress addr = new TCPAddress(_transport.getMyHost(), _transport.getPort());
|
||||||
if ( (addr != null) && (addr.getHost() != null) && (addr.getPort() > 0) ) {
|
|
||||||
|
if (addr.getPort() > 0) {
|
||||||
if (_listener != null) {
|
if (_listener != null) {
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.WARN))
|
||||||
_log.warn("Not starting another listener on " + addr
|
_log.warn("Not starting another listener on " + addr
|
||||||
@ -141,14 +142,15 @@ class TCPListener {
|
|||||||
int curDelay = 0;
|
int curDelay = 0;
|
||||||
while (_isRunning) {
|
while (_isRunning) {
|
||||||
try {
|
try {
|
||||||
if (_transport.shouldListenToAllInterfaces()) {
|
if ( (_transport.shouldListenToAllInterfaces()) || (_myAddress.getHost() == null) ) {
|
||||||
_socket = new ServerSocket(_myAddress.getPort());
|
_socket = new ServerSocket(_myAddress.getPort());
|
||||||
} else {
|
} else {
|
||||||
InetAddress listenAddr = getInetAddress(_myAddress.getHost());
|
InetAddress listenAddr = getInetAddress(_myAddress.getHost());
|
||||||
_socket = new ServerSocket(_myAddress.getPort(), 5, listenAddr);
|
_socket = new ServerSocket(_myAddress.getPort(), 5, listenAddr);
|
||||||
}
|
}
|
||||||
|
String host = (null == _myAddress.getHost() ? "0.0.0.0" : _myAddress.getHost());
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info("Begin looping for host " + _myAddress.getHost() + ":" + _myAddress.getPort());
|
_log.info("Begin looping for host " + host + ":" + _myAddress.getPort());
|
||||||
curDelay = 0;
|
curDelay = 0;
|
||||||
loop();
|
loop();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
@ -84,6 +84,8 @@ public class TCPTransport extends TransportImpl {
|
|||||||
|
|
||||||
/** Ordered list of supported I2NP protocols */
|
/** Ordered list of supported I2NP protocols */
|
||||||
public static final int[] SUPPORTED_PROTOCOLS = new int[] { 1 };
|
public static final int[] SUPPORTED_PROTOCOLS = new int[] { 1 };
|
||||||
|
/** blah, people shouldnt use defaults... */
|
||||||
|
public static final int DEFAULT_LISTEN_PORT = 8887;
|
||||||
|
|
||||||
/** Creates a new instance of TCPTransport */
|
/** Creates a new instance of TCPTransport */
|
||||||
public TCPTransport(RouterContext context) {
|
public TCPTransport(RouterContext context) {
|
||||||
@ -300,8 +302,8 @@ public class TCPTransport extends TransportImpl {
|
|||||||
|
|
||||||
public RouterAddress startListening() {
|
public RouterAddress startListening() {
|
||||||
configureLocalAddress();
|
configureLocalAddress();
|
||||||
|
_listener.startListening();
|
||||||
if (_myAddress != null) {
|
if (_myAddress != null) {
|
||||||
_listener.startListening();
|
|
||||||
return _myAddress.toRouterAddress();
|
return _myAddress.toRouterAddress();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -341,7 +343,12 @@ public class TCPTransport extends TransportImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPAddress getMyAddress() { return _myAddress; }
|
String getMyHost() {
|
||||||
|
if (_myAddress != null)
|
||||||
|
return _myAddress.getHost();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public String getStyle() { return STYLE; }
|
public String getStyle() { return STYLE; }
|
||||||
ConnectionTagManager getTagManager() { return _tagManager; }
|
ConnectionTagManager getTagManager() { return _tagManager; }
|
||||||
|
|
||||||
@ -352,6 +359,11 @@ public class TCPTransport extends TransportImpl {
|
|||||||
private void configureLocalAddress() {
|
private void configureLocalAddress() {
|
||||||
String addr = _context.getProperty(LISTEN_ADDRESS);
|
String addr = _context.getProperty(LISTEN_ADDRESS);
|
||||||
int port = getPort();
|
int port = getPort();
|
||||||
|
if ( (addr == null) || (addr.trim().length() <= 0) ) {
|
||||||
|
if (_log.shouldLog(Log.ERROR))
|
||||||
|
_log.error("External address is not specified - autodetecting IP (be sure to forward port " + port + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (port != -1) {
|
if (port != -1) {
|
||||||
TCPAddress address = new TCPAddress(addr, port);
|
TCPAddress address = new TCPAddress(addr, port);
|
||||||
boolean ok = allowAddress(address);
|
boolean ok = allowAddress(address);
|
||||||
@ -435,7 +447,7 @@ public class TCPTransport extends TransportImpl {
|
|||||||
if ( (_myAddress != null) && (_myAddress.getPort() > 0) )
|
if ( (_myAddress != null) && (_myAddress.getPort() > 0) )
|
||||||
return _myAddress.getPort();
|
return _myAddress.getPort();
|
||||||
|
|
||||||
String port = _context.getProperty(LISTEN_PORT);
|
String port = _context.getProperty(LISTEN_PORT, DEFAULT_LISTEN_PORT+"");
|
||||||
if (port != null) {
|
if (port != null) {
|
||||||
try {
|
try {
|
||||||
int portNum = Integer.parseInt(port);
|
int portNum = Integer.parseInt(port);
|
||||||
|
Reference in New Issue
Block a user