continue;
}
tps.add(
new TrackerPeerSource()
{
private TrackerPeerSource _delegate;
private TRTrackerAnnouncer ta;
private long ta_fixup;
private long last_scrape_time;
private int[] last_scrape;
private TrackerPeerSource
fixup()
{
long now = SystemTime.getMonotonousTime();
if ( now - ta_fixup > 1000 ){
TRTrackerAnnouncer current_ta = getTrackerClient();
if ( current_ta == ta ){
if ( current_ta != null && _delegate == null ){
_delegate = current_ta.getTrackerPeerSource( set );
}
}else{
if ( current_ta == null ){
_delegate = null;
}else{
_delegate = current_ta.getTrackerPeerSource( set );
}
ta = current_ta;
}
ta_fixup = now;
}
return( _delegate );
}
protected int[]
getScrape()
{
long now = SystemTime.getMonotonousTime();
if ( now - last_scrape_time > 30*1000 || last_scrape == null ){
TRTrackerScraper scraper = globalManager.getTrackerScraper();
int max_peers = -1;
int max_seeds = -1;
for ( URL u: urls ){
TRTrackerScraperResponse resp = scraper.peekScrape(torrent, u );
if ( resp != null ){
if ( !resp.isDHTBackup()){
int peers = resp.getPeers();
int seeds = resp.getSeeds();
if ( peers > max_peers ){
max_peers = peers;
}
if ( seeds > max_seeds ){
max_seeds = seeds;
}
}
}
}
last_scrape = new int[]{ max_seeds, max_peers };
last_scrape_time = now;
}
return( last_scrape );
}
public int
getType()
{
return( TrackerPeerSource.TP_TRACKER );
}
public String
getName()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( urls[0].toExternalForm());
}
return( delegate.getName());
}
public int
getStatus()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( ST_STOPPED );
}
return( delegate.getStatus());
}
public String
getStatusString()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( null );
}
return( delegate.getStatusString());
}
public int
getSeedCount()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( getScrape()[0] );
}
int seeds = delegate.getSeedCount();
if ( seeds < 0 ){
seeds = getScrape()[0];
}
return( seeds );
}
public int
getLeecherCount()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( getScrape()[1] );
}
int leechers = delegate.getLeecherCount();
if ( leechers < 0 ){
leechers = getScrape()[1];
}
return( leechers );
}
public int
getPeers()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( -1 );
}
return( delegate.getPeers());
}
public int
getInterval()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( -1 );
}
return( delegate.getInterval());
}
public int
getMinInterval()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( -1 );
}
return( delegate.getMinInterval());
}
public boolean
isUpdating()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( false );
}
return( delegate.isUpdating());
}
public int
getSecondsToUpdate()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( -1 );
}
return( delegate.getSecondsToUpdate());
}
public boolean
canManuallyUpdate()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( false );
}
return( delegate.canManuallyUpdate());
}
public void
manualUpdate()
{
TrackerPeerSource delegate = fixup();
if ( delegate != null ){
delegate.manualUpdate();
}
}
});
}
// cache peer source
tps.add(
new TrackerPeerSourceAdapter()
{
private TrackerPeerSource _delegate;
private TRTrackerAnnouncer ta;
private boolean enabled;
private long ta_fixup;
private TrackerPeerSource
fixup()
{
long now = SystemTime.getMonotonousTime();
if ( now - ta_fixup > 1000 ){
TRTrackerAnnouncer current_ta = getTrackerClient();
if ( current_ta == ta ){
if ( current_ta != null && _delegate == null ){
_delegate = current_ta.getCacheTrackerPeerSource();
}
}else{
if ( current_ta == null ){
_delegate = null;
}else{
_delegate = current_ta.getCacheTrackerPeerSource();
}
ta = current_ta;
}
enabled = controller.isPeerSourceEnabled( PEPeerSource.PS_BT_TRACKER );
ta_fixup = now;
}
return( _delegate );
}
public int
getType()
{
return( TrackerPeerSource.TP_TRACKER );
}
public String
getName()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( MessageText.getString( "tps.tracker.cache" ));
}
return( delegate.getName());
}
public int
getStatus()
{
TrackerPeerSource delegate = fixup();
if ( !enabled ){
return( ST_DISABLED );
}
if ( delegate == null ){
return( ST_STOPPED );
}
return( ST_ONLINE );
}
public int
getPeers()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null || !enabled ){
return( -1 );
}
return( delegate.getPeers());
}
});
}
// http seeds
try{
ExternalSeedPlugin esp = DownloadManagerController.getExternalSeedPlugin();
if ( esp != null ){
tps.add( esp.getTrackerPeerSource( PluginCoreUtils.wrap( this ) ));
}
}catch( Throwable e ){
}
// dht
try{
PluginInterface dht_pi = AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(DHTTrackerPlugin.class);
if ( dht_pi != null ){
tps.add(((DHTTrackerPlugin)dht_pi.getPlugin()).getTrackerPeerSource( PluginCoreUtils.wrap( this )));
}
}catch( Throwable e ){
}
// LAN
try{
PluginInterface lt_pi = AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(LocalTrackerPlugin.class);
if ( lt_pi != null ){
tps.add(((LocalTrackerPlugin)lt_pi.getPlugin()).getTrackerPeerSource( PluginCoreUtils.wrap( this )));
}
}catch( Throwable e ){
}
// Plugin
try{
tps.add(((DownloadImpl)PluginCoreUtils.wrap( this )).getTrackerPeerSource());
}catch( Throwable e ){
}
// PEX...
tps.add(
new TrackerPeerSourceAdapter()
{
private PEPeerManager _pm;
private TrackerPeerSource _delegate;
private TrackerPeerSource
fixup()
{
PEPeerManager pm = getPeerManager();
if ( pm == null ){
_delegate = null;
_pm = null;
}else if ( pm != _pm ){
_pm = pm;
_delegate = pm.getTrackerPeerSource();
}
return( _delegate );
}
public int
getType()
{
return( TP_PEX );
}
public int
getStatus()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( ST_STOPPED );
}else{
return( delegate.getStatus());
}
}
public String
getName()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( "" );
}else{
return( delegate.getName());
}
}
public int
getPeers()
{
TrackerPeerSource delegate = fixup();
if ( delegate == null ){
return( -1 );
}else{
return( delegate.getPeers());
}
}
});
// incoming