* NetDB: Fix handling reseed URLs with ports (ticket #1278)

by fixing the dup host check
This commit is contained in:
zzz
2014-06-29 00:44:31 +00:00
parent 861a1e26d7
commit 91bc16ce05
3 changed files with 35 additions and 26 deletions

View File

@@ -1,3 +1,6 @@
2014-06-29 zzz
* NetDB: Fix handling reseed URLs with ports (ticket #1278)
2014-06-28 zzz 2014-06-28 zzz
* NetDB: Add support for reseeding with su3 files (ticket #934) * NetDB: Add support for reseeding with su3 files (ticket #934)
* SAM: * SAM:

View File

@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 11; public final static long BUILD = 12;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";

View File

@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
@@ -267,7 +268,7 @@ public class Reseeder {
* @return count of routerinfos successfully fetched * @return count of routerinfos successfully fetched
*/ */
private int reseed(boolean echoStatus) { private int reseed(boolean echoStatus) {
List<String> URLList = new ArrayList<String>(); List<URL> URLList = new ArrayList<URL>();
String URLs = _context.getProperty(PROP_RESEED_URL); String URLs = _context.getProperty(PROP_RESEED_URL);
boolean defaulted = URLs == null; boolean defaulted = URLs == null;
boolean SSLDisable = _context.getBooleanProperty(PROP_SSL_DISABLE); boolean SSLDisable = _context.getBooleanProperty(PROP_SSL_DISABLE);
@@ -279,24 +280,33 @@ public class Reseeder {
URLs = DEFAULT_SSL_SEED_URL; URLs = DEFAULT_SSL_SEED_URL;
} }
StringTokenizer tok = new StringTokenizer(URLs, " ,"); StringTokenizer tok = new StringTokenizer(URLs, " ,");
while (tok.hasMoreTokens()) while (tok.hasMoreTokens()) {
URLList.add(tok.nextToken().trim()); try {
URLList.add(new URL(tok.nextToken().trim()));
} catch (MalformedURLException mue) {}
}
Collections.shuffle(URLList, _context.random()); Collections.shuffle(URLList, _context.random());
if (defaulted && !SSLDisable && !SSLRequired) { if (defaulted && !SSLDisable && !SSLRequired) {
// put the non-SSL at the end of the SSL // 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, " ,"); tok = new StringTokenizer(DEFAULT_SEED_URL, " ,");
while (tok.hasMoreTokens()) while (tok.hasMoreTokens()) {
URLList2.add(tok.nextToken().trim()); try {
URLList2.add(new URL(tok.nextToken().trim()));
} catch (MalformedURLException mue) {}
}
Collections.shuffle(URLList2, _context.random()); Collections.shuffle(URLList2, _context.random());
URLList.addAll(URLList2); URLList.addAll(URLList2);
} }
int total = 0; int total = 0;
for (int i = 0; i < URLList.size() && _isRunning; i++) { for (int i = 0; i < URLList.size() && _isRunning; i++) {
String url = URLList.get(i); URL url = URLList.get(i);
int dl = 0; int dl = 0;
if (ENABLE_SU3) if (ENABLE_SU3) {
dl = reseedSU3(url + SU3_FILENAME, echoStatus); try {
dl = reseedSU3(new URL(url.toString() + SU3_FILENAME), echoStatus);
} catch (MalformedURLException mue) {}
}
if (dl <= 0) if (dl <= 0)
dl = reseedOne(url, echoStatus); dl = reseedOne(url, echoStatus);
if (dl > 0) { if (dl > 0) {
@@ -304,15 +314,13 @@ public class Reseeder {
// Don't go on to the next URL if we have enough // Don't go on to the next URL if we have enough
if (total >= 100) if (total >= 100)
break; break;
// remove alternate version if we haven't tried it yet // remove alternate versions if we haven't tried them yet
String alt; for (int j = i + 1; j < URLList.size(); ) {
if (url.startsWith("http://")) if (url.getHost().equals(URLList.get(j).getHost()))
alt = url.replace("http://", "https://"); URLList.remove(j);
else else
alt = url.replace("https://", "http://"); j++;
int idx = URLList.indexOf(alt); }
if (idx > i)
URLList.remove(i);
} }
} }
return total; return total;
@@ -339,14 +347,13 @@ public class Reseeder {
* @param echoStatus apparently always false * @param echoStatus apparently always false
* @return count of routerinfos successfully fetched * @return count of routerinfos successfully fetched
**/ **/
private int reseedOne(String seedURL, boolean echoStatus) { private int reseedOne(URL seedURL, boolean echoStatus) {
try { try {
// Don't use context clock as we may be adjusting the time // Don't use context clock as we may be adjusting the time
final long timeLimit = System.currentTimeMillis() + MAX_TIME_PER_HOST; final long timeLimit = System.currentTimeMillis() + MAX_TIME_PER_HOST;
_checker.setStatus(_("Reseeding: fetching seed URL.")); _checker.setStatus(_("Reseeding: fetching seed URL."));
System.err.println("Reseeding from " + seedURL); System.err.println("Reseeding from " + seedURL);
URL dir = new URL(seedURL); byte contentRaw[] = readURL(seedURL);
byte contentRaw[] = readURL(dir);
if (contentRaw == null) { if (contentRaw == null) {
// Logging deprecated here since attemptFailed() provides better info // Logging deprecated here since attemptFailed() provides better info
_log.warn("Failed reading seed URL: " + seedURL); _log.warn("Failed reading seed URL: " + seedURL);
@@ -403,7 +410,7 @@ public class Reseeder {
_checker.setStatus( _checker.setStatus(
_("Reseeding: fetching router info from seed URL ({0} successful, {1} errors).", fetched, errors)); _("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; continue;
fetched++; fetched++;
if (echoStatus) { if (echoStatus) {
@@ -442,15 +449,14 @@ public class Reseeder {
* @return count of routerinfos successfully fetched * @return count of routerinfos successfully fetched
* @since 0.9.14 * @since 0.9.14
**/ **/
private int reseedSU3(String seedURL, boolean echoStatus) { private int reseedSU3(URL seedURL, boolean echoStatus) {
File contentRaw = null; File contentRaw = null;
File zip = null; File zip = null;
File tmpDir = null; File tmpDir = null;
try { try {
_checker.setStatus(_("Reseeding: fetching seed URL.")); _checker.setStatus(_("Reseeding: fetching seed URL."));
System.err.println("Reseeding from " + seedURL); System.err.println("Reseeding from " + seedURL);
URL dir = new URL(seedURL); contentRaw = fetchURL(seedURL);
contentRaw = fetchURL(dir);
if (contentRaw == null) { if (contentRaw == null) {
// Logging deprecated here since attemptFailed() provides better info // Logging deprecated here since attemptFailed() provides better info
_log.warn("Failed reading seed URL: " + seedURL); _log.warn("Failed reading seed URL: " + seedURL);