FileDocCategorySizeDatePackage
TRTrackerDHTAnnouncerImpl.javaAPI DocAzureus 3.0.3.47661Mon Feb 26 09:01:14 GMT 2007org.gudy.azureus2.core3.tracker.client.impl.dht

TRTrackerDHTAnnouncerImpl

public class TRTrackerDHTAnnouncerImpl extends org.gudy.azureus2.core3.tracker.client.impl.TRTrackerAnnouncerImpl
author
parg

Fields Summary
private org.gudy.azureus2.core3.torrent.TOTorrent
torrent
private org.gudy.azureus2.core3.util.HashWrapper
torrent_hash
private byte[]
data_peer_id
private String
tracker_status_str
private long
last_update_time
private int
state
private org.gudy.azureus2.core3.tracker.client.impl.TRTrackerAnnouncerResponseImpl
last_response
private boolean
manual
Constructors Summary
public TRTrackerDHTAnnouncerImpl(org.gudy.azureus2.core3.torrent.TOTorrent _torrent, String[] _networks, boolean _manual)

	
	
	
				
				
					 
	
		 
	
		super( _torrent );
		
		torrent		= _torrent;
		manual		= _manual;
		
		try{
			torrent_hash	= torrent.getHashWrapper();
			
		}catch( TOTorrentException e ){
			
			Debug.printStackTrace(e);
		}
		try{
			data_peer_id = ClientIDManagerImpl.getSingleton().generatePeerID( torrent, false );
			
		}catch( ClientIDException e ){

			 throw( new TRTrackerAnnouncerException( "TRTrackerAnnouncer: Peer ID generation fails", e ));
		}
		
		last_response = 
			new TRTrackerAnnouncerResponseImpl( 
				torrent.getAnnounceURL(),
				torrent_hash,
				TRTrackerAnnouncerResponse.ST_OFFLINE, 0, "Initialising" );
		
		tracker_status_str = MessageText.getString("PeerManager.status.checking") + "...";
	
Methods Summary
protected voidcheckCache()

		if ( last_response.getStatus() != TRTrackerAnnouncerResponse.ST_ONLINE ){
			
		     TRTrackerAnnouncerResponsePeer[]	cached_peers = getPeersFromCache(100);

		     if ( cached_peers.length > 0 ){
		     	
		     	last_response.setPeers( cached_peers );
		     	
				listeners.dispatch( LDT_TRACKER_RESPONSE, last_response );
		     }
		}
	
public voidclearIPOverride()

	
public voidcloneFrom(org.gudy.azureus2.core3.tracker.client.TRTrackerAnnouncer other)

		data_peer_id	= other.getPeerId();
	
public voidcomplete(boolean already_reported)

		state	= TS_COMPLETED;
	
public voiddestroy()

	
public voidgenerateEvidence(org.gudy.azureus2.core3.util.IndentWriter writer)

		writer.println( "DHT announce: " + (last_response==null?"null":last_response.getString()));
	
public org.gudy.azureus2.core3.tracker.client.TRTrackerAnnouncerResponsegetLastResponse()

		return( last_response );
	
public intgetLastUpdateTime()

		return( (int)(last_update_time/1000));
	
public byte[]getPeerId()

		return( data_peer_id );
	
public intgetPort()

		return(0);
	
public intgetStatus()

		return( state );
	
public java.lang.StringgetStatusString()

		return( tracker_status_str );
	
public intgetTimeUntilNextUpdate()

		long elapsed = (SystemTime.getCurrentTime() - last_update_time)/1000;
		
		return( (int)(last_response.getTimeToWait()-elapsed));
	
public org.gudy.azureus2.core3.torrent.TOTorrentgetTorrent()

		return( torrent );
	
public java.net.URLgetTrackerUrl()

		return( torrent.getAnnounceURL());
	
public booleanisManual()

		return( manual );
	
public voidrefreshListeners()

	
	
public voidresetTrackerUrl(boolean shuffle)

	
public voidsetAnnounceDataProvider(org.gudy.azureus2.core3.tracker.client.TRTrackerAnnouncerDataProvider provider)

		
	
public voidsetAnnounceResult(org.gudy.azureus2.plugins.download.DownloadAnnounceResult result)

		last_update_time	= SystemTime.getCurrentTime();
		
		TRTrackerAnnouncerResponseImpl response;
		
		if ( result.getResponseType() == DownloadAnnounceResult.RT_ERROR ){
			
			tracker_status_str = MessageText.getString("PeerManager.status.error"); 
		      
			String	reason = result.getError();
	
			if ( reason != null ){
		
				tracker_status_str += " (" + reason + ")";		
			}
			
	  		response = new TRTrackerAnnouncerResponseImpl(
				  				result.getURL(),
				  				torrent_hash,
				  				TRTrackerAnnouncerResponse.ST_OFFLINE, 
								result.getTimeToWait(), 
								reason );
		}else{
			DownloadAnnounceResultPeer[]	ext_peers = result.getPeers();
			
			TRTrackerAnnouncerResponsePeerImpl[] peers = new TRTrackerAnnouncerResponsePeerImpl[ext_peers.length];
				
			for (int i=0;i<ext_peers.length;i++){
				
				DownloadAnnounceResultPeer	ext_peer	= ext_peers[i];
				
				if (Logger.isEnabled())
					Logger.log(new LogEvent(torrent, LOGID, "EXTERNAL PEER DHT: ip="
							+ ext_peer.getAddress() + ",port=" + ext_peer.getPort() +",prot=" + ext_peer.getProtocol()));

				int		http_port	= 0;
				byte	az_version 	= TRTrackerAnnouncer.AZ_TRACKER_VERSION_1;
				
				peers[i] = new TRTrackerAnnouncerResponsePeerImpl( 
									ext_peer.getSource(),
									ext_peer.getPeerID(),
									ext_peer.getAddress(), 
									ext_peer.getPort(),
									ext_peer.getUDPPort(),
									http_port,
									ext_peer.getProtocol(),
									az_version,
									(short)0 );
			}
			
			addToTrackerCache( peers);
		
			tracker_status_str = MessageText.getString("PeerManager.status.ok");

			response = new TRTrackerAnnouncerResponseImpl( result.getURL(), torrent_hash, TRTrackerAnnouncerResponse.ST_ONLINE, result.getTimeToWait(), peers );
		}
		
		last_response = response;
				
		listeners.dispatch( LDT_TRACKER_RESPONSE, response );
	
public voidsetIPOverride(java.lang.String override)

	
public voidsetRefreshDelayOverrides(int percentage)

	
public voidsetTrackerUrl(java.net.URL url)

		Debug.out( "setTrackerURL not supported for DHT" );
	
public voidstop(boolean for_queue)

		state	= TS_STOPPED;
	
public voidupdate(boolean force)

		state = TS_DOWNLOADING;
		
		checkCache();