Changeset 81cb62f


Ignore:
Timestamp:
Dec 8, 2015 2:09:10 AM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7ea2be3
Parents:
8b42896
Message:

Sybil tool tweaks and enhancements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java

    r8b42896 r81cb62f  
    5454    // multiplied by size - 1
    5555    private static final double POINTS16 = 0.25;
     56    private static final double POINTS_FAMILY = -2.0;
    5657    private static final double MIN_CLOSE = 242.0;
    5758    private static final double OUR_KEY_FACTOR = 4.0;
     
    175176
    176177        // IP analysis
     178        renderIPGroupsFamily(out, buf, ris, points);
    177179        renderIPGroups32(out, buf, ris, points);
    178180        renderIPGroups24(out, buf, ris, points);
     
    337339    }
    338340
     341    private static class FoofComparator implements Comparator<String>, Serializable {
     342         private final ObjectCounter<String> _o;
     343         public FoofComparator(ObjectCounter<String> o) { _o = o;}
     344         public int compare(String l, String r) {
     345             // reverse by count
     346             int rv = _o.count(r) - _o.count(l);
     347             if (rv != 0)
     348                 return rv;
     349             // foward by name
     350             return l.compareTo(r);
     351        }
     352    }
     353
    339354    private void renderIPGroups32(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
    340355        buf.append("<h3>Floodfills with the Same IP</h3>");
     
    382397                renderRouterInfo(buf, info, null, false, false);
    383398                double point = POINTS32 * (count - 1);
    384                 addPoints(points, info.getHash(), point, "Same IP with " + (count - 1) + " other");
     399                addPoints(points, info.getHash(), point, "Same IP with " + (count - 1) + " other" + (( count > 2) ? "s" : ""));
    385400            }
    386401        }
     
    433448                renderRouterInfo(buf, info, null, false, false);
    434449                double point = POINTS24 * (count - 1);
    435                 addPoints(points, info.getHash(), point, "Same /24 IP with " + (count - 1) + " other");
     450                addPoints(points, info.getHash(), point, "Same /24 IP with " + (count - 1) + " other" + (( count > 2) ? "s" : ""));
    436451            }
    437452        }
     
    482497                //renderRouterInfo(buf, info, null, false, false);
    483498                double point = POINTS16 * (count - 1);
    484                 addPoints(points, info.getHash(), point, "Same /16 IP with " + (count - 1) + " other");
     499                addPoints(points, info.getHash(), point, "Same /16 IP with " + (count - 1) + " other" + (( count > 2) ? "s" : ""));
     500            }
     501        }
     502        if (!found)
     503            buf.append("<p>None</p>");
     504        out.write(buf.toString());
     505        out.flush();
     506        buf.setLength(0);
     507    }
     508
     509    private void renderIPGroupsFamily(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
     510        buf.append("<h3>Floodfills in the Same Declared Family</h3>");
     511        int sz = ris.size();
     512        ObjectCounter<String> oc = new ObjectCounter<String>();
     513        for (RouterInfo info : ris) {
     514            String fam = info.getOption("family");
     515            if (fam == null)
     516                continue;
     517            oc.increment(fam);
     518        }
     519        List<String> foo = new ArrayList<String>(oc.objects());
     520        Collections.sort(foo, new FoofComparator(oc));
     521        boolean found = false;
     522        DecimalFormat fmt = new DecimalFormat("#0.00");
     523        for (String s : foo) {
     524            int count = oc.count(s);
     525            buf.append("<p><b>").append(count).append(" floodfills in declared family \"").append(DataHelper.escapeHTML(s) + '"')
     526               .append("</b></p>");
     527            for (RouterInfo info : ris) {
     528                String fam = info.getOption("family");
     529                if (fam == null)
     530                    continue;
     531                if (!fam.equals(s))
     532                    continue;
     533                found = true;
     534                // limit display
     535                //renderRouterInfo(buf, info, null, false, false);
     536                double point = POINTS_FAMILY;
     537                if (count > 1)
     538                    addPoints(points, info.getHash(), point, "Same declared family \"" + DataHelper.escapeHTML(s) + "\" with " + (count - 1) + " other" + (( count > 2) ? "s" : ""));
     539                else
     540                    addPoints(points, info.getHash(), point, "Declared family \"" + DataHelper.escapeHTML(s) + '"');
    485541            }
    486542        }
     
    591647        buf.append("<b>Version: </b>").append(DataHelper.stripHTML(info.getVersion())).append("<br>\n");
    592648        buf.append("<b>Caps: </b>").append(DataHelper.stripHTML(info.getCapabilities())).append("<br>\n");
     649        String fam = info.getOption("family");
     650        if (fam != null)
     651            buf.append("<b>Family: </b>").append(DataHelper.stripHTML(fam)).append("<br>\n");
    593652        String kls = info.getOption("netdb.knownLeaseSets");
    594653        if (kls != null)
Note: See TracChangeset for help on using the changeset viewer.