* Router:

- Auto-hidden mode for bad countries
    - Don't put addresses in our RouterInfo when hidden
This commit is contained in:
zzz
2012-01-10 00:05:17 +00:00
parent c6e6a9d36e
commit 4ad6d699e7
9 changed files with 123 additions and 6 deletions

View File

@@ -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 = "";

View File

@@ -157,6 +157,7 @@
<%=intl._("The router is currently testing whether your UDP port is firewalled.")%>
<li class="tidylist"><b><%=intl._("Hidden")%></b> -
<%=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.")%>
<li class="tidylist"><b><%=intl._("WARN - Firewalled and Fast")%></b> -
<%=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.")%>

View File

@@ -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

View File

@@ -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
*/

View File

@@ -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;
}

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 = 1;
public final static long BUILD = 2;
/** for example "-test" */
public final static String EXTRA = "";

View File

@@ -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<String> _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));
}
}

View File

@@ -176,8 +176,11 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
_manager.renderStatusHTML(out, urlBase, sortFlags);
}
/** @return non-null, possibly empty */
@Override
public Set<RouterAddress> createAddresses() {
if (_context.router().isHidden())
return Collections.EMPTY_SET;
Map<String, RouterAddress> 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
*/

View File

@@ -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();
}
}
/****/
}