Search in sources :

Example 1 with TRTrackerAnnouncerResponsePeerImpl

use of com.biglybt.core.tracker.client.impl.TRTrackerAnnouncerResponsePeerImpl 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);
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) TRTrackerAnnouncerResponsePeerImpl(com.biglybt.core.tracker.client.impl.TRTrackerAnnouncerResponsePeerImpl) DownloadAnnounceResultPeer(com.biglybt.pif.download.DownloadAnnounceResultPeer) TRTrackerAnnouncerResponseImpl(com.biglybt.core.tracker.client.impl.TRTrackerAnnouncerResponseImpl)

Aggregations

LogEvent (com.biglybt.core.logging.LogEvent)1 TRTrackerAnnouncerResponseImpl (com.biglybt.core.tracker.client.impl.TRTrackerAnnouncerResponseImpl)1 TRTrackerAnnouncerResponsePeerImpl (com.biglybt.core.tracker.client.impl.TRTrackerAnnouncerResponsePeerImpl)1 DownloadAnnounceResultPeer (com.biglybt.pif.download.DownloadAnnounceResultPeer)1