use of com.biglybt.pif.peers.PeerManager in project BiglyBT by BiglySoftware.
the class LocalTrackerPlugin method handleTrackResult.
protected int handleTrackResult(ClientInstanceTracked tracked_inst) {
ClientInstance 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;
try {
mon.enter();
Map<String, Long> map = track_times.get(inst.getID());
if (map == null) {
map = new HashMap<>();
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 (1);
}
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);
}
return (is_seed ? 3 : 2);
}
Aggregations