forked from I2P_Developers/i2p.i2p
* GeoIP: Prevent startup NPE (ticket #413, thanks RN)
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.RouterInfo;
|
||||
import net.i2p.internal.InternalClientManager;
|
||||
import net.i2p.router.client.ClientManagerFacadeImpl;
|
||||
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
||||
@@ -170,8 +171,20 @@ public class RouterContext extends I2PAppContext {
|
||||
|
||||
/** what router is this context working for? */
|
||||
public Router router() { return _router; }
|
||||
/** convenience method for querying the router's ident */
|
||||
public Hash routerHash() { return _router.getRouterInfo().getIdentity().getHash(); }
|
||||
|
||||
/**
|
||||
* Convenience method for getting the router hash.
|
||||
* Equivalent to context.router().getRouterInfo().getIdentity().getHash()
|
||||
* @return may be null if called very early
|
||||
*/
|
||||
public Hash routerHash() {
|
||||
if (_router == null)
|
||||
return null;
|
||||
RouterInfo ri = _router.getRouterInfo();
|
||||
if (ri == null)
|
||||
return null;
|
||||
return ri.getIdentity().getHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* How are we coordinating clients for the router?
|
||||
|
@@ -16,6 +16,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.Log;
|
||||
@@ -251,7 +252,11 @@ class GeoIP {
|
||||
*/
|
||||
private void updateOurCountry() {
|
||||
String oldCountry = _context.router().getConfigSetting(PROP_IP_COUNTRY);
|
||||
String country = _context.commSystem().getCountry(_context.routerHash());
|
||||
Hash ourHash = _context.routerHash();
|
||||
// we should always have a RouterInfo by now, but we had one report of an NPE here
|
||||
if (ourHash == null)
|
||||
return;
|
||||
String country = _context.commSystem().getCountry(ourHash);
|
||||
if (country != null && !country.equals(oldCountry)) {
|
||||
_context.router().setConfigSetting(PROP_IP_COUNTRY, country);
|
||||
_context.router().saveConfig();
|
||||
|
Reference in New Issue
Block a user