From 3a392e84a9e89367c0b8cdeaa9c9732278947a51 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Mon, 22 Jun 2020 19:59:35 +0000 Subject: [PATCH] Sybil: Enable analysis and blocking by default --- .../java/src/net/i2p/router/sybil/Analysis.java | 17 +++++++++++++---- .../src/net/i2p/router/sybil/PersistSybil.java | 2 +- .../net/i2p/router/web/RouterConsoleRunner.java | 5 +++-- .../i2p/router/web/helpers/SybilRenderer.java | 10 +++++----- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java b/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java index 81e3f17147..5cc33969fc 100644 --- a/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java +++ b/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java @@ -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); } } diff --git a/apps/routerconsole/java/src/net/i2p/router/sybil/PersistSybil.java b/apps/routerconsole/java/src/net/i2p/router/sybil/PersistSybil.java index e459806f3a..5e72aacd08 100644 --- a/apps/routerconsole/java/src/net/i2p/router/sybil/PersistSybil.java +++ b/apps/routerconsole/java/src/net/i2p/router/sybil/PersistSybil.java @@ -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; diff --git a/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java b/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java index 25ce36bcb6..e2c12672b3 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java @@ -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); } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java index 15ebd196e3..6767d53855 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java @@ -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]); -- GitLab