}
final int f_i = i;
peers_for_announce.add(
new DownloadAnnounceResultPeer()
{
public String
getSource()
{
return( PEPeerSource.PS_DHT );
}
public String
getAddress()
{
return((String)addresses.get(f_i));
}
public int
getPort()
{
return(((Integer)ports.get(f_i)).intValue());
}
public int
getUDPPort()
{
return(((Integer)udp_ports.get(f_i)).intValue());
}
public byte[]
getPeerID()
{
return( null );
}
public short
getProtocol()
{
String flag = (String)flags.get(f_i);
short protocol;
if ( flag != null && flag.indexOf("C") != -1 ){
protocol = PROTOCOL_CRYPT;
}else{
protocol = PROTOCOL_NORMAL;
}
return( protocol );
}
});
}
if ( target.getType() == REG_TYPE_DERIVED && peers_for_announce.size() > 0 ){
PeerManager pm = download.getPeerManager();
if ( pm != null ){
// try some limited direct injection
List<DownloadAnnounceResultPeer> temp = new ArrayList<DownloadAnnounceResultPeer>( peers_for_announce );
Random rand = new Random();
for (int i=0;i<DIRECT_INJECT_PEER_MAX && temp.size() > 0; i++ ){
DownloadAnnounceResultPeer peer = temp.remove( rand.nextInt( temp.size()));
log( download, "Injecting derived peer " + peer.getAddress() + " into " + download.getName());
Map<Object,Object> user_data = new HashMap<Object,Object>();
user_data.put( Peer.PR_PRIORITY_CONNECTION, new Boolean( true ));
pm.addPeer(
peer.getAddress(),
peer.getPort(),
peer.getUDPPort(),
peer.getProtocol() == DownloadAnnounceResultPeer.PROTOCOL_CRYPT,
user_data );
}
}
}