Transport: Fix issues with leaving hidden mode (ticket #2557)

Lookup our IP even if not in our RI
Lookup IPv6 addresses detected in UDP
Javadocs
This commit is contained in:
zzz
2019-06-26 16:12:19 +00:00
parent 87109c8fef
commit 3e8386382b
5 changed files with 69 additions and 18 deletions

View File

@@ -1,3 +1,6 @@
2019-06-26 zzz
* Transport: Fix issues with leaving hidden mode (ticket #2557)
2019-06-25 zzz
* I2CP: Prevent sending message to a local meta destination
* imagegen: Catch render error (ticket #2507)

View File

@@ -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 = 13;
public final static long BUILD = 14;
/** for example "-test" */
public final static String EXTRA = "-rc";

View File

@@ -426,6 +426,9 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
}
}
/**
* @param ip ipv4 or ipv6
*/
@Override
public void queueLookup(byte[] ip) {
_geoIP.add(ip);
@@ -441,17 +444,20 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
}
/**
* Are we in a bad place
* Are we in a strict country
* @since 0.8.13
*/
@Override
public boolean isInStrictCountry() {
String us = getOurCountry();
return (us != null && StrictCountries.contains(us)) || _context.getBooleanProperty("router.forceBadCountry");
return (us != null && StrictCountries.contains(us)) || _context.getBooleanProperty("router.forceStrictCountry");
}
/**
* Are they in a bad place
* Are they in a strict country.
* Not recommended for our local router hash, as we may not be either in the cache or netdb,
* or may not be publishing an IP.
*
* @param peer non-null
* @since 0.9.16
*/
@@ -462,7 +468,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
}
/**
* Are they in a bad place
* Are they in a strict country
* @param ri non-null
* @since 0.9.16
*/
@@ -478,6 +484,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
/**
* Uses the transport IP first because that lookup is fast,
* then the IP from the netDb.
* Not recommended for our local router hash, as we may not be either in the cache or netdb,
* or may not be publishing an IP.
*
* As of 0.9.32, works only for literal IPs, returns null for host names.
*

View File

@@ -24,8 +24,11 @@ import com.maxmind.geoip2.DatabaseReader;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import net.i2p.data.router.RouterAddress;
import net.i2p.data.router.RouterInfo;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.router.transport.udp.UDPTransport;
import net.i2p.util.Addresses;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log;
@@ -160,6 +163,14 @@ public class GeoIP {
// clear the negative cache every few runs, to prevent it from getting too big
if (((++_lookupRunCount) % CLEAR) == 0)
_notFound.clear();
// add our detected addresses
Set<String> addrs = Addresses.getAddresses(false, true);
for (String ip : addrs) {
add(ip);
}
String lastIP = _context.getProperty(UDPTransport.PROP_IP);
if (lastIP != null)
add(lastIP);
// IPv4
Long[] search = _pendingSearch.toArray(new Long[_pendingSearch.size()]);
_pendingSearch.clear();
@@ -477,23 +488,53 @@ public class GeoIP {
return;
RouterContext ctx = (RouterContext) _context;
String oldCountry = ctx.router().getConfigSetting(PROP_IP_COUNTRY);
Hash ourHash = ctx.routerHash();
RouterInfo us = ctx.router().getRouterInfo();
String country = null;
// we should always have a RouterInfo by now, but we had one report of an NPE here
if (ourHash == null)
return;
String country = ctx.commSystem().getCountry(ourHash);
if (us != null) {
// try our published addresses
for (RouterAddress ra : us.getAddresses()) {
byte[] ip = ra.getIP();
if (ip != null) {
country = get(ip);
if (country != null)
break;
}
}
}
if (country == null) {
// try our detected addresses
Set<String> addrs = Addresses.getAddresses(false, true);
for (String ip : addrs) {
country = get(ip);
if (country != null)
break;
}
if (country == null) {
String lastIP = _context.getProperty(UDPTransport.PROP_IP);
if (lastIP != null)
country = get(lastIP);
}
}
if (_log.shouldInfo())
_log.info("Old country was " + oldCountry + " new country is " + country);
if (country != null && !country.equals(oldCountry)) {
boolean wasStrict = ctx.commSystem().isInStrictCountry();
ctx.router().saveConfig(PROP_IP_COUNTRY, country);
if (ctx.commSystem().isInStrictCountry() && ctx.getProperty(Router.PROP_HIDDEN_HIDDEN) == null) {
String name = fullName(country);
if (name == null)
name = country;
_log.logAlways(Log.WARN, "Setting hidden mode to protect you in " + name +
", you may override on the network configuration page");
boolean isStrict = ctx.commSystem().isInStrictCountry();
if (_log.shouldInfo())
_log.info("Old country was strict? " + wasStrict + "; new country is strict? " + isStrict);
if (wasStrict != isStrict && ctx.getProperty(Router.PROP_HIDDEN_HIDDEN) == null) {
if (isStrict) {
String name = fullName(country);
if (name == null)
name = country;
_log.logAlways(Log.WARN, "Setting hidden mode to protect you in " + name +
", you may override on the network configuration page");
}
ctx.router().rebuildRouterInfo();
}
}
/****/
}
/**

View File

@@ -1044,8 +1044,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (ourIP.length == 4 && !fixedPort)
changes.put(PROP_EXTERNAL_PORT, Integer.toString(ourPort));
// queue a country code lookup of the new IP
if (ourIP.length == 4)
_context.commSystem().queueLookup(ourIP);
_context.commSystem().queueLookup(ourIP);
// store these for laptop-mode (change ident on restart... or every time... when IP changes)
// IPV4 ONLY
String oldIP = _context.getProperty(PROP_IP);