Examples of HashWrapper


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();

        Iterator<DHTDBValueImpl>  it2 = mapping.getValues();
       
        List<DHTDBValueImpl>  values = new ArrayList<DHTDBValueImpl>();

        while( it2.hasNext()){
         
          DHTDBValueImpl  value = it2.next();       

          if ( value.isLocal()){
           
            if (( value.getFlags() | DHT.FLAG_PRECIOUS ) != 0 ){
             
              if ( now - value.getCreationTime() > PRECIOUS_CHECK_INTERVAL ){
               
                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    = 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++){
               
        control.putEncodedKey( key.getHash(), "Precious republish", values.get(i), 0, true );
      }
    }
  }
View Full Code Here

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

     
      while( it.hasNext()){
       
        DHTDBMapping  mapping = it.next();
         
        HashWrapper hw = mapping.getKey();
       
        if ( existing_times.size() > 0 ){
       
          existing_times.remove( hw );
        }
       
        if ( !applyRF( mapping )){
           
          continue;
        }
         
        applicable_keys.add( hw );
       
        byte[] key = hw.getBytes();
       
        /*
        List<DHTTransportContact>  contacts = control.getClosestKContactsList( key, true );

        for ( DHTTransportContact c: contacts ){
View Full Code Here

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

        min_create = Math.min( min_create, value.getCreationTime());
      }
     
      if ( min_period > 0 ){
       
        HashWrapper hw = mapping.getKey();
       
        Long  next_time = survey_mapping_times.get( hw );
       
        long now = SystemTime.getMonotonousTime();
       
View Full Code Here

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

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

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

     
      for ( Map.Entry<DHTTransportContact,Object[]> entry: replies.entrySet()){
       
        DHTTransportContact  contact = entry.getKey();
       
        HashWrapper hw = new HashWrapper( contact.getID());
       
        SurveyContactState  contact_state = survey_state.get( hw );
       
        if ( contact_state != null ){
         
          contact_state.updateContactDetails( contact );
         
        }else{
         
          contact_state = new SurveyContactState( contact );
         
          survey_state.put( hw, contact_state );
        }
       
        contact_state.updateUseTime();
       
        Object[]      temp  = entry.getValue();
       
        List<DHTDBMapping>  mappings   = (List<DHTDBMapping>)temp[0];
        List<byte[]>    reply    = (List<byte[]>)temp[1];
       
        if ( reply == null ){
                   
          contact_state.contactFailed();
         
        }else{
         
          contact_state.contactOK();

          if ( mappings.size() != reply.size()){
           
            Debug.out( "Inconsistent: mappings=" + mappings.size() + ", reply=" + reply.size());
           
            continue;
          }
         
          Iterator<DHTDBMapping>  it1 = mappings.iterator();
          Iterator<byte[]>    it2 = reply.iterator();
         
          while( it1.hasNext()){
           
            DHTDBMapping  mapping = it1.next();
            byte[]      rep    = it2.next();
           
            if ( rep == null ){
             
              contact_state.removeMapping( mapping );
             
            }else{
             
                // must match against our short-key mapping for consistency
             
              DHTDBMapping mapping_to_check = stored_values_prefix_map.get( mapping.getShortKey());
             
              if ( mapping_to_check == null ){
               
                // deleted
               
              }else{
               
                byte[] k = mapping_to_check.getKey().getBytes();
   
                int  rep_len = rep.length;
               
                if ( rep_len < 2 || rep_len >= k.length ){
                 
                  Debug.out( "Invalid rep_len: " + rep_len );
                 
                  continue;
                }
               
                boolean  match = true;
               
                int  offset = k.length-rep_len;
               
                for (int i=0;i<rep_len;i++){
                 
                  if ( rep[i] != k[i+offset] ){
                   
                    match = false;
                   
                    break;
                  }
                }
               
                if ( match ){
                               
                  contact_state.addMapping( mapping );
                 
                }else{
                 
                  contact_state.removeMapping( mapping );
                }
              }
            }
          }
         
          Set<DHTDBMapping> contact_mappings = contact_state.getMappings();
         
          for ( DHTDBMapping m: contact_mappings ){
           
            int[] t = totals.get( m );
           
            if ( t == null ){
             
              t = new int[]{ 2 };    // one for local node + 1 for them
             
              totals.put( m, t );
             
            }else{
             
              t[0]++;
            }
          }
        }
      }
           
      for (Map.Entry<DHTDBMapping,List<DHTTransportContact>> entry: mapping_to_node_map.entrySet()){
       
        DHTDBMapping        mapping   = entry.getKey();
        List<DHTTransportContact>  contacts   = entry.getValue();
       
        int[]  t = totals.get( mapping );
       
        int  copies;
       
        if ( t == null ){
         
          copies = 1;    // us!
         
        }else{
         
          copies = t[0];
        }
               
        Iterator<DHTDBValueImpl> values = mapping.getValues();
       
        if ( values.hasNext()){
       
          int  max_replication_factor = -1;
       
          while( values.hasNext()){
           
            DHTDBValueImpl value = values.next();
           
            int  rf = value.getReplicationFactor();
           
            if ( rf > max_replication_factor ){
             
              max_replication_factor = rf;
            }
          }
         
          if ( max_replication_factor == 0 ){
           
            continue;
          }
         
          if ( max_replication_factor > router.getK()){
           
            max_replication_factor = router.getK();
          }
         
          if ( copies < max_replication_factor ){
           
            int  required = max_replication_factor - copies;
           
            List<SurveyContactState> potential_targets = new ArrayList<SurveyContactState>();
           
            List<byte[]>  addresses = new ArrayList<byte[]>( contacts.size());
           
            for ( DHTTransportContact c: contacts ){
           
              if ( c.getProtocolVersion() < DHTTransportUDP.PROTOCOL_VERSION_REPLICATION_CONTROL3 ){
               
                continue;
              }
             
              addresses.add( c.getAddress().getAddress().getAddress());
             
              SurveyContactState  contact_state = survey_state.get( new HashWrapper( c.getID()));
             
              if ( contact_state != null && !contact_state.testMapping( mapping )){
               
                potential_targets.add( contact_state );
              }
            }
           
            Set<HashWrapper>  bad_addresses = new HashSet<HashWrapper>();
           
            for ( byte[] a1: addresses ){
             
              for ( byte[] a2: addresses ){
               
                  // ignore ipv6 for the moment...
               
                if ( a1 == a2 || a1.length != a2.length || a1.length != 4 ){
                 
                  continue;
                }
               
                  // ignore common /16 s
               
                if ( a1[0] == a2[0] && a1[1] == a2[1] ){
                 
                  log( "/16 match on " + ByteFormatter.encodeString( a1 ) + "/" + ByteFormatter.encodeString( a2 ));
                 
                  bad_addresses.add( new HashWrapper( a1 ));
                  bad_addresses.add( new HashWrapper( a2 ));
                }
              }
            }
           
            final byte[] key = mapping.getKey().getBytes();
           
            Collections.sort(
              potential_targets,
              new Comparator<SurveyContactState>()
              {
                public int
                compare(
                  SurveyContactState o1,
                  SurveyContactState o2)
                {
                  boolean o1_bad = o1.getConsecFails() >= 2;
                  boolean o2_bad = o2.getConsecFails() >= 2;
                 
                  if ( o1_bad == o2_bad ){
                   
                      // switch from age based to closest as per Roxana's advice
                   
                    if ( false ){
                     
                      long res = o2.getCreationTime() - o1.getCreationTime();
               
                      if ( res < 0 ){
                       
                        return( -1 );
                       
                      }else if ( res > 0 ){
                       
                        return( 1 );
                       
                      }else{
                       
                        return( 0 );
                      }
                    }else{
                     
                      return(
                        control.computeAndCompareDistances(
                            o1.getContact().getID(),
                            o2.getContact().getID(),
                            key ));
                    }
                  }else{
               
                    if ( o1_bad ){
                     
                      return( 1 );
                     
                    }else{
                     
                      return( -1 );
                    }
                  }
                }
              });
           
            int  avail = Math.min( required, potential_targets.size());
           
            for (int i=0;i<avail;i++){
             
              SurveyContactState target = potential_targets.get( i );
             
              if (   bad_addresses.size() > 0 &&
                  bad_addresses.contains( new HashWrapper( target.getContact().getAddress().getAddress().getAddress()))){
               
                  // make it look like this target has the mapping as we don't want to store it there but we want to treat it as
                  // if it has it, effectively reducing availability but not skewing storage in favour of potentially malicious nodes
               
                target.addMapping( mapping );
View Full Code Here

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

    final List<byte[]> reply = new ArrayList<byte[]>();
   
    try{
      this_mon.enter();
     
      SurveyContactState  existing_state = survey_state.get( new HashWrapper( originating_contact.getID()));
     
      if ( existing_state != null ){
       
        existing_state.updateContactDetails( originating_contact );
      }
View Full Code Here

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

     
      while( it1.hasNext()){
           
        Map.Entry<HashWrapper,DHTDBMapping>    entry = it1.next();
       
        HashWrapper    value_key  = entry.getKey();
       
        DHTDBMapping  mapping   = entry.getValue();
       
        /*
        if ( mapping.getIndirectSize() > 1000 ){
          mapping.print();
        }
        */
       
        DHTDBValue[]  values = mapping.get(null,0,(byte)0);
         
        for (int i=0;i<values.length;i++){
         
          DHTDBValue  value = values[i];
         
          /*
          byte[] v = value.getValue();
         
          Integer y = blah.get( v );
         
          if ( y == null ){
            blah.put( v, 1 );
          }else{
            blah.put( v, y+1 );
          }
          */
         
          Integer key = new Integer( value.isLocal()?0:1);
         
          Object[]  data = (Object[])count.get( key );
                 
          if ( data == null ){
           
            data = new Object[2];
           
            data[0] = new Integer(1);
           
            data[1] = "";
                 
            count.put( key, data );
 
          }else{
           
            data[0] = new Integer(((Integer)data[0]).intValue() + 1 );
          }
       
          String  s = (String)data[1];
         
          s += (s.length()==0?"":", ") + "key=" + DHTLog.getString2(value_key.getHash()) + ",val=" + value.getString();
         
          data[1= s;
        }
      }
     
      /*
      long  total_dup = 0;
     
      for ( byte[] k: blah.keys()){
       
        int c = blah.get( k );
       
        if ( c > 1 ){
         
          total_dup += ( c * k.length );
         
          System.out.println( "Dup: " + new String(k) + " -> " + c );
        }
      }
     
      System.out.println( "Total dup: " + total_dup );
      */
     
      Iterator<Integer> it2 = count.keySet().iterator();
     
      while( it2.hasNext()){
       
        Integer  k = it2.next();
       
        Object[]  data = (Object[])count.get(k);
       
        logger.log( "    " + k + " -> " + data[0] + " entries" ); // ": " + data[1]);
      }
     
      Iterator<Map.Entry<HashWrapper,DHTDBMapping>> it3 = stored_values.entrySet().iterator();
     
      String  str     = "    ";
      int    str_entries  = 0;
     
      while( it3.hasNext()){
           
        Map.Entry<HashWrapper,DHTDBMapping>    entry = it3.next();
       
        HashWrapper    value_key  = entry.getKey();
       
        DHTDBMapping  mapping   = entry.getValue();
       
        if ( str_entries == 16 ){
         
          logger.log( str );
         
          str = "    ";
         
          str_entries  = 0;
        }
       
        str_entries++;
       
        str += (str_entries==1?"":", ") + DHTLog.getString2(value_key.getHash()) + " -> " + mapping.getValueCount() + "/" + mapping.getHits()+"["+mapping.getLocalSize()+","+mapping.getDirectSize()+","+mapping.getIndirectSize() + "]";
      }
     
      if ( str_entries > 0 ){
       
        logger.log( str );
View Full Code Here

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

         
          Iterator<DHTDBMapping>  it = stored_values.values().iterator();
           
          boolean  overall_deleted = false;
         
          HashWrapper value_id = new HashWrapper( contact.getID());
         
          while( it.hasNext()){
           
            DHTDBMapping  mapping = it.next();
           
View Full Code Here

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

                }
              }
             
              lws = LightWeightSeedManager.getSingleton().add(
                  getName(),
                  new HashWrapper( hash ),
                  TorrentUtils.getDecentralisedEmptyURL(),
                  versioned_data_location,
                  new LightWeightSeedAdapter()
                  {
                    public TOTorrent
View Full Code Here

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

          to_compare.get( hash );

          try{
            managers_mon.enter();

            List  registrations = (List)registered_legacy_managers.get( new HashWrapper( hash ));

            if ( registrations != null ){

              routing_data = (PeerManagerRegistrationImpl)registrations.get(0);
            }
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.