forked from I2P_Developers/i2p.i2p
Update manager: Notify GeoIP type and file version
This commit is contained in:
@ -1147,13 +1147,13 @@ public class ConsoleUpdateManager implements UpdateManager, RouterApp {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////// End UpdateManager interface
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds to installed, removes from downloaded and available
|
* Adds to installed, removes from downloaded and available
|
||||||
|
* @param id subtype for plugins, or ""
|
||||||
* @param version null to remove from installed
|
* @param version null to remove from installed
|
||||||
|
* @since public since 0.9.45
|
||||||
*/
|
*/
|
||||||
private void notifyInstalled(UpdateType type, String id, String version) {
|
public void notifyInstalled(UpdateType type, String id, String version) {
|
||||||
UpdateItem ui = new UpdateItem(type, id);
|
UpdateItem ui = new UpdateItem(type, id);
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
_installed.remove(ui);
|
_installed.remove(ui);
|
||||||
@ -1173,6 +1173,8 @@ public class ConsoleUpdateManager implements UpdateManager, RouterApp {
|
|||||||
_available.remove(ui);
|
_available.remove(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////// End UpdateManager interface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds to downloaded, removes from available
|
* Adds to downloaded, removes from available
|
||||||
*/
|
*/
|
||||||
|
@ -230,6 +230,15 @@ public interface UpdateManager {
|
|||||||
*/
|
*/
|
||||||
public String getStatus();
|
public String getStatus();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the UpdateManager that a version is already installed.
|
||||||
|
*
|
||||||
|
* @param id subtype for plugins, or ""
|
||||||
|
* @param version null to remove from installed
|
||||||
|
* @since 0.9.45
|
||||||
|
*/
|
||||||
|
public void notifyInstalled(UpdateType type, String id, String version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For debugging
|
* For debugging
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,6 @@ public enum UpdateType {
|
|||||||
ROUTER_SIGNED,
|
ROUTER_SIGNED,
|
||||||
ROUTER_UNSIGNED,
|
ROUTER_UNSIGNED,
|
||||||
PLUGIN,
|
PLUGIN,
|
||||||
/** unused */
|
|
||||||
GEOIP,
|
GEOIP,
|
||||||
BLOCKLIST,
|
BLOCKLIST,
|
||||||
/** unused */
|
/** unused */
|
||||||
|
@ -10,6 +10,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -22,6 +23,7 @@ import com.maxmind.geoip.LookupService;
|
|||||||
import com.maxmind.geoip2.DatabaseReader;
|
import com.maxmind.geoip2.DatabaseReader;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.app.ClientAppManager;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.data.router.RouterAddress;
|
import net.i2p.data.router.RouterAddress;
|
||||||
@ -29,6 +31,8 @@ import net.i2p.data.router.RouterInfo;
|
|||||||
import net.i2p.router.Router;
|
import net.i2p.router.Router;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.transport.udp.UDPTransport;
|
import net.i2p.router.transport.udp.UDPTransport;
|
||||||
|
import net.i2p.update.UpdateManager;
|
||||||
|
import net.i2p.update.UpdateType;
|
||||||
import net.i2p.util.Addresses;
|
import net.i2p.util.Addresses;
|
||||||
import net.i2p.util.ConcurrentHashSet;
|
import net.i2p.util.ConcurrentHashSet;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
@ -185,6 +189,9 @@ public class GeoIP {
|
|||||||
LookupService ls = null;
|
LookupService ls = null;
|
||||||
try {
|
try {
|
||||||
ls = new LookupService(f, LookupService.GEOIP_STANDARD);
|
ls = new LookupService(f, LookupService.GEOIP_STANDARD);
|
||||||
|
Date date = ls.getDatabaseInfo().getDate();
|
||||||
|
if (date != null)
|
||||||
|
notifyVersion("GeoIPv4", date.getTime());
|
||||||
for (int i = 0; i < search.length; i++) {
|
for (int i = 0; i < search.length; i++) {
|
||||||
Long ipl = search[i];
|
Long ipl = search[i];
|
||||||
long ip = ipl.longValue();
|
long ip = ipl.longValue();
|
||||||
@ -251,6 +258,9 @@ public class GeoIP {
|
|||||||
LookupService ls = null;
|
LookupService ls = null;
|
||||||
try {
|
try {
|
||||||
ls = new LookupService(f, LookupService.GEOIP_STANDARD);
|
ls = new LookupService(f, LookupService.GEOIP_STANDARD);
|
||||||
|
Date date = ls.getDatabaseInfo().getDate();
|
||||||
|
if (date != null)
|
||||||
|
notifyVersion("GeoIPv6", date.getTime());
|
||||||
for (int i = 0; i < search.length; i++) {
|
for (int i = 0; i < search.length; i++) {
|
||||||
Long ipl = search[i];
|
Long ipl = search[i];
|
||||||
long ip = ipl.longValue();
|
long ip = ipl.longValue();
|
||||||
@ -347,6 +357,8 @@ public class GeoIP {
|
|||||||
DatabaseReader rv = b.build();
|
DatabaseReader rv = b.build();
|
||||||
if (_log.shouldDebug())
|
if (_log.shouldDebug())
|
||||||
_log.debug("Opened GeoIP2 Database, Metadata: " + rv.getMetadata());
|
_log.debug("Opened GeoIP2 Database, Metadata: " + rv.getMetadata());
|
||||||
|
long time = rv.getMetadata().getBuildDate().getTime();
|
||||||
|
notifyVersion("GeoIP2", time);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,6 +459,7 @@ public class GeoIP {
|
|||||||
String buf = null;
|
String buf = null;
|
||||||
br = new BufferedReader(new InputStreamReader(
|
br = new BufferedReader(new InputStreamReader(
|
||||||
new FileInputStream(geoFile), "ISO-8859-1"));
|
new FileInputStream(geoFile), "ISO-8859-1"));
|
||||||
|
notifyVersion("Torv4", geoFile.lastModified());
|
||||||
while ((buf = br.readLine()) != null && idx < search.length) {
|
while ((buf = br.readLine()) != null && idx < search.length) {
|
||||||
try {
|
try {
|
||||||
if (buf.charAt(0) == '#') {
|
if (buf.charAt(0) == '#') {
|
||||||
@ -480,6 +493,31 @@ public class GeoIP {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the update manager.
|
||||||
|
*
|
||||||
|
* @since 0.9.45
|
||||||
|
*/
|
||||||
|
private void notifyVersion(String subtype, long version) {
|
||||||
|
notifyVersion(_context, subtype, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the update manager.
|
||||||
|
*
|
||||||
|
* @since 0.9.45
|
||||||
|
*/
|
||||||
|
static void notifyVersion(I2PAppContext ctx, String subtype, long version) {
|
||||||
|
if (version <= 0)
|
||||||
|
return;
|
||||||
|
ClientAppManager cmgr = ctx.clientAppManager();
|
||||||
|
if (cmgr != null) {
|
||||||
|
UpdateManager umgr = (UpdateManager) cmgr.getRegisteredApp(UpdateManager.APP_NAME);
|
||||||
|
if (umgr != null)
|
||||||
|
umgr.notifyInstalled(UpdateType.GEOIP, subtype, Long.toString(version));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put our country code in the config, where others (such as Timestamper) can get it,
|
* Put our country code in the config, where others (such as Timestamper) can get it,
|
||||||
* and it will be there next time at startup.
|
* and it will be there next time at startup.
|
||||||
|
@ -65,7 +65,7 @@ public class GeoIPv6 {
|
|||||||
log.warn("GeoIP file not found: " + geoFile.getAbsolutePath());
|
log.warn("GeoIP file not found: " + geoFile.getAbsolutePath());
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
return readGeoIPFile(geoFile, search, codeCache, log);
|
return readGeoIPFile(context, geoFile, search, codeCache, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,13 +77,14 @@ public class GeoIPv6 {
|
|||||||
* or a zero-length array on total failure.
|
* or a zero-length array on total failure.
|
||||||
* Individual array elements will be null for lookup failure of that item.
|
* Individual array elements will be null for lookup failure of that item.
|
||||||
*/
|
*/
|
||||||
private static String[] readGeoIPFile(File geoFile, Long[] search, Map<String, String> codeCache, Log log) {
|
private static String[] readGeoIPFile(I2PAppContext context, File geoFile, Long[] search, Map<String, String> codeCache, Log log) {
|
||||||
String[] rv = new String[search.length];
|
String[] rv = new String[search.length];
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(geoFile)));
|
in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(geoFile)));
|
||||||
|
GeoIP.notifyVersion(context, "I2Pv6", geoFile.lastModified());
|
||||||
byte[] magic = new byte[MAGIC.length()];
|
byte[] magic = new byte[MAGIC.length()];
|
||||||
DataHelper.read(in, magic);
|
DataHelper.read(in, magic);
|
||||||
if (!DataHelper.eq(magic, DataHelper.getASCII(MAGIC)))
|
if (!DataHelper.eq(magic, DataHelper.getASCII(MAGIC)))
|
||||||
@ -368,6 +369,7 @@ public class GeoIPv6 {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
// readback for testing
|
// readback for testing
|
||||||
readGeoIPFile(outfile, new Long[] { Long.MAX_VALUE }, Collections.<String, String> emptyMap(), new Log(GeoIPv6.class));
|
readGeoIPFile(I2PAppContext.getGlobalContext(), outfile, new Long[] { Long.MAX_VALUE },
|
||||||
|
Collections.<String, String> emptyMap(), new Log(GeoIPv6.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user