forked from I2P_Developers/i2p.i2p
Sybil:
Show routers in analysis even if no RI available Date format fixes Put date in ban reason Show ban reason Add link to banlist
This commit is contained in:
@ -4,11 +4,13 @@ import java.io.IOException;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ import net.i2p.data.LeaseSet;
|
|||||||
import net.i2p.data.router.RouterAddress;
|
import net.i2p.data.router.RouterAddress;
|
||||||
import net.i2p.data.router.RouterInfo;
|
import net.i2p.data.router.RouterInfo;
|
||||||
import net.i2p.data.router.RouterKeyGenerator;
|
import net.i2p.data.router.RouterKeyGenerator;
|
||||||
|
import net.i2p.router.Banlist;
|
||||||
import net.i2p.router.JobImpl;
|
import net.i2p.router.JobImpl;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.TunnelPoolSettings;
|
import net.i2p.router.TunnelPoolSettings;
|
||||||
@ -38,6 +41,7 @@ import net.i2p.stat.RateStat;
|
|||||||
import net.i2p.util.Addresses;
|
import net.i2p.util.Addresses;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.ObjectCounter;
|
import net.i2p.util.ObjectCounter;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -353,12 +357,16 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
*/
|
*/
|
||||||
private void doBlocking(Map<Hash, Points> points) {
|
private void doBlocking(Map<Hash, Points> points) {
|
||||||
double threshold = DEFAULT_BLOCK_THRESHOLD;
|
double threshold = DEFAULT_BLOCK_THRESHOLD;
|
||||||
long blockUntil = _context.getProperty(Analysis.PROP_BLOCKTIME, DEFAULT_BLOCK_TIME) + _context.clock().now();
|
long now = _context.clock().now();
|
||||||
|
long blockUntil = _context.getProperty(Analysis.PROP_BLOCKTIME, DEFAULT_BLOCK_TIME) + now;
|
||||||
try {
|
try {
|
||||||
threshold = Double.parseDouble(_context.getProperty(PROP_THRESHOLD, Double.toString(DEFAULT_BLOCK_THRESHOLD)));
|
threshold = Double.parseDouble(_context.getProperty(PROP_THRESHOLD, Double.toString(DEFAULT_BLOCK_THRESHOLD)));
|
||||||
if (threshold < MIN_BLOCK_POINTS)
|
if (threshold < MIN_BLOCK_POINTS)
|
||||||
threshold = MIN_BLOCK_POINTS;
|
threshold = MIN_BLOCK_POINTS;
|
||||||
} catch (NumberFormatException nfe) {}
|
} catch (NumberFormatException nfe) {}
|
||||||
|
DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
|
||||||
|
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||||
|
String day = dfmt.format(now);
|
||||||
for (Map.Entry<Hash, Points> e : points.entrySet()) {
|
for (Map.Entry<Hash, Points> e : points.entrySet()) {
|
||||||
double p = e.getValue().getPoints();
|
double p = e.getValue().getPoints();
|
||||||
if (p >= threshold) {
|
if (p >= threshold) {
|
||||||
@ -371,7 +379,7 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
_context.blocklist().add(ip);
|
_context.blocklist().add(ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String reason = "Sybil analysis with " + fmt.format(p) + " threat points";
|
String reason = "Sybil analysis " + day + " with " + fmt.format(p) + " threat points";
|
||||||
_context.banlist().banlistRouter(h, reason, null, null, blockUntil);
|
_context.banlist().banlistRouter(h, reason, null, null, blockUntil);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -672,12 +680,25 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
private static final long DAY = 24*60*60*1000L;
|
private static final long DAY = 24*60*60*1000L;
|
||||||
|
|
||||||
public void addProfilePoints(List<RouterInfo> ris, Map<Hash, Points> points) {
|
public void addProfilePoints(List<RouterInfo> ris, Map<Hash, Points> points) {
|
||||||
|
Map<Hash, Banlist.Entry> banEntries = _context.banlist().getEntries();
|
||||||
long now = _context.clock().now();
|
long now = _context.clock().now();
|
||||||
RateAverages ra = RateAverages.getTemp();
|
RateAverages ra = RateAverages.getTemp();
|
||||||
for (RouterInfo info : ris) {
|
for (RouterInfo info : ris) {
|
||||||
Hash h = info.getHash();
|
Hash h = info.getHash();
|
||||||
if (_context.banlist().isBanlisted(h))
|
if (_context.banlist().isBanlisted(h)) {
|
||||||
addPoints(points, h, POINTS_BANLIST, "Banlisted");
|
StringBuilder buf = new StringBuilder("Banlisted");
|
||||||
|
Banlist.Entry entry = banEntries.get(h);
|
||||||
|
if (entry != null) {
|
||||||
|
if (entry.cause != null) {
|
||||||
|
buf.append(": ");
|
||||||
|
if (entry.causeCode != null)
|
||||||
|
buf.append(_t(entry.cause, entry.causeCode));
|
||||||
|
else
|
||||||
|
buf.append(_t(entry.cause));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addPoints(points, h, POINTS_BANLIST, buf.toString());
|
||||||
|
}
|
||||||
PeerProfile prof = _context.profileOrganizer().getProfileNonblocking(h);
|
PeerProfile prof = _context.profileOrganizer().getProfileNonblocking(h);
|
||||||
if (prof != null) {
|
if (prof != null) {
|
||||||
long heard = prof.getFirstHeardAbout();
|
long heard = prof.getFirstHeardAbout();
|
||||||
@ -777,6 +798,10 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
return Util.biLog2(a);
|
return Util.biLog2(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String _t(String s) {
|
||||||
|
return Messages.getString(s, _context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* translate a string with a parameter
|
* translate a string with a parameter
|
||||||
* This is a lot more expensive than _t(s), so use sparingly.
|
* This is a lot more expensive than _t(s), so use sparingly.
|
||||||
|
@ -63,6 +63,7 @@ public class SybilRenderer {
|
|||||||
|
|
||||||
private final RouterContext _context;
|
private final RouterContext _context;
|
||||||
private final DecimalFormat fmt = new DecimalFormat("#0.00");
|
private final DecimalFormat fmt = new DecimalFormat("#0.00");
|
||||||
|
private final DateFormat dfmt;
|
||||||
|
|
||||||
private static final int PAIRMAX = Analysis.PAIRMAX;
|
private static final int PAIRMAX = Analysis.PAIRMAX;
|
||||||
private static final int MAX = Analysis.MAX;
|
private static final int MAX = Analysis.MAX;
|
||||||
@ -72,6 +73,8 @@ public class SybilRenderer {
|
|||||||
|
|
||||||
public SybilRenderer(RouterContext ctx) {
|
public SybilRenderer(RouterContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
|
dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
|
||||||
|
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,6 +149,7 @@ public class SybilRenderer {
|
|||||||
"<div id=\"sybilnav\"><ul><li><a href=\"netdb?f=3\">Review stored analysis</a>" +
|
"<div id=\"sybilnav\"><ul><li><a href=\"netdb?f=3\">Review stored analysis</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=14\">Run new analysis</a>" +
|
"</li><li><a href=\"netdb?f=3&m=14\">Run new analysis</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=15\">Configure periodic analysis</a>" +
|
"</li><li><a href=\"netdb?f=3&m=15\">Configure periodic analysis</a>" +
|
||||||
|
"</li><li><a href=\"/profiles?f=3\">Review current bans</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=1\">Floodfill Summary</a>" +
|
"</li><li><a href=\"netdb?f=3&m=1\">Floodfill Summary</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=2\">Same Family</a>" +
|
"</li><li><a href=\"netdb?f=3&m=2\">Same Family</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=3\">IP close to us</a>" +
|
"</li><li><a href=\"netdb?f=3&m=3\">IP close to us</a>" +
|
||||||
@ -245,8 +249,6 @@ public class SybilRenderer {
|
|||||||
"Select stored analysis: " +
|
"Select stored analysis: " +
|
||||||
"<select name=\"date\">\n");
|
"<select name=\"date\">\n");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
|
||||||
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
|
||||||
for (Long date : dates) {
|
for (Long date : dates) {
|
||||||
buf.append("<option value=\"").append(date).append('\"');
|
buf.append("<option value=\"").append(date).append('\"');
|
||||||
if (first) {
|
if (first) {
|
||||||
@ -320,8 +322,6 @@ public class SybilRenderer {
|
|||||||
private void renderFFSummary(Writer out, StringBuilder buf, List<RouterInfo> ris, double avgMinDist) throws IOException {
|
private void renderFFSummary(Writer out, StringBuilder buf, List<RouterInfo> ris, double avgMinDist) throws IOException {
|
||||||
renderRouterInfo(buf, _context.router().getRouterInfo(), null, true, false);
|
renderRouterInfo(buf, _context.router().getRouterInfo(), null, true, false);
|
||||||
buf.append("<h3 id=\"known\" class=\"sybils\">Known Floodfills: ").append(ris.size()).append("</h3>");
|
buf.append("<h3 id=\"known\" class=\"sybils\">Known Floodfills: ").append(ris.size()).append("</h3>");
|
||||||
DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
|
||||||
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
|
||||||
buf.append("<div id=\"sybils_summary\">\n" +
|
buf.append("<div id=\"sybils_summary\">\n" +
|
||||||
"<b>Average closest floodfill distance:</b> ").append(fmt.format(avgMinDist)).append("<br>\n" +
|
"<b>Average closest floodfill distance:</b> ").append(fmt.format(avgMinDist)).append("<br>\n" +
|
||||||
"<b>Routing Data:</b> \"").append(DataHelper.getUTF8(_context.routerKeyGenerator().getModData()))
|
"<b>Routing Data:</b> \"").append(DataHelper.getUTF8(_context.routerKeyGenerator().getModData()))
|
||||||
@ -468,13 +468,8 @@ public class SybilRenderer {
|
|||||||
List<Hash> warns = new ArrayList<Hash>(points.keySet());
|
List<Hash> warns = new ArrayList<Hash>(points.keySet());
|
||||||
Collections.sort(warns, new PointsComparator(points));
|
Collections.sort(warns, new PointsComparator(points));
|
||||||
ReasonComparator rcomp = new ReasonComparator();
|
ReasonComparator rcomp = new ReasonComparator();
|
||||||
DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
|
||||||
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
|
||||||
buf.append("<h3 id=\"threats\" class=\"sybils\">Routers with Most Threat Points as of " + dfmt.format(new Date(date)) + "</h3>");
|
buf.append("<h3 id=\"threats\" class=\"sybils\">Routers with Most Threat Points as of " + dfmt.format(new Date(date)) + "</h3>");
|
||||||
for (Hash h : warns) {
|
for (Hash h : warns) {
|
||||||
RouterInfo ri = _context.netDb().lookupRouterInfoLocally(h);
|
|
||||||
if (ri == null)
|
|
||||||
continue;
|
|
||||||
Points pp = points.get(h);
|
Points pp = points.get(h);
|
||||||
double p = pp.getPoints();
|
double p = pp.getPoints();
|
||||||
if (p < MIN_DISPLAY_POINTS)
|
if (p < MIN_DISPLAY_POINTS)
|
||||||
@ -490,7 +485,15 @@ public class SybilRenderer {
|
|||||||
buf.append("<li><b>").append(s, 0, c+1).append("</b>").append(s, c+1, s.length()).append("</li>");
|
buf.append("<li><b>").append(s, 0, c+1).append("</b>").append(s, c+1, s.length()).append("</li>");
|
||||||
}
|
}
|
||||||
buf.append("</ul>");
|
buf.append("</ul>");
|
||||||
|
RouterInfo ri = _context.netDb().lookupRouterInfoLocally(h);
|
||||||
|
if (ri != null) {
|
||||||
renderRouterInfo(buf, ri, null, false, false);
|
renderRouterInfo(buf, ri, null, false, false);
|
||||||
|
} else {
|
||||||
|
String hash = h.toBase64();
|
||||||
|
buf.append("<a name=\"").append(hash, 0, 6).append("\"></a><table class=\"sybil_routerinfo\"><tr>" +
|
||||||
|
"<th><b>" + _t("Router") + ":</b> <code>").append(hash).append("</code></th>" +
|
||||||
|
"<th><b>Router info not available</b></th><th></th></tr></table>\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeBuf(out, buf);
|
writeBuf(out, buf);
|
||||||
@ -962,9 +965,9 @@ public class SybilRenderer {
|
|||||||
out.write("<h3>Distance to " + from.toBase64() + "</h3>");
|
out.write("<h3>Distance to " + from.toBase64() + "</h3>");
|
||||||
prev = null;
|
prev = null;
|
||||||
final int limit = Math.min(10, sybils.size());
|
final int limit = Math.min(10, sybils.size());
|
||||||
DateFormat dfmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
|
DateFormat utcfmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
|
||||||
for (int i = start; i <= days; i++) {
|
for (int i = start; i <= days; i++) {
|
||||||
out.write("<h3 class=\"tabletitle\">Distance for " + dfmt.format(new Date(now)) +
|
out.write("<h3 class=\"tabletitle\">Distance for " + utcfmt.format(new Date(now)) +
|
||||||
"</h3><table class=\"sybil_distance\"><tr><th>Hash<th>Distance<th>Distance from previous</tr>\n");
|
"</h3><table class=\"sybil_distance\"><tr><th>Hash<th>Distance<th>Distance from previous</tr>\n");
|
||||||
Hash rkey = rkgen.getRoutingKey(from, now);
|
Hash rkey = rkgen.getRoutingKey(from, now);
|
||||||
xor = new XORComparator<Hash>(rkey);
|
xor = new XORComparator<Hash>(rkey);
|
||||||
|
Reference in New Issue
Block a user