forked from I2P_Developers/i2p.i2p
Sybil: Skip comment lines in stored files
Escape % in stored reasons Improve error handling when loading files
This commit is contained in:
@ -64,6 +64,8 @@ public class PersistSybil {
|
||||
Writer out = null;
|
||||
try {
|
||||
out = new OutputStreamWriter(new GZIPOutputStream(new SecureFileOutputStream(file)));
|
||||
out.write("# Format (one per line)\n");
|
||||
out.write("# Base64 router hash:total points%points:reason%points:reason ...\n");
|
||||
for (Map.Entry<Hash, Points> entry : entries.entrySet()) {
|
||||
Hash h = entry.getKey();
|
||||
Points p = entry.getValue();
|
||||
@ -114,6 +116,8 @@ public class PersistSybil {
|
||||
in = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (line.startsWith("#"))
|
||||
continue;
|
||||
int colon = line.indexOf(':');
|
||||
if (colon != 44)
|
||||
continue;
|
||||
@ -192,6 +196,8 @@ public class PersistSybil {
|
||||
if (d < cutoff) {
|
||||
if (file.delete())
|
||||
deleted++;
|
||||
else if (_log.shouldWarn())
|
||||
_log.warn("Failed to delete: " + file);
|
||||
}
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class Points implements Comparable<Points> {
|
||||
public void toString(StringBuilder buf) {
|
||||
buf.append(points);
|
||||
for (String r : reasons) {
|
||||
buf.append('%').append(r);
|
||||
buf.append('%').append(r.replace("%", "%"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ import net.i2p.util.VersionComparator;
|
||||
public class SybilRenderer {
|
||||
|
||||
private final RouterContext _context;
|
||||
private final Log _log;
|
||||
private final DecimalFormat fmt = new DecimalFormat("#0.00");
|
||||
private final DateFormat dfmt;
|
||||
|
||||
@ -74,6 +75,7 @@ public class SybilRenderer {
|
||||
|
||||
public SybilRenderer(RouterContext ctx) {
|
||||
_context = ctx;
|
||||
_log = ctx.logManager().getLog(SybilRenderer.class);
|
||||
dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
|
||||
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
}
|
||||
@ -206,11 +208,14 @@ public class SybilRenderer {
|
||||
try {
|
||||
points = ps.load(date);
|
||||
} catch (IOException ioe) {
|
||||
out.write("<b>No analysis found for " + new Date(date) + "</b>");
|
||||
_log.error("loading stored analysis for date: " + date, ioe);
|
||||
out.write("<b>Failed to load analysis for " + dfmt.format(new Date(date)) + "</b>: " +
|
||||
DataHelper.escapeHTML(ioe.toString()));
|
||||
return;
|
||||
}
|
||||
if (points.isEmpty()) {
|
||||
out.write("<b>No analysis found for " + new Date(date) + "</b>");
|
||||
_log.error("empty stored analysis or bad file format for date: " + date);
|
||||
out.write("<b>Corrupt analysis file for " + dfmt.format(new Date(date)) + "</b>");
|
||||
} else {
|
||||
renderThreatsHTML(out, buf, date, points);
|
||||
}
|
||||
|
Reference in New Issue
Block a user