forked from I2P_Developers/i2p.i2p
Sybil: Delete old stored analysis if configured
Fix display of config tab
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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");
|
||||
|
@ -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<RouterInfo> 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 {
|
||||
"<table><tr><td>Background analysis run frequency:</td><td><select name=\"runFrequency\">");
|
||||
for (int i = 0; i < HOURS.length; i++) {
|
||||
buf.append("<option value=\"");
|
||||
buf.append(Integer.toString(HOURS[i]));
|
||||
buf.append(HOURS[i]);
|
||||
buf.append('"');
|
||||
long time = HOURS[i] * 60*60*1000L;
|
||||
if (time == freq)
|
||||
@ -328,7 +329,24 @@ public class SybilRenderer {
|
||||
buf.append(HelperBase.CHECKED);
|
||||
buf.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></td><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);
|
||||
for (int i = 0; i <DAYS.length; i++) {
|
||||
buf.append("<option value=\"");
|
||||
buf.append(DAYS[i]);
|
||||
buf.append('"');
|
||||
long time = DAYS[i] * 24*60*60*1000L;
|
||||
if (time == age)
|
||||
buf.append(" selected=\"selected\"");
|
||||
buf.append('>');
|
||||
if (DAYS[i] > 0)
|
||||
buf.append(DataHelper.formatDuration2(time));
|
||||
else
|
||||
buf.append(_t("Never"));
|
||||
buf.append("</option>\n");
|
||||
}
|
||||
buf.append("</td></tr>\n<tr><td></td><td>" +
|
||||
"<input type=\"submit\" name=\"action\" class=\"accept\" value=\"Save\" />" +
|
||||
"</td></tr></table></form>\n");
|
||||
writeBuf(out, buf);
|
||||
|
Reference in New Issue
Block a user