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_NEW = 4.0;
private static final double POINTS_BANLIST = 25.0;
private static final double DEFAULT_BLOCK_THRESHOLD = 50.0;
private static final long DEFAULT_BLOCK_TIME = 7*24*60*60*1000L;
public static final boolean DEFAULT_BLOCK = true;
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;
/** Get via getInstance() */
@ -188,7 +191,7 @@ public class Analysis extends JobImpl implements RouterApp {
}
public synchronized void schedule() {
long freq = _context.getProperty(PROP_FREQUENCY, 0L);
long freq = _context.getProperty(PROP_FREQUENCY, DEFAULT_FREQUENCY);
if (freq > 0) {
List<Long> previous = _persister.load();
long now = _context.clock().now() + 15*1000;
@ -372,7 +375,7 @@ public class Analysis extends JobImpl implements RouterApp {
// Profile analysis
addProfilePoints(ris, points);
addVersionPoints(ris, points);
if (_context.getBooleanProperty(PROP_BLOCK))
if (_context.getProperty(PROP_BLOCK, DEFAULT_BLOCK))
doBlocking(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";
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);
}
}

View File

@ -180,7 +180,7 @@ public class PersistSybil {
* @since 0.9.41
*/
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)
return;
long cutoff = _context.clock().now() - age;

View File

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

View File

@ -297,7 +297,7 @@ public class SybilRenderer {
* @since 0.9.38
*/
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" +
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
"<input type=\"hidden\" name=\"m\" value=\"15\">\n" +
@ -317,10 +317,10 @@ public class SybilRenderer {
buf.append(_t("Never"));
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);
String thresh = _context.getProperty(Analysis.PROP_THRESHOLD, "50");
long days = _context.getProperty(Analysis.PROP_BLOCKTIME, 7*24*60*60*1000L) / (24*60*60*1000L);
String thresh = _context.getProperty(Analysis.PROP_THRESHOLD, Double.toString(Analysis.DEFAULT_BLOCK_THRESHOLD));
long days = _context.getProperty(Analysis.PROP_BLOCKTIME, Analysis.DEFAULT_BLOCK_TIME) / (24*60*60*1000L);
buf.append("</select></td></tr>\n<tr><td>" +
"Auto-block routers?</td><td><input type=\"checkbox\" class=\"optbox\" value=\"1\" name=\"block\" ");
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>" +
"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\">");
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++) {
buf.append("<option value=\"");
buf.append(DAYS[i]);