diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java index 56a2299e4..8f9a20749 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java @@ -140,7 +140,8 @@ public class ConfigNetHandler extends FormHandler { if (!_ratesOnly) { // IP Settings - String oldUdp = _context.getProperty(UDPTransport.PROP_SOURCES, UDPTransport.DEFAULT_SOURCES); + String oldUdp = _context.getProperty(UDPTransport.PROP_SOURCES, + _context.router().isHidden() ? "hidden" : UDPTransport.DEFAULT_SOURCES); String oldUHost = _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST, ""); if (_udpAutoIP != null) { String uhost = ""; diff --git a/apps/routerconsole/jsp/confignet.jsp b/apps/routerconsole/jsp/confignet.jsp index 78dd68fda..e67f6fe3a 100644 --- a/apps/routerconsole/jsp/confignet.jsp +++ b/apps/routerconsole/jsp/confignet.jsp @@ -157,6 +157,7 @@ <%=intl._("The router is currently testing whether your UDP port is firewalled.")%>
  • <%=intl._("Hidden")%> - <%=intl._("The router is not configured to publish its address, therefore it does not expect incoming connections.")%> + <%=intl._("Hidden mode is automatically enabled for added protection in certain countries.")%>
  • <%=intl._("WARN - Firewalled and Fast")%> - <%=intl._("You have configured I2P to share more than 128KBps of bandwidth, but you are firewalled.")%> <%=intl._("While I2P will work fine in this configuration, if you really have over 128KBps of bandwidth to share, it will be much more helpful to the network if you open your firewall.")%> diff --git a/history.txt b/history.txt index cf153fc66..60c210c2a 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,14 @@ +2012-01-10 zzz + * Console: + - Add info to error 500 page + - Add indication on summary bar when in VM comm system + - Make graceful the default for HUP (ticket #580) + - Fix class error on wrapper 3.1.1 + * i2prouter: Don't attempt to translate strings from script + * Router: + - Auto-hidden mode for bad countries + - Don't put addresses in our RouterInfo when hidden + 2012-01-08 zzz * Plugins: - Enforce min and max Jetty versions at plugin installation diff --git a/router/java/src/net/i2p/router/CommSystemFacade.java b/router/java/src/net/i2p/router/CommSystemFacade.java index f9644f388..9bc1ae535 100644 --- a/router/java/src/net/i2p/router/CommSystemFacade.java +++ b/router/java/src/net/i2p/router/CommSystemFacade.java @@ -61,14 +61,22 @@ public abstract class CommSystemFacade implements Service { public boolean isEstablished(Hash dest) { return false; } public byte[] getIP(Hash dest) { return null; } public void queueLookup(byte[] ip) {} + /** @since 0.8.11 */ public String getOurCountry() { return null; } + + /** @since 0.8.13 */ + public boolean isInBadCountry() { return false; } + public String getCountry(Hash peer) { return null; } public String getCountryName(String code) { return code; } public String renderPeerHTML(Hash peer) { return peer.toBase64().substring(0, 4); } + /** @since 0.8.13 */ + public boolean isDummy() { return true; } + /** * Tell other transports our address changed */ diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 0e95d8c6e..084731b7b 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -241,8 +241,6 @@ public class Router implements RouterClock.ClockShiftListener { String now = Long.toString(System.currentTimeMillis()); _config.put("router.firstInstalled", now); _config.put("router.updateLastInstalled", now); - // only compatible with new i2prouter script - _config.put("router.gracefulHUP", "true"); saveConfig(); } // ********* Start no threads before here ********* // @@ -592,14 +590,22 @@ public class Router implements RouterClock.ClockShiftListener { RouterInfo ri = _routerInfo; if ( (ri != null) && (ri.isHidden()) ) return true; - return _context.getBooleanProperty(PROP_HIDDEN_HIDDEN); + String h = _context.getProperty(PROP_HIDDEN_HIDDEN); + if (h != null) + return Boolean.valueOf(h).booleanValue(); + return _context.commSystem().isInBadCountry(); } /** + * Only called at startup via LoadRouterInfoJob and RebuildRouterInfoJob. + * Not called by periodic RepublishLocalRouterInfoJob. + * We don't want to change the cert on the fly as it changes the router hash. + * RouterInfo.isHidden() checks the capability, but RouterIdentity.isHidden() checks the cert. + * There's no reason to ever add a hidden cert? * @return the certificate for a new RouterInfo - probably a null cert. */ public Certificate createCertificate() { - if (isHidden()) + if (_context.getBooleanProperty(PROP_HIDDEN)) return new Certificate(Certificate.CERTIFICATE_TYPE_HIDDEN, null); return Certificate.NULL_CERT; } diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 87e5bffca..282c18b42 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -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 = 1; + public final static long BUILD = 2; /** for example "-test" */ public final static String EXTRA = ""; diff --git a/router/java/src/net/i2p/router/transport/BadCountries.java b/router/java/src/net/i2p/router/transport/BadCountries.java new file mode 100644 index 000000000..1431dcb60 --- /dev/null +++ b/router/java/src/net/i2p/router/transport/BadCountries.java @@ -0,0 +1,65 @@ +package net.i2p.router.transport; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +/** + * Maintain a list of bad places. + * @since 0.8.13 + */ +abstract class BadCountries { + + private static final Set _countries; + + // zzz.i2p/topics/969 + // List created based on the Press Freedom Index. Those countries with a score of higher than 50 are included: + // http://en.wikipedia.org/wiki/Press_Freedom_Index + // Except: + // I don't really think that is usage of I2P is dangerous in countries from CIS + // General situation is really bad (like in Russia) but people here doesn't have problems with Ecnryption usage. + + static { + String[] c = { + /* Afghanistan */ "AF", + /* Bahrain */ "BH", + /* Brunei */ "BN", + /* Burma */ "MM", + /* China */ "CN", + /* Colombia */ "CO", + /* Cuba */ "CU", + /* Democratic Republic of the Congo */ "CD", + /* Equatorial Guinea */ "GQ", + /* Eritrea */ "ER", + /* Fiji */ "FJ", + /* Honduras */ "HN", + /* Iran */ "IR", + /* Laos */ "LA", + /* Libya */ "LY", + /* Malaysia */ "MY", + /* Nigeria */ "NG", + /* North Korea */ "KP", + /* Pakistan */ "PK", + /* Palestinian Territories */ "PS", + /* Philippines */ "PH", + /* Rwanda */ "RW", + /* Saudi Arabia */ "SA", + /* Somalia */ "SO", + /* Sri Lanka */ "LK", + /* Sudan */ "SD", + /* Swaziland */ "SZ", + /* Syria */ "SY", + /* Thailand */ "TH", + /* Tunisia */ "TN", + /* Vietnam */ "VN", + /* Yemen */ "YE" + }; + _countries = new HashSet(Arrays.asList(c)); + } + + /** @param country non-null, two letter code, case-independent */ + public static boolean contains(String country) { + return _countries.contains(country.toUpperCase(Locale.US)); + } +} diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index f4ddab5e4..c1302b9aa 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -176,8 +176,11 @@ public class CommSystemFacadeImpl extends CommSystemFacade { _manager.renderStatusHTML(out, urlBase, sortFlags); } + /** @return non-null, possibly empty */ @Override public Set createAddresses() { + if (_context.router().isHidden()) + return Collections.EMPTY_SET; Map addresses = null; boolean newCreated = false; @@ -450,6 +453,15 @@ public class CommSystemFacadeImpl extends CommSystemFacade { return _context.getProperty(GeoIP.PROP_IP_COUNTRY); } + /** + * Are we in a bad place + * @since 0.8.13 + */ + public boolean isInBadCountry() { + String us = getOurCountry(); + return us != null && (BadCountries.contains(us) || _context.getBooleanProperty("router.forceBadCountry")); + } + /** * Uses the transport IP first because that lookup is fast, * then the SSU IP from the netDb. @@ -517,6 +529,10 @@ public class CommSystemFacadeImpl extends CommSystemFacade { return buf.toString(); } + /** @since 0.8.13 */ + @Override + public boolean isDummy() { return false; } + /** * Translate */ diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java index a8c8d04df..8a97a1f5f 100644 --- a/router/java/src/net/i2p/router/transport/GeoIP.java +++ b/router/java/src/net/i2p/router/transport/GeoIP.java @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import net.i2p.I2PAppContext; import net.i2p.data.DataHelper; import net.i2p.data.Hash; +import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.Log; @@ -283,6 +284,14 @@ class GeoIP { if (country != null && !country.equals(oldCountry)) { _context.router().setConfigSetting(PROP_IP_COUNTRY, country); _context.router().saveConfig(); + if (_context.commSystem().isInBadCountry() && _context.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"); + _context.router().rebuildRouterInfo(); + } } /****/ }