FileDocCategorySizeDatePackage
DownloadingRanker.javaAPI DocAzureus 3.0.3.43315Tue Jul 25 11:59:18 BST 2006com.aelitis.azureus.core.peermanager.uploadslots

DownloadingRanker

public class DownloadingRanker extends Object
Unchoker implementation to be used while in downloading mode.

Fields Summary
Constructors Summary
public DownloadingRanker()

    /* nothing */
  
Methods Summary
public org.gudy.azureus2.core3.peer.impl.PEPeerTransportgetNextOptimisticPeer(java.util.ArrayList all_peers)

  	return UnchokerUtil.getNextOptimisticPeer( all_peers, true, true );  //TODO extract and optimize?
  
public java.util.ArrayListrankPeers(int max_to_unchoke, java.util.ArrayList all_peers)

  
  	 ArrayList best_peers = new ArrayList();
  	 long[] bests = new long[ max_to_unchoke ];  //ensure we never rank more peers than needed
  	 
    
    //fill slots with peers who we are currently downloading the fastest from
    for( int i=0; i < all_peers.size(); i++ ) {
    	PEPeerTransport peer = (PEPeerTransport)all_peers.get( i );

      if( peer.isInteresting() && UnchokerUtil.isUnchokable( peer, false ) ) {  //viable peer found
        long rate = peer.getStats().getSmoothDataReceiveRate();
        if( rate > 256 ) {  //filter out really slow peers
          UnchokerUtil.updateLargestValueFirstSort( rate, bests, peer, best_peers, 0 );
        }
      }
    }
    
    
    //if we havent yet picked enough slots
    if( best_peers.size() < max_to_unchoke ) {  
      int start_pos = best_peers.size();
      
      //fill the remaining slots with peers that we have downloaded from in the past
      for( int i=0; i < all_peers.size(); i++ ) {
      	PEPeerTransport peer = (PEPeerTransport)all_peers.get( i );

        if( peer.isInteresting() && UnchokerUtil.isUnchokable( peer, false ) && !best_peers.contains( peer ) ) {  //viable peer found
          long uploaded_ratio = peer.getStats().getTotalDataBytesSent() / (peer.getStats().getTotalDataBytesReceived() + (DiskManager.BLOCK_SIZE-1));
          //make sure we haven't already uploaded several times as much data as they've sent us
          if( uploaded_ratio <3) {
            UnchokerUtil.updateLargestValueFirstSort( peer.getStats().getTotalDataBytesReceived(), bests, peer, best_peers, start_pos );
          }  
        }
      }
    }
    
    
    return best_peers;