if (Logger.isEnabled()){
Logger.log(new LogEvent(torrent, LOGID,
"Tracker Announcer is Requesting: " + reqUrl));
}
ByteArrayOutputStream message = new ByteArrayOutputStream();
URL udpAnnounceURL = null;
boolean udp_probe = false;
// if we have multiple tracker URLs then do something sensible about
if ( protocol.equalsIgnoreCase("udp")){
if ( udpAnnounceEnabled ){
udpAnnounceURL = reqUrl;
}else{
throw( new IOException( "UDP Tracker protocol disabled" ));
}
}else if ( protocol.equalsIgnoreCase("http") &&
!az_tracker &&
announceCount % autoUDPprobeEvery == 0 &&
udpAnnounceEnabled ){
// if we don't know this tracker supports UDP then don't probe on
// first announce as we don't want a large delay on torrent startup
// also if we are stopping we don't want to initiate a probe as
// we want the stop instruction to get to tracker if possible
if ( ( stopped ||
announceCount == 0 ||
( announceCount < trackerUrlLists.size() && announceFailCount == announceCount )) &&
!TRTrackerUtils.isUDPProbeOK(reqUrl)){
// skip probe
}else{
udpAnnounceURL = new URL(reqUrl.toString().replaceFirst("^http", "udp"));
udp_probe = true;
}
}
if ( udpAnnounceURL != null ){
failure_reason = announceUDP( reqUrl, message, udp_probe );
if ((failure_reason != null || message.size() == 0) && udp_probe){
// automatic UDP probe failed, use HTTP again
udpAnnounceURL = null;
if ( autoUDPprobeEvery < 16 ){
autoUDPprobeEvery <<= 1;
}else{
// unregister in case the tracker somehow changed its capabilities
TRTrackerUtils.setUDPProbeResult(reqUrl, false);
}
if (Logger.isEnabled()){
Logger.log(new LogEvent(torrent, LOGID, LogEvent.LT_INFORMATION, "redirection of http announce [" + tracker_url[0] + "] to udp failed, will retry in " + autoUDPprobeEvery + " announces"));
}
}else if (failure_reason == null && udp_probe){
TRTrackerUtils.setUDPProbeResult(reqUrl, true);
if (Logger.isEnabled()){
Logger.log(new LogEvent(torrent, LOGID, LogEvent.LT_INFORMATION, "redirection of http announce [" + tracker_url[0] + "] to udp successful"));
}
autoUDPprobeEvery = 1;
}
}
announceCount++;
if ( udpAnnounceURL == null){
failure_reason = announceHTTP( tracker_url, reqUrl, message );
}
// if we've got some kind of response then return it
if ( message.size() > 0 ){
return( message.toByteArray());
}
if ( failure_reason == null ){
failure_reason = "No data received from tracker";