forked from I2P_Developers/i2p.i2p
Sybil: Add background run form
This commit is contained in:
@ -192,6 +192,8 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
when = Math.max(when, now + MIN_UPTIME - up);
|
when = Math.max(when, now + MIN_UPTIME - up);
|
||||||
getTiming().setStartAfter(when);
|
getTiming().setStartAfter(when);
|
||||||
_context.jobQueue().addJob(this);
|
_context.jobQueue().addJob(this);
|
||||||
|
} else {
|
||||||
|
_context.jobQueue().removeJob(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import java.util.Locale;
|
|||||||
import net.i2p.crypto.SigType;
|
import net.i2p.crypto.SigType;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.util.SystemVersion;
|
import net.i2p.util.SystemVersion;
|
||||||
|
import net.i2p.router.sybil.Analysis;
|
||||||
import net.i2p.router.web.FormHandler;
|
import net.i2p.router.web.FormHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,6 +220,21 @@ public class NetDbHelper extends FormHandler {
|
|||||||
protected void processForm() {
|
protected void processForm() {
|
||||||
_postOK = "Run new analysis".equals(_action) ||
|
_postOK = "Run new analysis".equals(_action) ||
|
||||||
"Review analysis".equals(_action);
|
"Review analysis".equals(_action);
|
||||||
|
if ("Save".equals(_action)) {
|
||||||
|
String newTime = getJettyString("runFrequency");
|
||||||
|
if (newTime != null) {
|
||||||
|
try {
|
||||||
|
long ntime = Long.parseLong(newTime) * 60*60*1000;
|
||||||
|
if (_context.router().saveConfig(Analysis.PROP_FREQUENCY, Long.toString(ntime)))
|
||||||
|
addFormNotice(_t("Configuration saved successfully."));
|
||||||
|
else
|
||||||
|
addFormError("Error saving the configuration (applied but not saved) - please see the error logs");
|
||||||
|
Analysis.getInstance(_context).schedule();
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
addFormError("bad value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,6 +67,7 @@ public class SybilRenderer {
|
|||||||
private static final int MAX = Analysis.MAX;
|
private static final int MAX = Analysis.MAX;
|
||||||
private static final double MIN_CLOSE = Analysis.MIN_CLOSE;
|
private static final double MIN_CLOSE = Analysis.MIN_CLOSE;
|
||||||
private static final double MIN_DISPLAY_POINTS = 12.01;
|
private static final double MIN_DISPLAY_POINTS = 12.01;
|
||||||
|
private static final int[] HOURS = { 1, 6, 24, 7*24, 30*24, 0 };
|
||||||
|
|
||||||
public SybilRenderer(RouterContext ctx) {
|
public SybilRenderer(RouterContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
@ -143,6 +144,7 @@ public class SybilRenderer {
|
|||||||
"If you see anything you would like to discuss with the devs, contact us on IRC #i2p-dev.</b></p>" +
|
"If you see anything you would like to discuss with the devs, contact us on IRC #i2p-dev.</b></p>" +
|
||||||
"<div id=\"sybilnav\"><ul><li><a href=\"netdb?f=3\">Review stored analysis</a>" +
|
"<div id=\"sybilnav\"><ul><li><a href=\"netdb?f=3\">Review stored analysis</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=14\">Run new analysis</a>" +
|
"</li><li><a href=\"netdb?f=3&m=14\">Run new analysis</a>" +
|
||||||
|
"</li><li><a href=\"netdb?f=3&m=15\">Configure periodic analysis</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=1\">Floodfill Summary</a>" +
|
"</li><li><a href=\"netdb?f=3&m=1\">Floodfill Summary</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=2\">Same Family</a>" +
|
"</li><li><a href=\"netdb?f=3&m=2\">Same Family</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=3\">IP close to us</a>" +
|
"</li><li><a href=\"netdb?f=3&m=3\">IP close to us</a>" +
|
||||||
@ -215,8 +217,11 @@ public class SybilRenderer {
|
|||||||
}
|
}
|
||||||
renderThreatsHTML(out, buf, now, points);
|
renderThreatsHTML(out, buf, now, points);
|
||||||
} else if (mode == 14) {
|
} else if (mode == 14) {
|
||||||
// show form
|
// show run form
|
||||||
renderRunForm(out, buf, nonce);
|
renderRunForm(out, buf, nonce);
|
||||||
|
} else if (mode == 15) {
|
||||||
|
// show background form
|
||||||
|
renderBackgroundForm(out, buf, nonce);
|
||||||
} else {
|
} else {
|
||||||
out.write("Unknown mode " + mode);
|
out.write("Unknown mode " + mode);
|
||||||
}
|
}
|
||||||
@ -235,7 +240,7 @@ public class SybilRenderer {
|
|||||||
buf.append("<form action=\"netdb\" method=\"POST\">\n" +
|
buf.append("<form action=\"netdb\" method=\"POST\">\n" +
|
||||||
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
|
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
|
||||||
"<input type=\"hidden\" name=\"m\" value=\"12\">\n" +
|
"<input type=\"hidden\" name=\"m\" value=\"12\">\n" +
|
||||||
"<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n" +
|
"<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" >\n" +
|
||||||
"Select stored analysis: " +
|
"Select stored analysis: " +
|
||||||
"<select name=\"date\">\n");
|
"<select name=\"date\">\n");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
@ -256,16 +261,45 @@ public class SybilRenderer {
|
|||||||
writeBuf(out, buf);
|
writeBuf(out, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.38
|
||||||
|
*/
|
||||||
|
private static void renderRunForm(Writer out, StringBuilder buf, String nonce) throws IOException {
|
||||||
|
buf.append("<form action=\"netdb\" method=\"POST\">\n" +
|
||||||
|
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
|
||||||
|
"<input type=\"hidden\" name=\"m\" value=\"13\">\n" +
|
||||||
|
"<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" >\n" +
|
||||||
|
"<input type=\"submit\" name=\"action\" class=\"go\" value=\"Run new analysis\" />" +
|
||||||
|
"</form>\n");
|
||||||
|
writeBuf(out, buf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 0.9.38
|
* @since 0.9.38
|
||||||
*/
|
*/
|
||||||
private void renderRunForm(Writer out, StringBuilder buf, String nonce) throws IOException {
|
private void renderBackgroundForm(Writer out, StringBuilder buf, String nonce) throws IOException {
|
||||||
|
long freq = _context.getProperty(Analysis.PROP_FREQUENCY, 0L);
|
||||||
buf.append("<form action=\"netdb\" method=\"POST\">\n" +
|
buf.append("<form action=\"netdb\" method=\"POST\">\n" +
|
||||||
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
|
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
|
||||||
"<input type=\"hidden\" name=\"m\" value=\"13\">\n" +
|
"<input type=\"hidden\" name=\"m\" value=\"15\">\n" +
|
||||||
"<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n" +
|
"<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" >\n" +
|
||||||
"<input type=\"submit\" name=\"action\" class=\"go\" value=\"Run new analysis\" />" +
|
"Background analysis run frequency: <select name=\"runFrequency\">");
|
||||||
|
for (int i = 0; i < HOURS.length; i++) {
|
||||||
|
buf.append("<option value=\"");
|
||||||
|
buf.append(Integer.toString(HOURS[i]));
|
||||||
|
buf.append('"');
|
||||||
|
long time = HOURS[i] * 60*60*1000L;
|
||||||
|
if (time == freq)
|
||||||
|
buf.append(" selected=\"selected\"");
|
||||||
|
buf.append('>');
|
||||||
|
if (HOURS[i] > 0)
|
||||||
|
buf.append(DataHelper.formatDuration2(time));
|
||||||
|
else
|
||||||
|
buf.append(_t("Never"));
|
||||||
|
buf.append("</option>\n");
|
||||||
|
}
|
||||||
|
buf.append("</select> " +
|
||||||
|
"<input type=\"submit\" name=\"action\" class=\"accept\" value=\"Save\" />" +
|
||||||
"</form>\n");
|
"</form>\n");
|
||||||
writeBuf(out, buf);
|
writeBuf(out, buf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user