FileDocCategorySizeDatePackage
NetworkManager.javaAPI DocAzureus 3.0.3.418177Tue Jul 17 18:03:12 BST 2007com.aelitis.azureus.core.networkmanager

NetworkManager

public class NetworkManager extends Object

Fields Summary
public static final int
UNLIMITED_RATE
private static final NetworkManager
instance
private static int
max_download_rate_bps
private static int
max_upload_rate_bps_normal
private static int
max_upload_rate_bps_seeding_only
private static int
max_upload_rate_bps
private static boolean
lan_rate_enabled
private static int
max_lan_upload_rate_bps
private static int
max_lan_download_rate_bps
private static boolean
seeding_only_mode_allowed
private static boolean
seeding_only_mode
public static boolean
REQUIRE_CRYPTO_HANDSHAKE
public static boolean
INCOMING_HANDSHAKE_FALLBACK_ALLOWED
public static boolean
OUTGOING_HANDSHAKE_FALLBACK_ALLOWED
private final WriteController
write_controller
private final ReadController
read_controller
private final TransferProcessor
upload_processor
private final TransferProcessor
download_processor
private final TransferProcessor
lan_upload_processor
private final TransferProcessor
lan_download_processor
private NetworkManagerStats
stats
public static final int
CRYPTO_OVERRIDE_NONE
public static final int
CRYPTO_OVERRIDE_REQUIRED
public static final int
CRYPTO_OVERRIDE_NOT_REQUIRED
Constructors Summary
private NetworkManager()

  
  
    
  
Methods Summary
public voidaddRateLimiter(NetworkConnectionBase peer_connection, LimitedRateGroup group, boolean upload)

	  if ( upload ){
		  if ( lan_upload_processor.isRegistered( peer_connection )){
			  
		  		lan_upload_processor.addRateLimiter( peer_connection, group );
	
		  }else{
		  		upload_processor.addRateLimiter( peer_connection, group );
		  } 
	  }else{
		  if ( lan_download_processor.isRegistered( peer_connection )){
			  
			  	lan_download_processor.addRateLimiter( peer_connection, group );
	
		  }else{
		  		download_processor.addRateLimiter( peer_connection, group );
		  } 
	  }
  
public voidaddReadEntity(RateControlledEntity entity)
Add a download entity for read processing.

param
entity to add

    read_controller.addReadEntity( entity );
  
public voidaddWriteEntity(RateControlledEntity entity)
Add an upload entity for write processing.

param
entity to add

    write_controller.addWriteEntity( entity );
  
public NetworkConnectionbindTransport(Transport transport, MessageStreamEncoder encoder, MessageStreamDecoder decoder)

	  return( NetworkConnectionFactory.create( transport, encoder, decoder ));
  
public voidcancelIncomingConnectionRouting(com.aelitis.azureus.core.networkmanager.NetworkManager$ByteMatcher matcher)
Cancel a request for inbound connection routing.

param
matcher byte sequence originally used to register

	  IncomingConnectionManager.getSingleton().deregisterMatchBytes( matcher );
  
public NetworkConnectioncreateConnection(ConnectionEndpoint target, MessageStreamEncoder encoder, MessageStreamDecoder decoder, boolean connect_with_crypto, boolean allow_fallback, byte[][] shared_secrets)
Create a new unconnected remote network connection (for outbound-initiated connections).

param
remote_address to connect to
param
encoder default message stream encoder to use for the outgoing queue
param
decoder default message stream decoder to use for the incoming queue
return
a new connection

 
    return NetworkConnectionFactory.create( target, encoder, decoder, connect_with_crypto, allow_fallback, shared_secrets );
  
public voiddowngradeTransferProcessing(NetworkConnectionBase peer_connection)
Downgrade the given connection back to a normal-speed network transfer handling.

param
peer_connection to downgrade

	  if( lan_upload_processor.isRegistered( peer_connection )) {
  		lan_upload_processor.downgradePeerConnection( peer_connection );
  		lan_download_processor.downgradePeerConnection( peer_connection );
  	}
  	else {
  		upload_processor.downgradePeerConnection( peer_connection );
  		download_processor.downgradePeerConnection( peer_connection );
  	}
  
public static booleangetCryptoRequired(int override_level)

  
  
    
  
		 
  
	  if ( override_level == CRYPTO_OVERRIDE_NONE ){
	    
		  return( REQUIRE_CRYPTO_HANDSHAKE );
		  
	  }else if ( override_level == CRYPTO_OVERRIDE_REQUIRED ){
	    		
		  return( true );
		  
	  }else{
		  
		  return( false );
	  }
  
public static intgetMaxDownloadRateBPS()

    if( max_download_rate_bps == UNLIMITED_RATE )  return 0;
    return max_download_rate_bps; 
  
public static intgetMaxUploadRateBPSNormal()

    if( max_upload_rate_bps_normal == UNLIMITED_RATE )  return 0;
    return max_upload_rate_bps_normal;
  
public static intgetMaxUploadRateBPSSeedingOnly()

    if( max_upload_rate_bps_seeding_only == UNLIMITED_RATE )  return 0;
    return max_upload_rate_bps_seeding_only;
  
public static intgetMinMssSize()

  return Math.min( TCPNetworkManager.getTcpMssSize(), UDPNetworkManager.getUdpMssSize()); 
public static com.aelitis.azureus.core.networkmanager.NetworkManagergetSingleton()
Get the singleton instance of the network manager.

