I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit f4956b06 authored by jrandom's avatar jrandom Committed by zzz
Browse files

be more careful on startup

parent 9a2f7c26
No related branches found
No related tags found
No related merge requests found
......@@ -76,7 +76,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
if (addr != null)
addresses.add(addr);
addresses.addAll(_manager.getAddresses());
if (_manager != null)
addresses.addAll(_manager.getAddresses());
if (_log.shouldLog(Log.INFO))
_log.info("Creating addresses: " + addresses);
......
......@@ -63,10 +63,11 @@ class TCPListener {
_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() {
TCPAddress addr = _transport.getMyAddress();
if ( (addr != null) && (addr.getHost() != null) && (addr.getPort() > 0) ) {
TCPAddress addr = new TCPAddress(_transport.getMyHost(), _transport.getPort());
if (addr.getPort() > 0) {
if (_listener != null) {
if (_log.shouldLog(Log.WARN))
_log.warn("Not starting another listener on " + addr
......@@ -141,14 +142,15 @@ class TCPListener {
int curDelay = 0;
while (_isRunning) {
try {
if (_transport.shouldListenToAllInterfaces()) {
if ( (_transport.shouldListenToAllInterfaces()) || (_myAddress.getHost() == null) ) {
_socket = new ServerSocket(_myAddress.getPort());
} else {
InetAddress listenAddr = getInetAddress(_myAddress.getHost());
_socket = new ServerSocket(_myAddress.getPort(), 5, listenAddr);
}
String host = (null == _myAddress.getHost() ? "0.0.0.0" : _myAddress.getHost());
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;
loop();
} catch (IOException ioe) {
......
......@@ -84,6 +84,8 @@ public class TCPTransport extends TransportImpl {
/** Ordered list of supported I2NP protocols */
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 */
public TCPTransport(RouterContext context) {
......@@ -300,8 +302,8 @@ public class TCPTransport extends TransportImpl {
public RouterAddress startListening() {
configureLocalAddress();
_listener.startListening();
if (_myAddress != null) {
_listener.startListening();
return _myAddress.toRouterAddress();
} else {
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; }
ConnectionTagManager getTagManager() { return _tagManager; }
......@@ -352,6 +359,11 @@ public class TCPTransport extends TransportImpl {
private void configureLocalAddress() {
String addr = _context.getProperty(LISTEN_ADDRESS);
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) {
TCPAddress address = new TCPAddress(addr, port);
boolean ok = allowAddress(address);
......@@ -435,7 +447,7 @@ public class TCPTransport extends TransportImpl {
if ( (_myAddress != null) && (_myAddress.getPort() > 0) )
return _myAddress.getPort();
String port = _context.getProperty(LISTEN_PORT);
String port = _context.getProperty(LISTEN_PORT, DEFAULT_LISTEN_PORT+"");
if (port != null) {
try {
int portNum = Integer.parseInt(port);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment