use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class BadAvailTimeItem method refresh.
@Override
public void refresh(TableCell cell, long timestamp) {
DownloadManager dm = (DownloadManager) cell.getDataSource();
long value = dm == null ? -1 : dm.getStats().getAvailWentBadTime();
int seeds = 0;
if (value == 0) {
// zero means no recorded last bad availability time (bad=transition from >=1 -> < 1)
PEPeerManager pm = dm.getPeerManager();
if (pm == null || pm.getMinAvailability() < 1.0) {
long stopped = dm.getDownloadState().getLongAttribute(DownloadManagerState.AT_TIME_STOPPED);
if (stopped > 0) {
value = stopped;
} else {
value = -1;
}
} else {
seeds = pm.getNbSeeds();
value = -2;
}
}
if (value > 0) {
super.refresh(cell, value);
} else {
String text;
if (value == -2) {
if (dm.isDownloadComplete(false)) {
text = now_string;
value = Long.MAX_VALUE;
} else {
text = now_string + " " + seeds;
value = Long.MAX_VALUE - 1000000 + seeds;
}
} else {
text = "";
}
if (!cell.setSortValue(value) && cell.isValid()) {
return;
}
cell.setText(text);
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class DownloadNameItem method refresh.
/* (non-Javadoc)
* @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
*/
@Override
public void refresh(TableCell cell) {
PEPeer peer = (PEPeer) cell.getDataSource();
if (peer == null) {
cell.setText("");
return;
}
PEPeerManager manager = peer.getManager();
if (manager == null) {
cell.setText("");
return;
}
cell.setText(manager.getDisplayName());
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method getTrackerPeerSources.
@Override
public List<TrackerPeerSource> getTrackerPeerSources() {
try {
this_mon.enter();
Object[] tps_data = (Object[]) getUserData(TPS_Key);
List<TrackerPeerSource> tps;
if (tps_data == null) {
tps = new ArrayList<>();
TOTorrentListener tol = new TOTorrentListener() {
@Override
public void torrentChanged(TOTorrent torrent, int type) {
if (type == TOTorrentListener.CT_ANNOUNCE_URLS) {
List<DownloadManagerTPSListener> to_inform = null;
try {
this_mon.enter();
torrent.removeListener(this);
setUserData(TPS_Key, null);
if (tps_listeners != null) {
to_inform = new ArrayList<>(tps_listeners);
}
} finally {
this_mon.exit();
}
if (to_inform != null) {
for (DownloadManagerTPSListener l : to_inform) {
try {
l.trackerPeerSourcesChanged();
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
}
};
setUserData(TPS_Key, new Object[] { tps, tol });
Download plugin_download = PluginCoreUtils.wrap(this);
if (isDestroyed() || plugin_download == null) {
return (tps);
}
// tracker peer sources
final TOTorrent t = getTorrent();
if (t != null) {
t.addListener(tol);
TOTorrentAnnounceURLSet[] sets = t.getAnnounceURLGroup().getAnnounceURLSets();
if (sets.length == 0) {
sets = new TOTorrentAnnounceURLSet[] { t.getAnnounceURLGroup().createAnnounceURLSet(new URL[] { torrent.getAnnounceURL() }) };
}
for (final TOTorrentAnnounceURLSet set : sets) {
final URL[] urls = set.getAnnounceURLs();
if (urls.length == 0 || TorrentUtils.isDecentralised(urls[0])) {
continue;
}
tps.add(new TrackerPeerSource() {
private TrackerPeerSource _delegate;
private TRTrackerAnnouncer ta;
private long ta_fixup;
private long last_scrape_fixup_time;
private Object[] 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 Object[] getScrape() {
long now = SystemTime.getMonotonousTime();
if (now - last_scrape_fixup_time > 30 * 1000 || last_scrape == null) {
TRTrackerScraper scraper = globalManager.getTrackerScraper();
int max_peers = -1;
int max_seeds = -1;
int max_comp = -1;
int max_time = 0;
int min_scrape = Integer.MAX_VALUE;
String status_str = null;
boolean found_usable = false;
for (URL u : urls) {
TRTrackerScraperResponse resp = scraper.peekScrape(torrent, u);
if (resp != null) {
if (!resp.isDHTBackup()) {
found_usable = true;
int peers = resp.getPeers();
int seeds = resp.getSeeds();
int comp = resp.getCompleted();
if (peers > max_peers) {
max_peers = peers;
}
if (seeds > max_seeds) {
max_seeds = seeds;
}
if (comp > max_comp) {
max_comp = comp;
}
if (resp.getStatus() != TRTrackerScraperResponse.ST_INITIALIZING) {
status_str = resp.getStatusString();
int time = resp.getScrapeTime();
if (time > max_time) {
max_time = time;
}
long next_scrape = resp.getNextScrapeStartTime();
if (next_scrape > 0) {
int ns = (int) (next_scrape / 1000);
if (ns < min_scrape) {
min_scrape = ns;
}
}
}
}
}
}
if (found_usable || last_scrape == null) {
last_scrape = new Object[] { max_seeds, max_peers, max_time, min_scrape, max_comp, status_str };
}
last_scrape_fixup_time = now;
}
return (last_scrape);
}
@Override
public int getType() {
return (TrackerPeerSource.TP_TRACKER);
}
@Override
public String getName() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (urls[0].toExternalForm());
}
return (delegate.getName());
}
@Override
public int getStatus() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (ST_STOPPED);
}
return (delegate.getStatus());
}
@Override
public String getStatusString() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return ((String) getScrape()[5]);
}
return (delegate.getStatusString());
}
@Override
public int getSeedCount() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return ((Integer) getScrape()[0]);
}
int seeds = delegate.getSeedCount();
if (seeds < 0) {
seeds = (Integer) getScrape()[0];
}
return (seeds);
}
@Override
public int getLeecherCount() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return ((Integer) getScrape()[1]);
}
int leechers = delegate.getLeecherCount();
if (leechers < 0) {
leechers = (Integer) getScrape()[1];
}
return (leechers);
}
@Override
public int getCompletedCount() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return ((Integer) getScrape()[4]);
}
int comp = delegate.getCompletedCount();
if (comp < 0) {
comp = (Integer) getScrape()[4];
}
return (comp);
}
@Override
public int getPeers() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (-1);
}
return (delegate.getPeers());
}
@Override
public int getInterval() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
Object[] si = getScrape();
int last = (Integer) si[2];
int next = (Integer) si[3];
if (last > 0 && next < Integer.MAX_VALUE && last < next) {
return (next - last);
}
return (-1);
}
return (delegate.getInterval());
}
@Override
public int getMinInterval() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (-1);
}
return (delegate.getMinInterval());
}
@Override
public boolean isUpdating() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (false);
}
return (delegate.isUpdating());
}
@Override
public int getLastUpdate() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return ((Integer) getScrape()[2]);
}
return (delegate.getLastUpdate());
}
@Override
public int getSecondsToUpdate() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (-1);
}
return (delegate.getSecondsToUpdate());
}
@Override
public boolean canManuallyUpdate() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (false);
}
return (delegate.canManuallyUpdate());
}
@Override
public void manualUpdate() {
TrackerPeerSource delegate = fixup();
if (delegate != null) {
delegate.manualUpdate();
}
}
@Override
public boolean canDelete() {
return (true);
}
@Override
public void delete() {
List<List<String>> lists = TorrentUtils.announceGroupsToList(t);
List<String> rem = new ArrayList<>();
for (URL u : urls) {
rem.add(u.toExternalForm());
}
lists = TorrentUtils.removeAnnounceURLs2(lists, rem, false);
TorrentUtils.listToAnnounceGroups(lists, t);
}
});
}
// 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);
}
@Override
public int getType() {
return (TrackerPeerSource.TP_TRACKER);
}
@Override
public String getName() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (MessageText.getString("tps.tracker.cache"));
}
return (delegate.getName());
}
@Override
public int getStatus() {
TrackerPeerSource delegate = fixup();
if (!enabled) {
return (ST_DISABLED);
}
if (delegate == null) {
return (ST_STOPPED);
}
return (ST_ONLINE);
}
@Override
public int getPeers() {
TrackerPeerSource delegate = fixup();
if (delegate == null || !enabled) {
return (-1);
}
return (delegate.getPeers());
}
});
}
try {
ExternalSeedPlugin esp = DownloadManagerController.getExternalSeedPlugin();
if (esp != null) {
tps.add(esp.getTrackerPeerSource(plugin_download));
}
} catch (Throwable e) {
}
try {
PluginInterface dht_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(DHTTrackerPlugin.class);
if (dht_pi != null) {
tps.add(((DHTTrackerPlugin) dht_pi.getPlugin()).getTrackerPeerSource(plugin_download));
}
} catch (Throwable e) {
}
try {
PluginInterface lt_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(LocalTrackerPlugin.class);
if (lt_pi != null) {
tps.add(((LocalTrackerPlugin) lt_pi.getPlugin()).getTrackerPeerSource(plugin_download));
}
} catch (Throwable e) {
}
try {
tps.add(((DownloadImpl) plugin_download).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);
}
@Override
public int getType() {
return (TP_PEX);
}
@Override
public int getStatus() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (ST_STOPPED);
} else {
return (delegate.getStatus());
}
}
@Override
public String getName() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return ("");
} else {
return (delegate.getName());
}
}
@Override
public int getPeers() {
TrackerPeerSource delegate = fixup();
if (delegate == null) {
return (-1);
} else {
return (delegate.getPeers());
}
}
});
// incoming
tps.add(new TrackerPeerSourceAdapter() {
private long fixup_time;
private PEPeerManager _pm;
private int tcp;
private int udp;
private int utp;
private int total;
private boolean enabled;
private PEPeerManager fixup() {
long now = SystemTime.getMonotonousTime();
if (now - fixup_time > 1000) {
PEPeerManager pm = _pm = getPeerManager();
if (pm != null) {
tcp = pm.getNbRemoteTCPConnections();
udp = pm.getNbRemoteUDPConnections();
utp = pm.getNbRemoteUTPConnections();
total = pm.getStats().getTotalIncomingConnections();
}
enabled = controller.isPeerSourceEnabled(PEPeerSource.PS_INCOMING);
fixup_time = now;
}
return (_pm);
}
@Override
public int getType() {
return (TP_INCOMING);
}
@Override
public int getStatus() {
PEPeerManager delegate = fixup();
if (delegate == null) {
return (ST_STOPPED);
} else if (!enabled) {
return (ST_DISABLED);
} else {
return (ST_ONLINE);
}
}
@Override
public String getName() {
PEPeerManager delegate = fixup();
if (delegate == null || !enabled) {
return ("");
} else {
return (MessageText.getString("tps.incoming.details", new String[] { String.valueOf(tcp), String.valueOf(udp + utp), String.valueOf(total) }));
}
}
@Override
public int getPeers() {
PEPeerManager delegate = fixup();
if (delegate == null || !enabled) {
return (-1);
} else {
return (tcp + udp);
}
}
});
} else {
tps = (List<TrackerPeerSource>) tps_data[0];
}
return (tps);
} finally {
this_mon.exit();
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method generateEvidence.
@Override
public void generateEvidence(IndentWriter writer) {
writer.println(toString());
PEPeerManager pm = getPeerManager();
try {
writer.indent();
writer.println("Save Dir: " + Debug.secretFileName(getSaveLocation().toString()));
if (current_peers.size() > 0) {
writer.println("# Peers: " + current_peers.size());
}
if (current_pieces.size() > 0) {
writer.println("# Pieces: " + current_pieces.size());
}
writer.println("Listeners: DownloadManager=" + listeners.size() + "; Disk=" + controller.getDiskListenerCount() + "; Peer=" + peer_listeners.size() + "; Tracker=" + tracker_listeners.size());
writer.println("SR: " + iSeedingRank);
String sFlags = "";
if (open_for_seeding) {
sFlags += "Opened for Seeding; ";
}
if (data_already_allocated) {
sFlags += "Data Already Allocated; ";
}
if (assumedComplete) {
sFlags += "onlySeeding; ";
}
if (persistent) {
sFlags += "persistent; ";
}
if (sFlags.length() > 0) {
writer.println("Flags: " + sFlags);
}
stats.generateEvidence(writer);
download_manager_state.generateEvidence(writer);
if (pm != null) {
pm.generateEvidence(writer);
}
// note, PeerManager generates DiskManager evidence
controller.generateEvidence(writer);
TRTrackerAnnouncer announcer = tracker_client;
if (announcer != null) {
announcer.generateEvidence(writer);
}
TRTrackerScraperResponse scrape = getTrackerScrapeResponse();
if (scrape == null) {
writer.println("Scrape: null");
} else {
writer.println("Scrape: " + scrape.getString());
}
} finally {
writer.exdent();
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method getHealthStatus.
@Override
public int getHealthStatus() {
int state = getState();
PEPeerManager peerManager = controller.getPeerManager();
TRTrackerAnnouncer tc = getTrackerClient();
if (tc != null && peerManager != null && (state == STATE_DOWNLOADING || state == STATE_SEEDING)) {
int nbSeeds = getNbSeeds();
int nbPeers = getNbPeers();
int nbRemotes = peerManager.getNbRemoteTCPConnections() + peerManager.getNbRemoteUTPConnections();
TRTrackerAnnouncerResponse announce_response = tc.getLastResponse();
int trackerStatus = announce_response.getStatus();
boolean isSeed = (state == STATE_SEEDING);
if ((nbSeeds + nbPeers) == 0) {
if (isSeed) {
// not connected to any peer and seeding
return WEALTH_NO_TRACKER;
}
// not connected to any peer and downloading
return WEALTH_KO;
}
if (!isSeed) {
if (trackerStatus == TRTrackerAnnouncerResponse.ST_OFFLINE || trackerStatus == TRTrackerAnnouncerResponse.ST_REPORTED_ERROR) {
return WEALTH_NO_TRACKER;
}
}
if (nbRemotes == 0) {
TRTrackerScraperResponse scrape_response = getTrackerScrapeResponse();
if (scrape_response != null && scrape_response.isValid()) {
if (nbSeeds == scrape_response.getSeeds() && nbPeers == scrape_response.getPeers()) {
return WEALTH_OK;
}
}
return WEALTH_NO_REMOTE;
}
return WEALTH_OK;
} else if (state == STATE_ERROR) {
return WEALTH_ERROR;
} else {
return WEALTH_STOPPED;
}
}
Aggregations