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

SeedingRanker

public class SeedingRanker extends Object
Unchoker implementation to be used while in seeding mode.

Fields Summary
Constructors Summary
public SeedingRanker()

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

  	PEPeerTransport picked = getNextOptimisticPeerExec( all_peers );
  	
  	//TODO test to see if peers really are picked evenly
  	
  	return picked;  	
  
private org.gudy.azureus2.core3.peer.impl.PEPeerTransportgetNextOptimisticPeerExec(java.util.ArrayList all_peers)

  	
  	if( all_peers.isEmpty() )  {  //no connected peers
  		Debug.out( "all_peers.isEmpty()" );
  		return null;
  	}  	
  	
  	int pos = RandomUtils.nextInt( all_peers.size() );  //pick a random peer to start
  	
  	for( int i=0; i < all_peers.size(); i++ ) {  //ensure we only loop once
  		
  		PEPeerTransport peer = (PEPeerTransport)all_peers.get( pos );  //get next potential peer
  		
  		if( peer.isChokedByMe() && UnchokerUtil.isUnchokable( peer, true ) ) {   //filter out peers already unchoked, and unchokable
  			
  			return peer;  //found the next optimistic!  			
  		}
  		
  		pos++;  //try next
  		
  		if( pos >= all_peers.size() ) {  //loop 'round if necessary
  			pos = 0;
  		}  		
  	}
  	
  	Debug.out( "no optimistic-able seeding peers found" );
  	return null;