while( it2.hasNext()){
Map.Entry entry = (Map.Entry)it2.next();
Download dl = (Download)entry.getKey();
boolean now = ((Boolean)entry.getValue()).booleanValue();
if ( now ){
track_now.add( dl );
}
active_set.add( dl );
}
if( track_now.size() > 0 ){
to_do.put( buddy, track_now );
}
}
}
}
synchronized( actively_tracking ){
Iterator it = active_set.iterator();
while( it.hasNext()){
Download dl = (Download)it.next();
if ( !actively_tracking.contains( dl )){
actively_tracking.add( dl );
trackPeers( dl );
}
}
it = actively_tracking.iterator();
while( it.hasNext()){
Download dl = (Download)it.next();
if ( !active_set.contains( dl )){
it.remove();
untrackPeers( dl );
}
}
}
Iterator it = to_do.entrySet().iterator();
while( it.hasNext()){
Map.Entry entry = (Map.Entry)it.next();
BuddyPluginBuddy buddy = (BuddyPluginBuddy)entry.getKey();
if ( !buddy.isOnline( false )){
continue;
}
InetAddress ip = buddy.getAdjustedIP();
if ( ip == null ){
continue;
}
int tcp_port = buddy.getTCPPort();
int udp_port = buddy.getUDPPort();
List downloads = (List)entry.getValue();
for (int i=0;i<downloads.size();i++){
Download download = (Download)downloads.get(i);
PeerManager pm = download.getPeerManager();
if ( pm == null ){
continue;
}
Peer[] existing_peers = pm.getPeers( ip.getHostAddress());
boolean connected = false;
for (int j=0;j<existing_peers.length;j++){
Peer peer = existing_peers[j];
if ( peer.getTCPListenPort() == tcp_port ||
peer.getUDPListenPort() == udp_port ){
connected = true;
break;
}
}
if ( connected ){
log( download.getName() + " - peer " + ip.getHostAddress() + " already connected" );
continue;
}
log( download.getName() + " - connecting to peer " + ip.getHostAddress());
PEPeerManager c_pm = PluginCoreUtils.unwrap( pm );
Map user_data = new LightHashMap();