FileDocCategorySizeDatePackage
DHTImpl.javaAPI DocAzureus 3.0.3.47598Thu Jun 28 16:08:24 BST 2007com.aelitis.azureus.core.dht.impl

DHTImpl

public class DHTImpl extends Object implements com.aelitis.azureus.core.dht.DHT
author
parg

Fields Summary
private com.aelitis.azureus.core.dht.DHTStorageAdapter
storage_adapter
private com.aelitis.azureus.core.dht.nat.DHTNATPuncherAdapter
nat_adapter
private DHTControl
control
private com.aelitis.azureus.core.dht.nat.DHTNATPuncher
nat_puncher
private com.aelitis.azureus.core.dht.speed.DHTSpeedTester
speed_tester
private Properties
properties
private com.aelitis.azureus.core.dht.DHTLogger
logger
Constructors Summary
public DHTImpl(DHTTransport _transport, Properties _properties, com.aelitis.azureus.core.dht.DHTStorageAdapter _storage_adapter, com.aelitis.azureus.core.dht.nat.DHTNATPuncherAdapter _nat_adapter, com.aelitis.azureus.core.dht.DHTLogger _logger)

		
		properties		= _properties;
		storage_adapter	= _storage_adapter;
		nat_adapter		= _nat_adapter;
		logger			= _logger;
		
		DHTNetworkPositionManager.initialise( storage_adapter );
		
		DHTLog.setLogger( logger );
		
		int		K 		= getProp( PR_CONTACTS_PER_NODE, 			DHTControl.K_DEFAULT );
		int		B 		= getProp( PR_NODE_SPLIT_FACTOR, 			DHTControl.B_DEFAULT );
		int		max_r	= getProp( PR_MAX_REPLACEMENTS_PER_NODE, 	DHTControl.MAX_REP_PER_NODE_DEFAULT );
		int		s_conc 	= getProp( PR_SEARCH_CONCURRENCY, 			DHTControl.SEARCH_CONCURRENCY_DEFAULT );
		int		l_conc 	= getProp( PR_LOOKUP_CONCURRENCY, 			DHTControl.LOOKUP_CONCURRENCY_DEFAULT );
		int		o_rep 	= getProp( PR_ORIGINAL_REPUBLISH_INTERVAL, 	DHTControl.ORIGINAL_REPUBLISH_INTERVAL_DEFAULT );
		int		c_rep 	= getProp( PR_CACHE_REPUBLISH_INTERVAL, 	DHTControl.CACHE_REPUBLISH_INTERVAL_DEFAULT );
		int		c_n 	= getProp( PR_CACHE_AT_CLOSEST_N, 			DHTControl.CACHE_AT_CLOSEST_N_DEFAULT );
		
		control = DHTControlFactory.create( 
				new DHTControlAdapter()
				{
					public DHTStorageAdapter
					getStorageAdapter()
					{
						return( storage_adapter );
					}
					
					public boolean
					isDiversified(
						byte[]		key )
					{
						if ( storage_adapter == null ){
							
							return( false );
						}
						
						return( storage_adapter.isDiversified( key ));
					}
					
					public byte[][]
					diversify(
						DHTTransportContact	cause,
						boolean				put_operation,
						boolean				existing,
						byte[]				key,
						byte				type,
						boolean				exhaustive )
					{
						boolean	valid;
						
						if ( existing ){
							
							valid =	 	type == DHT.DT_FREQUENCY ||
										type == DHT.DT_SIZE ||
										type == DHT.DT_NONE;
						}else{
							
							valid = 	type == DHT.DT_FREQUENCY ||
										type == DHT.DT_SIZE;
						}
						
						if ( storage_adapter != null && valid ){
							
							if ( existing ){
								
								return( storage_adapter.getExistingDiversification( key, put_operation, exhaustive ));
								
							}else{
								
								return( storage_adapter.createNewDiversification( cause, key, put_operation, type, exhaustive ));
							}
						}else{
							
							if ( !valid ){
								
								Debug.out( "Invalid diversification received: type = " + type );
							}
							
							if ( existing ){
								
								return( new byte[][]{ key });
								
							}else{
								
								return( new byte[0][] );
							}
						}
					}
				},
				_transport, 
				K, B, max_r,
				s_conc, l_conc, 
				o_rep, c_rep, c_n,
				logger );
		
		if ( nat_adapter != null ){
			
			nat_puncher	= DHTNATPuncherFactory.create( nat_adapter, this );
		}
		
		speed_tester = DHTSpeedTesterFactory.create( this );
	
Methods Summary
public voiddestroy()

		if ( nat_puncher != null ){
			
			nat_puncher.destroy();
		}
		
		DHTNetworkPositionManager.destroy( storage_adapter );
	
public voidexportState(java.io.DataOutputStream os, int max)

	
		control.exportState( os, max );
	
public voidget(byte[] key, java.lang.String description, byte flags, int max_values, long timeout, boolean exhaustive, boolean high_priority, com.aelitis.azureus.core.dht.DHTOperationListener listener)

		control.get( key, description, flags, max_values, timeout, exhaustive, high_priority, listener );
	
public DHTControlgetControl()

		return( control );
	
public com.aelitis.azureus.core.dht.db.DHTDBgetDataBase()

		return( control.getDataBase());
	
public intgetIntProperty(java.lang.String name)

		return(((Integer)properties.get(name)).intValue());
	
public DHTTransportValuegetLocalValue(byte[] key)

		return( control.getLocalValue( key ));
	
public com.aelitis.azureus.core.dht.DHTLoggergetLogger()

		return( logger );
	
public com.aelitis.azureus.core.dht.nat.DHTNATPunchergetNATPuncher()

		return( nat_puncher );
	
protected intgetProp(java.lang.String name, int def)

		Integer	x = (Integer)properties.get(name);
		
		if ( x == null ){
			
			properties.put( name, new Integer( def ));
			
			return( def );
		}
		
		return( x.intValue());
	
public com.aelitis.azureus.core.dht.router.DHTRoutergetRouter()

		return( control.getRouter());
	
public com.aelitis.azureus.core.dht.speed.DHTSpeedTestergetSpeedTester()

		return( speed_tester );
	
public com.aelitis.azureus.core.dht.DHTStorageAdaptergetStorageAdapter()

		return( storage_adapter );
	
public DHTTransportgetTransport()

		return( control.getTransport());
	
public voidimportState(java.io.DataInputStream is)

	
		control.importState( is );
	
public voidintegrate(boolean full_wait)

		control.seed( full_wait );	
		
		if ( nat_puncher!= null ){
			
			nat_puncher.start();
		}
	
public booleanisDiversified(byte[] key)

		return( control.isDiversified( key ));
	
public voidprint()

		control.print();
	
public voidput(byte[] key, java.lang.String description, byte[] value, byte flags, com.aelitis.azureus.core.dht.DHTOperationListener listener)

		control.put( key, description, value, flags, listener );
	
public byte[]remove(byte[] key, java.lang.String description, com.aelitis.azureus.core.dht.DHTOperationListener listener)

		return( control.remove( key, description, listener ));
	
public voidsetLogging(boolean on)

		DHTLog.setLogging( on );