diff --git a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java index c5e479a76..a27ea1221 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java @@ -1147,13 +1147,13 @@ public class ConsoleUpdateManager implements UpdateManager, RouterApp { return rv; } - ///////// End UpdateManager interface - /** * Adds to installed, removes from downloaded and available + * @param id subtype for plugins, or "" * @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); if (version == null) { _installed.remove(ui); @@ -1173,6 +1173,8 @@ public class ConsoleUpdateManager implements UpdateManager, RouterApp { _available.remove(ui); } + ///////// End UpdateManager interface + /** * Adds to downloaded, removes from available */ diff --git a/core/java/src/net/i2p/update/UpdateManager.java b/core/java/src/net/i2p/update/UpdateManager.java index 57065dcb3..716c2fbac 100644 --- a/core/java/src/net/i2p/update/UpdateManager.java +++ b/core/java/src/net/i2p/update/UpdateManager.java @@ -230,6 +230,15 @@ public interface UpdateManager { */ 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 */ diff --git a/core/java/src/net/i2p/update/UpdateType.java b/core/java/src/net/i2p/update/UpdateType.java index 8277df98c..548a84c67 100644 --- a/core/java/src/net/i2p/update/UpdateType.java +++ b/core/java/src/net/i2p/update/UpdateType.java @@ -12,7 +12,6 @@ public enum UpdateType { ROUTER_SIGNED, ROUTER_UNSIGNED, PLUGIN, - /** unused */ GEOIP, BLOCKLIST, /** unused */ diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java index 358cf1f4c..ce77b9c4c 100644 --- a/router/java/src/net/i2p/router/transport/GeoIP.java +++ b/router/java/src/net/i2p/router/transport/GeoIP.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.Arrays; +import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -22,6 +23,7 @@ import com.maxmind.geoip.LookupService; import com.maxmind.geoip2.DatabaseReader; import net.i2p.I2PAppContext; +import net.i2p.app.ClientAppManager; import net.i2p.data.DataHelper; import net.i2p.data.Hash; 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.RouterContext; 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.ConcurrentHashSet; import net.i2p.util.Log; @@ -185,6 +189,9 @@ public class GeoIP { LookupService ls = null; try { 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++) { Long ipl = search[i]; long ip = ipl.longValue(); @@ -251,6 +258,9 @@ public class GeoIP { LookupService ls = null; try { 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++) { Long ipl = search[i]; long ip = ipl.longValue(); @@ -347,6 +357,8 @@ public class GeoIP { DatabaseReader rv = b.build(); if (_log.shouldDebug()) _log.debug("Opened GeoIP2 Database, Metadata: " + rv.getMetadata()); + long time = rv.getMetadata().getBuildDate().getTime(); + notifyVersion("GeoIP2", time); return rv; } @@ -447,6 +459,7 @@ public class GeoIP { String buf = null; br = new BufferedReader(new InputStreamReader( new FileInputStream(geoFile), "ISO-8859-1")); + notifyVersion("Torv4", geoFile.lastModified()); while ((buf = br.readLine()) != null && idx < search.length) { try { if (buf.charAt(0) == '#') { @@ -480,6 +493,31 @@ public class GeoIP { 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, * and it will be there next time at startup. diff --git a/router/java/src/net/i2p/router/transport/GeoIPv6.java b/router/java/src/net/i2p/router/transport/GeoIPv6.java index 7f36aa6dc..ef7c6813b 100644 --- a/router/java/src/net/i2p/router/transport/GeoIPv6.java +++ b/router/java/src/net/i2p/router/transport/GeoIPv6.java @@ -65,7 +65,7 @@ public class GeoIPv6 { log.warn("GeoIP file not found: " + geoFile.getAbsolutePath()); 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. * Individual array elements will be null for lookup failure of that item. */ - private static String[] readGeoIPFile(File geoFile, Long[] search, Map codeCache, Log log) { + private static String[] readGeoIPFile(I2PAppContext context, File geoFile, Long[] search, Map codeCache, Log log) { String[] rv = new String[search.length]; int idx = 0; long start = System.currentTimeMillis(); InputStream in = null; try { in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(geoFile))); + GeoIP.notifyVersion(context, "I2Pv6", geoFile.lastModified()); byte[] magic = new byte[MAGIC.length()]; DataHelper.read(in, magic); if (!DataHelper.eq(magic, DataHelper.getASCII(MAGIC))) @@ -368,6 +369,7 @@ public class GeoIPv6 { System.exit(1); } // readback for testing - readGeoIPFile(outfile, new Long[] { Long.MAX_VALUE }, Collections. emptyMap(), new Log(GeoIPv6.class)); + readGeoIPFile(I2PAppContext.getGlobalContext(), outfile, new Long[] { Long.MAX_VALUE }, + Collections. emptyMap(), new Log(GeoIPv6.class)); } }