Changeset 10354df


Ignore:
Timestamp:
May 18, 2019 9:45:55 PM (11 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f2f5df0
Parents:
03bd3e2
Message:

Sybil: Option to run on non-floodfills too

Location:
apps/routerconsole/java/src/net/i2p/router
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/sybil/Analysis.java

    r03bd3e2 r10354df  
    6666    public static final String PROP_THRESHOLD = "router.sybilThreshold";
    6767    public static final String PROP_BLOCK = "router.sybilBlock.enable";
     68    public static final String PROP_NONFF = "router.sybilIncludeAll";
    6869    public static final String PROP_BLOCKTIME = "router.sybilBlock.period";
    6970    private static final long MIN_FREQUENCY = 60*60*1000L;
     
    8283    private static final double POINTS_US16 = 10.0;
    8384    private static final double POINTS_FAMILY = -10.0;
     85    private static final double POINTS_NONFF = -5.0;
    8486    private static final double POINTS_BAD_OUR_FAMILY = 100.0;
    8587    private static final double POINTS_OUR_FAMILY = -100.0;
     
    127129        long now = _context.clock().now();
    128130        _log.info("Running analysis");
    129         Map<Hash, Points> points = backgroundAnalysis();
     131        Map<Hash, Points> points = backgroundAnalysis(_context.getBooleanProperty(PROP_NONFF));
    130132        if (!points.isEmpty()) {
    131133            try {
     
    283285     *  Analyze threats. No output.
    284286     *  Return separate maps for each cause instead?
     287     *  @param includeAll false for floodfills only
    285288     *  @since 0.9.38
    286289     */
    287     public synchronized Map<Hash, Points> backgroundAnalysis() {
     290    public synchronized Map<Hash, Points> backgroundAnalysis(boolean includeAll) {
    288291        _wasRun = true;
    289292        Map<Hash, Points> points = new HashMap<Hash, Points>(64);
     
    291294        if (us == null)
    292295            return points;
    293         List<RouterInfo> ris = getFloodfills(us);
     296        List<RouterInfo> ris;
     297        if (includeAll) {
     298            Set<RouterInfo> set = _context.netDb().getRouters();
     299            ris = new ArrayList<RouterInfo>(set.size());
     300            for (RouterInfo ri : set) {
     301                if (!ri.getIdentity().getHash().equals(us))
     302                ris.add(ri);
     303            }
     304        } else {
     305            ris = getFloodfills(us);
     306        }
    294307        if (ris.isEmpty())
    295308            return points;
     309        if (_log.shouldWarn())
     310            _log.warn("Analyzing " + ris.size() + " routers, including non-floodfills? " + includeAll);
    296311
    297312        double avgMinDist = getAvgMinDist(ris);
     
    397412        for (int i = 0; i < sz; i++) {
    398413            RouterInfo info1 = ris.get(i);
     414            // don't do distance calculation for non-floodfills
     415            if (!info1.getCapabilities().contains("f"))
     416                continue;
    399417            for (int j = i + 1; j < sz; j++) {
    400418                RouterInfo info2 = ris.get(j);
     419                // don't do distance calculation for non-floodfills
     420                if (!info2.getCapabilities().contains("f"))
     421                    continue;
    401422                BigInteger dist = HashDistance.getDistance(info1.getHash(), info2.getHash());
    402423                if (pairs.isEmpty()) {
     
    700721                addPoints(points, h, POINTS_BANLIST, buf.toString());
    701722            }
     723            // don't do profile calcluations for non-floodfills
     724            if (!info.getCapabilities().contains("f"))
     725                continue;
    702726            PeerProfile prof = _context.profileOrganizer().getProfileNonblocking(h);
    703727            if (prof != null) {
     
    749773            if (!caps.contains("R"))
    750774                addPoints(points, h, POINTS_UNREACHABLE, "Unreachable: " + DataHelper.escapeHTML(caps));
     775            if (!caps.contains("f"))
     776                addPoints(points, h, POINTS_NONFF, "Non-floodfill");
    751777            String hisFullVer = info.getVersion();
    752778            if (!hisFullVer.startsWith("0.9.")) {
     
    780806        for (int i = 0; i < count; i++) {
    781807            RouterInfo ri = ris.get(i);
     808            // don't do distance calculation for non-floodfills
     809            if (!ri.getCapabilities().contains("f"))
     810                continue;
    782811            BigInteger bidist = HashDistance.getDistance(us, ri.getHash());
    783812            double dist = biLog2(bidist);
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java

    r03bd3e2 r10354df  
    243243                    String enable = getJettyString("block");
    244244                    toSave.put(Analysis.PROP_BLOCK, Boolean.toString(enable != null));
     245                    String nonff = getJettyString("nonff");
     246                    toSave.put(Analysis.PROP_NONFF, Boolean.toString(nonff != null));
    245247                    if (_context.router().saveConfig(toSave, null))
    246248                        addFormNotice(_t("Configuration saved successfully."));
     
    274276                if (_mode == 12 && !_postOK)
    275277                    _mode = 0;
    276                 else if (_mode == 13 && !_postOK)
     278                else if ((_mode == 13 || _mode == 16) && !_postOK)
    277279                    _mode = 14;
    278280                (new SybilRenderer(_context)).getNetDbSummary(_out, _newNonce, _mode, _date);
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java

    r03bd3e2 r10354df  
    135135        Analysis analysis = Analysis.getInstance(_context);
    136136        List<RouterInfo> ris = null;
    137         if (mode != 0 && mode != 12 && mode != 13 && mode != 14) {
     137        if (mode != 0 && mode != 12 && mode != 13 && mode != 14 && mode != 16) {
    138138            ris = analysis.getFloodfills(us);
    139139            if (ris.isEmpty()) {
     
    209209                renderThreatsHTML(out, buf, date, points);
    210210            }
    211         } else if (mode == 13) {
     211        } else if (mode == 13 || mode == 16) {
    212212            // run analysis and store it
    213213            long now = _context.clock().now();
    214             points = analysis.backgroundAnalysis();
     214            points = analysis.backgroundAnalysis(mode == 16);
    215215            if (!points.isEmpty()) {
    216216                PersistSybil ps = analysis.getPersister();
     
    274274                   "<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" >\n" +
    275275                   "<input type=\"submit\" name=\"action\" class=\"go\" value=\"Run new analysis\" />" +
     276                   "(floodfills only)" +
     277                   "</form><br>\n");
     278        buf.append("<form action=\"netdb\" method=\"POST\">\n" +
     279                   "<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
     280                   "<input type=\"hidden\" name=\"m\" value=\"16\">\n" +
     281                   "<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" >\n" +
     282                   "<input type=\"submit\" name=\"action\" class=\"go\" value=\"Run new analysis\" />" +
     283                   "(all routers)" +
    276284                   "</form>\n");
    277285        writeBuf(out, buf);
     
    303311        }
    304312        boolean auto = _context.getBooleanProperty(Analysis.PROP_BLOCK);
     313        boolean nonff = _context.getBooleanProperty(Analysis.PROP_NONFF);
    305314        String thresh = _context.getProperty(Analysis.PROP_THRESHOLD, "50");
    306315        long days = _context.getProperty(Analysis.PROP_BLOCKTIME, 7*24*60*60*1000L) / (24*60*60*1000L);
     
    308317                   "Auto-block routers?</td><td><input type=\"checkbox\" class=\"optbox\" value=\"1\" name=\"block\" ");
    309318        if (auto)
     319            buf.append(HelperBase.CHECKED);
     320        buf.append("></td></tr>\n<tr><td>" +
     321                   "Include non-floodfills?</td><td><input type=\"checkbox\" class=\"optbox\" value=\"1\" name=\"nonff\" ");
     322        if (nonff)
    310323            buf.append(HelperBase.CHECKED);
    311324        buf.append("></td></tr>\n<tr><td>" +
Note: See TracChangeset for help on using the changeset viewer.