Changeset 3846e08 for router


Ignore:
Timestamp:
Dec 22, 2016 12:46:38 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
63a2a6d
Parents:
e625e67b
Message:

Router: More efficiently check blocklist when receiving new RI

Location:
router/java/src/net/i2p/router
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/Blocklist.java

    re625e67b r3846e08  
    8080    // temp
    8181    private Map<Hash, String> _peerBlocklist = new HashMap<Hash, String>(4);
     82   
     83    private static final String PROP_BLOCKLIST_ENABLED = "router.blocklist.enable";
     84    private static final String PROP_BLOCKLIST_DETAIL = "router.blocklist.detail";
     85    private static final String PROP_BLOCKLIST_FILE = "router.blocklist.file";
     86    private static final String BLOCKLIST_FILE_DEFAULT = "blocklist.txt";
     87    private static final String BLOCKLIST_FEED_FILE = "docs/feed/blocklist/blocklist.txt";
    8288
    8389    /**
     
    106112        _blocklistFeedFile = new File(BLOCKLIST_FEED_FILE);
    107113    }
    108    
    109     private static final String PROP_BLOCKLIST_ENABLED = "router.blocklist.enable";
    110     private static final String PROP_BLOCKLIST_DETAIL = "router.blocklist.detail";
    111     private static final String PROP_BLOCKLIST_FILE = "router.blocklist.file";
    112     private static final String BLOCKLIST_FILE_DEFAULT = "blocklist.txt";
    113     private static final String BLOCKLIST_FEED_FILE = "docs/feed/blocklist/blocklist.txt";
    114114
    115115    /**
     
    657657        if (pinfo == null)
    658658            return Collections.emptyList();
     659        return getAddresses(pinfo);
     660    }
     661
     662    /**
     663     * Will not contain duplicates.
     664     * @since 0.9.29
     665     */
     666    private static List<byte[]> getAddresses(RouterInfo pinfo) {
    659667        List<byte[]> rv = new ArrayList<byte[]>(4);
    660668        // for each peer address
     
    686694        for (byte[] ip : ips) {
    687695            if (isBlocklisted(ip)) {
     696                if (! _context.banlist().isBanlisted(peer))
     697                    // nice knowing you...
     698                    banlist(peer, ip);
     699                return true;
     700            }
     701        }
     702        return false;
     703    }
     704
     705    /**
     706     * Does the peer's IP address appear in the blocklist?
     707     * If so, and it isn't banlisted, banlist it forever...
     708     * @since 0.9.29
     709     */
     710    public boolean isBlocklisted(RouterInfo pinfo) {
     711        List<byte[]> ips = getAddresses(pinfo);
     712        if (ips.isEmpty())
     713            return false;
     714        for (byte[] ip : ips) {
     715            if (isBlocklisted(ip)) {
     716                Hash peer = pinfo.getHash();
    688717                if (! _context.banlist().isBanlisted(peer))
    689718                    // nice knowing you...
  • router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseStoreMessageJob.java

    re625e67b r3846e08  
    161161                    if (prevNetDb == null) {
    162162                        if ((!getContext().banlist().isBanlistedForever(key)) &&
    163                             getContext().blocklist().isBlocklisted(key) &&
     163                            getContext().blocklist().isBlocklisted(ri) &&
    164164                            _log.shouldLog(Log.WARN))
    165165                                _log.warn("Blocklisting new peer " + key + ' ' + ri);
     
    169169                        if ((!newAddr.equals(oldAddr)) &&
    170170                            (!getContext().banlist().isBanlistedForever(key)) &&
    171                             getContext().blocklist().isBlocklisted(key) &&
     171                            getContext().blocklist().isBlocklisted(ri) &&
    172172                            _log.shouldLog(Log.WARN))
    173173                                _log.warn("New address received, Blocklisting old peer " + key + ' ' + ri);
Note: See TracChangeset for help on using the changeset viewer.