Changeset 38bfca1


Ignore:
Timestamp:
Feb 13, 2011 8:29:59 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
8549988
Parents:
1f702f1e
Message:
  • GeoIP: Prevent startup NPE (ticket #413, thanks RN)
Location:
router/java/src/net/i2p/router
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/RouterContext.java

    r1f702f1e r38bfca1  
    77import net.i2p.I2PAppContext;
    88import net.i2p.data.Hash;
     9import net.i2p.data.RouterInfo;
    910import net.i2p.internal.InternalClientManager;
    1011import net.i2p.router.client.ClientManagerFacadeImpl;
     
    171172    /** what router is this context working for? */
    172173    public Router router() { return _router; }
    173     /** convenience method for querying the router's ident */
    174     public Hash routerHash() { return _router.getRouterInfo().getIdentity().getHash(); }
     174
     175    /**
     176     *  Convenience method for getting the router hash.
     177     *  Equivalent to context.router().getRouterInfo().getIdentity().getHash()
     178     *  @return may be null if called very early
     179     */
     180    public Hash routerHash() {
     181        if (_router == null)
     182            return null;
     183        RouterInfo ri = _router.getRouterInfo();
     184        if (ri == null)
     185            return null;
     186        return ri.getIdentity().getHash();
     187    }
    175188
    176189    /**
  • router/java/src/net/i2p/router/transport/GeoIP.java

    r1f702f1e r38bfca1  
    1717
    1818import net.i2p.data.DataHelper;
     19import net.i2p.data.Hash;
    1920import net.i2p.router.RouterContext;
    2021import net.i2p.util.ConcurrentHashSet;
     
    252253    private void updateOurCountry() {
    253254        String oldCountry = _context.router().getConfigSetting(PROP_IP_COUNTRY);
    254         String country = _context.commSystem().getCountry(_context.routerHash());
     255        Hash ourHash = _context.routerHash();
     256        // we should always have a RouterInfo by now, but we had one report of an NPE here
     257        if (ourHash == null)
     258            return;
     259        String country = _context.commSystem().getCountry(ourHash);
    255260        if (country != null && !country.equals(oldCountry)) {
    256261            _context.router().setConfigSetting(PROP_IP_COUNTRY, country);
Note: See TracChangeset for help on using the changeset viewer.