Package com.aelitis.azureus.core.util.bloom

Examples of com.aelitis.azureus.core.util.bloom.BloomFilter


             
      int udp = pc.getUDPListenPort();
     
      if ( udp != 0 && udp == pc.getTCPListenPort()){
       
        BloomFilter filter = prefer_udp_bloom;
       
        if ( filter == null ){
         
          filter = prefer_udp_bloom = BloomFilterFactory.createAddOnly( PREFER_UDP_BLOOM_SIZE );       
        }
       
        if ( filter.getEntryCount() < PREFER_UDP_BLOOM_SIZE / 10 ){
                     
          filter.add( pc.getIp().getBytes());
        }
      }
    }

    final int piece = pc.getUniqueAnnounce();
View Full Code Here


           
                // see if we have previous record of this address as udp connectable
             
              byte[]  address = item.getIP().getBytes();
             
              BloomFilter  bloom = prefer_udp_bloom;
             
              if ( bloom != null && bloom.contains( address )){
                               
                udp_port = tcp_port;
              }
            }
           
View Full Code Here

  activateRequest(
    InetSocketAddress  address )
  {
    if ( getState() == DownloadManager.STATE_QUEUED ){
     
      BloomFilter  bloom = activation_bloom;
     
      if ( bloom == null ){
       
        activation_bloom = bloom = BloomFilterFactory.createAddRemove4Bit( BLOOM_SIZE );
      }
     
      byte[]  address_bytes = address.getAddress().getAddress();
         
      int  hit_count = bloom.add( address_bytes );
     
      if ( hit_count > 5 ){
       
        Logger.log(
            new LogEvent(
              this,
              LogIDs.CORE,
              LogEvent.LT_WARNING,
              "Activate request for " + getDisplayName() + " from " + address + " denied as too many recently received" ));

        return( false );
      }
     
      Logger.log(new LogEvent(this, LogIDs.CORE, "Activate request for " + getDisplayName() + " from " + address ));

      long  now = SystemTime.getCurrentTime();

        // we don't really care about the bloom filter filling up and giving false positives
        // as activation events should be fairly rare
     
      if ( now < activation_bloom_create_time || now - activation_bloom_create_time > ACTIVATION_REBUILD_TIME ){
       
        activation_bloom = BloomFilterFactory.createAddRemove4Bit( BLOOM_SIZE );
       
        activation_bloom_create_time  = now;
      }
     
      activation_count = bloom.getEntryCount();
     
      activation_count_time = now;
     
      return( download_manager.activateRequest( activation_count ));
    }
View Full Code Here

 
  public void
  deactivateRequest(
    InetSocketAddress  address )
  {
    BloomFilter  bloom = activation_bloom;
   
    if ( bloom != null ){
   
      byte[]  address_bytes = address.getAddress().getAddress();

      int  count = bloom.count( address_bytes);
     
      for (int i=0;i<count;i++){
       
        bloom.remove( address_bytes );
      }
     
      activation_count = bloom.getEntryCount();
    }
  }
View Full Code Here

      ip_count_bloom_filter = address_bytes;
     
      return;
    }
   
    BloomFilter filter;
   
    if ( ip_count_bloom_filter instanceof byte[] ){
     
      byte[]  existing_address = (byte[])ip_count_bloom_filter;
     
      ip_count_bloom_filter = filter = BloomFilterFactory.createAddRemove4Bit( IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK );
     
      filter.add( existing_address );
     
    }else{
     
      filter = (BloomFilter)ip_count_bloom_filter;
    }
               
    int  hit_count = filter.add( address_bytes );
   
    if ( DHTLog.LOCAL_BLOOM_TRACE ){
   
      System.out.println( "direct local add from " + originator.getAddress() + ", hit count = " + hit_count );
    }

      // allow up to 10% bloom filter utilisation
   
    if ( filter.getSize() / filter.getEntryCount() < 10 ){
     
      rebuildIPBloomFilter( true );
    }
   
    if ( hit_count >= 15 ){
View Full Code Here

      }
     
      return;
    }
   
    BloomFilter filter = (BloomFilter)ip_count_bloom_filter;
   
    int  hit_count = filter.remove( address_bytes );
   
    if DHTLog.LOCAL_BLOOM_TRACE ){
   
      System.out.println( "direct local remove from " + originator.getAddress() + ", hit count = " + hit_count );
   
View Full Code Here

 
  protected void
  rebuildIPBloomFilter(
    boolean  increase_size )
  {
    BloomFilter  new_filter;
   
    int  old_size;
   
    if ( ip_count_bloom_filter instanceof BloomFilter ){
     
      old_size = ((BloomFilter)ip_count_bloom_filter).getSize();
     
    }else{
     
      old_size = IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK;
    }
   
    if ( increase_size ){
     
      new_filter = BloomFilterFactory.createAddRemove4Bit( old_size + IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK );
     
    }else{
     
      new_filter = BloomFilterFactory.createAddRemove4Bit( old_size );
    }
   
    try{
        // only do flood prevention on direct stores as we can't trust the originator
        // details for indirect and this can be used to DOS a direct store later
     
      Iterator<DHTDBValueImpl>  it = getDirectValues();
     
      int  max_hits  = 0;
     
      while( it.hasNext()){
       
        DHTDBValueImpl  val = it.next();
       
        if ( !val.isLocal()){
         
          // logger.log( "    adding " + val.getOriginator().getAddress());
         
          int  hits = new_filter.add( val.getOriginator().getAddress().getAddress().getAddress());
 
          if ( hits > max_hits ){
           
            max_hits  = hits;
          }
        }
      }
     
      if DHTLog.LOCAL_BLOOM_TRACE ){

        db.log( "Rebuilt local IP bloom filter, size = " + new_filter.getSize() + ", entries =" + new_filter.getEntryCount()+", max hits = " + max_hits );
      }

    }finally{
     
      ip_count_bloom_filter = new_filter;
View Full Code Here

  protected void
  rebuildIPBloomFilter(
    boolean  increase_size )
  {
    BloomFilter  new_filter;
   
    if ( increase_size ){
     
      new_filter = BloomFilterFactory.createAddRemove8Bit( ip_count_bloom_filter.getSize() + IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK );
     
    }else{
     
      new_filter = BloomFilterFactory.createAddRemove8Bit( ip_count_bloom_filter.getSize());
     
    }
   
    try{
     
      //Map    sender_map  = new HashMap();
      //List  senders    = new ArrayList();
     
      Iterator<DHTDBMapping>  it = stored_values.values().iterator();
     
      int  max_hits = 0;
     
      while( it.hasNext()){
       
        DHTDBMapping  mapping = it.next();

        mapping.rebuildIPBloomFilter( false );
       
        Iterator<DHTDBValueImpl>  it2 = mapping.getDirectValues();
       
        while( it2.hasNext()){
         
          DHTDBValueImpl  val = it2.next();
         
          if ( !val.isLocal()){
           
            // logger.log( "    adding " + val.getOriginator().getAddress());
           
            int  hits = new_filter.add( val.getOriginator().getAddress().getAddress().getAddress());
           
            if ( hits > max_hits ){
             
              max_hits = hits;
            }
          }
        }
       
          // survey our neighbourhood
       
        /*
         * its is non-trivial to do anything about nodes that get "close" to us and then
         * spam us with crap. Ultimately, of course, to take a key out you "just" create
         * the 20 closest nodes to the key and then run nodes that swallow all registrations
         * and return nothing. 
         * Protecting against one or two such nodes that flood crap requires crap to be
         * identified. Tracing shows a large disparity between number of values registered
         * per neighbour (factors of 100), so an approach based on number of registrations
         * is non-trivial (assuming future scaling of the DHT, what do we consider crap?)
         * A further approach would be to query the claimed originators of values (obviously
         * a low bandwith approach, e.g. query 3 values from the contact with highest number
         * of forwarded values). This requires originators to support long term knowledge of
         * what they've published (we don't want to blacklist a neighbour because an originator
         * has deleted a value/been restarted). We also then have to consider how to deal with
         * non-responses to queries (assuming an affirmative Yes -> value has been forwarded
         * correnctly, No -> probably crap). We can't treat non-replies as No. Thus a bad
         * neighbour only has to forward crap with originators that aren't AZ nodes (very
         * easy to do!) to break this aproach.
         *
         *
        it2 = mapping.getIndirectValues();
       
        while( it2.hasNext()){
         
          DHTDBValueImpl  val = (DHTDBValueImpl)it2.next();
         
          DHTTransportContact sender = val.getSender();
         
          HashWrapper  hw = new HashWrapper( sender.getID());
         
          Integer  sender_count = (Integer)sender_map.get( hw );
         
          if ( sender_count == null ){
           
            sender_count = new Integer(1);
           
            senders.add( sender );
           
          }else{
           
            sender_count = new Integer( sender_count.intValue() + 1 );           
          }
         
          sender_map.put( hw, sender_count );
        } 
        */
      }
     
      logger.log( "Rebuilt global IP bloom filter, size=" + new_filter.getSize() + ", entries=" + new_filter.getEntryCount()+", max hits=" + max_hits );
       
      /*
      senders = control.sortContactsByDistance( senders );
     
      for (int i=0;i<senders.size();i++){
View Full Code Here

    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());
View Full Code Here

   
    public boolean
    hasBeenSentTo(
      DHTTransportContact  contact )
    {
      BloomFilter  filter = sent_to_bloom;
     
      if ( filter == null ){
       
        return( false );
      }
     
      return( filter.contains( contact.getID()));
    }
View Full Code Here

TOP

Related Classes of com.aelitis.azureus.core.util.bloom.BloomFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.