From 91bc16ce05d1bd7c99c99d66c088494c15dd0c80 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sun, 29 Jun 2014 00:44:31 +0000 Subject: [PATCH] * NetDB: Fix handling reseed URLs with ports (ticket #1278) by fixing the dup host check --- history.txt | 3 + .../src/net/i2p/router/RouterVersion.java | 2 +- .../i2p/router/networkdb/reseed/Reseeder.java | 56 ++++++++++--------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/history.txt b/history.txt index c4dcf07fce..763e1415a0 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,6 @@ +2014-06-29 zzz + * NetDB: Fix handling reseed URLs with ports (ticket #1278) + 2014-06-28 zzz * NetDB: Add support for reseeding with su3 files (ticket #934) * SAM: diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 5a58b19bc2..e36cd3b143 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 11; + public final static long BUILD = 12; /** for example "-test" */ public final static String EXTRA = ""; diff --git a/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java b/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java index f3a79b78d1..821ab5d95a 100644 --- a/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java +++ b/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java @@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -267,7 +268,7 @@ public class Reseeder { * @return count of routerinfos successfully fetched */ private int reseed(boolean echoStatus) { - List<String> URLList = new ArrayList<String>(); + List<URL> URLList = new ArrayList<URL>(); String URLs = _context.getProperty(PROP_RESEED_URL); boolean defaulted = URLs == null; boolean SSLDisable = _context.getBooleanProperty(PROP_SSL_DISABLE); @@ -279,24 +280,33 @@ public class Reseeder { URLs = DEFAULT_SSL_SEED_URL; } StringTokenizer tok = new StringTokenizer(URLs, " ,"); - while (tok.hasMoreTokens()) - URLList.add(tok.nextToken().trim()); + while (tok.hasMoreTokens()) { + try { + URLList.add(new URL(tok.nextToken().trim())); + } catch (MalformedURLException mue) {} + } Collections.shuffle(URLList, _context.random()); if (defaulted && !SSLDisable && !SSLRequired) { // put the non-SSL at the end of the SSL - List<String> URLList2 = new ArrayList<String>(); + List<URL> URLList2 = new ArrayList<URL>(); tok = new StringTokenizer(DEFAULT_SEED_URL, " ,"); - while (tok.hasMoreTokens()) - URLList2.add(tok.nextToken().trim()); + while (tok.hasMoreTokens()) { + try { + URLList2.add(new URL(tok.nextToken().trim())); + } catch (MalformedURLException mue) {} + } Collections.shuffle(URLList2, _context.random()); URLList.addAll(URLList2); } int total = 0; for (int i = 0; i < URLList.size() && _isRunning; i++) { - String url = URLList.get(i); + URL url = URLList.get(i); int dl = 0; - if (ENABLE_SU3) - dl = reseedSU3(url + SU3_FILENAME, echoStatus); + if (ENABLE_SU3) { + try { + dl = reseedSU3(new URL(url.toString() + SU3_FILENAME), echoStatus); + } catch (MalformedURLException mue) {} + } if (dl <= 0) dl = reseedOne(url, echoStatus); if (dl > 0) { @@ -304,15 +314,13 @@ public class Reseeder { // Don't go on to the next URL if we have enough if (total >= 100) break; - // remove alternate version if we haven't tried it yet - String alt; - if (url.startsWith("http://")) - alt = url.replace("http://", "https://"); - else - alt = url.replace("https://", "http://"); - int idx = URLList.indexOf(alt); - if (idx > i) - URLList.remove(i); + // remove alternate versions if we haven't tried them yet + for (int j = i + 1; j < URLList.size(); ) { + if (url.getHost().equals(URLList.get(j).getHost())) + URLList.remove(j); + else + j++; + } } } return total; @@ -339,14 +347,13 @@ public class Reseeder { * @param echoStatus apparently always false * @return count of routerinfos successfully fetched **/ - private int reseedOne(String seedURL, boolean echoStatus) { + private int reseedOne(URL seedURL, boolean echoStatus) { try { // Don't use context clock as we may be adjusting the time final long timeLimit = System.currentTimeMillis() + MAX_TIME_PER_HOST; _checker.setStatus(_("Reseeding: fetching seed URL.")); System.err.println("Reseeding from " + seedURL); - URL dir = new URL(seedURL); - byte contentRaw[] = readURL(dir); + byte contentRaw[] = readURL(seedURL); if (contentRaw == null) { // Logging deprecated here since attemptFailed() provides better info _log.warn("Failed reading seed URL: " + seedURL); @@ -403,7 +410,7 @@ public class Reseeder { _checker.setStatus( _("Reseeding: fetching router info from seed URL ({0} successful, {1} errors).", fetched, errors)); - if (!fetchSeed(seedURL, iter.next())) + if (!fetchSeed(seedURL.toString(), iter.next())) continue; fetched++; if (echoStatus) { @@ -442,15 +449,14 @@ public class Reseeder { * @return count of routerinfos successfully fetched * @since 0.9.14 **/ - private int reseedSU3(String seedURL, boolean echoStatus) { + private int reseedSU3(URL seedURL, boolean echoStatus) { File contentRaw = null; File zip = null; File tmpDir = null; try { _checker.setStatus(_("Reseeding: fetching seed URL.")); System.err.println("Reseeding from " + seedURL); - URL dir = new URL(seedURL); - contentRaw = fetchURL(dir); + contentRaw = fetchURL(seedURL); if (contentRaw == null) { // Logging deprecated here since attemptFailed() provides better info _log.warn("Failed reading seed URL: " + seedURL); -- GitLab