use of com.biglybt.pif.download.DownloadAnnounceResultPeer in project BiglyBT by BiglySoftware.
the class TRTrackerDHTAnnouncerImpl method setAnnounceResult.
@Override
public void setAnnounceResult(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();
List<TRTrackerAnnouncerResponsePeerImpl> peers_list = new ArrayList<>(ext_peers.length);
for (int i = 0; i < ext_peers.length; i++) {
DownloadAnnounceResultPeer ext_peer = ext_peers[i];
if (ext_peer == null) {
continue;
}
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_list.add(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));
}
TRTrackerAnnouncerResponsePeerImpl[] peers = peers_list.toArray(new TRTrackerAnnouncerResponsePeerImpl[peers_list.size()]);
helper.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;
TRTrackerAnnouncerResponsePeer[] peers = response.getPeers();
if (peers == null || peers.length < 5) {
TRTrackerAnnouncerResponsePeer[] cached_peers = helper.getPeersFromCache(100);
if (cached_peers.length > 0) {
Set<TRTrackerAnnouncerResponsePeer> new_peers = new TreeSet<>(new Comparator<TRTrackerAnnouncerResponsePeer>() {
@Override
public int compare(TRTrackerAnnouncerResponsePeer o1, TRTrackerAnnouncerResponsePeer o2) {
return (o1.compareTo(o2));
}
});
if (peers != null) {
new_peers.addAll(Arrays.asList(peers));
}
new_peers.addAll(Arrays.asList(cached_peers));
response.setPeers(new_peers.toArray(new TRTrackerAnnouncerResponsePeer[new_peers.size()]));
}
}
helper.informResponse(this, response);
}
use of com.biglybt.pif.download.DownloadAnnounceResultPeer in project BiglyBT by BiglySoftware.
the class TRTrackerBTAnnouncerImpl method setAnnounceResult.
@Override
public void setAnnounceResult(DownloadAnnounceResult result) {
// this is how the results from "external" announces get into the system
// really should refactor so that "normal" and "external" mechanisms are
// just instances of the same generic approach
TRTrackerAnnouncerResponseImpl response;
String status;
if (result.getResponseType() == DownloadAnnounceResult.RT_ERROR) {
status = MessageText.getString("PeerManager.status.error");
String reason = result.getError();
if (reason != null) {
status += " (" + reason + ")";
}
response = new TRTrackerAnnouncerResponseImpl(result.getURL(), torrent_hash, TRTrackerAnnouncerResponse.ST_OFFLINE, result.getTimeToWait(), reason);
} else {
DownloadAnnounceResultPeer[] ext_peers = result.getPeers();
List l_peers = new ArrayList(ext_peers.length);
boolean ps_enabled = announce_data_provider != null && announce_data_provider.isPeerSourceEnabled(PEPeerSource.PS_BT_TRACKER);
for (int i = 0; i < ext_peers.length; i++) {
DownloadAnnounceResultPeer ext_peer = ext_peers[i];
String ps = ext_peer.getSource();
if (!ps_enabled && ps.equals(PEPeerSource.PS_BT_TRACKER)) {
continue;
} else {
int http_port = 0;
byte az_version = TRTrackerAnnouncer.AZ_TRACKER_VERSION_1;
TRTrackerAnnouncerResponsePeerImpl p = 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);
l_peers.add(p);
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, "EXTERNAL PEER: " + p.getString()));
}
}
TRTrackerAnnouncerResponsePeerImpl[] peers = new TRTrackerAnnouncerResponsePeerImpl[l_peers.size()];
l_peers.toArray(peers);
helper.addToTrackerCache(peers);
if (ps_enabled || peers.length > 0 || ext_peers.length == 0) {
status = MessageText.getString("PeerManager.status.ok");
} else {
status = MessageText.getString("PeerManager.status.ps_disabled");
peers = new TRTrackerAnnouncerResponsePeerImpl[0];
}
response = new TRTrackerAnnouncerResponseImpl(result.getURL(), torrent_hash, TRTrackerAnnouncerResponse.ST_ONLINE, result.getTimeToWait(), peers);
}
if (last_response == null || last_response.getStatus() != TRTrackerAnnouncerResponse.ST_ONLINE) {
URL result_url = result.getURL();
boolean update_is_dht = TorrentUtils.isDecentralised(result_url);
tracker_status_str = status + " (" + (update_is_dht ? MessageText.getString("dht.backup.only") : (result_url == null ? "<null>" : result_url.getHost())) + ")";
}
helper.informResponse(this, response);
}
Aggregations