Package com.aelitis.azureus.core.dht.transport

Examples of com.aelitis.azureus.core.dht.transport.DHTTransportContact


    // we don't check for flooding on indirect stores as this could be used to force a
    // direct store to be bounced (flood a node with indirect stores before the direct
    // store occurs)
 

    DHTTransportContact  originator = value.getOriginator();

    byte[] address_bytes = originator.getAddress().getAddress().getAddress();
   
    // System.out.println( "addToBloom: existing=" + ip_count_bloom_filter );

    if ( ip_count_bloom_filter == null ){
     
      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 ){
View Full Code Here


 
  protected void
  removeFromBloom(
    DHTDBValueImpl  value )
  {
    DHTTransportContact  originator = value.getOriginator();
   
    if ( ip_count_bloom_filter == null ){

      return;
    }
   
    byte[] address_bytes = originator.getAddress().getAddress().getAddress();

    if ( ip_count_bloom_filter instanceof byte[] ){

      byte[]  existing_address = (byte[])ip_count_bloom_filter;

      if ( Arrays.equals( address_bytes, existing_address )){
       
        ip_count_bloom_filter = null;
      }
     
      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

              run()
              {
                try{
                  while( !bt_tester.isDestroyed()){
                   
                    DHTTransportContact  contact = null;
                   
                    synchronized( ok ){
                     
                      if ( ok[0] < num_threads && f_contacts.size() > 0 ){
                       
                        contact = (DHTTransportContact)f_contacts.remove(0);
                      }
                    }
                   
                    if ( contact == null ){
                     
                      break;
                    }
                   
                    try{
                      DistributedDatabaseContact ddb_contact = ddb.importContact( contact.getAddress());
                     
                      if ( tryTest( bt_tester, ddb_contact )){
                       
                        synchronized( ok ){
                         
                          ok[0]++;
                        }
                      }
                    }catch( Throwable e ){
                     
                      listener.logError( "Contact import for " + contact.getName() + " failed", e );
                    }
                  }
                }finally{
                 
                  sem.release();
View Full Code Here

  {
    // don't replace a closer cache value with a further away one. in particular
    // we have to avoid the case where the original publisher of a key happens to
    // be close to it and be asked by another node to cache it!

    DHTTransportContact  originator     = new_value.getOriginator();
    DHTTransportContact  sender       = new_value.getSender();

    HashWrapper  originator_id = new HashWrapper( originator.getID());
   
    boolean  direct = Arrays.equals( originator.getID(), sender.getID());
   
    if ( direct ){
     
        // direct contact from the originator is straight forward
     
View Full Code Here

  private HashWrapper
  getOriginatorValueID(
    DHTDBValueImpl  value )
  {
    DHTTransportContact  originator  = value.getOriginator();
   
    byte[]  originator_id  = originator.getID();
   
      // relaxed this due to problems caused by multiple publishes by an originator
      // with the same key but variant values (e.g. seed/peer counts). Seeing as we
      // only accept cache-forwards from contacts that are "close" enough to us to
      // be performing such a forward, the DOS possibilities here are limited (a nasty
View Full Code Here

                      }else if ( lhs.equals( "stats" )){
                       
                        try{
                          pos = rhs.lastIndexOf( ":" );
                         
                          DHTTransportContact  contact;
                         
                          if ( pos == -1 ){
                         
                            contact = transport.getLocalContact();
                           
                          }else{
                           
                            String  host = rhs.substring(0,pos);
                            int    port = Integer.parseInt( rhs.substring(pos+1));
                           
                            contact =
                                transport.importContact(
                                    new InetSocketAddress( host, port ),
                                    transport.getProtocolVersion());
                          }
                         
                          log.log( "Stats request to " + contact.getName());
                         
                          DHTTransportFullStats stats = contact.getStats();
                           
                          log.log( "Stats:" + (stats==null?"<null>":stats.getString()));
                           
                          DHTControlActivity[] activities = dht.getControl().getActivities();
                           
View Full Code Here

          }
        });
     
      dht.setLogging( _logging );
     
      DHTTransportContact root_seed = importRootSeed();
     
      storage_manager.importContacts( dht );
     
      plugin_interface.getUtilities().createTimer( "DHTExport", true ).addPeriodicEvent(
          10*60*1000,
 
View Full Code Here

             
            }
          }
        }
       
        DHTTransportContact  root_to_remove = null;
       
        if ( peers_imported == 0 ){
       
          root_to_remove = importRootSeed();
         
View Full Code Here

         
        }
       
        for (int j=0;j<contacts.size();j++){
         
          DHTTransportContact  contact = (DHTTransportContact)contacts.get(j);
         
          if ( router.isID( contact.getID())){
           
            continue// ignore ourselves
          }
         
          Object[]  data = (Object[])contact_map.get( new HashWrapper(contact.getID()));
         
          if ( data == null ){
           
            data  = new Object[]{ contact, new ArrayList<HashWrapper>()};
           
            contact_map.put( new HashWrapper(contact.getID()), data );
          }
         
          ((List<HashWrapper>)data[1]).add( key );
        }
      }
   
      Iterator<Object[]> it2 = contact_map.values().iterator();
     
      while( it2.hasNext()){
       
        final Object[]  data = it2.next();
       
        final DHTTransportContact  contact = (DHTTransportContact)data[0];
       
          // move to anti-spoof on cache forwards - gotta do a find-node first
          // to get the random id
       
        final AESemaphore  sem = new AESemaphore( "DHTDB:cacheForward" );
       
        contact.sendFindNode(
            new DHTTransportReplyHandlerAdapter()
            {
              public void
              findNodeReply(
                DHTTransportContact   _contact,
                DHTTransportContact[]  _contacts )
              { 
                anti_spoof_done.add( _contact );
             
                try{
                  // System.out.println( "cacheForward: pre-store findNode OK" );
               
                  List<HashWrapper>        keys  = (List<HashWrapper>)data[1];
                   
                  byte[][]        store_keys     = new byte[keys.size()][];
                  DHTTransportValue[][]  store_values   = new DHTTransportValue[store_keys.length][];
                 
                  keys_published[0] += store_keys.length;
                 
                  for (int i=0;i<store_keys.length;i++){
                   
                    HashWrapper  wrapper = keys.get(i);
                   
                    store_keys[i] = wrapper.getHash();
                   
                    List<DHTDBValueImpl>    values  = republish.get( wrapper );
                   
                    store_values[i] = new DHTTransportValue[values.size()];
             
                    values_published[0] += store_values[i].length;
                   
                    for (int j=0;j<values.size();j++){
                   
                      DHTDBValueImpl  value  = values.get(j);
                       
                        // we reduce the cache distance by 1 here as it is incremented by the
                        // recipients
                     
                      store_values[i][j] = value.getValueForRelay(local_contact);
                    }
                  }
                   
                  List<DHTTransportContact>  contacts = new ArrayList<DHTTransportContact>();
                 
                  contacts.add( contact );
                 
                  republish_ops[0]++;
                 
                  control.putDirectEncodedKeys(
                      store_keys,
                      "Republish cache",
                      store_values,
                      contacts );
                }finally{
                 
                  sem.release();
                }
              }
             
              public void
              failed(
                DHTTransportContact   _contact,
                Throwable        _error )
              {
                try{
                  // System.out.println( "cacheForward: pre-store findNode Failed" );
 
                  DHTLog.log( "cacheForward: pre-store findNode failed " + DHTLog.getString( _contact ) + " -> failed: " + _error.getMessage());
                                     
                  router.contactDead( _contact.getID(), false);
                 
                }finally{
                 
                  sem.release();
                }
              }
            },
            contact.getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_ANTI_SPOOF2?new byte[0]:new byte[20] );
       
        sem.reserve();
      }
     
      try{
        this_mon.enter();
       
        for (int i=0;i<stop_caching.size();i++){
         
          DHTDBMapping  mapping = (DHTDBMapping)stored_values.remove( stop_caching.get(i));
         
          if ( mapping != null ){
           
            removeFromPrefixMap( mapping );
           
            mapping.destroy();
          }
        }
      }finally{
       
        this_mon.exit();
      }
    }
   
    DHTStorageBlock[]  direct_key_blocks = getDirectKeyBlocks();

    if ( direct_key_blocks.length > 0 ){
         
      for (int i=0;i<direct_key_blocks.length;i++){
     
        final DHTStorageBlock  key_block = direct_key_blocks[i];
       
        List  contacts = control.getClosestKContactsList( key_block.getKey(), false );

        boolean  forward_it = false;
       
          // ensure that the key is close enough to us
       
        for (int j=0;j<contacts.size();j++){

          final DHTTransportContact  contact = (DHTTransportContact)contacts.get(j);

          if ( router.isID( contact.getID())){
           
            forward_it  = true;
           
            break;
          }
        }
         
        for (int j=0; forward_it && j<contacts.size();j++){
         
          final DHTTransportContact  contact = (DHTTransportContact)contacts.get(j);
         
          if ( key_block.hasBeenSentTo( contact )){
           
            continue;
          }
         
          if ( router.isID( contact.getID())){
           
            continue// ignore ourselves
          }

          if ( contact.getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_BLOCK_KEYS ){
           
            final Runnable task =
              new Runnable()
              {
                public void
                run()
                {
                  contact.sendKeyBlock(
                    new DHTTransportReplyHandlerAdapter()
                    {
                      public void
                      keyBlockReply(
                        DHTTransportContact   _contact )
                      {
                        DHTLog.log( "key block forward ok " + DHTLog.getString( _contact ));
                       
                        key_block.sentTo( _contact );
                      }
                     
                      public void
                      failed(
                        DHTTransportContact   _contact,
                        Throwable        _error )
                      {
                        DHTLog.log( "key block forward failed " + DHTLog.getString( _contact ) + " -> failed: " + _error.getMessage());
                      }
                    },
                    key_block.getRequest(),
                    key_block.getCertificate());
                }
              };
           
              if ( anti_spoof_done.contains( contact )){
               
                task.run();
               
              }else{
               
                contact.sendFindNode(
                    new DHTTransportReplyHandlerAdapter()
                    {
                      public void
                      findNodeReply(
                        DHTTransportContact   contact,
                        DHTTransportContact[]  contacts )
                      { 
                        task.run();
                      }
                      public void
                      failed(
                        DHTTransportContact   _contact,
                        Throwable        _error )
                      {
                        // System.out.println( "nodeAdded: pre-store findNode Failed" );

                        DHTLog.log( "pre-kb findNode failed " + DHTLog.getString( _contact ) + " -> failed: " + _error.getMessage());
                                           
                        router.contactDead( _contact.getID(), false);
                      }
                    },
                    contact.getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_ANTI_SPOOF2?new byte[0]:new byte[20] );
              }
          }
        }
      }
    }
View Full Code Here

      }
     
      entry = to_do.removeFirst();
    }
   
    DHTTransportContact contact = entry.getKey();
   
    boolean  handled = false;
   
    try{
      if ( contact.getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_REPLICATION_CONTROL3 ){
     
        if ( DEBUG_SURVEY ){
          System.out.println( "Hitting " + contact.getString());
        }
       
        final List<DHTDBMapping>  mapping_list = new ArrayList<DHTDBMapping>();
       
        ByteArrayHashMap<List<DHTDBMapping>>  map = entry.getValue();
       
        List<byte[]> prefixes = map.keys();
 
        List<Object[]> encoded = new ArrayList<Object[]>( prefixes.size() );         
       
        try{
          this_mon.enter();
     
          SurveyContactState contact_state = survey_state.get( new HashWrapper( contact.getID()));
         
          for ( byte[] prefix: prefixes ){
           
            int  prefix_len = prefix.length;
            int  suffix_len = QUERY_STORE_REQUEST_ENTRY_SIZE - prefix_len;
           
            List<DHTDBMapping> mappings = map.get( prefix );
           
            List<byte[]> l = new ArrayList<byte[]>( mappings.size());
           
            encoded.add( new Object[]{ prefix, l });
           
              // remove entries that we know the contact already has
              // and then add them back in in the query-reply. note that we
              // still need to hit the contact if we end up with no values to
              // query as need to ascertain liveness. We might want to wait until,
              // say, 2 subsequent fails before treating contact as dead
           
            for ( DHTDBMapping m: mappings ){
           
              if ( contact_state != null ){
               
                if ( contact_state.testMapping(m)){
             
                  if ( DEBUG_SURVEY ){
                    System.out.println( "    skipping " + ByteFormatter.encodeString( m.getKey().getBytes()) + " as contact already has" );
                  }
                 
                  continue;
                }
              }
             
              mapping_list.add( m );
             
              byte[]  k = m.getKey().getBytes();
             
              byte[]  suffix = new byte[ suffix_len ];
             
              System.arraycopy( k, prefix_len, suffix, 0, suffix_len );
             
              l.add( suffix );
            }
          }
       
          if ( contact.getID().equals( survey_my_id )){
           
            Debug.out( "inconsistent - we shouldn't query ourselves!" );
          }
         
          contact.sendQueryStore(
            new DHTTransportReplyHandlerAdapter()
            {
              public void
              queryStoreReply(
                DHTTransportContact contact,
                List<byte[]>    response )
              {
                try{
                  if ( DEBUG_SURVEY ){
                    System.out.println( "response " + response.size());
                   
                    for (int i=0;i<response.size();i++){
                     
                      System.out.println( "    " + ByteFormatter.encodeString( response.get(i)));
                    }
                  }
                }finally{
               
                  doQuery( survey_my_id, total, mapping_to_node_map, to_do, replies, contact, mapping_list, response );
                }
              }
             
              public void
              failed(
                DHTTransportContact   contact,
                Throwable        error )
              {
                try{
                  if ( DEBUG_SURVEY ){
                    System.out.println( "Failed: " + Debug.getNestedExceptionMessage( error ));
                  }
                }finally{
                 
                  doQuery( survey_my_id, total, mapping_to_node_map, to_do, replies, contact, mapping_list, null );
                }
              }
            }, QUERY_STORE_REQUEST_ENTRY_SIZE, encoded );
         
          handled = true;
         
        }finally{
         
          this_mon.exit();
        }
      }else{
        if ( DEBUG_SURVEY ){
          System.out.println( "Not hitting " + contact.getString());
        }
      }
    }finally{
     
      if ( !handled ){
View Full Code Here

TOP

Related Classes of com.aelitis.azureus.core.dht.transport.DHTTransportContact

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.