protected int
handleTrackResult(
AZInstanceTracked tracked_inst )
{
AZInstance inst = tracked_inst.getInstance();
Download download = (Download)tracked_inst.getTarget().getTarget();
boolean is_seed = tracked_inst.isSeed();
long now = plugin_interface.getUtilities().getCurrentSystemTime();
boolean skip = false;
// this code is here to deal with multiple interface machines that receive the result multiple times
try{
mon.enter();
Map<String,Long> map = track_times.get( inst.getID() );
if ( map == null ){
map = new HashMap<String, Long>();
track_times.put( inst.getID(), map );
}
String dl_key = plugin_interface.getUtilities().getFormatters().encodeBytesToString(download.getTorrent().getHash());
Long last_track = map.get( dl_key );
if ( last_track != null ){
long lt = last_track.longValue();
if ( now - lt < 30*1000 ){
skip = true;
}
}
map.put( dl_key, new Long(now));
}finally{
mon.exit();
}
if ( skip ){
return( -1 );
}
log.log( "Tracked: " + inst.getString() + ": " + download.getName() + ", seed = " + is_seed );
if ( download.isComplete() && is_seed ){
return( is_seed?1:0 );
}
PeerManager peer_manager = download.getPeerManager();
if ( peer_manager != null ){
String peer_ip = inst.getInternalAddress().getHostAddress();
int peer_tcp_port = inst.getTCPListenPort();
int peer_udp_port = inst.getUDPListenPort();
log.log( " " + download.getName() + ": Injecting peer " + peer_ip + ":" + peer_tcp_port + "/" + peer_udp_port);
peer_manager.addPeer( peer_ip, peer_tcp_port, peer_udp_port, false );
}