@Override public int getEntryCount() { return( current_filter.getEntryCount()); }
@Override public int getSize() { return( current_filter.getSize()); }
@Override public String getString() { return( "ind=" + current_filter_index + ",filt=" + current_filter.getString()); } }
protected boolean isPersistentlyDeleted( RelatedContent content ) { if ( persist_del_bloom == null ){ List<byte[]> entries = loadPersistentlyDeleted(); persist_del_bloom = BloomFilterFactory.createAddOnly( Math.max( PD_BLOOM_INITIAL_SIZE, entries.size()*10 + PD_BLOOM_INCREMENT_SIZE )); for ( byte[] k: entries ){ persist_del_bloom.add( k ); } } byte[] key = getPermDelKey( content ); return( persist_del_bloom.contains( key )); }
@Override public void sentTo( DHTTransportContact contact ) { BloomFilter filter = sent_to_bloom; if ( filter == null || filter.getEntryCount() > 100 ){ filter = BloomFilterFactory.createAddOnly(500); sent_to_bloom = filter; } filter.add( contact.getID()); } }
protected void setKnownSeed( InetSocketAddress address ) { synchronized( registered_legacy_managers ){ if ( known_seeds == null ){ known_seeds = BloomFilterFactory.createAddOnly( 1024 ); } // can't include port as it will be a randomly allocated one in general. two people behind the // same NAT will have to connect to each other using LAN peer finder known_seeds.add( AddressUtils.getAddressBytes( address )); } }
@Override public void deactivateRequest( InetSocketAddress address ) { BloomFilter bloom = activation_bloom; if ( bloom != null ){ byte[] address_bytes = AddressUtils.getAddressBytes( address ); int count = bloom.count( address_bytes); for (int i=0;i<count;i++){ bloom.remove( address_bytes ); } activation_count = bloom.getEntryCount(); } }
@Override public boolean contains( byte[] value ) { return( current_filter.contains(value)); }
protected boolean tooManyUnauthConnections( String originator ) { synchronized( this ){ if ( unauth_bloom == null ){ unauth_bloom = BloomFilterFactory.createAddRemove4Bit( UNAUTH_BLOOM_CHUNK ); unauth_bloom_create_time = SystemTime.getCurrentTime(); } int hit_count = unauth_bloom.add( originator.getBytes()); if ( hit_count >= 8 ){ Debug.out( "Too many recent unauthorised connection attempts from " + originator ); return( true ); } return( false ); } }
protected DHTUDPPacketHandler( DHTUDPPacketHandlerFactory _factory, int _network, PRUDPPacketHandler _packet_handler, DHTUDPRequestHandler _request_handler ) { factory = _factory; network = _network; packet_handler = _packet_handler; request_handler = _request_handler; bloom1 = BloomFilterFactory.createAddOnly( BLOOM_FILTER_SIZE ); bloom2 = BloomFilterFactory.createAddOnly( BLOOM_FILTER_SIZE ); stats = new DHTUDPPacketHandlerStats( packet_handler ); }
public BloomFilterRotator( BloomFilter _target, int _num ) { filters = new BloomFilter[_num]; filters[0] = _target; for (int i=1;i<filters.length;i++){ filters[i] = _target.getReplica(); } current_filter = _target; current_filter_index = 0; }
@Override public int remove( byte[] value ) { int res = 0; for (int i=0;i<filters.length;i++){ BloomFilter filter = filters[i]; int r = filter.remove( value ); if ( filter == current_filter ){ res = r; } } return( res ); }
@Override public int count( byte[] value ) { return( current_filter.count( value )); }
@Override public void clear() { start_time = SystemTime.getMonotonousTime(); for ( BloomFilter filter: filters ){ filter.clear(); } }
protected void updateBloom( InetSocketAddress destination_address ) { // allow unresolved through (e.g. ipv6 dht seed) as handled later if ( !destination_address.isUnresolved()){ long diff = SystemTime.getCurrentTime() - last_bloom_rotation_time; if( diff < 0 || diff > BLOOM_ROTATION_PERIOD ) { // System.out.println( "bloom rotate: entries = " + bloom1.getEntryCount() + "/" + bloom2.getEntryCount()); bloom1 = bloom2; bloom2 = BloomFilterFactory.createAddOnly( BLOOM_FILTER_SIZE ); last_bloom_rotation_time = SystemTime.getCurrentTime(); } byte[] address_bytes = destination_address.getAddress().getAddress(); bloom1.add( address_bytes ); bloom2.add( address_bytes ); } }
@Override public boolean hasBeenSentTo( DHTTransportContact contact ) { BloomFilter filter = sent_to_bloom; if ( filter == null ){ return( false ); } return( filter.contains( contact.getID())); }
protected void resetPersistentlyDeleted() { FileUtil.deleteResilientConfigFile( PERSIST_DEL_FILE ); persist_del_bloom = BloomFilterFactory.createAddOnly( PD_BLOOM_INITIAL_SIZE ); }
protected void timerTick( boolean enabled, int tick_count ) { checkDDB(); if ( enabled ){ harvestBlooms(); if ( tick_count % HARVEST_BLOOM_SE_RESET_TICKS == 0 ){ harvest_se_requester_bloom = harvest_se_requester_bloom.getReplica(); } if ( tick_count % HARVEST_BLOOM_OP_RESET_TICKS == 0 ){ harvest_op_requester_bloom = harvest_op_requester_bloom.getReplica(); } } checkKeyBloom(); testKeyBloom(); }
protected void decrementValueAdds( DHTTransportContact contact ) { byte[] bloom_key = contact.getBloomKey(); int hit_count = ip_count_bloom_filter.remove( bloom_key ); if ( DHTLog.GLOBAL_BLOOM_TRACE ){ System.out.println( "direct remove from " + contact.getAddress() + ", hit count = " + hit_count ); } }
protected boolean isKnownSeed( InetSocketAddress address ) { synchronized( registered_legacy_managers ){ if ( known_seeds == null ){ return( false ); } return( known_seeds.contains( AddressUtils.getAddressBytes( address ))); } }