I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 7931451a authored by zzz's avatar zzz
Browse files

* Reseed: Limit to 200 per URL, shuffle selection, add some logging

parent 39e5ff7e
No related branches found
No related tags found
No related merge requests found
...@@ -91,8 +91,9 @@ public class ReseedHandler { ...@@ -91,8 +91,9 @@ public class ReseedHandler {
public boolean isRunning() { return _isRunning; } public boolean isRunning() { return _isRunning; }
public void run() { public void run() {
_isRunning = true; _isRunning = true;
System.out.println("Reseed start");
reseed(false); reseed(false);
System.out.println("Reseeding complete"); System.out.println("Reseed complete");
System.setProperty("net.i2p.router.web.ReseedHandler.reseedInProgress", "false"); System.setProperty("net.i2p.router.web.ReseedHandler.reseedInProgress", "false");
_isRunning = false; _isRunning = false;
} }
...@@ -133,7 +134,7 @@ public class ReseedHandler { ...@@ -133,7 +134,7 @@ public class ReseedHandler {
} }
/** /**
* Fetch a directory listing and then all the routerInfo files in the listing. * Fetch a directory listing and then up to 200 routerInfo files in the listing.
* The listing must contain (exactly) strings that match: * The listing must contain (exactly) strings that match:
* href="routerInfo-{hash}.dat"> * href="routerInfo-{hash}.dat">
* and then it fetches the files * and then it fetches the files
...@@ -147,6 +148,7 @@ public class ReseedHandler { ...@@ -147,6 +148,7 @@ public class ReseedHandler {
try { try {
System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",""); System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage","");
System.setProperty("net.i2p.router.web.ReseedHandler.statusMessage","Reseeding: fetching seed URL."); System.setProperty("net.i2p.router.web.ReseedHandler.statusMessage","Reseeding: fetching seed URL.");
System.err.println("Reseed from " + seedURL);
URL dir = new URL(seedURL); URL dir = new URL(seedURL);
byte contentRaw[] = readURL(dir); byte contentRaw[] = readURL(dir);
if (contentRaw == null) { if (contentRaw == null) {
...@@ -160,7 +162,8 @@ public class ReseedHandler { ...@@ -160,7 +162,8 @@ public class ReseedHandler {
String content = new String(contentRaw); String content = new String(contentRaw);
Set urls = new HashSet(); Set urls = new HashSet();
int cur = 0; int cur = 0;
while (true) { int total = 0;
while (total++ < 1000) {
int start = content.indexOf("href=\"routerInfo-", cur); int start = content.indexOf("href=\"routerInfo-", cur);
if (start < 0) if (start < 0)
break; break;
...@@ -170,7 +173,7 @@ public class ReseedHandler { ...@@ -170,7 +173,7 @@ public class ReseedHandler {
urls.add(name); urls.add(name);
cur = end + 1; cur = end + 1;
} }
if (urls.size() <= 0) { if (total <= 0) {
_log.error("Read " + contentRaw.length + " bytes from seed " + seedURL + ", but found no routerInfo URLs."); _log.error("Read " + contentRaw.length + " bytes from seed " + seedURL + ", but found no routerInfo URLs.");
System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage", System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",
"Last reseed failed fully (no routerInfo URLs at seed URL). " + "Last reseed failed fully (no routerInfo URLs at seed URL). " +
...@@ -178,13 +181,16 @@ public class ReseedHandler { ...@@ -178,13 +181,16 @@ public class ReseedHandler {
return; return;
} }
List urlList = new ArrayList(urls);
Collections.shuffle(urlList);
int fetched = 0; int fetched = 0;
int errors = 0; int errors = 0;
for (Iterator iter = urls.iterator(); iter.hasNext(); ) { // 200 max from one URL
for (Iterator iter = urlList.iterator(); iter.hasNext() && fetched < 200; ) {
try { try {
System.setProperty("net.i2p.router.web.ReseedHandler.statusMessage", System.setProperty("net.i2p.router.web.ReseedHandler.statusMessage",
"Reseeding: fetching router info from seed URL (" + "Reseeding: fetching router info from seed URL (" +
fetched + " successful, " + errors + " errors, " + urls.size() + " total)."); fetched + " successful, " + errors + " errors, " + total + " total).");
fetchSeed(seedURL, (String)iter.next()); fetchSeed(seedURL, (String)iter.next());
fetched++; fetched++;
...@@ -197,24 +203,24 @@ public class ReseedHandler { ...@@ -197,24 +203,24 @@ public class ReseedHandler {
errors++; errors++;
} }
} }
if (echoStatus) System.out.println(); System.err.println("Reseed got " + fetched + " router infos from " + seedURL);
int failPercent = 100 * errors / urls.size(); int failPercent = 100 * errors / total;
// Less than 10% of failures is considered success, // Less than 10% of failures is considered success,
// because some routerInfos will always fail. // because some routerInfos will always fail.
if ((failPercent >= 10) && (failPercent < 90)) { if ((failPercent >= 10) && (failPercent < 90)) {
System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage", System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",
"Last reseed failed partly (" + failPercent + "% of " + urls.size() + "). " + "Last reseed failed partly (" + failPercent + "% of " + total + "). " +
RESEED_TIPS); RESEED_TIPS);
} }
if (failPercent >= 90) { if (failPercent >= 90) {
System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage", System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",
"Last reseed failed (" + failPercent + "% of " + urls.size() + "). " + "Last reseed failed (" + failPercent + "% of " + total + "). " +
RESEED_TIPS); RESEED_TIPS);
} }
// 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 (fetched > 25) if (fetched >= 100)
_isRunning = false; _isRunning = false;
} catch (Throwable t) { } catch (Throwable t) {
System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage", System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment