From 2d239edf34e2f58216b2147de1f86137c81d3184 Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 5 Sep 2021 10:47:10 -0400 Subject: [PATCH] Update: Get backup URLs from news feed Remove hardcoded backup URLs Parse i2p, clearnet, and clearnet-ssl URLs from news Write i2p, clearnet, and clearnet-ssl URLs to old news format Clearnet and clearnet-ssl URLs currently unused; no handler is registered --- .../src/net/i2p/router/news/NewsMetadata.java | 11 ++++ .../net/i2p/router/news/NewsXMLParser.java | 32 +++++++++- .../router/update/ConsoleUpdateManager.java | 14 +---- .../net/i2p/router/update/NewsFetcher.java | 60 +++++++++++++++---- .../i2p/router/web/ConfigUpdateHandler.java | 18 ------ 5 files changed, 92 insertions(+), 43 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/news/NewsMetadata.java b/apps/routerconsole/java/src/net/i2p/router/news/NewsMetadata.java index 9abf512ef..2e8872661 100644 --- a/apps/routerconsole/java/src/net/i2p/router/news/NewsMetadata.java +++ b/apps/routerconsole/java/src/net/i2p/router/news/NewsMetadata.java @@ -63,8 +63,19 @@ public class NewsMetadata { public static class Update implements Comparable { public String type; public String torrent; + /** + * Stored as of 0.9.52, but there is no registered handler + */ public List clearnet; + /** + * Stored as of 0.9.52, but there is no registered handler + */ public List ssl; + /** + * In-net URLs + * @since 0.9.52 + */ + public List i2pnet; @Override public int compareTo(Update other) { diff --git a/apps/routerconsole/java/src/net/i2p/router/news/NewsXMLParser.java b/apps/routerconsole/java/src/net/i2p/router/news/NewsXMLParser.java index 710d293bd..16240cbfe 100644 --- a/apps/routerconsole/java/src/net/i2p/router/news/NewsXMLParser.java +++ b/apps/routerconsole/java/src/net/i2p/router/news/NewsXMLParser.java @@ -258,7 +258,37 @@ public class NewsXMLParser { String href = t.getAttributeValue("href"); if (href.length() > 0) { update.torrent = href.trim(); - totalSources += 1; + totalSources++; + } + } + List urlNodes = getNodes(u, "i2p:clearnet"); + for (Node n1 : urlNodes) { + String href = n1.getAttributeValue("href"); + if (href.length() > 0) { + if (update.clearnet == null) + update.clearnet = new ArrayList(4); + update.clearnet.add(href.trim()); + totalSources++; + } + } + urlNodes = getNodes(u, "i2p:clearnetssl"); + for (Node n2 : urlNodes) { + String href = n2.getAttributeValue("href"); + if (href.length() > 0) { + if (update.ssl == null) + update.ssl = new ArrayList(4); + update.ssl.add(href.trim()); + totalSources++; + } + } + urlNodes = getNodes(u, "i2p:url"); + for (Node n3 : urlNodes) { + String href = n3.getAttributeValue("href"); + if (href.length() > 0) { + if (update.i2pnet == null) + update.i2pnet = new ArrayList(4); + update.i2pnet.add(href.trim()); + totalSources++; } } 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 a1f461e24..14582769c 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java @@ -1293,18 +1293,8 @@ public class ConsoleUpdateManager implements UpdateManager, RouterApp { } case ROUTER_SIGNED_SU3: - { - String URLs = ConfigUpdateHandler.SU3_UPDATE_URLS; - StringTokenizer tok = new StringTokenizer(URLs, " ,\r\n"); - List rv = new ArrayList(); - while (tok.hasMoreTokens()) { - try { - rv.add(new URI(tok.nextToken().trim())); - } catch (URISyntaxException use) {} - } - Collections.shuffle(rv, _context.random()); - return rv; - } + // handled in NewsFetcher + break; case ROUTER_UNSIGNED: String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL); diff --git a/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java b/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java index 249a34b00..5043ca623 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java @@ -14,7 +14,6 @@ import java.net.URISyntaxException; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -205,8 +204,13 @@ class NewsFetcher extends UpdateRunner { private static final String CLEARNET_SU2_KEY = "su2clearnet"; private static final String CLEARNET_HTTP_SU3_KEY = "su3clearnet"; private static final String CLEARNET_HTTPS_SU3_KEY = "su3ssl"; - private static final String I2P_SUD_KEY = "sudi2p"; - private static final String I2P_SU2_KEY = "su2i2p"; + // unused + //private static final String I2P_SUD_KEY = "sudi2p"; + //private static final String I2P_SU2_KEY = "su2i2p"; + /** + * @since 0.9.52 + */ + private static final String I2P_SU3_KEY = "su3i2p"; /** * Parse the installed (not the temp) news file for the latest version. @@ -281,14 +285,14 @@ class NewsFetcher extends UpdateRunner { Map> sourceMap = new HashMap>(4); // Must do su3 first //if (ConfigUpdateHandler.USE_SU3_UPDATE) { - sourceMap.put(HTTP, _mgr.getUpdateURLs(ROUTER_SIGNED_SU3, "", HTTP)); + addMethod(HTTP, args.get(I2P_SU3_KEY), sourceMap); addMethod(TORRENT, args.get(SU3_KEY), sourceMap); addMethod(HTTP_CLEARNET, args.get(CLEARNET_HTTP_SU3_KEY), sourceMap); addMethod(HTTPS_CLEARNET, args.get(CLEARNET_HTTPS_SU3_KEY), sourceMap); // notify about all sources at once _mgr.notifyVersionAvailable(this, _currentURI, ROUTER_SIGNED_SU3, "", sourceMap, ver, ""); - sourceMap.clear(); + // sourceMap.clear(); //} // now do sud/su2 - DISABLED //sourceMap.put(HTTP, _mgr.getUpdateURLs(ROUTER_SIGNED, "", HTTP)); @@ -630,13 +634,13 @@ class NewsFetcher extends UpdateRunner { long oldTime = _context.getProperty(PROP_BLOCKLIST_TIME, 0L); if (ble.updated <= oldTime) { if (_log.shouldWarn()) - _log.warn("Not processing blocklist " + new Date(ble.updated) + - ", already have " + new Date(oldTime)); + _log.warn("Not processing blocklist " + DataHelper.formatDate(ble.updated) + + ", already have " + DataHelper.formatDate(oldTime)); return; } Blocklist bl = _context.blocklist(); Banlist ban = _context.banlist(); - String reason = "Blocklist feed " + new Date(ble.updated); + String reason = "Blocklist feed " + DataHelper.formatDate(ble.updated); int banned = 0; for (Iterator iter = ble.entries.iterator(); iter.hasNext(); ) { String s = iter.next(); @@ -732,7 +736,7 @@ class NewsFetcher extends UpdateRunner { out = new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(to), "UTF-8")); out.write("\n"); if (entries == null) return; @@ -782,4 +796,26 @@ class NewsFetcher extends UpdateRunner { } catch (IOException ioe) {} } } + + /** + * Write out key="foo,bar,baz". + * Values cannot contain ',' + * + * @param values if null or empty, does nothing + * @since 0.9.52 + */ + private static void writeList(Writer out, String key, List values) throws IOException { + if (values == null || values.isEmpty()) + return; + out.write(' '); + out.write(key); + out.write("=\""); + int sz = values.size(); + for (int i = 0; i < sz; i++) { + out.write(values.get(i)); + if (i != sz - 1) + out.write(','); + } + out.write('"'); + } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java index 37567a8ea..62cee630a 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java @@ -132,24 +132,6 @@ public class ConfigUpdateHandler extends FormHandler { USE_SU3_UPDATE = files != null && files.length > 0; } - private static final String DEFAULT_SU3_UPDATE_URLS = - "http://echelon.i2p/i2p/i2pupdate.su3\r\n" + - //"http://inr.i2p/i2p/i2pupdate.su3\r\n" + - //"http://meeh.i2p/i2pupdate/i2pupdate.su3\r\n" + - "http://stats.i2p/i2p/i2pupdate.su3\r\n" + - // "http://www.i2p2.i2p/_static/i2pupdate.su3\r\n" + - //"http://update.dg.i2p/files/i2pupdate.su3"; - //"http://update.killyourtv.i2p/i2pupdate.su3\r\n" ; - // "http://update.postman.i2p/i2pupdate.su3" ; - // project download server - "http://whnxvjwjhzsske5yevyokhskllvtisv5ueokw6yvh6t7zqrpra2q.b32.i2p/current/i2pupdate.su3"; - - /** - * Empty string if disabled. Cannot be overridden by config. - * @since 0.9.9 - */ - public static final String SU3_UPDATE_URLS = USE_SU3_UPDATE ? DEFAULT_SU3_UPDATE_URLS : ""; - public static final String PROP_TRUSTED_KEYS = "router.trustedUpdateKeys"; /**