FileDocCategorySizeDatePackage
TrackerWebContextImpl.javaAPI DocAzureus 3.0.3.44749Wed Sep 12 23:18:04 BST 2007org.gudy.azureus2.pluginsimpl.local.tracker

TrackerWebContextImpl

public class TrackerWebContextImpl extends TrackerWCHelper implements TRTrackerServerListener
author
parg

Fields Summary
protected TRTrackerServer
server
protected List
auth_listeners
Constructors Summary
public TrackerWebContextImpl(TrackerImpl _tracker, String name, int port, int protocol, InetAddress bind_ip)

	
	 
	
			
				
					
					
			 
	
		 
	
		setTracker( _tracker );
				
		try{
			
			if ( protocol == Tracker.PR_HTTP ){
				
				server = TRTrackerServerFactory.create( name, TRTrackerServerFactory.PR_TCP, port, bind_ip, false, false );
				
			}else{
				
				server = TRTrackerServerFactory.createSSL( name, TRTrackerServerFactory.PR_TCP, port, bind_ip, false, false );
			}
			
			server.addListener( this );
			
		}catch( TRTrackerServerException e ){
			
			throw( new TrackerException("TRTrackerServerFactory failed", e ));
		}
	
Methods Summary
public voidaddAuthenticationListener(TrackerAuthenticationListener l)

	
		try{
			this_mon.enter();
		
			auth_listeners.add(l);
			
			if ( auth_listeners.size() == 1 ){
				
				server.addAuthenticationListener( this );
			}
		}finally{
			
			this_mon.exit();
		}
	
public byte[]authenticate(java.net.URL resource, java.lang.String user)

		for (int i=0;i<auth_listeners.size();i++){
			
			try{
				byte[] res = ((TrackerAuthenticationListener)auth_listeners.get(i)).authenticate( resource, user );
				
				if ( res != null ){
					
					return( res );
				}
			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
			}
		}
		
		return( null );
	
public booleanauthenticate(java.net.URL resource, java.lang.String user, java.lang.String password)

		for (int i=0;i<auth_listeners.size();i++){
			
			try{
				boolean res = ((TrackerAuthenticationListener)auth_listeners.get(i)).authenticate( resource, user, password );
				
				if ( res ){
					
					return(true );
				}
			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
			}
		}
		
		return( false );
	
public booleandenied(byte[] hash, boolean explicit)

		return( false );
	
public voiddestroy()

		super.destroy();
		
		auth_listeners.clear();
		
		server.removeAuthenticationListener( this );
		
		server.close();
	
public java.lang.StringgetHostName()

		return( server.getHost());
	
public java.lang.StringgetName()

		return( server.getName());
	
public intgetPort()

		return( server.getPort());
	
public intgetProtocol()

		return( server.isSSL()?Tracker.PR_HTTPS:Tracker.PR_HTTP );
	
public java.net.URL[]getURLs()

		try{
			URL	url = new URL((server.isSSL()?"https":"http") + "://" +	server.getHost() + ":" + server.getPort() + "/" );
				
				// quick fix for badly specified host whereby a valid URL is constructed but the port lost. For example, if#
				// someone has entered http://1.2.3.4 as the host
			
			if ( url.getPort() != server.getPort()){
				
				Debug.out( "Invalid URL '" + url + "' - check tracker configuration" );
				
				url = new URL( "http://i.am.invalid:" + server.getPort() + "/" );
			}
			
			return(	new URL[]{ url });
			
		}catch( MalformedURLException e ){
			
			Debug.printStackTrace( e );
			
			return( null );
		}
	
public booleanpermitted(java.lang.String originator, byte[] hash, boolean explicit)

		return( false );
	
public voidremoveAuthenticationListener(TrackerAuthenticationListener l)

	
		try{
			this_mon.enter();
		
			auth_listeners.remove(l);
			
			if ( auth_listeners.size() == 0 ){
					
				server.removeAuthenticationListener( this );
			}
		}finally{
			
			this_mon.exit();
		}