forked from I2P_Developers/i2p.i2p
Transport: Start first GeoIP lookup when netdb is ready
This commit is contained in:
@ -184,6 +184,12 @@ public abstract class CommSystemFacade implements Service {
|
||||
*/
|
||||
public DHSessionKeyBuilder.Factory getDHFactory() { return null; }
|
||||
|
||||
/**
|
||||
* Router must call after netdb is initialized
|
||||
* @since 0.9.41
|
||||
*/
|
||||
public void initGeoIP() {}
|
||||
|
||||
/*
|
||||
* Reachability status codes
|
||||
*
|
||||
|
@ -875,6 +875,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
// so we probably don't need to throw it to the timer queue,
|
||||
// but just to be safe
|
||||
_context.simpleTimer2().addEvent(r, 0);
|
||||
_context.commSystem().initGeoIP();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import net.i2p.util.I2PThread;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
import net.i2p.util.SystemVersion;
|
||||
import net.i2p.util.Translate;
|
||||
|
||||
public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
@ -55,7 +56,6 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
_netMonitorStatus = true;
|
||||
_geoIP = new GeoIP(_context);
|
||||
_manager = new TransportManager(_context);
|
||||
startGeoIP();
|
||||
}
|
||||
|
||||
public synchronized void startup() {
|
||||
@ -363,8 +363,17 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
* tunnel selection, banlisting, etc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Router must call after netdb is initialized
|
||||
* @since 0.9.41
|
||||
*/
|
||||
@Override
|
||||
public void initGeoIP() {
|
||||
startGeoIP();
|
||||
}
|
||||
|
||||
/* We hope the routerinfos are read in and things have settled down by now, but it's not required to be so */
|
||||
private static final int START_DELAY = 5*60*1000;
|
||||
private static final int START_DELAY = SystemVersion.isSlow() ? 5*60*1000 : 5*1000;
|
||||
private static final int LOOKUP_TIME = 30*60*1000;
|
||||
|
||||
private void startGeoIP() {
|
||||
|
@ -126,7 +126,7 @@ public class GeoIP {
|
||||
* Blocking lookup of all pending IPs.
|
||||
* Results will be added to the table and available via get() after completion.
|
||||
*/
|
||||
public void blockingLookup() {
|
||||
void blockingLookup() {
|
||||
if (! _context.getBooleanPropertyDefaultTrue(PROP_GEOIP_ENABLED)) {
|
||||
_pendingSearch.clear();
|
||||
_pendingIPv6Search.clear();
|
||||
@ -153,6 +153,7 @@ public class GeoIP {
|
||||
return;
|
||||
File geoip2 = getGeoIP2();
|
||||
DatabaseReader dbr = null;
|
||||
long start = _context.clock().now();
|
||||
try {
|
||||
// clear the negative cache every few runs, to prevent it from getting too big
|
||||
if (((++_lookupRunCount) % CLEAR) == 0)
|
||||
@ -295,6 +296,8 @@ public class GeoIP {
|
||||
if (dbr != null) try { dbr.close(); } catch (IOException ioe) {}
|
||||
_lock.set(false);
|
||||
}
|
||||
if (_log.shouldInfo())
|
||||
_log.info("GeoIP processing finished, time: " + (_context.clock().now() - start));
|
||||
}
|
||||
}
|
||||
|
||||
@ -423,7 +426,6 @@ public class GeoIP {
|
||||
}
|
||||
String[] rv = new String[search.length];
|
||||
int idx = 0;
|
||||
long start = _context.clock().now();
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
String buf = null;
|
||||
@ -459,9 +461,6 @@ public class GeoIP {
|
||||
if (br != null) try { br.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
|
||||
if (_log.shouldLog(Log.INFO)) {
|
||||
_log.info("GeoIP processing finished, time: " + (_context.clock().now() - start));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -499,7 +498,7 @@ public class GeoIP {
|
||||
* Add to the list needing lookup
|
||||
* @param ip IPv4 or IPv6
|
||||
*/
|
||||
public void add(String ip) {
|
||||
void add(String ip) {
|
||||
byte[] pib = Addresses.getIP(ip);
|
||||
if (pib == null) return;
|
||||
add(pib);
|
||||
@ -509,7 +508,7 @@ public class GeoIP {
|
||||
* Add to the list needing lookup
|
||||
* @param ip IPv4 or IPv6
|
||||
*/
|
||||
public void add(byte ip[]) {
|
||||
void add(byte ip[]) {
|
||||
add(toLong(ip));
|
||||
}
|
||||
|
||||
@ -529,7 +528,7 @@ public class GeoIP {
|
||||
* @param ip IPv4 or IPv6
|
||||
* @return lower-case code, generally two letters, or null.
|
||||
*/
|
||||
public String get(String ip) {
|
||||
String get(String ip) {
|
||||
byte[] pib = Addresses.getIP(ip);
|
||||
if (pib == null) return null;
|
||||
return get(pib);
|
||||
@ -540,7 +539,7 @@ public class GeoIP {
|
||||
* @param ip IPv4 or IPv6
|
||||
* @return lower-case code, generally two letters, or null.
|
||||
*/
|
||||
public String get(byte ip[]) {
|
||||
String get(byte ip[]) {
|
||||
return get(toLong(ip));
|
||||
}
|
||||
|
||||
@ -597,7 +596,7 @@ public class GeoIP {
|
||||
* @param code two-letter lower case code
|
||||
* @return untranslated name or null
|
||||
*/
|
||||
public String fullName(String code) {
|
||||
String fullName(String code) {
|
||||
return _codeToName.get(code);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user