forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 17371fd6f9ef94bbb60a66c6bacb6828d6a4cde5)
to branch 'i2p.i2p.zzz.ipv6' (head 065a076899a2581b4196e626f2b0654c3d39518a)
This commit is contained in:
@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 20;
|
||||
public final static long BUILD = 21;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "-ipv6";
|
||||
|
@ -274,8 +274,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
* This should really be moved to ntcp/NTCPTransport.java, why is it here?
|
||||
*/
|
||||
@Override
|
||||
public synchronized void notifyReplaceAddress(RouterAddress UDPAddr) {
|
||||
if (UDPAddr == null)
|
||||
public synchronized void notifyReplaceAddress(RouterAddress udpAddr) {
|
||||
if (udpAddr == null)
|
||||
return;
|
||||
NTCPTransport t = (NTCPTransport) _manager.getTransport(NTCPTransport.STYLE);
|
||||
if (t == null)
|
||||
@ -309,19 +309,38 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
// Auto Port Setting
|
||||
// old behavior (<= 0.7.3): auto-port defaults to false, and true trumps explicit setting
|
||||
// new behavior (>= 0.7.4): auto-port defaults to true, but explicit setting trumps auto
|
||||
// TODO rewrite this to operate on ints instead of strings
|
||||
String oport = newProps.getProperty(NTCPAddress.PROP_PORT);
|
||||
String nport = null;
|
||||
String cport = _context.getProperty(PROP_I2NP_NTCP_PORT);
|
||||
if (cport != null && cport.length() > 0) {
|
||||
nport = cport;
|
||||
} else if (_context.getBooleanPropertyDefaultTrue(PROP_I2NP_NTCP_AUTO_PORT)) {
|
||||
nport = UDPAddr.getOption(UDPAddress.PROP_PORT);
|
||||
// 0.9.6 change
|
||||
// This wasn't quite right, as udpAddr is the EXTERNAL port and we really
|
||||
// want NTCP to bind to the INTERNAL port the first time,
|
||||
// because if they are different, the NAT is changing them, and
|
||||
// it probably isn't mapping UDP and TCP the same.
|
||||
Transport udp = _manager.getTransport(UDPTransport.STYLE);
|
||||
if (udp != null) {
|
||||
int udpIntPort = udp.getRequestedPort();
|
||||
if (udpIntPort > 0)
|
||||
// should always be true
|
||||
nport = Integer.toString(udpIntPort);
|
||||
}
|
||||
if (nport == null)
|
||||
// fallback
|
||||
nport = udpAddr.getOption(UDPAddress.PROP_PORT);
|
||||
}
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("old: " + oport + " config: " + cport + " new: " + nport);
|
||||
if (nport == null || nport.length() <= 0)
|
||||
return;
|
||||
if (oport == null || ! oport.equals(nport)) {
|
||||
// 0.9.6 change
|
||||
// Don't have NTCP "chase" SSU's external port,
|
||||
// as it may change, possibly frequently.
|
||||
//if (oport == null || ! oport.equals(nport)) {
|
||||
if (oport == null) {
|
||||
newProps.setProperty(NTCPAddress.PROP_PORT, nport);
|
||||
changed = true;
|
||||
}
|
||||
@ -348,7 +367,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
_log.info("old: " + ohost + " config: " + name + " auto: " + enabled + " status: " + status);
|
||||
if (enabled.equals("always") ||
|
||||
(Boolean.parseBoolean(enabled) && status == STATUS_OK)) {
|
||||
String nhost = UDPAddr.getOption(UDPAddress.PROP_HOST);
|
||||
String nhost = udpAddr.getOption(UDPAddress.PROP_HOST);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("old: " + ohost + " config: " + name + " new: " + nhost);
|
||||
if (nhost == null || nhost.length() <= 0)
|
||||
|
@ -382,19 +382,12 @@ public class TransportManager implements TransportEventListener {
|
||||
Set<Port> rv = new HashSet(4);
|
||||
for (Transport t : _transports.values()) {
|
||||
int port = t.getRequestedPort();
|
||||
for (RouterAddress ra : t.getCurrentAddresses()) {
|
||||
int p = ra.getPort();
|
||||
if (p > 0)
|
||||
port = p;
|
||||
// Use UDP port for NTCP too - see comment in NTCPTransport.getRequestedPort() for why this is here
|
||||
if (t.getStyle().equals(NTCPTransport.STYLE) && port <= 0 &&
|
||||
_context.getBooleanProperty(CommSystemFacadeImpl.PROP_I2NP_NTCP_AUTO_PORT)) {
|
||||
Transport udp = getTransport(UDPTransport.STYLE);
|
||||
if (udp != null)
|
||||
port = t.getRequestedPort();
|
||||
}
|
||||
if (port > 0)
|
||||
rv.add(new Port(t.getStyle(), port));
|
||||
// Use UDP port for NTCP too - see comment in NTCPTransport.getRequestedPort() for why this is here
|
||||
if (t.getStyle().equals(NTCPTransport.STYLE) && port <= 0 &&
|
||||
_context.getBooleanProperty(CommSystemFacadeImpl.PROP_I2NP_NTCP_AUTO_PORT)) {
|
||||
Transport udp = getTransport(UDPTransport.STYLE);
|
||||
if (udp != null)
|
||||
port = t.getRequestedPort();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
@ -187,7 +187,11 @@ class EventPumper implements Runnable {
|
||||
} catch (IOException ioe) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error selecting", ioe);
|
||||
}
|
||||
} catch (CancelledKeyException cke) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error selecting", cke);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lastFailsafeIteration + FAILSAFE_ITERATION_FREQ < System.currentTimeMillis()) {
|
||||
// in the *cough* unthinkable possibility that there are bugs in
|
||||
|
@ -636,6 +636,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
|
||||
//private boolean bindAllInterfaces() { return true; }
|
||||
|
||||
/** caller must synch on this */
|
||||
private void configureLocalAddress() {
|
||||
RouterContext ctx = getContext();
|
||||
if (ctx == null) {
|
||||
@ -682,8 +683,17 @@ public class NTCPTransport extends TransportImpl {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return current port, else NTCP configured port, else -1 (but not UDP port if auto)
|
||||
*/
|
||||
@Override
|
||||
public int getRequestedPort() {
|
||||
NTCPAddress addr = _myAddress;
|
||||
if (addr != null) {
|
||||
int port = addr.getPort();
|
||||
if (port > 0)
|
||||
return port;
|
||||
}
|
||||
// would be nice to do this here but we can't easily get to the UDP transport.getRequested_Port()
|
||||
// from here, so we do it in TransportManager.
|
||||
// if (Boolean.valueOf(_context.getProperty(CommSystemFacadeImpl.PROP_I2NP_NTCP_AUTO_PORT)).booleanValue())
|
||||
|
@ -86,7 +86,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
|
||||
/** summary info to distribute */
|
||||
private RouterAddress _externalAddress;
|
||||
/** port number on which we can be reached, or -1 for error, or 0 for unset */
|
||||
/**
|
||||
* Port number on which we can be reached, or -1 for error, or 0 for unset
|
||||
* Do NOT use this for current internal port - use _endpoint.getListenPort()
|
||||
*/
|
||||
private int _externalListenPort;
|
||||
/** IP address of externally reachable host, or null */
|
||||
private InetAddress _externalListenHost;
|
||||
@ -317,19 +320,18 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
|
||||
// Requested bind port
|
||||
// This may be -1 or may not be honored if busy,
|
||||
// Priority: Configured internal, then already used, then configured external
|
||||
// we will check below after starting up the endpoint.
|
||||
int port;
|
||||
int oldIPort = _context.getProperty(PROP_INTERNAL_PORT, -1);
|
||||
int oldBindPort = _endpoint != null ? _endpoint.getListenPort() : -1;
|
||||
int oldEPort = _context.getProperty(PROP_EXTERNAL_PORT, -1);
|
||||
if (_externalListenPort <= 0) {
|
||||
// no explicit external port, so lets try an internal one
|
||||
if (oldIPort > 0)
|
||||
port = oldIPort;
|
||||
else
|
||||
port = oldEPort;
|
||||
} else {
|
||||
port = _externalListenPort;
|
||||
}
|
||||
if (oldIPort > 0)
|
||||
port = oldIPort;
|
||||
else if (oldBindPort > 0)
|
||||
port = oldBindPort;
|
||||
else
|
||||
port = oldEPort;
|
||||
if (bindToAddr != null && _log.shouldLog(Log.WARN))
|
||||
_log.warn("Binding only to " + bindToAddr);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
@ -461,14 +463,23 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
}
|
||||
|
||||
/**
|
||||
* _externalListenPort should always be set (by startup()) before this is called,
|
||||
* so the returned value should be > 0
|
||||
* The current or configured internal port.
|
||||
* UDPEndpoint should always be instantiated (and a random port picked if not configured)
|
||||
* before this is called, so the returned value should be > 0
|
||||
* unless the endpoint failed to bind.
|
||||
*/
|
||||
@Override
|
||||
public int getRequestedPort() {
|
||||
if (_externalListenPort > 0)
|
||||
return _externalListenPort;
|
||||
return _context.getProperty(PROP_INTERNAL_PORT, -1);
|
||||
if (_endpoint != null) {
|
||||
int rv = _endpoint.getListenPort();
|
||||
if (rv > 0)
|
||||
return rv;
|
||||
}
|
||||
// fallbacks
|
||||
int rv = _context.getProperty(PROP_INTERNAL_PORT, -1);
|
||||
if (rv > 0)
|
||||
return rv;
|
||||
return _context.getProperty(PROP_EXTERNAL_PORT, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user