Changeset de18ebbb


Ignore:
Timestamp:
May 24, 2009 6:30:47 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c639525
Parents:
47e32c8
Message:

save our own geoip location in the config

Location:
router/java/src/net/i2p/router/transport
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java

    r47e32c8 rde18ebbb  
    405405     *  Uses the transport IP first because that lookup is fast,
    406406     *  then the SSU IP from the netDb.
     407     *
     408     *  @return two-letter lower-case country code or null
    407409     */
    408410    public String getCountry(Hash peer) {
  • router/java/src/net/i2p/router/transport/GeoIP.java

    r47e32c8 rde18ebbb  
    1616import java.util.concurrent.atomic.AtomicBoolean;
    1717
    18 import net.i2p.I2PAppContext;
    1918import net.i2p.data.DataHelper;
     19import net.i2p.router.RouterContext;
    2020import net.i2p.util.ConcurrentHashSet;
    2121import net.i2p.util.Log;
     
    3838public class GeoIP {
    3939    private Log _log;
    40     private I2PAppContext _context;
     40    private RouterContext _context;
    4141    private final Map<String, String> _codeToName;
    4242    private final Map<Long, String> _IPToCountry;
     
    4545    private final AtomicBoolean _lock;
    4646   
    47     public GeoIP(I2PAppContext context) {
     47    public GeoIP(RouterContext context) {
    4848        _context = context;
    4949        _log = context.logManager().getLog(GeoIP.class);
     
    6060    static final String GEOIP_FILE_DEFAULT = "geoip.txt";
    6161    static final String COUNTRY_FILE_DEFAULT = "countries.txt";
     62    public static final String PROP_IP_COUNTRY = "i2np.lastCountry";
    6263
    6364    /**
     
    8889        LookupJob j = new LookupJob();
    8990        j.run();
     91        updateOurCountry();
    9092    }
    9193
     
    234236
    235237    /**
     238     *  Put our country code in the config, where others (such as Timestamper) can get it,
     239     *  and it will be there next time at startup.
     240     */
     241    private void updateOurCountry() {
     242        String oldCountry = _context.router().getConfigSetting(PROP_IP_COUNTRY);
     243        String country = _context.commSystem().getCountry(_context.routerHash());
     244        if (country != null && !country.equals(oldCountry)) {
     245            _context.router().setConfigSetting(PROP_IP_COUNTRY, country);
     246            _context.router().saveConfig();
     247        }
     248    }
     249
     250    /**
    236251     * Add to the list needing lookup
    237252     */
     
    297312    }
    298313
     314/*** doesn't work since switched to RouterContext above
    299315    public static void main(String args[]) {
    300316        GeoIP g = new GeoIP(new I2PAppContext());
     
    310326
    311327    }
     328***/
    312329}
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r47e32c8 rde18ebbb  
    475475            if (!fixedPort)
    476476                _context.router().setConfigSetting(PROP_EXTERNAL_PORT, ourPort+"");
     477            // queue a country code lookup of the new IP
     478            _context.commSystem().queueLookup(ourIP);
    477479            // store these for laptop-mode (change ident on restart... or every time... when IP changes)
    478480            _context.router().setConfigSetting(PROP_IP, _externalListenHost.getHostAddress());
Note: See TracChangeset for help on using the changeset viewer.