Search in sources :

Example 11 with PeerManager

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);
}
Also used : PeerManager(com.biglybt.pif.peers.PeerManager) ClientInstance(com.biglybt.core.instancemanager.ClientInstance) Download(com.biglybt.pif.download.Download)

Aggregations

PeerManager (com.biglybt.pif.peers.PeerManager)11 Download (com.biglybt.pif.download.Download)5 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 Peer (com.biglybt.pif.peers.Peer)3 InetSocketAddress (java.net.InetSocketAddress)3 PEPeer (com.biglybt.core.peer.PEPeer)2 Torrent (com.biglybt.pif.torrent.Torrent)2 ClientInstance (com.biglybt.core.instancemanager.ClientInstance)1 LightWeightSeed (com.biglybt.core.lws.LightWeightSeed)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)1 PluginInterface (com.biglybt.pif.PluginInterface)1 DownloadPeerListener (com.biglybt.pif.download.DownloadPeerListener)1 DownloadScrapeResult (com.biglybt.pif.download.DownloadScrapeResult)1 DownloadStats (com.biglybt.pif.download.DownloadStats)1 RateLimiter (com.biglybt.pif.network.RateLimiter)1 PeerManagerStats (com.biglybt.pif.peers.PeerManagerStats)1 TorrentImpl (com.biglybt.pifimpl.local.torrent.TorrentImpl)1 DHTPluginContact (com.biglybt.plugin.dht.DHTPluginContact)1 DHTPluginOperationListener (com.biglybt.plugin.dht.DHTPluginOperationListener)1