forked from I2P_Developers/i2p.i2p
Router: Add IPv6 analysis to Sybil checker
Add to console sybil page Fix links for IPs close to us Header and reason tweaks Increase verified family credit
This commit is contained in:
@@ -134,8 +134,8 @@ public class SybilRenderer {
|
|||||||
Hash us = _context.routerHash();
|
Hash us = _context.routerHash();
|
||||||
Analysis analysis = Analysis.getInstance(_context);
|
Analysis analysis = Analysis.getInstance(_context);
|
||||||
List<RouterInfo> ris = null;
|
List<RouterInfo> ris = null;
|
||||||
if (mode != 0 && mode < 12) {
|
if (mode != 0 && (mode < 12 || mode == 17 || mode == 18)) {
|
||||||
if (mode >= 2 && mode <= 6) {
|
if (mode >= 2 && (mode <= 6 || mode == 17 || mode == 18)) {
|
||||||
// review all routers for family and IP analysis
|
// review all routers for family and IP analysis
|
||||||
ris = analysis.getAllRouters(us);
|
ris = analysis.getAllRouters(us);
|
||||||
} else {
|
} else {
|
||||||
@@ -159,8 +159,10 @@ public class SybilRenderer {
|
|||||||
"</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>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=4\">Same IP</a>" +
|
"</li><li><a href=\"netdb?f=3&m=4\">Same IP</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=5\">Same /24</a>" +
|
"</li><li><a href=\"netdb?f=3&m=5\">Same IPv4 /24</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=6\">Same /16</a>" +
|
"</li><li><a href=\"netdb?f=3&m=6\">Same IPv4 /16</a>" +
|
||||||
|
"</li><li><a href=\"netdb?f=3&m=17\">Same IPv6 /64</a>" +
|
||||||
|
"</li><li><a href=\"netdb?f=3&m=18\">Same IPv6 /48</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=7\">Pair distance</a>" +
|
"</li><li><a href=\"netdb?f=3&m=7\">Pair distance</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=8\">Close to us</a>" +
|
"</li><li><a href=\"netdb?f=3&m=8\">Close to us</a>" +
|
||||||
"</li><li><a href=\"netdb?f=3&m=9\">Close to us tomorrow</a>" +
|
"</li><li><a href=\"netdb?f=3&m=9\">Close to us tomorrow</a>" +
|
||||||
@@ -189,6 +191,10 @@ public class SybilRenderer {
|
|||||||
renderIP24Summary(out, buf, analysis, ris, points);
|
renderIP24Summary(out, buf, analysis, ris, points);
|
||||||
} else if (mode == 6) {
|
} else if (mode == 6) {
|
||||||
renderIP16Summary(out, buf, analysis, ris, points);
|
renderIP16Summary(out, buf, analysis, ris, points);
|
||||||
|
} else if (mode == 17) {
|
||||||
|
renderIP64Summary(out, buf, analysis, ris, points);
|
||||||
|
} else if (mode == 18) {
|
||||||
|
renderIP48Summary(out, buf, analysis, ris, points);
|
||||||
} else if (mode == 7) {
|
} else if (mode == 7) {
|
||||||
renderPairSummary(out, buf, analysis, ris, points);
|
renderPairSummary(out, buf, analysis, ris, points);
|
||||||
} else if (mode == 8) {
|
} else if (mode == 8) {
|
||||||
@@ -385,8 +391,10 @@ public class SybilRenderer {
|
|||||||
List<RouterInfo> ri32 = new ArrayList<RouterInfo>(4);
|
List<RouterInfo> ri32 = new ArrayList<RouterInfo>(4);
|
||||||
List<RouterInfo> ri24 = new ArrayList<RouterInfo>(4);
|
List<RouterInfo> ri24 = new ArrayList<RouterInfo>(4);
|
||||||
List<RouterInfo> ri16 = new ArrayList<RouterInfo>(4);
|
List<RouterInfo> ri16 = new ArrayList<RouterInfo>(4);
|
||||||
analysis.calculateIPGroupsUs(ris, points, ri32, ri24, ri16);
|
List<RouterInfo> ri64 = new ArrayList<RouterInfo>(4);
|
||||||
renderIPGroupsUs(out, buf, ri32, ri24, ri16);
|
List<RouterInfo> ri48 = new ArrayList<RouterInfo>(4);
|
||||||
|
analysis.calculateIPGroupsUs(ris, points, ri32, ri24, ri16, ri64, ri48);
|
||||||
|
renderIPGroupsUs(out, buf, ri32, ri24, ri16, ri64, ri48);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -413,6 +421,22 @@ public class SybilRenderer {
|
|||||||
renderIPGroups16(out, buf, map);
|
renderIPGroups16(out, buf, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
private void renderIP64Summary(Writer out, StringBuilder buf, Analysis analysis, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
|
||||||
|
Map<Long, List<RouterInfo>> map = analysis.calculateIPGroups64(ris, points);
|
||||||
|
renderIPGroups64(out, buf, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
private void renderIP48Summary(Writer out, StringBuilder buf, Analysis analysis, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
|
||||||
|
Map<Long, List<RouterInfo>> map = analysis.calculateIPGroups48(ris, points);
|
||||||
|
renderIPGroups48(out, buf, map);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 0.9.38 split out from renderRouterInfoHTML()
|
* @since 0.9.38 split out from renderRouterInfoHTML()
|
||||||
*/
|
*/
|
||||||
@@ -565,16 +589,17 @@ public class SybilRenderer {
|
|||||||
writeBuf(out, buf);
|
writeBuf(out, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FooComparator implements Comparator<Integer>, Serializable {
|
private static class FooComparator<K extends Comparable> implements Comparator<K>, Serializable {
|
||||||
private final Map<Integer, List<RouterInfo>> _o;
|
private final Map<K, List<RouterInfo>> _o;
|
||||||
public FooComparator(Map<Integer, List<RouterInfo>> o) { _o = o;}
|
public FooComparator(Map<K, List<RouterInfo>> o) { _o = o;}
|
||||||
public int compare(Integer l, Integer r) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public int compare(K l, K r) {
|
||||||
// reverse by count
|
// reverse by count
|
||||||
int rv = _o.get(r).size() - _o.get(l).size();
|
int rv = _o.get(r).size() - _o.get(l).size();
|
||||||
if (rv != 0)
|
if (rv != 0)
|
||||||
return rv;
|
return rv;
|
||||||
// foward by IP
|
// forward by IP
|
||||||
return l.intValue() - r.intValue();
|
return l.compareTo(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,7 +612,7 @@ public class SybilRenderer {
|
|||||||
int rv = _o.get(r).size() - _o.get(l).size();
|
int rv = _o.get(r).size() - _o.get(l).size();
|
||||||
if (rv != 0)
|
if (rv != 0)
|
||||||
return rv;
|
return rv;
|
||||||
// foward by name
|
// forward by name
|
||||||
return _comp.compare(l, r);
|
return _comp.compare(l, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,7 +621,8 @@ public class SybilRenderer {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void renderIPGroupsUs(Writer out, StringBuilder buf, List<RouterInfo> ri32,
|
private void renderIPGroupsUs(Writer out, StringBuilder buf, List<RouterInfo> ri32,
|
||||||
List<RouterInfo> ri24, List<RouterInfo> ri16) throws IOException {
|
List<RouterInfo> ri24, List<RouterInfo> ri16,
|
||||||
|
List<RouterInfo> ri64, List<RouterInfo> ri48) throws IOException {
|
||||||
buf.append("<h3 id=\"ourIP\" class=\"sybils\">Routers close to Our IP</h3>");
|
buf.append("<h3 id=\"ourIP\" class=\"sybils\">Routers close to Our IP</h3>");
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (RouterInfo info : ri32) {
|
for (RouterInfo info : ri32) {
|
||||||
@@ -608,14 +634,28 @@ public class SybilRenderer {
|
|||||||
}
|
}
|
||||||
for (RouterInfo info : ri24) {
|
for (RouterInfo info : ri24) {
|
||||||
buf.append("<p id=\"sybil_info\"><b>");
|
buf.append("<p id=\"sybil_info\"><b>");
|
||||||
buf.append("Same /24 as us");
|
buf.append("Same IPv4 /24 as us");
|
||||||
buf.append(":</b></p>");
|
buf.append(":</b></p>");
|
||||||
renderRouterInfo(buf, info, null, false, false);
|
renderRouterInfo(buf, info, null, false, false);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
for (RouterInfo info : ri16) {
|
for (RouterInfo info : ri16) {
|
||||||
buf.append("<p id=\"sybil_info\"><b>");
|
buf.append("<p id=\"sybil_info\"><b>");
|
||||||
buf.append("Same /16 as us");
|
buf.append("Same IPv4 /16 as us");
|
||||||
|
buf.append(":</b></p>");
|
||||||
|
renderRouterInfo(buf, info, null, false, false);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
for (RouterInfo info : ri64) {
|
||||||
|
buf.append("<p id=\"sybil_info\"><b>");
|
||||||
|
buf.append("Same IPv6 /64 as us");
|
||||||
|
buf.append(":</b></p>");
|
||||||
|
renderRouterInfo(buf, info, null, false, false);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
for (RouterInfo info : ri48) {
|
||||||
|
buf.append("<p id=\"sybil_info\"><b>");
|
||||||
|
buf.append("Same IPv6 /48 as us");
|
||||||
buf.append(":</b></p>");
|
buf.append(":</b></p>");
|
||||||
renderRouterInfo(buf, info, null, false, false);
|
renderRouterInfo(buf, info, null, false, false);
|
||||||
found = true;
|
found = true;
|
||||||
@@ -629,9 +669,9 @@ public class SybilRenderer {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void renderIPGroups32(Writer out, StringBuilder buf, Map<Integer, List<RouterInfo>> map) throws IOException {
|
private void renderIPGroups32(Writer out, StringBuilder buf, Map<Integer, List<RouterInfo>> map) throws IOException {
|
||||||
buf.append("<h3 id=\"sameIP\" class=\"sybils\">Routers with the Same IP</h3>");
|
buf.append("<h3 id=\"sameIP\" class=\"sybils\">Routers with the same IPv4</h3>");
|
||||||
List<Integer> foo = new ArrayList<Integer>(map.keySet());
|
List<Integer> foo = new ArrayList<Integer>(map.keySet());
|
||||||
Collections.sort(foo, new FooComparator(map));
|
Collections.sort(foo, new FooComparator<Integer>(map));
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Integer ii : foo) {
|
for (Integer ii : foo) {
|
||||||
List<RouterInfo> ris = map.get(ii);
|
List<RouterInfo> ris = map.get(ii);
|
||||||
@@ -659,9 +699,9 @@ public class SybilRenderer {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void renderIPGroups24(Writer out, StringBuilder buf, Map<Integer, List<RouterInfo>> map) throws IOException {
|
private void renderIPGroups24(Writer out, StringBuilder buf, Map<Integer, List<RouterInfo>> map) throws IOException {
|
||||||
buf.append("<h3 id=\"same24\" class=\"sybils\">Routers in the Same /24 (2 minimum)</h3>");
|
buf.append("<h3 id=\"same24\" class=\"sybils\">Routers in the same IPv4 /24</h3>");
|
||||||
List<Integer> foo = new ArrayList<Integer>(map.keySet());
|
List<Integer> foo = new ArrayList<Integer>(map.keySet());
|
||||||
Collections.sort(foo, new FooComparator(map));
|
Collections.sort(foo, new FooComparator<Integer>(map));
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Integer ii : foo) {
|
for (Integer ii : foo) {
|
||||||
List<RouterInfo> ris = map.get(ii);
|
List<RouterInfo> ris = map.get(ii);
|
||||||
@@ -688,9 +728,9 @@ public class SybilRenderer {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void renderIPGroups16(Writer out, StringBuilder buf, Map<Integer, List<RouterInfo>> map) throws IOException {
|
private void renderIPGroups16(Writer out, StringBuilder buf, Map<Integer, List<RouterInfo>> map) throws IOException {
|
||||||
buf.append("<h3 id=\"same16\" class=\"sybils\">Routers in the Same /16 (4 minimum)</h3>");
|
buf.append("<h3 id=\"same16\" class=\"sybils\">Routers in the same IPv4 /16 (4 minimum)</h3>");
|
||||||
List<Integer> foo = new ArrayList<Integer>(map.keySet());
|
List<Integer> foo = new ArrayList<Integer>(map.keySet());
|
||||||
Collections.sort(foo, new FooComparator(map));
|
Collections.sort(foo, new FooComparator<Integer>(map));
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Integer ii : foo) {
|
for (Integer ii : foo) {
|
||||||
List<RouterInfo> ris = map.get(ii);
|
List<RouterInfo> ris = map.get(ii);
|
||||||
@@ -712,6 +752,67 @@ public class SybilRenderer {
|
|||||||
writeBuf(out, buf);
|
writeBuf(out, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
private void renderIPGroups64(Writer out, StringBuilder buf, Map<Long, List<RouterInfo>> map) throws IOException {
|
||||||
|
buf.append("<h3 id=\"same64\" class=\"sybils\">Routers in the same IPv6 /64</h3>");
|
||||||
|
List<Long> foo = new ArrayList<Long>(map.keySet());
|
||||||
|
Collections.sort(foo, new FooComparator<Long>(map));
|
||||||
|
boolean found = false;
|
||||||
|
for (Long ii : foo) {
|
||||||
|
List<RouterInfo> ris = map.get(ii);
|
||||||
|
int count = ris.size();
|
||||||
|
long i = ii.longValue();
|
||||||
|
int i0 = (int) ((i >> 48) & 0xffff);
|
||||||
|
int i2 = (int) ((i >> 32) & 0xffff);
|
||||||
|
int i4 = (int) ((i >> 16) & 0xffff);
|
||||||
|
int i6 = (int) (i & 0xffff);
|
||||||
|
String sip = Integer.toString(i0, 16) + ":" + Integer.toString(i2, 16) + ':' +
|
||||||
|
Integer.toString(i4, 16) + ':' + Integer.toString(i6, 16) + "::";
|
||||||
|
buf.append("<p class=\"sybil_info\"><b>").append(count).append(" routers with IP <a href=\"/netdb?ip=")
|
||||||
|
.append(sip).append("&sybil\">").append(sip)
|
||||||
|
.append("</a></b></p>");
|
||||||
|
for (RouterInfo info : ris) {
|
||||||
|
found = true;
|
||||||
|
renderRouterInfo(buf, info, null, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
buf.append("<p class=\"notfound\">None</p>");
|
||||||
|
writeBuf(out, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
private void renderIPGroups48(Writer out, StringBuilder buf, Map<Long, List<RouterInfo>> map) throws IOException {
|
||||||
|
buf.append("<h3 id=\"same48\" class=\"sybils\">Routers in the same IPv6 /48 (4 minimum)</h3>");
|
||||||
|
List<Long> foo = new ArrayList<Long>(map.keySet());
|
||||||
|
Collections.sort(foo, new FooComparator<Long>(map));
|
||||||
|
boolean found = false;
|
||||||
|
for (Long ii : foo) {
|
||||||
|
List<RouterInfo> ris = map.get(ii);
|
||||||
|
int count = ris.size();
|
||||||
|
long i = ii.longValue();
|
||||||
|
int i0 = (int) ((i >> 32) & 0xffff);
|
||||||
|
int i2 = (int) ((i >> 16) & 0xffff);
|
||||||
|
int i4 = (int) (i & 0xffff);
|
||||||
|
String sip = Integer.toString(i0, 16) + ":" + Integer.toString(i2, 16) + ':' +
|
||||||
|
Integer.toString(i4, 16) + "::";
|
||||||
|
buf.append("<p class=\"sybil_info\"><b>").append(count).append(" routers with IP <a href=\"/netdb?ip=")
|
||||||
|
.append(sip).append("&sybil\">").append(sip)
|
||||||
|
.append("</a></b></p>");
|
||||||
|
for (RouterInfo info : ris) {
|
||||||
|
found = true;
|
||||||
|
renderRouterInfo(buf, info, null, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
buf.append("<p class=\"notfound\">None</p>");
|
||||||
|
writeBuf(out, buf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@@ -85,8 +85,15 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
private static final double POINTS_US32 = 25.0;
|
private static final double POINTS_US32 = 25.0;
|
||||||
private static final double POINTS_US24 = 20.0;
|
private static final double POINTS_US24 = 20.0;
|
||||||
private static final double POINTS_US16 = 10.0;
|
private static final double POINTS_US16 = 10.0;
|
||||||
|
|
||||||
|
// IPv6 since 0.9.57, likely to be on top of IPv4, so make lower
|
||||||
|
private static final double POINTS_V6_US64 = 12.5;
|
||||||
|
private static final double POINTS_V6_US48 = 5.0;
|
||||||
|
private static final double POINTS64 = 2.0;
|
||||||
|
private static final double POINTS48 = 0.5;
|
||||||
|
|
||||||
private static final double POINTS_FAMILY = -10.0;
|
private static final double POINTS_FAMILY = -10.0;
|
||||||
private static final double POINTS_FAMILY_VERIFIED = POINTS_FAMILY * 2;
|
private static final double POINTS_FAMILY_VERIFIED = POINTS_FAMILY * 4;
|
||||||
private static final double POINTS_NONFF = -5.0;
|
private static final double POINTS_NONFF = -5.0;
|
||||||
private static final double POINTS_BAD_FAMILY = 20.0;
|
private static final double POINTS_BAD_FAMILY = 20.0;
|
||||||
private static final double POINTS_BAD_OUR_FAMILY = 100.0;
|
private static final double POINTS_BAD_OUR_FAMILY = 100.0;
|
||||||
@@ -374,13 +381,14 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
|
|
||||||
// IP analysis
|
// IP analysis
|
||||||
calculateIPGroupsFamily(ris, points);
|
calculateIPGroupsFamily(ris, points);
|
||||||
List<RouterInfo> ri32 = new ArrayList<RouterInfo>(4);
|
// unused here, just for the console, so use the same for all of them
|
||||||
List<RouterInfo> ri24 = new ArrayList<RouterInfo>(4);
|
List<RouterInfo> dummy = new DummyList();
|
||||||
List<RouterInfo> ri16 = new ArrayList<RouterInfo>(4);
|
calculateIPGroupsUs(ris, points, dummy, dummy, dummy, dummy, dummy);
|
||||||
calculateIPGroupsUs(ris, points, ri32, ri24, ri16);
|
|
||||||
calculateIPGroups32(ris, points);
|
calculateIPGroups32(ris, points);
|
||||||
calculateIPGroups24(ris, points);
|
calculateIPGroups24(ris, points);
|
||||||
calculateIPGroups16(ris, points);
|
calculateIPGroups16(ris, points);
|
||||||
|
calculateIPGroups64(ris, points);
|
||||||
|
calculateIPGroups48(ris, points);
|
||||||
|
|
||||||
// Pairwise distance analysis
|
// Pairwise distance analysis
|
||||||
List<Pair> pairs = new ArrayList<Pair>(PAIRMAX);
|
List<Pair> pairs = new ArrayList<Pair>(PAIRMAX);
|
||||||
@@ -427,6 +435,15 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
private static class DummyList extends ArrayList<RouterInfo> {
|
||||||
|
public DummyList() { super(0); }
|
||||||
|
@Override
|
||||||
|
public boolean add(RouterInfo ri) { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocklist and Banlist if configured
|
* Blocklist and Banlist if configured
|
||||||
* @since 0.9.41
|
* @since 0.9.41
|
||||||
@@ -545,46 +562,118 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* v6 only
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
private static byte[] getIPv6(RouterInfo ri) {
|
||||||
|
for (RouterAddress ra : ri.getAddresses()) {
|
||||||
|
byte[] rv = ra.getIP();
|
||||||
|
if (rv != null && rv.length == 16)
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ri32 out parameter
|
* @param ri32 out parameter
|
||||||
* @param ri24 out parameter
|
* @param ri24 out parameter
|
||||||
* @param ri16 out parameter
|
* @param ri16 out parameter
|
||||||
|
* @param ri64 out parameter
|
||||||
|
* @param ri48 out parameter
|
||||||
* @since 0.9.38 split out from renderIPGroupsUs()
|
* @since 0.9.38 split out from renderIPGroupsUs()
|
||||||
*/
|
*/
|
||||||
public void calculateIPGroupsUs(List<RouterInfo> ris, Map<Hash, Points> points,
|
public void calculateIPGroupsUs(List<RouterInfo> ris, Map<Hash, Points> points,
|
||||||
List<RouterInfo> ri32, List<RouterInfo> ri24, List<RouterInfo> ri16) {
|
List<RouterInfo> ri32, List<RouterInfo> ri24, List<RouterInfo> ri16,
|
||||||
|
List<RouterInfo> ri64, List<RouterInfo> ri48) {
|
||||||
RouterInfo us = _context.router().getRouterInfo();
|
RouterInfo us = _context.router().getRouterInfo();
|
||||||
byte[] ourIP = getIP(us);
|
byte[] ourIP = getIP(us);
|
||||||
if (ourIP == null) {
|
if (ourIP == null) {
|
||||||
String last = _context.getProperty("i2np.lastIP");
|
String last = _context.getProperty("i2np.lastIP");
|
||||||
if (last == null)
|
if (last != null)
|
||||||
return;
|
ourIP = Addresses.getIPOnly(last);
|
||||||
ourIP = Addresses.getIPOnly(last);
|
}
|
||||||
if (ourIP == null)
|
byte[] ourIPv6 = getIPv6(us);
|
||||||
return;
|
if (ourIPv6 == null) {
|
||||||
|
String last = _context.getProperty("i2np.lastIPv6");
|
||||||
|
if (last != null)
|
||||||
|
ourIPv6 = Addresses.getIPOnly(last);
|
||||||
|
}
|
||||||
|
if (ourIP == null && ourIPv6 == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String reason32;
|
||||||
|
String reason24;
|
||||||
|
String reason16;
|
||||||
|
String reason64;
|
||||||
|
String reason48;
|
||||||
|
|
||||||
|
if (ourIP != null) {
|
||||||
|
reason32 = "Same IP as <a href=\"/netdb?ip=" +
|
||||||
|
Addresses.toString(ourIP) +
|
||||||
|
"&sybil\">us</a>";
|
||||||
|
reason24 = "Same IPv4 /24 as <a href=\"/netdb?ip=" +
|
||||||
|
(ourIP[0] & 0xff) + '.' +
|
||||||
|
(ourIP[1] & 0xff) + '.' +
|
||||||
|
(ourIP[2] & 0xff) +
|
||||||
|
".0/24&sybil\">us</a>";
|
||||||
|
reason16 = "Same IPv4 /16 as <a href=\"/netdb?ip=" +
|
||||||
|
(ourIP[0] & 0xff) + '.' +
|
||||||
|
(ourIP[1] & 0xff) +
|
||||||
|
".0.0/16&sybil\">us</a>";
|
||||||
|
} else {
|
||||||
|
reason32 = null;
|
||||||
|
reason24 = null;
|
||||||
|
reason16 = null;
|
||||||
|
}
|
||||||
|
if (ourIPv6 != null) {
|
||||||
|
reason64 = "Same IPv6 /64 as <a href=\"/netdb?ip=" +
|
||||||
|
Integer.toString(((ourIPv6[0] << 8) & 0xff00) | (ourIPv6[1] & 0xff), 16) + ':' +
|
||||||
|
Integer.toString(((ourIPv6[2] << 8) & 0xff00) | (ourIPv6[3] & 0xff), 16) + ':' +
|
||||||
|
Integer.toString(((ourIPv6[4] << 8) & 0xff00) | (ourIPv6[5] & 0xff), 16) + ':' +
|
||||||
|
Integer.toString(((ourIPv6[6] << 8) & 0xff00) | (ourIPv6[7] & 0xff), 16) +
|
||||||
|
"::&sybil\">us</a>";
|
||||||
|
reason48 = "Same IPv6 /48 as <a href=\"/netdb?ip=" +
|
||||||
|
Integer.toString(((ourIPv6[0] << 8) & 0xff00) | (ourIPv6[1] & 0xff), 16) + ':' +
|
||||||
|
Integer.toString(((ourIPv6[2] << 8) & 0xff00) | (ourIPv6[3] & 0xff), 16) + ':' +
|
||||||
|
Integer.toString(((ourIPv6[4] << 8) & 0xff00) | (ourIPv6[5] & 0xff), 16) +
|
||||||
|
"::&sybil\">us</a>";
|
||||||
|
} else {
|
||||||
|
reason64 = null;
|
||||||
|
reason48 = null;
|
||||||
}
|
}
|
||||||
String reason32 = "Same IP as <a href=\"/netdb?ip=" +
|
|
||||||
ourIP[0] + '.' + ourIP[1] + '.' + ourIP[2] + '.' + ourIP[3] + "&sybil\">us</a>";
|
|
||||||
String reason24 = "Same /24 IP as <a href=\"/netdb?ip=" +
|
|
||||||
ourIP[0] + '.' + ourIP[1] + '.' + ourIP[2] + ".0/24&sybil\">us</a>";
|
|
||||||
String reason16 = "Same /16 IP as <a href=\"/netdb?ip=" +
|
|
||||||
ourIP[0] + '.' + ourIP[1] + ".0.0/16&sybil\">us</a>";
|
|
||||||
for (RouterInfo info : ris) {
|
for (RouterInfo info : ris) {
|
||||||
byte[] ip = getIP(info);
|
if (ourIP != null) {
|
||||||
if (ip == null)
|
byte[] ip = getIP(info);
|
||||||
continue;
|
if (ip == null)
|
||||||
if (ip[0] == ourIP[0] && ip[1] == ourIP[1]) {
|
continue;
|
||||||
if (ip[2] == ourIP[2]) {
|
if (ip[0] == ourIP[0] && ip[1] == ourIP[1]) {
|
||||||
if (ip[3] == ourIP[3]) {
|
if (ip[2] == ourIP[2]) {
|
||||||
addPoints(points, info.getHash(), POINTS_US32, reason32);
|
if (ip[3] == ourIP[3]) {
|
||||||
ri32.add(info);
|
addPoints(points, info.getHash(), POINTS_US32, reason32);
|
||||||
|
ri32.add(info);
|
||||||
|
} else {
|
||||||
|
addPoints(points, info.getHash(), POINTS_US24, reason24);
|
||||||
|
ri24.add(info);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
addPoints(points, info.getHash(), POINTS_US24, reason24);
|
addPoints(points, info.getHash(), POINTS_US16, reason16);
|
||||||
ri24.add(info);
|
ri16.add(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ourIPv6 != null) {
|
||||||
|
byte[] ip = getIPv6(info);
|
||||||
|
if (ip == null)
|
||||||
|
continue;
|
||||||
|
if (DataHelper.eq(ip, 0, ourIPv6, 0, 6)) {
|
||||||
|
if (ip[6] == ourIPv6[6] && ip[7] == ourIPv6[7]) {
|
||||||
|
addPoints(points, info.getHash(), POINTS_V6_US64, reason64);
|
||||||
|
ri64.add(info);
|
||||||
|
} else {
|
||||||
|
addPoints(points, info.getHash(), POINTS_V6_US48, reason48);
|
||||||
|
ri48.add(info);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
addPoints(points, info.getHash(), POINTS_US16, reason16);
|
|
||||||
ri16.add(info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -666,7 +755,7 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
int i0 = i >> 16;
|
int i0 = i >> 16;
|
||||||
int i1 = (i >> 8) & 0xff;
|
int i1 = (i >> 8) & 0xff;
|
||||||
int i2 = i & 0xff;
|
int i2 = i & 0xff;
|
||||||
String reason = "Same /24 IP with <a href=\"/netdb?ip=" +
|
String reason = "Same IPv4 /24 with <a href=\"/netdb?ip=" +
|
||||||
i0 + '.' + i1 + '.' + i2 + ".0/24&sybil\">" +
|
i0 + '.' + i1 + '.' + i2 + ".0/24&sybil\">" +
|
||||||
(count - 1) + " other" + (( count > 2) ? "s" : "") + "</a>";
|
(count - 1) + " other" + (( count > 2) ? "s" : "") + "</a>";
|
||||||
for (RouterInfo info : ris) {
|
for (RouterInfo info : ris) {
|
||||||
@@ -717,7 +806,7 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
int i = ii.intValue();
|
int i = ii.intValue();
|
||||||
int i0 = i >> 8;
|
int i0 = i >> 8;
|
||||||
int i1 = i & 0xff;
|
int i1 = i & 0xff;
|
||||||
String reason = "Same /16 IP with <a href=\"/netdb?ip=" +
|
String reason = "Same IPv4 /16 with <a href=\"/netdb?ip=" +
|
||||||
i0 + '.' + i1 + ".0.0/16&sybil\">" +
|
i0 + '.' + i1 + ".0.0/16&sybil\">" +
|
||||||
(count - 1) + " other" + (( count > 2) ? "s" : "") + "</a>";
|
(count - 1) + " other" + (( count > 2) ? "s" : "") + "</a>";
|
||||||
for (RouterInfo info : ris) {
|
for (RouterInfo info : ris) {
|
||||||
@@ -735,6 +824,129 @@ public class Analysis extends JobImpl implements RouterApp {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
public Map<Long, List<RouterInfo>> calculateIPGroups64(List<RouterInfo> ris, Map<Hash, Points> points) {
|
||||||
|
ObjectCounter<Long> oc = new ObjectCounter<Long>();
|
||||||
|
for (RouterInfo info : ris) {
|
||||||
|
byte[] ip = getIPv6(info);
|
||||||
|
if (ip == null)
|
||||||
|
continue;
|
||||||
|
Long x = Long.valueOf(DataHelper.fromLong8(ip, 0));
|
||||||
|
oc.increment(x);
|
||||||
|
}
|
||||||
|
Map<Long, List<RouterInfo>> rv = new HashMap<Long, List<RouterInfo>>();
|
||||||
|
for (Long ii : oc.objects()) {
|
||||||
|
int count = oc.count(ii);
|
||||||
|
if (count >= 2)
|
||||||
|
rv.put(ii, new ArrayList<RouterInfo>(count));
|
||||||
|
}
|
||||||
|
for (Map.Entry<Long, List<RouterInfo>> e : rv.entrySet()) {
|
||||||
|
Long ii = e.getKey();
|
||||||
|
int count = oc.count(ii);
|
||||||
|
double point = POINTS64 * (count - 1);
|
||||||
|
long i = ii.longValue();
|
||||||
|
int i0 = (int) ((i >> 56) & 0xff);
|
||||||
|
int i1 = (int) ((i >> 48) & 0xff);
|
||||||
|
int i2 = (int) ((i >> 40) & 0xff);
|
||||||
|
int i3 = (int) ((i >> 32) & 0xff);
|
||||||
|
int i4 = (int) ((i >> 24) & 0xff);
|
||||||
|
int i5 = (int) ((i >> 16) & 0xff);
|
||||||
|
int i6 = (int) ((i >> 8) & 0xff);
|
||||||
|
int i7 = (int) (i & 0xff);
|
||||||
|
String reason = "Same IPv6 /64 with <a href=\"/netdb?ip=" +
|
||||||
|
Integer.toString((i0 << 8) | i1, 16) + ':' +
|
||||||
|
Integer.toString((i2 << 8) | i3, 16) + ':' +
|
||||||
|
Integer.toString((i4 << 8) | i5, 16) + ':' +
|
||||||
|
Integer.toString((i6 << 8) | i7, 16) +
|
||||||
|
"::&sybil\">" +
|
||||||
|
(count - 1) + " other" + (( count > 2) ? "s" : "") + "</a>";
|
||||||
|
for (RouterInfo info : ris) {
|
||||||
|
byte[] ip = getIPv6(info);
|
||||||
|
if (ip == null)
|
||||||
|
continue;
|
||||||
|
if ((ip[0] & 0xff) != i0)
|
||||||
|
continue;
|
||||||
|
if ((ip[1] & 0xff) != i1)
|
||||||
|
continue;
|
||||||
|
if ((ip[2] & 0xff) != i2)
|
||||||
|
continue;
|
||||||
|
if ((ip[3] & 0xff) != i3)
|
||||||
|
continue;
|
||||||
|
if ((ip[4] & 0xff) != i4)
|
||||||
|
continue;
|
||||||
|
if ((ip[5] & 0xff) != i5)
|
||||||
|
continue;
|
||||||
|
if ((ip[6] & 0xff) != i6)
|
||||||
|
continue;
|
||||||
|
if ((ip[7] & 0xff) != i7)
|
||||||
|
continue;
|
||||||
|
e.getValue().add(info);
|
||||||
|
addPoints(points, info.getHash(), point, reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.57
|
||||||
|
*/
|
||||||
|
public Map<Long, List<RouterInfo>> calculateIPGroups48(List<RouterInfo> ris, Map<Hash, Points> points) {
|
||||||
|
ObjectCounter<Long> oc = new ObjectCounter<Long>();
|
||||||
|
for (RouterInfo info : ris) {
|
||||||
|
byte[] ip = getIPv6(info);
|
||||||
|
if (ip == null)
|
||||||
|
continue;
|
||||||
|
Long x = Long.valueOf(DataHelper.fromLong(ip, 0, 6));
|
||||||
|
oc.increment(x);
|
||||||
|
}
|
||||||
|
Map<Long, List<RouterInfo>> rv = new HashMap<Long, List<RouterInfo>>();
|
||||||
|
for (Long ii : oc.objects()) {
|
||||||
|
int count = oc.count(ii);
|
||||||
|
if (count >= 4)
|
||||||
|
rv.put(ii, new ArrayList<RouterInfo>(count));
|
||||||
|
}
|
||||||
|
for (Map.Entry<Long, List<RouterInfo>> e : rv.entrySet()) {
|
||||||
|
Long ii = e.getKey();
|
||||||
|
int count = oc.count(ii);
|
||||||
|
double point = POINTS48 * (count - 1);
|
||||||
|
long i = ii.longValue();
|
||||||
|
int i0 = (int) ((i >> 40) & 0xff);
|
||||||
|
int i1 = (int) ((i >> 32) & 0xff);
|
||||||
|
int i2 = (int) ((i >> 24) & 0xff);
|
||||||
|
int i3 = (int) ((i >> 16) & 0xff);
|
||||||
|
int i4 = (int) ((i >> 8) & 0xff);
|
||||||
|
int i5 = (int) (i & 0xff);
|
||||||
|
String reason = "Same IPv6 /48 with <a href=\"/netdb?ip=" +
|
||||||
|
Integer.toString((i0 << 8) | i1, 16) + ':' +
|
||||||
|
Integer.toString((i2 << 8) | i3, 16) + ':' +
|
||||||
|
Integer.toString((i4 << 8) | i5, 16) +
|
||||||
|
"::&sybil\">" +
|
||||||
|
(count - 1) + " other" + (( count > 2) ? "s" : "") + "</a>";
|
||||||
|
for (RouterInfo info : ris) {
|
||||||
|
byte[] ip = getIPv6(info);
|
||||||
|
if (ip == null)
|
||||||
|
continue;
|
||||||
|
if ((ip[0] & 0xff) != i0)
|
||||||
|
continue;
|
||||||
|
if ((ip[1] & 0xff) != i1)
|
||||||
|
continue;
|
||||||
|
if ((ip[2] & 0xff) != i2)
|
||||||
|
continue;
|
||||||
|
if ((ip[3] & 0xff) != i3)
|
||||||
|
continue;
|
||||||
|
if ((ip[4] & 0xff) != i4)
|
||||||
|
continue;
|
||||||
|
if ((ip[5] & 0xff) != i5)
|
||||||
|
continue;
|
||||||
|
e.getValue().add(info);
|
||||||
|
addPoints(points, info.getHash(), point, reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return map of family name to list of routers in that family
|
* @return map of family name to list of routers in that family
|
||||||
* @since 0.9.38 split out from renderIPGroupsFamily()
|
* @since 0.9.38 split out from renderIPGroupsFamily()
|
||||||
|
Reference in New Issue
Block a user