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();
TRTrackerAnnouncerResponsePeerImpl[] peers = new TRTrackerAnnouncerResponsePeerImpl[ext_peers.length];
for (int i=0;i<ext_peers.length;i++){
DownloadAnnounceResultPeer ext_peer = ext_peers[i];
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[i] = 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 );
}
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<TRTrackerAnnouncerResponsePeer>(
new Comparator<TRTrackerAnnouncerResponsePeer>()
{
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 );
}