1092
1100
boolean udp_probe = false;
1094
if (protocol.equalsIgnoreCase("udp") && udpAnnounceEnabled)
1102
// if we have multiple tracker URLs then do something sensible about
1104
if ( protocol.equalsIgnoreCase("udp") && udpAnnounceEnabled ){
1096
1106
udpAnnounceURL = reqUrl;
1097
} else if (protocol.equalsIgnoreCase("http") && !az_tracker
1098
&& announceCount % autoUDPprobeEvery == 0 && udpAnnounceEnabled)
1100
// if we don't know this tracker supports UDP then don't probe on
1101
// first announce as we don't want a large delay on torrent startup
1102
// also if we are stopping we don't want to initiate a probe as
1103
// we want the stop instruction to get to tracker if possible
1104
if ((stopped || announceCount == 0) && !TRTrackerUtils.isUDPProbeOK(reqUrl))
1108
}else if ( protocol.equalsIgnoreCase("http") &&
1110
announceCount % autoUDPprobeEvery == 0 &&
1111
udpAnnounceEnabled ){
1113
// if we don't know this tracker supports UDP then don't probe on
1114
// first announce as we don't want a large delay on torrent startup
1115
// also if we are stopping we don't want to initiate a probe as
1116
// we want the stop instruction to get to tracker if possible
1119
announceCount == 0 ||
1120
( announceCount < trackerUrlLists.size() && announceFailCount == announceCount )) &&
1121
!TRTrackerUtils.isUDPProbeOK(reqUrl)){
1109
1126
udpAnnounceURL = new URL(reqUrl.toString().replaceFirst("^http", "udp"));
1110
1128
udp_probe = true;
1114
if (udpAnnounceURL != null)
1116
failure_reason = announceUDP(reqUrl, message, !udp_probe);
1117
if ((failure_reason != null || message.size() == 0) && udp_probe)
1119
// automatic UDP probe failed, use HTTP again
1132
if ( udpAnnounceURL != null ){
1134
failure_reason = announceUDP( reqUrl, message, udp_probe );
1136
if ((failure_reason != null || message.size() == 0) && udp_probe){
1138
// automatic UDP probe failed, use HTTP again
1120
1140
udpAnnounceURL = null;
1121
if (autoUDPprobeEvery < 16)
1142
if ( autoUDPprobeEvery < 16 ){
1122
1144
autoUDPprobeEvery <<= 1;
1123
else // unregister in case the tracker somehow changed its capabilities
1147
// unregister in case the tracker somehow changed its capabilities
1124
1149
TRTrackerUtils.setUDPProbeResult(reqUrl, false);
1125
if (Logger.isEnabled())
1152
if (Logger.isEnabled()){
1126
1153
Logger.log(new LogEvent(torrent, LOGID, LogEvent.LT_INFORMATION, "redirection of http announce [" + tracker_url[0] + "] to udp failed, will retry in " + autoUDPprobeEvery + " announces"));
1155
}else if (failure_reason == null && udp_probe){
1128
} else if (failure_reason == null && udp_probe)
1130
1157
TRTrackerUtils.setUDPProbeResult(reqUrl, true);
1131
if (Logger.isEnabled())
1159
if (Logger.isEnabled()){
1132
1160
Logger.log(new LogEvent(torrent, LOGID, LogEvent.LT_INFORMATION, "redirection of http announce [" + tracker_url[0] + "] to udp successful"));
1133
1163
autoUDPprobeEvery = 1;
1137
1167
announceCount++;
1139
if ( udpAnnounceURL == null)
1169
if ( udpAnnounceURL == null){
1140
1171
failure_reason = announceHTTP( tracker_url, reqUrl, message );
1142
// if we've got some kind of response then return it
1143
if ( message.size() > 0 )
1174
// if we've got some kind of response then return it
1176
if ( message.size() > 0 ){
1144
1178
return( message.toByteArray());
1147
1181
if ( failure_reason == null ){
1148
1183
failure_reason = "No data received from tracker";
1152
1185
}catch( SSLException e ){
1154
1187
// e.printStackTrace();
2903
2938
throw( new IOException( "peers missing from response" ));
2905
2940
}else if (!metaData.containsKey("peers6")){
2906
// we got nothing useful under peers and no peers6 either
2942
// we got nothing useful under peers and no peers6 either
2907
2944
throw( new IOException( "peers missing from response" ));
2911
2948
final byte[] v6peers = (byte[])metaData.get("peers6");
2912
if (v6peers != null)
2914
// 16 bytes for v6 + 2 bytes for port
2950
if ( v6peers != null ){
2952
// 16 bytes for v6 + 2 bytes for port
2915
2954
final int entry_size = 18;
2918
2956
final byte[] rawAddr = new byte[16];
2920
for (int i = 0; i <= v6peers.length - entry_size; i += entry_size)
2922
System.arraycopy(v6peers, i, rawAddr, 0, 16);
2958
for (int i=0; i<v6peers.length; i+=entry_size ){
2960
System.arraycopy( v6peers, i, rawAddr, 0, 16 );
2923
2962
String ip = InetAddress.getByAddress(rawAddr).getHostAddress();
2924
int tcp_port = rawAddr[i+16] * 256 + rawAddr[i+17];
2925
if (tcp_port < 0 || tcp_port > 65535)
2927
if (Logger.isEnabled())
2964
int po1 = 0xFF & v6peers[i+16];
2965
int po2 = 0xFF & v6peers[i+17];
2967
int tcp_port = po1*256 + po2;
2969
if (tcp_port < 0 || tcp_port > 65535){
2971
if (Logger.isEnabled()){
2928
2973
Logger.log(new LogEvent(torrent, LOGID, LogEvent.LT_ERROR, "Invalid compactv6 peer port given: " + ip + ": " + tcp_port));
2931
byte[] peer_peer_id = getAnonymousPeerId(ip, tcp_port);
2979
byte[] peer_peer_id = getAnonymousPeerId( ip, tcp_port );
2932
2981
short protocol = DownloadAnnounceResultPeer.PROTOCOL_NORMAL;
2933
2983
TRTrackerAnnouncerResponsePeerImpl peer = new TRTrackerAnnouncerResponsePeerImpl(PEPeerSource.PS_BT_TRACKER, peer_peer_id, ip, tcp_port, 0, 0, protocol, TRTrackerAnnouncer.AZ_TRACKER_VERSION_1, (short) 0);
2934
if (Logger.isEnabled())
2985
if (Logger.isEnabled()){
2935
2987
Logger.log(new LogEvent(torrent, LOGID, "COMPACTv6 PEER: " + peer.getString()));
2936
2990
valid_meta_peers.add(peer);