From ce2a2cf684dfe7d45124868e1e92dfbd7c024902 Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 21 Nov 2014 13:02:57 +0000 Subject: [PATCH] Only need one torrent magnet; tighten update type spec --- .../src/net/i2p/router/news/NewsMetadata.java | 2 +- .../net/i2p/router/news/NewsXMLParser.java | 38 ++++++++++--------- .../net/i2p/router/update/NewsFetcher.java | 12 +++--- 3 files changed, 26 insertions(+), 26 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 e418c8640..96ba51e25 100644 --- a/apps/routerconsole/java/src/net/i2p/router/news/NewsMetadata.java +++ b/apps/routerconsole/java/src/net/i2p/router/news/NewsMetadata.java @@ -35,7 +35,7 @@ public class NewsMetadata { public static class Update implements Comparable { public String type; - public List torrent; + public String torrent; public List clearnet; public List ssl; 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 2ad84c3d2..9e1786e55 100644 --- a/apps/routerconsole/java/src/net/i2p/router/news/NewsXMLParser.java +++ b/apps/routerconsole/java/src/net/i2p/router/news/NewsXMLParser.java @@ -196,30 +196,32 @@ public class NewsXMLParser { List updates = new ArrayList(); List updateNodes = getNodes(r, "i2p:update"); + Set types = new HashSet(); for (Node u : updateNodes) { // returns "" for none String type = u.getAttributeValue("type"); - if (type.length() > 0) { - NewsMetadata.Update update = new NewsMetadata.Update(); - update.type = type; - int totalSources = 0; + if (type.isEmpty()) + throw new I2PParserException("update with no type"); + if (types.contains(type)) + throw new I2PParserException("update with duplicate type"); + NewsMetadata.Update update = new NewsMetadata.Update(); + update.type = type; + types.add(type); + int totalSources = 0; - List torrents = new ArrayList(); - List torrentNodes = getNodes(u, "i2p:torrent"); - for (Node t : torrentNodes) { - // returns "" for none - String href = t.getAttributeValue("href"); - if (href.length() > 0) { - torrents.add(href); - } + Node t = u.getNode("i2p:torrent"); + if (t != null) { + // returns "" for none + String href = t.getAttributeValue("href"); + if (href.length() > 0) { + update.torrent = href; + totalSources += 1; } - update.torrent = torrents; - totalSources += torrents.size(); - - if (totalSources == 0) - throw new I2PParserException("no sources for update type " + type); - updates.add(update); } + + if (totalSources == 0) + throw new I2PParserException("no sources for update type " + type); + updates.add(update); } Collections.sort(updates); release.updates = updates; 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 9b9bc1ffb..f8b6fd140 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java @@ -469,13 +469,11 @@ class NewsFetcher extends UpdateRunner { String su3Torrent = ""; String su2Torrent = ""; for (NewsMetadata.Update update : latestRelease.updates) { - if (update.torrent.size() > 0) { - // Only take the first torrent magnet - // TODO handle multiple torrent magnetss - if ("su3".equals(update.type) && su3Torrent.isEmpty()) - su3Torrent = update.torrent.get(0); - else if ("su2".equals(update.type) && su2Torrent.isEmpty()) - su2Torrent = update.torrent.get(0); + if (update.torrent != null) { + if ("su3".equals(update.type)) + su3Torrent = update.torrent; + else if ("su2".equals(update.type)) + su2Torrent = update.torrent; } } if (!su2Torrent.isEmpty())