Sybil: Auto-block UI

This commit is contained in:
zzz
2019-05-13 12:15:19 +00:00
parent ff71540428
commit 48a92ca1e7
3 changed files with 43 additions and 8 deletions

View File

@ -59,6 +59,9 @@ public class Analysis extends JobImpl implements RouterApp {
*/
public static final String APP_NAME = "sybil";
public static final String PROP_FREQUENCY = "router.sybilFrequency";
public static final String PROP_THRESHOLD = "router.sybilThreshold";
public static final String PROP_BLOCK = "router.sybilBlock.enable";
public static final String PROP_BLOCKTIME = "router.sybilBlock.period";
private static final long MIN_FREQUENCY = 60*60*1000L;
private static final long MIN_UPTIME = 75*60*1000L;

View File

@ -1,7 +1,9 @@
package net.i2p.router.web.helpers;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import net.i2p.crypto.SigType;
import net.i2p.data.DataHelper;
@ -221,11 +223,26 @@ public class NetDbHelper extends FormHandler {
_postOK = "Run new 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)))
Map<String, String> toSave = new HashMap<String, String>(4);
String newTime = getJettyString("runFrequency");
if (newTime != null) {
long ntime = Long.parseLong(newTime) * 60*60*1000;
toSave.put(Analysis.PROP_FREQUENCY, Long.toString(ntime));
}
String thresh = getJettyString("threshold");
if (thresh != null && thresh.length() > 0) {
float val = Float.parseFloat(thresh);
toSave.put(Analysis.PROP_THRESHOLD, Float.toString(val));
}
String days = getJettyString("days");
if (days != null && days.length() > 0) {
long val = 24*60*60*1000L * Integer.parseInt(days);
toSave.put(Analysis.PROP_BLOCKTIME, Long.toString(val));
}
String enable = getJettyString("block");
toSave.put(Analysis.PROP_BLOCK, Boolean.toString(enable != null));
if (_context.router().saveConfig(toSave, null))
addFormNotice(_t("Configuration saved successfully."));
else
addFormError("Error saving the configuration (applied but not saved) - please see the error logs");
@ -233,7 +250,6 @@ public class NetDbHelper extends FormHandler {
} catch (NumberFormatException nfe) {
addFormError("bad value");
}
}
}
}

View File

@ -39,6 +39,7 @@ import net.i2p.router.sybil.Points;
import static net.i2p.router.sybil.Util.biLog2;
import net.i2p.router.tunnel.pool.TunnelPool;
import net.i2p.router.util.HashDistance;
import net.i2p.router.web.HelperBase;
import net.i2p.router.web.Messages;
import net.i2p.stat.Rate;
import net.i2p.stat.RateAverages;
@ -283,7 +284,7 @@ public class SybilRenderer {
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
"<input type=\"hidden\" name=\"m\" value=\"15\">\n" +
"<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" >\n" +
"Background analysis run frequency: <select name=\"runFrequency\">");
"<table><tr><td>Background analysis run frequency:</td><td><select name=\"runFrequency\">");
for (int i = 0; i < HOURS.length; i++) {
buf.append("<option value=\"");
buf.append(Integer.toString(HOURS[i]));
@ -298,9 +299,24 @@ public class SybilRenderer {
buf.append(_t("Never"));
buf.append("</option>\n");
}
buf.append("</select> " +
boolean auto = _context.getBooleanProperty(Analysis.PROP_BLOCK);
String thresh = _context.getProperty(Analysis.PROP_THRESHOLD, "50");
long days = 7;
String time = _context.getProperty(Analysis.PROP_BLOCKTIME);
if (time != null) {
try {
days = Long.parseLong(time) / (24*60*60*1000L);
} catch (NumberFormatException nfe) {}
}
buf.append("</select></td></tr>\n<tr><td>" +
"Auto-block routers?</td><td><input type=\"checkbox\" class=\"optbox\" value=\"1\" name=\"block\" ");
if (auto)
buf.append(HelperBase.CHECKED);
buf.append("></td></tr>\n<tr><td>" +
"Minimum threat points to block:</td><td><input type=\"text\" name=\"threshold\" value=\"").append(thresh).append("\"></td></tr>\n<tr><td>" +
"Days to block:</td><td><input type=\"text\" name=\"days\" value=\"").append(days).append("\"></td></tr>\n<tr><td></td><td>" +
"<input type=\"submit\" name=\"action\" class=\"accept\" value=\"Save\" />" +
"</form>\n");
"</td></tr></table></form>\n");
writeBuf(out, buf);
}