Search in sources :

Example 16 with BloomFilter

use of com.biglybt.core.util.bloom.BloomFilter in project BiglyBT by BiglySoftware.

the class DHTPluginStorageManager method verifyKeyBlock.

protected boolean verifyKeyBlock(keyBlock kb, DHTTransportContact originator) {
    byte[] id = originator == null ? new byte[20] : originator.getID();
    BloomFilter filter = kb_verify_fail_bloom;
    long now = SystemTime.getCurrentTime();
    if (filter == null || kb_verify_fail_bloom_create_time > now || now - kb_verify_fail_bloom_create_time > 30 * 60 * 1000) {
        kb_verify_fail_bloom_create_time = now;
        filter = BloomFilterFactory.createAddOnly(4000);
        kb_verify_fail_bloom = filter;
    }
    if (filter.contains(id)) {
        log.log("KB: request verify denied");
        return (false);
    }
    try {
        Signature verifier = Signature.getInstance("MD5withRSA");
        verifier.initVerify(key_block_public_key);
        verifier.update(kb.getRequest());
        if (!verifier.verify(kb.getCertificate())) {
            log.log("KB: request verify failed for " + DHTLog.getString2(kb.getKey()));
            filter.add(id);
            return (false);
        }
        log.log("KB: request verify ok " + DHTLog.getString2(kb.getKey()) + ", add = " + kb.isAdd() + ", direct = " + kb.isDirect());
        return (true);
    } catch (Throwable e) {
        return (false);
    }
}
Also used : Signature(java.security.Signature) BloomFilter(com.biglybt.core.util.bloom.BloomFilter)

Example 17 with BloomFilter

use of com.biglybt.core.util.bloom.BloomFilter in project BiglyBT by BiglySoftware.

the class BloomFilterRotator method serialiseToMap.

protected void serialiseToMap(Map<String, Object> x) {
    synchronized (filters) {
        String cla = this.getClass().getName();
        if (cla.startsWith(BloomFilterImpl.MY_PACKAGE)) {
            cla = cla.substring(BloomFilterImpl.MY_PACKAGE.length());
        }
        x.put("_impl", cla);
        List<Map<String, Object>> list = new ArrayList<>();
        for (BloomFilter filter : filters) {
            list.add(filter.serialiseToMap());
        }
        x.put("list", list);
        x.put("index", new Long(current_filter_index));
    }
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) BloomFilter(com.biglybt.core.util.bloom.BloomFilter)

Aggregations

BloomFilter (com.biglybt.core.util.bloom.BloomFilter)17 DownloadInfo (com.biglybt.core.content.RelatedContentManager.DownloadInfo)2 DHTTransportContact (com.biglybt.core.dht.transport.DHTTransportContact)2 DHTPluginContact (com.biglybt.plugin.dht.DHTPluginContact)2 DHTInterface (com.biglybt.plugin.dht.DHTPluginInterface.DHTInterface)2 ContentCache (com.biglybt.core.content.RelatedContentManager.ContentCache)1 LogEvent (com.biglybt.core.logging.LogEvent)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetSocketAddress (java.net.InetSocketAddress)1 Signature (java.security.Signature)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1