return
the network manager

  return instance;  
public NetworkManagerStatsgetStats()

	  return( stats );
  
public voidinitialize()

	HTTPNetworkManager.getSingleton();  
	   
    AzureusCoreFactory.getSingleton().getGlobalManager().addListener( new GlobalManagerListener() {
      public void downloadManagerAdded( DownloadManager dm ){}
      public void downloadManagerRemoved( DownloadManager dm ){}
      public void destroyInitiated(){}
      public void destroyed(){}

      public void seedingStatusChanged( boolean seeding_only ) {
        seeding_only_mode = seeding_only;
        refreshRates();
      }
    });
  
public static booleanisLANRateEnabled()

     
    
  
  
	  return( lan_rate_enabled );
  
public static booleanisSeedingOnlyUploadRate()

    return seeding_only_mode_allowed && seeding_only_mode;
  
private static voidrefreshRates()

    if( isSeedingOnlyUploadRate() ) {
      max_upload_rate_bps = max_upload_rate_bps_seeding_only;
    }
    else {
      max_upload_rate_bps = max_upload_rate_bps_normal;
    }
    
    if( max_upload_rate_bps < 1024 ) {
      Debug.out( "max_upload_rate_bps < 1024=" +max_upload_rate_bps);
    }
    
    	//ensure that mss isn't greater than up/down rate limits
    
    int	min_rate = Math.min( max_upload_rate_bps, 
    					Math.min( max_download_rate_bps, 
    						Math.min( max_lan_upload_rate_bps, max_lan_download_rate_bps )));
    
    TCPNetworkManager.refreshRates( min_rate );
    UDPNetworkManager.refreshRates( min_rate );
  
public voidremoveRateLimiter(NetworkConnectionBase peer_connection, LimitedRateGroup group, boolean upload)

	  if ( upload ){
		  if ( lan_upload_processor.isRegistered( peer_connection )){
			  
		  		lan_upload_processor.removeRateLimiter( peer_connection, group );
	
		  }else{
		  		upload_processor.removeRateLimiter( peer_connection, group );
		  } 
	  }else{
		  if ( lan_download_processor.isRegistered( peer_connection )){
			  
			  	lan_download_processor.removeRateLimiter( peer_connection, group );
	
		  }else{
		  		download_processor.removeRateLimiter( peer_connection, group );
		  } 
	  }
  
public voidremoveReadEntity(RateControlledEntity entity)
Remove a download entity from read processing.

param
entity to remove

    read_controller.removeReadEntity( entity );
  
public voidremoveWriteEntity(RateControlledEntity entity)
Remove an upload entity from write processing.

param
entity to remove

    write_controller.removeWriteEntity( entity );
  
public voidrequestIncomingConnectionRouting(com.aelitis.azureus.core.networkmanager.NetworkManager$ByteMatcher matcher, com.aelitis.azureus.core.networkmanager.NetworkManager$RoutingListener listener, MessageStreamFactory factory)
Request the acceptance and routing of new incoming connections that match the given initial byte sequence.

param
matcher initial byte sequence used for routing
param
listener for handling new inbound connections
param
factory to use for creating default stream encoder/decoders

	  IncomingConnectionManager.getSingleton().registerMatchBytes( matcher, new IncomingConnectionManager.MatchListener() {
      public boolean
      autoCryptoFallback()
      {
    	return( listener.autoCryptoFallback());
      }
      public void connectionMatched( Transport	transport, Object routing_data ) {
        listener.connectionRouted( NetworkConnectionFactory.create( transport, factory.createEncoder(), factory.createDecoder() ), routing_data );
      }
    });
  
public voidstartTransferProcessing(NetworkConnectionBase peer_connection)
Register peer connection for network upload and download handling. NOTE: The given max rate limits are ignored until the connection is upgraded. NOTE: The given max rate limits are ignored for LANLocal connections.

param
peer_connection to register for network transfer processing
param
upload_group upload rate limit group
param
download_group download rate limit group

  	if( peer_connection.isLANLocal() && lan_rate_enabled ) {
  		lan_upload_processor.registerPeerConnection( peer_connection, true );
  		lan_download_processor.registerPeerConnection( peer_connection, false );
  	}
  	else {
  		upload_processor.registerPeerConnection( peer_connection, true );
  		download_processor.registerPeerConnection( peer_connection, false );
  	}
  
public voidstopTransferProcessing(NetworkConnectionBase peer_connection)
Cancel network upload and download handling for the given connection.

param
peer_connection to cancel

  	if( lan_upload_processor.isRegistered( peer_connection )) {
  		lan_upload_processor.deregisterPeerConnection( peer_connection );
  		lan_download_processor.deregisterPeerConnection( peer_connection );
  	}
  	else {
  		upload_processor.deregisterPeerConnection( peer_connection );
  		download_processor.deregisterPeerConnection( peer_connection );
  	}
  
public voidupgradeTransferProcessing(NetworkConnectionBase peer_connection)
Upgrade the given connection to high-speed network transfer handling.

param
peer_connection to upgrade

	  if( lan_upload_processor.isRegistered( peer_connection )) {
  		lan_upload_processor.upgradePeerConnection( peer_connection );
  		lan_download_processor.upgradePeerConnection( peer_connection );
  	}
  	else {
  		upload_processor.upgradePeerConnection( peer_connection );
  		download_processor.upgradePeerConnection( peer_connection );
  	}