Changeset 8840532 for apps


Ignore:
Timestamp:
May 13, 2019 1:28:04 PM (11 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
0531801
Parents:
48a92ca
Message:

Sybil: Auto-blocking

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

    r48a92ca r8840532  
    8888    private static final double POINTS_NEW = 4.0;
    8989    private static final double POINTS_BANLIST = 25.0;
     90    private static final double DEFAULT_BLOCK_THRESHOLD = 50.0;
     91    private static final long DEFAULT_BLOCK_TIME = 7*24*60*60*1000L;
     92    public static final float MIN_BLOCK_POINTS = 12.01f;
    9093
    9194    /** Get via getInstance() */
     
    340343        addProfilePoints(ris, points);
    341344        addVersionPoints(ris, points);
     345        if (_context.getBooleanProperty(PROP_BLOCK))
     346            doBlocking(points);
    342347        return points;
     348    }
     349
     350    /**
     351     *  Blocklist and Banlist if configured
     352     *  @since 0.9.41
     353     */
     354    private void doBlocking(Map<Hash, Points> points) {
     355        double threshold = DEFAULT_BLOCK_THRESHOLD;
     356        long blockUntil = _context.getProperty(Analysis.PROP_BLOCKTIME, DEFAULT_BLOCK_TIME) + _context.clock().now();
     357        try {
     358            threshold = Double.parseDouble(_context.getProperty(PROP_THRESHOLD, Double.toString(DEFAULT_BLOCK_THRESHOLD)));
     359            if (threshold < MIN_BLOCK_POINTS)
     360                threshold = MIN_BLOCK_POINTS;
     361        } catch (NumberFormatException nfe) {}
     362        for (Map.Entry<Hash, Points> e : points.entrySet()) {
     363            double p = e.getValue().getPoints();
     364            if (p >= threshold) {
     365                Hash h = e.getKey();
     366                RouterInfo ri = _context.netDb().lookupRouterInfoLocally(h);
     367                if (ri != null) {
     368                    for (RouterAddress ra : ri.getAddresses()) {
     369                        byte[] ip = ra.getIP();
     370                        if (ip != null)
     371                             _context.blocklist().add(ip);
     372                    }
     373                }
     374                String reason = "Sybil analysis with " + fmt.format(p) + " threat points";
     375                _context.banlist().banlistRouter(h, reason, null, null, blockUntil);
     376            }
     377        }
    343378    }
    344379
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java

    r48a92ca r8840532  
    233233                    String thresh = getJettyString("threshold");
    234234                    if (thresh != null && thresh.length() > 0) {
    235                         float val = Float.parseFloat(thresh);
     235                        float val = Math.max(Float.parseFloat(thresh), Analysis.MIN_BLOCK_POINTS);
    236236                        toSave.put(Analysis.PROP_THRESHOLD, Float.toString(val));
    237237                    }
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java

    r48a92ca r8840532  
    302302        boolean auto = _context.getBooleanProperty(Analysis.PROP_BLOCK);
    303303        String thresh = _context.getProperty(Analysis.PROP_THRESHOLD, "50");
    304         long days = 7;
    305         String time = _context.getProperty(Analysis.PROP_BLOCKTIME);
    306         if (time != null) {
    307             try {
    308                 days = Long.parseLong(time) / (24*60*60*1000L);
    309             } catch (NumberFormatException nfe) {}
    310         }
     304        long days = _context.getProperty(Analysis.PROP_BLOCKTIME, 7*24*60*60*1000L) / (24*60*60*1000L);
    311305        buf.append("</select></td></tr>\n<tr><td>" +
    312306                   "Auto-block routers?</td><td><input type=\"checkbox\" class=\"optbox\" value=\"1\" name=\"block\" ");
Note: See TracChangeset for help on using the changeset viewer.