Reseed: Improve status feedback in logs, summary bar, and /configreseed

- Show proxy info, if applicable, in logs
- Show status in summary bar for manual reseed (previously hidden if more than 30 routers)
- Show status in summary bar after successul completion
- Show reseed button in summary bar if less than 50 known RIs (previously 30)
- Show current status on /configreseed if already running
- Consolidate proxy settings detection in ReseedRunner constructor
- Enhance help text on /configreseed (tickets #423, #1130)
This commit is contained in:
zzz
2017-11-18 18:47:50 +00:00
parent 33aac1b125
commit 0ba207cb01
4 changed files with 229 additions and 96 deletions

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.i2p.router.networkdb.reseed.ReseedChecker;
import net.i2p.router.networkdb.reseed.Reseeder;
/**
@ -21,15 +22,18 @@ public class ConfigReseedHandler extends FormHandler {
@Override
protected void processForm() {
ReseedChecker checker = _context.netDb().reseedChecker();
if (_action.equals(_t("Save changes and reseed now"))) {
saveChanges();
if (!_context.netDb().reseedChecker().requestReseed()) {
if (!checker.requestReseed()) {
addFormError(_t("Reseeding is already in progress"));
addCheckerStatus(checker);
} else {
// skip the nonce checking in ReseedHandler
addFormNotice(_t("Starting reseed process"));
}
} else if (_action.equals(_t("Reseed from URL"))) {
// threaded
String val = getJettyString("url");
if (val != null)
val = val.trim();
@ -45,33 +49,31 @@ public class ConfigReseedHandler extends FormHandler {
return;
}
try {
if (!_context.netDb().reseedChecker().requestReseed(url)) {
if (!checker.requestReseed(url)) {
addFormError(_t("Reseeding is already in progress"));
addCheckerStatus(checker);
} else {
// wait a while for completion but not forever
for (int i = 0; i < 40; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException ie) {}
if (!_context.netDb().reseedChecker().inProgress())
if (!checker.inProgress())
break;
}
String status = _context.netDb().reseedChecker().getStatus();
String error = _context.netDb().reseedChecker().getError();
if (error.length() > 0) {
addFormErrorNoEscape(error);
} else if (status.length() > 0) {
addFormNoticeNoEscape(status);
} else if (_context.netDb().reseedChecker().inProgress()) {
addFormNotice(_t("Reseed in progress, check summary bar for status"));
} else {
addFormNotice(_t("Reseed complete, check summary bar for status"));
if (!addCheckerStatus(checker)) {
if (checker.inProgress()) {
addFormNotice(_t("Reseed in progress, check summary bar for status"));
} else {
addFormNotice(_t("Reseed complete, check summary bar for status"));
}
}
}
} catch (IllegalArgumentException iae) {
addFormError(_t("Bad URL {0}", val) + " - " + iae.getMessage());
}
} else if (_action.equals(_t("Reseed from file"))) {
// inline
InputStream in = _requestWrapper.getInputStream("file");
try {
// non-null but zero bytes if no file entered, don't know why
@ -79,9 +81,10 @@ public class ConfigReseedHandler extends FormHandler {
addFormError(_t("You must enter a file"));
return;
}
int count = _context.netDb().reseedChecker().requestReseed(in);
int count = checker.requestReseed(in);
if (count <= 0) {
addFormError(_t("Reseed from file failed"));
addCheckerStatus(checker);
} else {
addFormNotice(ngettext("Reseed successful, loaded {0} router info from file",
"Reseed successful, loaded {0} router infos from file",
@ -89,6 +92,7 @@ public class ConfigReseedHandler extends FormHandler {
}
} catch (IOException ioe) {
addFormError(_t("Reseed from file failed") + " - " + ioe);
addCheckerStatus(checker);
} finally {
// it's really a ByteArrayInputStream but we'll play along...
if (in != null)
@ -102,6 +106,24 @@ public class ConfigReseedHandler extends FormHandler {
//addFormError(_t("Unsupported") + ' ' + _action + '.');
}
/**
* @return true if anything was output
* @since 0.9.33
*/
private boolean addCheckerStatus(ReseedChecker checker) {
String error = checker.getError();
if (error.length() > 0) {
addFormErrorNoEscape(error);
return true;
}
String status = checker.getStatus();
if (status.length() > 0) {
addFormNoticeNoEscape(status);
return true;
}
return false;
}
private void resetUrlList() {
if (_context.router().saveConfig(Reseeder.PROP_RESEED_URL, null))
addFormNotice(_t("URL list reset successfully"));

View File

@ -23,6 +23,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.RouterVersion;
import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.networkdb.reseed.ReseedChecker;
import net.i2p.router.transport.TransportUtil;
import net.i2p.stat.Rate;
import net.i2p.stat.RateStat;
@ -153,7 +154,7 @@ public class SummaryHelper extends HelperBase {
/** allowReseed */
public boolean allowReseed() {
return _context.netDb().isInitialized() &&
(_context.netDb().getKnownRouters() < 30) ||
(_context.netDb().getKnownRouters() < ReseedChecker.MINIMUM) ||
_context.getBooleanProperty("i2p.alwaysAllowReseed");
}
@ -942,13 +943,20 @@ public class SummaryHelper extends HelperBase {
.append("</a></h4>");
}
boolean reseedInProgress = _context.netDb().reseedChecker().inProgress();
// If showing the reseed link is allowed
if (allowReseed()) {
if (reseedInProgress) {
// While reseed occurring, show status message instead
buf.append("<div class=\"sb_notice\"><i>").append(_context.netDb().reseedChecker().getStatus()).append("</i></div>");
} else {
ReseedChecker checker = _context.netDb().reseedChecker();
String status = checker.getStatus();
if (status.length() > 0) {
// Show status message even if not running, timer in ReseedChecker should remove after 20 minutes
buf.append("<div class=\"sb_notice\"><i>").append(checker.getStatus()).append("</i></div>");
}
if (!checker.inProgress()) {
// If a new reseed isn't running, and the last reseed had errors, show error message
String reseedErrorMessage = checker.getError();
if (reseedErrorMessage.length() > 0) {
buf.append("<div class=\"sb_notice\"><i>").append(reseedErrorMessage).append("</i></div>");
}
// If showing the reseed link is allowed
if (allowReseed()) {
// While no reseed occurring, show reseed link
long nonce = _context.random().nextLong();
String prev = System.getProperty("net.i2p.router.web.ReseedHandler.nonce");
@ -961,13 +969,6 @@ public class SummaryHelper extends HelperBase {
buf.append("\" class=\"reload\" value=\"Reseed\" >").append(_t("Reseed")).append("</button></form></p>\n");
}
}
// If a new reseed ain't running, and the last reseed had errors, show error message
if (!reseedInProgress) {
String reseedErrorMessage = _context.netDb().reseedChecker().getError();
if (reseedErrorMessage.length() > 0) {
buf.append("<div class=\"sb_notice\"><i>").append(reseedErrorMessage).append("</i></div>");
}
}
if (buf.length() <= 0)
return "";
return buf.toString();