Examples of HashWrapper


Examples of org.gudy.azureus2.core3.util.HashWrapper

    // 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
     
      addDirectValue( originator_id, new_value );
     
        // remove any indirect values we might already have for this
     
      Iterator<Map.Entry<HashWrapper,DHTDBValueImpl>>  it = indirect_originator_value_map.entrySet().iterator();
     
      List<HashWrapper>  to_remove = new ArrayList<HashWrapper>();
     
      while( it.hasNext()){
       
        Map.Entry<HashWrapper,DHTDBValueImpl>  entry = it.next();
       
        HashWrapper    existing_key  = entry.getKey();
       
        DHTDBValueImpl  existing_value  = entry.getValue();
 
        if ( Arrays.equals( existing_value.getOriginator().getID(), originator.getID())){
       
          to_remove.add( existing_key );
        }
      }
     
      for (int i=0;i<to_remove.size();i++){
       
        removeIndirectValue((HashWrapper)to_remove.get(i));
      }
    }else{
     
        // not direct. if we have a value already for this originator then
        // we drop the value as the originator originated one takes precedence
     
      if (   direct_originator_map_may_be_null != null &&
          direct_originator_map_may_be_null.get( originator_id ) != null ){
       
        return;
      }
           
        // rule (b) - one entry per originator/value pair
       
      HashWrapper  originator_value_id = getOriginatorValueID( new_value );

      DHTDBValueImpl existing_value = indirect_originator_value_map.get( originator_value_id );
     
      if ( existing_value != null ){
       
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

      // 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
      // contact can only trash originator values for things it happens to be close to)
   
    return( new HashWrapper( originator_id ));
   
    /*
    byte[]  value_bytes   = value.getValue();

    byte[]  x = new byte[originator_id.length + value_bytes.length];
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

   
      while( it.hasNext() && ( max==0 || res.size()< max )){
     
        Map.Entry<HashWrapper,DHTDBValueImpl>  entry = it.next();
       
        HashWrapper    entry_key  = entry.getKey();
       
        DHTDBValueImpl  entry_value = entry.getValue();
           
        HashWrapper  x = new HashWrapper( entry_value.getValue());
       
        if ( duplicate_check.contains( x )){
         
          continue;
        }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

    if ( direct_originator_map_may_be_null == null ){
     
      return( null );
    }
   
    HashWrapper originator_id = new HashWrapper( originator.getID());
   
    DHTDBValueImpl  res = (DHTDBValueImpl)direct_originator_map_may_be_null.get( originator_id );
   
    return( res );
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

  remove(
    DHTTransportContact   originator )
  {
      // local remove
   
    HashWrapper originator_id = new HashWrapper( originator.getID());
   
    DHTDBValueImpl  res = removeDirectValue( originator_id );
   
    return( res );
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

        
         byte[]  encoded = hasher.getDigest();
                         
      synchronized( global_shared_secrets ){
       
        global_shared_secrets.put( new HashWrapper( encoded ), secrets[i] );
      }
    }
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

        
         byte[]  encoded = hasher.getDigest();
                         
      synchronized( global_shared_secrets ){
       
        global_shared_secrets.remove( new HashWrapper( encoded ));
      }
    }
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

                decode[i] ^= sha1[i];
              }
             
              synchronized( global_shared_secrets ){
               
                shared_secret  = (byte[])global_shared_secrets.get( new HashWrapper( decode ));
              }
             
              if ( shared_secret == null ){
               
                throw( new IOException( "No matching shared secret" ));
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

     
      while( it.hasNext()){
       
        Map.Entry<HashWrapper,DHTDBMapping>  entry = it.next();
       
        HashWrapper    key    = (HashWrapper)entry.getKey();
       
        DHTDBMapping  mapping  = (DHTDBMapping)entry.getValue();
       
        Iterator<DHTDBValueImpl>  it2 = mapping.getValues();
       
        List<DHTDBValueImpl>  values = new ArrayList<DHTDBValueImpl>();
       
        while( it2.hasNext()){
         
          DHTDBValueImpl  value = it2.next();
       
          if ( value != null && value.isLocal()){
           
            // we're republising the data, reset the creation time
           
            value.setCreationTime();

            values.add( value );
          }
        }
       
        if ( values.size() > 0 ){
         
          republish.put( key, values );
         
        }
      }
    }finally{
     
      this_mon.exit();
    }
   
    Iterator<Map.Entry<HashWrapper,List<DHTDBValueImpl>>>  it = republish.entrySet().iterator();
   
    while( it.hasNext()){
     
      Map.Entry<HashWrapper,List<DHTDBValueImpl>>  entry = it.next();
     
      HashWrapper      key    = (HashWrapper)entry.getKey();
     
      List<DHTDBValueImpl>    values  = entry.getValue();
     
        // no point in worry about multi-value puts here as it is extremely unlikely that
        // > 1 value will locally stored, or > 1 value will go to the same contact
     
      for (int i=0;i<values.size();i++){
       
        values_published++;
       
        control.putEncodedKey( key.getHash(), "Republish", values.get(i), 0, true );
      }
    }
   
    return( values_published );
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.HashWrapper

     
      while( it.hasNext()){
       
        Map.Entry<HashWrapper,DHTDBMapping>  entry = it.next();
       
        HashWrapper      key    = entry.getKey();
       
        DHTDBMapping    mapping  = entry.getValue();
       
          // assume that if we've diversified then the other k-1 locations are under similar
          // stress and will have done likewise - no point in republishing cache values to them
          // New nodes joining will have had stuff forwarded to them regardless of diversification
          // status
       
        if ( mapping.getDiversificationType() != DHT.DT_NONE ){
         
          continue;
        }
       
        Iterator<DHTDBValueImpl>  it2 = mapping.getValues();
       
        boolean  all_rf_values = it2.hasNext();
       
        List<DHTDBValueImpl>  values = new ArrayList<DHTDBValueImpl>();
       
        while( it2.hasNext()){
         
          DHTDBValueImpl  value = it2.next();
       
          if ( value.isLocal()){
           
            all_rf_values = false;
           
          }else{
           
            if ( value.getReplicationFactor() == DHT.REP_FACT_DEFAULT ){
             
              all_rf_values = false;
            }
           
              // if this value was stored < period ago then we assume that it was
              // also stored to the other k-1 locations at the same time and therefore
              // we don't need to re-store it
           
            if ( now < value.getStoreTime()){
             
                // deal with clock changes
             
              value.setStoreTime( now );
             
            }else if ( now - value.getStoreTime() <= cache_republish_interval ){
             
              // System.out.println( "skipping store" );
             
            }else{
               
              values.add( value );
            }
          }
        }

        if ( all_rf_values ){
         
            // if surveying is disabled then we swallow values here to prevent them
            // from being replicated using the existing technique and muddying the waters
         
          values.clear()// handled by the survey process
         
          republish_via_survey.add( mapping );
        }
         
        if ( values.size() > 0 ){
           
          republish.put( key, values );
        }
      }
    }finally{
     
      this_mon.exit();
    }
   
    if ( republish_via_survey.size() > 0 ){
   
        // we still check for being too far away here
     
      List<HashWrapper>  stop_caching = new ArrayList<HashWrapper>();

      for ( DHTDBMapping mapping: republish_via_survey ){
       
        HashWrapper      key    = mapping.getKey();
       
        byte[]  lookup_id  = key.getHash();

        List<DHTTransportContact>  contacts = control.getClosestKContactsList( lookup_id, false );
       
          // if we are no longer one of the K closest contacts then we shouldn't
          // cache the value
     
        boolean  keep_caching  = false;
     
        for (int j=0;j<contacts.size();j++){
     
          if ( router.isID(((DHTTransportContact)contacts.get(j)).getID())){
         
            keep_caching  = true;
         
            break;
          }
        }
     
        if ( !keep_caching ){
         
          DHTLog.log( "Dropping cache entry for " + DHTLog.getString( lookup_id ) + " as now too far away" );
         
          stop_caching.add( key );
        }
      }
     
      if ( stop_caching.size() > 0 ){
       
        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();
        }
      }
    }
   
    final int[]  values_published  = {0};
    final int[]  keys_published    = {0};
    final int[]  republish_ops    = {0};
   
    final HashSet<DHTTransportContact>  anti_spoof_done  = new HashSet<DHTTransportContact>();
   
    if ( republish.size() > 0 ){
     
      // System.out.println( "cache replublish" );
     
        // The approach is to refresh all leaves in the smallest subtree, thus populating the tree with
        // sufficient information to directly know which nodes to republish the values
        // to.
     
        // However, I'm going to rely on the "refresh idle leaves" logic above
        // (that's required to keep the DHT alive in general) to ensure that all
        // k-buckets are reasonably up-to-date
         
      Iterator<Map.Entry<HashWrapper,List<DHTDBValueImpl>>>  it1 = republish.entrySet().iterator();
     
      List<HashWrapper>  stop_caching = new ArrayList<HashWrapper>();
     
        // build a map of contact -> list of keys to republish
     
      Map<HashWrapper,Object[]>  contact_map  = new HashMap<HashWrapper,Object[]>();
     
      while( it1.hasNext()){
       
        Map.Entry<HashWrapper,List<DHTDBValueImpl>>  entry = it1.next();
       
        HashWrapper      key    = entry.getKey();
       
        byte[]  lookup_id  = key.getHash();
       
          // just use the closest contacts - if some have failed then they'll
          // get flushed out by this operation. Grabbing just the live ones
          // is a bad idea as failures may rack up against the live ones due
          // to network problems and kill them, leaving the dead ones!
       
        List<DHTTransportContact>  contacts = control.getClosestKContactsList( lookup_id, false );
             
          // if we are no longer one of the K closest contacts then we shouldn't
          // cache the value
       
        boolean  keep_caching  = false;
       
        for (int j=0;j<contacts.size();j++){
       
          if ( router.isID(((DHTTransportContact)contacts.get(j)).getID())){
           
            keep_caching  = true;
           
            break;
          }
        }
       
        if ( !keep_caching ){
         
          DHTLog.log( "Dropping cache entry for " + DHTLog.getString( lookup_id ) + " as now too far away" );
         
          stop_caching.add( key );
         
            // we carry on and do one last publish
         
        }
       
        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()];
             
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.