use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class DHTTrackerPlugin method getTrackerPeerSources.
public TrackerPeerSource[] getTrackerPeerSources(final Torrent torrent) {
TrackerPeerSource vuze_dht = new TrackerPeerSourceAdapter() {
private volatile boolean query_done;
private volatile int status = TrackerPeerSource.ST_INITIALISING;
private volatile int seeds = 0;
private volatile int leechers = 0;
private void fixup() {
if (initialised_sem.isReleasedForever()) {
synchronized (this) {
if (query_done) {
return;
}
query_done = true;
status = TrackerPeerSource.ST_UPDATING;
}
dht.get(torrent.getHash(), "Availability lookup for '" + torrent.getName() + "'", DHTPlugin.FLAG_DOWNLOADING, NUM_WANT, ANNOUNCE_DERIVED_TIMEOUT, false, true, new DHTPluginOperationListener() {
@Override
public void starts(byte[] key) {
}
@Override
public boolean diversified() {
return (true);
}
@Override
public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
if ((value.getFlags() & DHTPlugin.FLAG_DOWNLOADING) == 1) {
seeds++;
} else {
leechers++;
}
}
@Override
public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
}
@Override
public void complete(byte[] key, boolean timeout_occurred) {
status = TrackerPeerSource.ST_ONLINE;
}
});
}
}
@Override
public int getType() {
return (TrackerPeerSource.TP_DHT);
}
@Override
public String getName() {
return (Constants.APP_NAME + " DHT");
}
@Override
public int getStatus() {
fixup();
return (status);
}
@Override
public int getSeedCount() {
fixup();
int result = seeds;
if (result == 0 && status != TrackerPeerSource.ST_ONLINE) {
return (-1);
}
return (result);
}
@Override
public int getLeecherCount() {
fixup();
int result = leechers;
if (result == 0 && status != TrackerPeerSource.ST_ONLINE) {
return (-1);
}
return (result);
}
@Override
public int getPeers() {
return (-1);
}
@Override
public boolean isUpdating() {
return (status == TrackerPeerSource.ST_UPDATING);
}
};
if (alt_lookup_handler != null) {
TrackerPeerSource alt_dht = new TrackerPeerSourceAdapter() {
private volatile int status = TrackerPeerSource.ST_UPDATING;
private volatile int peers = 0;
{
alt_lookup_handler.get(torrent.getHash(), false, new DHTTrackerPluginAlt.LookupListener() {
@Override
public void foundPeer(InetSocketAddress address) {
peers++;
}
@Override
public boolean isComplete() {
return (false);
}
@Override
public void completed() {
status = TrackerPeerSource.ST_ONLINE;
}
});
}
@Override
public int getType() {
return (TrackerPeerSource.TP_DHT);
}
@Override
public String getName() {
return ("Mainline DHT");
}
@Override
public int getStatus() {
return (status);
}
@Override
public int getPeers() {
int result = peers;
if (result == 0 && status != TrackerPeerSource.ST_ONLINE) {
return (-1);
}
return (result);
}
@Override
public boolean isUpdating() {
return (status == TrackerPeerSource.ST_UPDATING);
}
};
return (new TrackerPeerSource[] { vuze_dht, alt_dht });
} else {
return (new TrackerPeerSource[] { vuze_dht });
}
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class TrackerView method updateSelectedContent.
protected void updateSelectedContent() {
if (tv == null) {
return;
}
Object[] dataSources = tv.getSelectedDataSources(true);
if (dataSources.length == 0) {
String id = "DMDetails_Sources";
if (manager != null) {
if (manager.getTorrent() != null) {
id += "." + manager.getInternalName();
} else {
id += ":" + manager.getSize();
}
SelectedContentManager.changeCurrentlySelectedContent(id, new SelectedContent[] { new SelectedContent(manager) });
} else {
SelectedContentManager.changeCurrentlySelectedContent(id, null);
}
} else {
SelectedContent[] sc = new SelectedContent[dataSources.length];
for (int i = 0; i < sc.length; i++) {
Object ds = dataSources[i];
if (ds instanceof TrackerPeerSource) {
sc[i] = new SelectedContent("Source: " + ((TrackerPeerSource) ds).getName());
} else {
sc[i] = new SelectedContent("Source: " + ds);
}
}
SelectedContentManager.changeCurrentlySelectedContent(tv.getTableID(), sc, tv);
}
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class PeersItem method refresh.
@Override
public void refresh(TableCell cell) {
TrackerPeerSource ps = (TrackerPeerSource) cell.getDataSource();
int value = (ps == null) ? -1 : ps.getPeers();
if (!cell.setSortValue(value) && cell.isValid()) {
return;
}
cell.setText(value < 0 ? "" : String.valueOf(value));
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class ReportedDownItem method refresh.
@Override
public void refresh(TableCell cell) {
TrackerPeerSource ps = (TrackerPeerSource) cell.getDataSource();
long[] stats = (ps == null) ? null : ps.getReportedStats();
long sort;
String str;
if (stats != null) {
long gu = stats[1];
long uu = stats[3];
long su = stats[5];
sort = gu != 0 ? gu : (uu != 0 ? uu : su);
if (sort == 0) {
str = "";
} else {
if (uu > 0) {
str = DisplayFormatters.formatByteCountToKiBEtc(uu);
} else {
str = "";
}
if (gu != 0 && gu != uu) {
str = DisplayFormatters.formatByteCountToKiBEtc(gu) + (str.isEmpty() ? "" : ("/" + str));
}
if (su > 0) {
str += " (" + DisplayFormatters.formatByteCountToKiBEtc(su) + ")";
}
}
} else {
sort = -1;
str = "";
}
if (!cell.setSortValue(sort) && cell.isValid()) {
return;
}
cell.setText(str);
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class SeedsItem method refresh.
@Override
public void refresh(TableCell cell) {
TrackerPeerSource ps = (TrackerPeerSource) cell.getDataSource();
int value = (ps == null) ? -1 : ps.getSeedCount();
if (!cell.setSortValue(value) && cell.isValid()) {
return;
}
cell.setText(value < 0 ? "" : String.valueOf(value));
}
Aggregations