FileDocCategorySizeDatePackage
TrackerPeerAuthPlugin.javaAPI DocAzureus 3.0.3.418524Thu May 24 05:26:48 BST 2007com.aelitis.azureus.plugins.tracker.peerauth

TrackerPeerAuthPlugin

public class TrackerPeerAuthPlugin extends Object implements org.gudy.azureus2.plugins.download.DownloadManagerListener, org.gudy.azureus2.plugins.Plugin

Fields Summary
private static final String
PLUGIN_NAME
private static final String
PLUGIN_CONFIGSECTION_ID
private static final int
DEFAULT_CHECK_PERIOD
private static final String
STATE_ENABLED
private static final String
STATE_DISABLED
private static final int
TIMER_PERIOD
private org.gudy.azureus2.plugins.PluginInterface
plugin_interface
private org.gudy.azureus2.plugins.torrent.TorrentAttribute
ta_state
private org.gudy.azureus2.plugins.logging.LoggerChannel
log
private Map
dt_map
private org.gudy.azureus2.core3.util.ThreadPool
thread_pool
Constructors Summary
Methods Summary
public voiddownloadAdded(org.gudy.azureus2.plugins.download.Download download)

		Torrent	torrent = download.getTorrent();
		
		if ( torrent != null && torrent.isPrivate()){
			
			download.addTrackerListener( 
				new DownloadTrackerListener()
				{
					public void 
					scrapeResult(
						DownloadScrapeResult result )
					{
						
					}

					public void 
					announceResult(
						DownloadAnnounceResult result )
					{
						if ( result.getResponseType() == DownloadAnnounceResult.RT_SUCCESS ){
							
							Map	ext = result.getExtensions();
							
							boolean	enabled = true;
							
							int		check_period	= DEFAULT_CHECK_PERIOD;
							
							if ( ext != null ){
								
								// TODO: detect enabled state
								
								// TODO: get check period
							}
							
							download.setAttribute( ta_state, enabled?STATE_ENABLED:STATE_DISABLED );

							setState( download, enabled, check_period );
						}
					}
				});
			
			String state = download.getAttribute( ta_state );
			

			if ( state != null ){
				
				boolean	enabled = state.equals( STATE_ENABLED );
				
				setState( download, enabled, DEFAULT_CHECK_PERIOD );
			}
		}
	
public voiddownloadRemoved(org.gudy.azureus2.plugins.download.Download download)

		synchronized( dt_map ){
		
			dt_map.remove( download );
		}
	
public voidinitialize(org.gudy.azureus2.plugins.PluginInterface _plugin_interface)

	
	 
	
		 	 
	
		plugin_interface = _plugin_interface;
		
		plugin_interface.getPluginProperties().setProperty( "plugin.version", 	"1.0" );
		plugin_interface.getPluginProperties().setProperty( "plugin.name", 		PLUGIN_NAME );

		ta_state 	= plugin_interface.getTorrentManager().getPluginAttribute( "state" );
		
		log = plugin_interface.getLogger().getTimeStampedChannel(PLUGIN_NAME);
		
		UIManager	ui_manager = plugin_interface.getUIManager();
		
		BasicPluginConfigModel	config = ui_manager.createBasicPluginConfigModel( ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID );

		config.addLabelParameter2( "Plugin.trackerpeerauth.info" );		
		
		final BasicPluginViewModel	view_model = 
			plugin_interface.getUIManager().createBasicPluginViewModel( "Plugin.trackerpeerauth.name" );

		view_model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
		view_model.getActivity().setVisible( false );
		view_model.getProgress().setVisible( false );
		
		log.addListener(
				new LoggerChannelListener()
				{
					public void
					messageLogged(
						int		type,
						String	content )
					{
						view_model.getLogArea().appendText( content + "\n" );
					}
					
					public void
					messageLogged(
						String		str,
						Throwable	error )
					{
						if ( str.length() > 0 ){
							view_model.getLogArea().appendText( str + "\n" );
						}
						
						StringWriter sw = new StringWriter();
						
						PrintWriter	pw = new PrintWriter( sw );
						
						error.printStackTrace( pw );
						
						pw.flush();
						
						view_model.getLogArea().appendText( sw.toString() + "\n" );
					}
				});
		
		System.out.println( "**** tracker peer auth disabled ****" );
		
		/*

		plugin_interface.getDownloadManager().addListener( this );
		
		SimpleTimer.addPeriodicEvent(
			"TrackerPeerAuthPlugin:checker",
			TIMER_PERIOD,
			new TimerEventPerformer()
			{
				private long	tick_count = 0;
				
				public void
				perform(
					TimerEvent	event )
				{
					tick_count++;
					
					synchronized( dt_map ){
						
						Iterator	it = dt_map.values().iterator();
						
						while( it.hasNext()){
							
							((DownloadTracker)it.next()).checkPeers( tick_count );
						}
					}
				}
			});
			*/
	
protected voidlog(org.gudy.azureus2.plugins.download.Download download, java.lang.String str)

		log.log( "Download '" + download.getName() + "' - " + str );
	
protected voidsetState(org.gudy.azureus2.plugins.download.Download download, boolean enabled, int check_period)

		synchronized( dt_map ){

			if ( enabled ){
						
				DownloadTracker existing = (DownloadTracker)dt_map.get( download );
			
				if ( existing == null ){
			
					DownloadTracker	dt = new DownloadTracker( download, check_period );
				
					dt_map.put( download, dt );
					
				}else{
					
					existing.setCheckPeriod( check_period );
				}
			}else{
							
				dt_map.remove( download );
			}
		}