FileDocCategorySizeDatePackage
TRTrackerServerTCP.javaAPI DocAzureus 3.0.3.46716Tue Dec 19 09:26:56 GMT 2006org.gudy.azureus2.core3.tracker.server.impl.tcp

TRTrackerServerTCP

public abstract class TRTrackerServerTCP extends TRTrackerServerImpl

Fields Summary
private static int
THREAD_POOL_SIZE
public static long
PROCESSING_GET_LIMIT
public static int
PROCESSING_POST_MULTIPLIER
private boolean
ssl
private int
port
private boolean
apply_ip_filter
private ThreadPool
thread_pool
static boolean
LOG_DOS_TO_FILE
protected static File
dos_log_file
protected static AEMonitor
class_mon
Map
DOS_map
List
dos_list
long
last_dos_check
long
MAX_DOS_ENTRIES
long
MAX_DOS_RETENTION
int
DOS_CHECK_DEAD_WOOD_COUNT
int
DOS_MIN_INTERVAL
int
dos_check_count
Constructors Summary
public TRTrackerServerTCP(String _name, int _port, boolean _ssl, boolean _apply_ip_filter, boolean _start_up_ready)

		super( _name, _start_up_ready );
		
		port					= _port;
		ssl						= _ssl;
		apply_ip_filter			= _apply_ip_filter;

		thread_pool = new ThreadPool( "TrackerServer:TCP:"+port, THREAD_POOL_SIZE );
			
		if ( PROCESSING_GET_LIMIT > 0 ){
			
			thread_pool.setExecutionLimit( PROCESSING_GET_LIMIT );
		}
	
Methods Summary
protected booleancheckDOS(java.lang.String ip)

	
	 
	
				 
	
		 
	
		InetAddress	inet_address = InetAddress.getByName(ip);
		
		if ( inet_address.isLoopbackAddress() || InetAddress.getLocalHost().equals( inet_address )){
			
			return( false);
		}
		
		boolean	res;
		
		last_dos_check = SystemTime.getCurrentTime();
		
		DOSEntry	entry = (DOSEntry)DOS_map.get(ip);
		
		if ( entry == null ){
						
			entry = new DOSEntry(ip);
			
			DOS_map.put( ip, entry );
			
			res	= false;
			
		}else{
	
			res = last_dos_check - entry.last_time < DOS_MIN_INTERVAL;
			
			if ( res && LOG_DOS_TO_FILE ){
				
				dos_list.add( entry );
			}
			
			entry.last_time = last_dos_check;
		}
		
			// remove dead wood
		
		dos_check_count++;
		
		if ( dos_check_count == DOS_CHECK_DEAD_WOOD_COUNT ){
			
			dos_check_count = 0;
			
			Iterator	it = DOS_map.values().iterator();
			
			while( it.hasNext()){
				
				DOSEntry	this_entry = (DOSEntry)it.next();
				
				if ( last_dos_check - this_entry.last_time > MAX_DOS_RETENTION ){
					
					it.remove();
										
				}else{
					
					break;
				}
			}
			
			if ( dos_list.size() > 0 ){
				
				try{
					class_mon.enter();
					
					if ( dos_log_file == null ){
											
						dos_log_file = new File( System.getProperty("user.dir" ) + File.separator + "dos.log" );
					}
					
					PrintWriter pw = null;
					
					try{
						
						pw = new PrintWriter( new FileWriter( dos_log_file, true ));
						
						for (int i=0;i<dos_list.size();i++){
							
							DOSEntry	this_entry = (DOSEntry)dos_list.get(i);
							
							String ts = new SimpleDateFormat("hh:mm:ss - ").format( new Date(this_entry.last_time ));
						
							pw.println( ts + this_entry.ip );
						}
						
					}catch( Throwable e ){
						
					}finally{
						
						dos_list.clear();
						
						if ( pw != null ){
							
							try{
								
								pw.close();
								
							}catch( Throwable e ){
							}
						}
					}
				}finally{
					
					class_mon.exit();
				}
			}
		}
		
		return( res );
	
protected booleancheckDOSRemove(java.util.Map$Entry eldest)

		boolean res = 	DOS_map.size() > MAX_DOS_ENTRIES || 
						last_dos_check - ((DOSEntry)eldest.getValue()).last_time > 	MAX_DOS_RETENTION;
				
		return( res );
	
public java.lang.StringgetHost()

		return( COConfigurationManager.getStringParameter( "Tracker IP", "" ));
	
public intgetPort()

		return( port );
	
protected booleanhandleExternalRequest(java.net.InetSocketAddress client_address, java.lang.String user, java.lang.String url, java.net.URL absolute_url, java.lang.String header, java.io.InputStream is, java.io.OutputStream os)

		for (int i=0;i<listeners.size();i++){
			
			TRTrackerServerListener	listener;
			
			try{
				this_mon.enter();
				
				if ( i >= listeners.size()){
					
					break;
				}
				
				listener = (TRTrackerServerListener)listeners.elementAt(i);
				
			}finally{
				
				this_mon.exit();
			}
			
			if (listener.handleExternalRequest( client_address, user, url, absolute_url, header, is, os )){
				
				return( true );
			}
		}
		
		return( false );
	
protected booleanisIPFilterEnabled()

		return( apply_ip_filter );
	
public booleanisSSL()

		return( ssl );
	
public voidrunProcessor(TRTrackerServerProcessorTCP processor)

		thread_pool.run( processor );
	
protected voidsetPort(int _port)

		port	= _port;