forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 96b4e09e85e0947d0b9df188f4861664073f07a6)
to branch 'i2p.i2p.zzz.jetty6' (head 4024ef4f6e6c5e4ca6a7803614dc769ca654ac5f)
This commit is contained in:
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 = "";
|
||||
|
65
router/java/src/net/i2p/router/transport/BadCountries.java
Normal file
65
router/java/src/net/i2p/router/transport/BadCountries.java
Normal 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));
|
||||
}
|
||||
}
|
@ -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
|
||||
*/
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
/****/
|
||||
}
|
||||
|
Reference in New Issue
Block a user