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 056789cdc..59852a113 100644 --- a/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java +++ b/apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java @@ -67,6 +67,7 @@ public class Analysis extends JobImpl implements RouterApp { public static final String PROP_BLOCK = "router.sybilEnableBlocking"; public static final String PROP_NONFF = "router.sybilAnalyzeAll"; public static final String PROP_BLOCKTIME = "router.sybilBlockPeriod"; + public static final String PROP_REMOVETIME = "router.sybilDeleteOld"; private static final long MIN_FREQUENCY = 60*60*1000L; private static final long MIN_UPTIME = 75*60*1000L; @@ -133,6 +134,7 @@ public class Analysis extends JobImpl implements RouterApp { try { _log.info("Storing analysis"); _persister.store(now, points); + _persister.removeOld(); _log.info("Store complete"); } catch (IOException ioe) { _log.error("Failed to store analysis", ioe); @@ -151,6 +153,7 @@ public class Analysis extends JobImpl implements RouterApp { changeState(STARTING); changeState(RUNNING); _cmgr.register(this); + _persister.removeOld(); schedule(); } 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 23ad7f3b0..fde9c8ceb 100644 --- a/apps/routerconsole/java/src/net/i2p/router/sybil/PersistSybil.java +++ b/apps/routerconsole/java/src/net/i2p/router/sybil/PersistSybil.java @@ -169,6 +169,37 @@ public class PersistSybil { return rv; } + /** + * Remove all files older than configured threshold + * Inline for now, thread later if necessary + * + * @since 0.9.41 + */ + public synchronized void removeOld() { + long age = _context.getProperty(Analysis.PROP_REMOVETIME, 0L); + if (age < 60*1000) + return; + long cutoff = _context.clock().now() - age; + File dir = new File(_context.getConfigDir(), DIR); + File[] files = dir.listFiles(new FileSuffixFilter(PFX, SFX)); + if (files == null) + return; + int deleted = 0; + for (File file : files) { + try { + String name = file.getName(); + long d = Long.parseLong(name.substring(PFX.length(), name.length() - SFX.length())); + if (d < cutoff) { + if (file.delete()) + deleted++; + } + } catch (NumberFormatException nfe) {} + } + if (deleted > 0 && _log.shouldWarn()) + _log.warn("Deleted " + deleted + " old analysis files"); + } + + /** * Delete the file for a particular date * 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 ccdb51c0f..8531305b3 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 @@ -240,6 +240,11 @@ public class NetDbHelper extends FormHandler { long val = 24*60*60*1000L * Integer.parseInt(days); toSave.put(Analysis.PROP_BLOCKTIME, Long.toString(val)); } + String age = getJettyString("deleteAge"); + if (age != null && age.length() > 0) { + long val = 24*60*60*1000L * Integer.parseInt(age); + toSave.put(Analysis.PROP_REMOVETIME, Long.toString(val)); + } String enable = getJettyString("block"); toSave.put(Analysis.PROP_BLOCK, Boolean.toString(enable != null)); String nonff = getJettyString("nonff"); 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 0f413732e..f01e6020d 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 @@ -70,6 +70,7 @@ public class SybilRenderer { private static final double MIN_CLOSE = Analysis.MIN_CLOSE; private static final double MIN_DISPLAY_POINTS = 12.01; private static final int[] HOURS = { 1, 6, 24, 7*24, 30*24, 0 }; + private static final int[] DAYS = { 2, 7, 30, 90, 365, 0 }; public SybilRenderer(RouterContext ctx) { _context = ctx; @@ -134,7 +135,7 @@ public class SybilRenderer { Hash us = _context.routerHash(); Analysis analysis = Analysis.getInstance(_context); List ris = null; - if (mode != 0 && mode != 12 && mode != 13 && mode != 14 && mode != 16) { + if (mode != 0 && mode < 12) { if (mode >= 2 && mode <= 6) { // review all routers for family and IP analysis ris = analysis.getAllRouters(us); @@ -302,7 +303,7 @@ public class SybilRenderer { "\n\n\n\n\n
Background analysis run frequency:
" + "Minimum threat points to block:
" + - "Days to block:
" + + "Days to block:
" + + "Delete stored analysis older than:
" + "" + "
\n"); writeBuf(out, buf);