From 48a92ca1e7a5fe5573a5071fb1ca754af1802975 Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 13 May 2019 12:15:19 +0000 Subject: [PATCH] Sybil: Auto-block UI --- .../src/net/i2p/router/sybil/Analysis.java | 3 +++ .../i2p/router/web/helpers/NetDbHelper.java | 26 +++++++++++++++---- .../i2p/router/web/helpers/SybilRenderer.java | 22 +++++++++++++--- 3 files changed, 43 insertions(+), 8 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 31ad8bf90..ea8ebfd0f 100644 --- a/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java +++ b/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java @@ -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; diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java index f8e05bde5..8daed98bf 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java @@ -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 toSave = new HashMap(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"); } - } } } 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 8d358a681..49725ba64 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 @@ -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 { "\n" + "\n" + "\n" + - "Background analysis run frequency: "); for (int i = 0; i < HOURS.length; i++) { buf.append("