String peer_str = "";
for (int i=0;i<peers.size() && i < MAX_PEERS_PER_QUERY; i++ ){
Peer peer = (Peer)peers.get(i);
List peer_data = new ArrayList();
peer_data.add( download.getTorrent().getHash());
peer_data.add( peer.getId());
peer_data.add( peer.getIp());
map.put( "peer" + i, peer_data );
peer_str += (i==0?"":",") + peer.getIp();
}
log( "Checking " + url_str + " : peers=" + peer_str );
byte[] encoded = BEncoder.encode( map, true );
HttpURLConnection connection = (HttpURLConnection)target.openConnection();
String data = "authpeers=" + new String(encoded, "ISO-8859-1" );
System.out.println( "sending '" + data + "'" );
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", Constants.AZUREUS_NAME + " " + Constants.AZUREUS_VERSION);
connection.setRequestProperty( "Connection", "close" );
connection.addRequestProperty( "Accept-Encoding", "gzip" );
out = new OutputStreamWriter(connection.getOutputStream());
out.write(data);
out.flush();
in = new BufferedInputStream(connection.getInputStream());
Map result_map = BDecoder.decode( in );
for (int i=0;i<peers.size() && i < MAX_PEERS_PER_QUERY; i++ ){
Peer peer = (Peer)peers.get(i);
Long enabled = (Long)result_map.get( "peer" + i );
if ( enabled == null ){
log( "No response for peer '" + peer.getIp() + "'" );
}else{
boolean ok = enabled.longValue() != 0;
recordPeer( "auth check", peer.getId(), peer.getIp(), peer.getPort(), ok );
if ( !ok ){
removePeer( peer );
}