Sybil: Enable analysis and blocking by default

This commit is contained in:
zzz
2020-06-22 19:59:35 +00:00
parent c119de6188
commit 3a392e84a9
4 changed files with 22 additions and 12 deletions

View File

@ -93,8 +93,11 @@ public class Analysis extends JobImpl implements RouterApp {
private static final double POINTS_UNREACHABLE = 4.0; private static final double POINTS_UNREACHABLE = 4.0;
private static final double POINTS_NEW = 4.0; private static final double POINTS_NEW = 4.0;
private static final double POINTS_BANLIST = 25.0; private static final double POINTS_BANLIST = 25.0;
private static final double DEFAULT_BLOCK_THRESHOLD = 50.0; public static final boolean DEFAULT_BLOCK = true;
private static final long DEFAULT_BLOCK_TIME = 7*24*60*60*1000L; public static final double DEFAULT_BLOCK_THRESHOLD = 75.0;
public static final long DEFAULT_BLOCK_TIME = 7*24*60*60*1000L;
public static final long DEFAULT_REMOVE_TIME = 30*24*60*60*1000L;
public static final long DEFAULT_FREQUENCY = 24*60*60*1000L;
public static final float MIN_BLOCK_POINTS = 12.01f; public static final float MIN_BLOCK_POINTS = 12.01f;
/** Get via getInstance() */ /** Get via getInstance() */
@ -188,7 +191,7 @@ public class Analysis extends JobImpl implements RouterApp {
} }
public synchronized void schedule() { public synchronized void schedule() {
long freq = _context.getProperty(PROP_FREQUENCY, 0L); long freq = _context.getProperty(PROP_FREQUENCY, DEFAULT_FREQUENCY);
if (freq > 0) { if (freq > 0) {
List<Long> previous = _persister.load(); List<Long> previous = _persister.load();
long now = _context.clock().now() + 15*1000; long now = _context.clock().now() + 15*1000;
@ -372,7 +375,7 @@ public class Analysis extends JobImpl implements RouterApp {
// Profile analysis // Profile analysis
addProfilePoints(ris, points); addProfilePoints(ris, points);
addVersionPoints(ris, points); addVersionPoints(ris, points);
if (_context.getBooleanProperty(PROP_BLOCK)) if (_context.getProperty(PROP_BLOCK, DEFAULT_BLOCK))
doBlocking(points); doBlocking(points);
return points; return points;
} }
@ -404,6 +407,12 @@ public class Analysis extends JobImpl implements RouterApp {
} }
} }
String reason = "Sybil analysis " + day + " with " + fmt.format(p) + " threat points"; String reason = "Sybil analysis " + day + " with " + fmt.format(p) + " threat points";
if (_log.shouldWarn()) {
if (ri != null)
_log.warn("Banned by " + reason + " and blocking IPs:\n" + ri);
else
_log.warn("Banned " + h.toBase64() + " by " + reason);
}
_context.banlist().banlistRouter(h, reason, null, null, blockUntil); _context.banlist().banlistRouter(h, reason, null, null, blockUntil);
} }
} }

View File

@ -180,7 +180,7 @@ public class PersistSybil {
* @since 0.9.41 * @since 0.9.41
*/ */
public synchronized void removeOld() { public synchronized void removeOld() {
long age = _context.getProperty(Analysis.PROP_REMOVETIME, 0L); long age = _context.getProperty(Analysis.PROP_REMOVETIME, Analysis.DEFAULT_REMOVE_TIME);
if (age < 60*1000) if (age < 60*1000)
return; return;
long cutoff = _context.clock().now() - age; long cutoff = _context.clock().now() - age;

View File

@ -887,8 +887,9 @@ public class RouterConsoleRunner implements RouterApp {
ConfigServiceHandler.registerSignalHandler(_context); ConfigServiceHandler.registerSignalHandler(_context);
if (_mgr != null && if (_mgr != null &&
_context.getBooleanProperty(HelperBase.PROP_ADVANCED) && //_context.getBooleanProperty(HelperBase.PROP_ADVANCED) &&
_context.getProperty(Analysis.PROP_FREQUENCY, 0L) > 0) { !SystemVersion.isSlow() &&
_context.getProperty(Analysis.PROP_FREQUENCY, Analysis.DEFAULT_FREQUENCY) > 0) {
// registers and starts itself // registers and starts itself
Analysis.getInstance(_context); Analysis.getInstance(_context);
} }

View File

@ -297,7 +297,7 @@ public class SybilRenderer {
* @since 0.9.38 * @since 0.9.38
*/ */
private void renderBackgroundForm(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); long freq = _context.getProperty(Analysis.PROP_FREQUENCY, Analysis.DEFAULT_FREQUENCY);
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=\"15\">\n" + "<input type=\"hidden\" name=\"m\" value=\"15\">\n" +
@ -317,10 +317,10 @@ public class SybilRenderer {
buf.append(_t("Never")); buf.append(_t("Never"));
buf.append("</option>\n"); buf.append("</option>\n");
} }
boolean auto = _context.getBooleanProperty(Analysis.PROP_BLOCK); boolean auto = _context.getProperty(Analysis.PROP_BLOCK, Analysis.DEFAULT_BLOCK);
boolean nonff = _context.getBooleanProperty(Analysis.PROP_NONFF); boolean nonff = _context.getBooleanProperty(Analysis.PROP_NONFF);
String thresh = _context.getProperty(Analysis.PROP_THRESHOLD, "50"); String thresh = _context.getProperty(Analysis.PROP_THRESHOLD, Double.toString(Analysis.DEFAULT_BLOCK_THRESHOLD));
long days = _context.getProperty(Analysis.PROP_BLOCKTIME, 7*24*60*60*1000L) / (24*60*60*1000L); long days = _context.getProperty(Analysis.PROP_BLOCKTIME, Analysis.DEFAULT_BLOCK_TIME) / (24*60*60*1000L);
buf.append("</select></td></tr>\n<tr><td>" + buf.append("</select></td></tr>\n<tr><td>" +
"Auto-block routers?</td><td><input type=\"checkbox\" class=\"optbox\" value=\"1\" name=\"block\" "); "Auto-block routers?</td><td><input type=\"checkbox\" class=\"optbox\" value=\"1\" name=\"block\" ");
if (auto) if (auto)
@ -333,7 +333,7 @@ public class SybilRenderer {
"Minimum threat points to block:</td><td><input type=\"text\" name=\"threshold\" value=\"").append(thresh).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>" + "Days to block:</td><td><input type=\"text\" name=\"days\" value=\"").append(days).append("\"></td></tr>\n<tr><td>" +
"Delete stored analysis older than:</td><td><select name=\"deleteAge\">"); "Delete stored analysis older than:</td><td><select name=\"deleteAge\">");
long age = _context.getProperty(Analysis.PROP_REMOVETIME, 0L); long age = _context.getProperty(Analysis.PROP_REMOVETIME, Analysis.DEFAULT_REMOVE_TIME);
for (int i = 0; i <DAYS.length; i++) { for (int i = 0; i <DAYS.length; i++) {
buf.append("<option value=\""); buf.append("<option value=\"");
buf.append(DAYS[i]); buf.append(DAYS[i]);