Search in sources :

Example 41 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class PlayUtils method isExternallyPlayable.

private static boolean isExternallyPlayable(DiskManagerFileInfo file) {
    String name = file.getFile(true).getName();
    try {
        Download dl = file.getDownload();
        if (dl != null) {
            String is = PluginCoreUtils.unwrap(dl).getDownloadState().getAttribute(DownloadManagerState.AT_INCOMP_FILE_SUFFIX);
            if (is != null && name.endsWith(is)) {
                name = name.substring(0, name.length() - is.length());
            }
        }
    } catch (Throwable e) {
    }
    int extIndex = name.lastIndexOf(".");
    if (extIndex > -1) {
        String ext = name.substring(extIndex);
        if (ext == null) {
            return false;
        }
        ext = ext.toLowerCase();
        if (getPlayableFileExtensions().contains(ext)) {
            return true;
        }
    }
    return false;
}
Also used : Download(com.biglybt.pif.download.Download)

Example 42 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class DHTPluginImpl method checkForReSeed.

public void checkForReSeed(boolean force) {
    int seed_limit = 32;
    try {
        long[] router_stats = dht.getRouter().getStats().getStats();
        if (router_stats[DHTRouterStats.ST_CONTACTS_LIVE] < seed_limit || force) {
            if (force) {
                log.log("Reseeding");
            } else {
                log.log("Less than 32 live contacts, reseeding");
            }
            int peers_imported = 0;
            if (network == DHT.NW_AZ_MAIN || network == DHT.NW_AZ_MAIN_V6) {
                // first look for peers to directly import
                Download[] downloads = plugin_interface.getDownloadManager().getDownloads();
                outer: for (int i = 0; i < downloads.length; i++) {
                    Download download = downloads[i];
                    PeerManager pm = download.getPeerManager();
                    if (pm == null) {
                        continue;
                    }
                    Peer[] peers = pm.getPeers();
                    for (int j = 0; j < peers.length; j++) {
                        Peer p = peers[j];
                        int peer_udp_port = p.getUDPNonDataListenPort();
                        if (peer_udp_port != 0) {
                            boolean is_v6 = p.getIp().contains(":");
                            if (is_v6 == v6) {
                                String ip = p.getIp();
                                if (AENetworkClassifier.categoriseAddress(ip) == AENetworkClassifier.AT_PUBLIC) {
                                    if (importSeed(ip, peer_udp_port) != null) {
                                        peers_imported++;
                                        if (peers_imported > seed_limit) {
                                            break outer;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (peers_imported < 16) {
                    List<InetSocketAddress> list = VersionCheckClient.getSingleton().getDHTBootstrap(network != DHT.NW_AZ_MAIN_V6);
                    for (InetSocketAddress address : list) {
                        if (importSeed(address) != null) {
                            peers_imported++;
                            if (peers_imported > seed_limit) {
                                break;
                            }
                        }
                    }
                }
            } else if (network == DHT.NW_BIGLYBT_MAIN) {
                List<InetSocketAddress> list = VersionCheckClient.getSingleton().getDHTBootstrap(true);
                for (InetSocketAddress address : list) {
                    if (importSeed(address) != null) {
                        peers_imported++;
                        if (peers_imported > seed_limit) {
                            break;
                        }
                    }
                }
            }
            if (peers_imported < seed_limit) {
                List<DHTTransportAlternativeContact> contacts = DHTUDPUtils.getAlternativeContacts(network == DHT.NW_AZ_MAIN_V6 ? DHTTransportAlternativeNetwork.AT_BIGLYBT_IPV6 : DHTTransportAlternativeNetwork.AT_BIGLYBT_IPV4, seed_limit - peers_imported);
                for (DHTTransportAlternativeContact c : contacts) {
                    Map<String, Object> props = c.getProperties();
                    String ip = MapUtils.getMapString(props, "a", null);
                    int port = (int) MapUtils.getMapLong(props, "p", 0);
                    if (ip != null && port > 0) {
                        if (importSeed(ip, port) != null) {
                            peers_imported++;
                            if (peers_imported > seed_limit) {
                                break;
                            }
                        }
                    }
                }
            }
            DHTTransportContact root_to_remove = null;
            if (peers_imported == 0) {
                root_to_remove = importRootSeed();
                if (root_to_remove != null) {
                    peers_imported++;
                }
            }
            if (peers_imported > 0) {
                integrateDHT(false, root_to_remove);
            } else {
                log.log("No valid peers found to reseed from");
            }
        }
    } catch (Throwable e) {
        log.log(e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Peer(com.biglybt.pif.peers.Peer) PeerManager(com.biglybt.pif.peers.PeerManager) Download(com.biglybt.pif.download.Download)

Example 43 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class PrivacyView method injectResult.

private static void injectResult(Download download, int[] result) {
    DownloadScrapeResult scrape = download.getAggregatedScrapeResult();
    if (scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
        int total = scrape.getNonSeedCount() + scrape.getSeedCount();
        if (total >= result[0] + result[1]) {
            return;
        }
    }
    download.setScrapeResult(new DownloadScrapeResult() {

        @Override
        public Download getDownload() {
            return (null);
        }

        @Override
        public int getResponseType() {
            return (RT_SUCCESS);
        }

        @Override
        public int getSeedCount() {
            return (result[0]);
        }

        @Override
        public int getNonSeedCount() {
            return (result[1]);
        }

        @Override
        public long getScrapeStartTime() {
            return (SystemTime.getCurrentTime());
        }

        @Override
        public void setNextScrapeStartTime(long nextScrapeStartTime) {
        }

        @Override
        public long getNextScrapeStartTime() {
            return (0);
        }

        @Override
        public String getStatus() {
            return ("OK");
        }

        @Override
        public URL getURL() {
            try {
                return (new URL("dht:"));
            } catch (Throwable e) {
                return (null);
            }
        }
    });
}
Also used : Download(com.biglybt.pif.download.Download) DownloadScrapeResult(com.biglybt.pif.download.DownloadScrapeResult) Point(org.eclipse.swt.graphics.Point) URL(java.net.URL)

Example 44 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class NetworkAdminSpeedTesterBTImpl method start.

/**
 * The downloads have been stopped just need to do the testing.
 * @param tot - Torrent recieved from testing service.
 */
public synchronized void start(TOTorrent tot) {
    if (test_started) {
        Debug.out("Test already started!");
        return;
    }
    test_started = true;
    // OK lets start the test.
    try {
        TorrentUtils.setFlag(tot, TorrentUtils.TORRENT_FLAG_LOW_NOISE, true);
        Torrent torrent = new TorrentImpl(tot);
        String fileName = torrent.getName();
        sendStageUpdateToListeners(MessageText.getString("SpeedTestWizard.stage.message.preparing"));
        // create a blank file of specified size. (using the temporary name.)
        File saveLocation = AETemporaryFileHandler.createTempFile();
        File baseDir = saveLocation.getParentFile();
        File blankFile = FileUtil.newFile(baseDir, fileName);
        File blankTorrentFile = FileUtil.newFile(baseDir, "speedTestTorrent.torrent");
        torrent.writeToFile(blankTorrentFile);
        URL announce_url = torrent.getAnnounceURL();
        if (announce_url.getProtocol().equalsIgnoreCase("https")) {
            SESecurityManager.setCertificateHandler(announce_url, new SECertificateListener() {

                @Override
                public boolean trustCertificate(String resource, X509Certificate cert) {
                    return (true);
                }
            });
        }
        Download speed_download = plugin.getDownloadManager().addDownloadStopped(torrent, blankTorrentFile, blankFile);
        speed_download.setBooleanAttribute(speedTestAttrib, true);
        DownloadManager core_download = PluginCoreUtils.unwrap(speed_download);
        core_download.setPieceCheckingEnabled(false);
        // make sure we've got a bunch of upload slots
        core_download.getDownloadState().setIntParameter(DownloadManagerState.PARAM_MAX_UPLOADS, 32);
        core_download.getDownloadState().setIntParameter(DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING, 32);
        if (use_crypto) {
            core_download.setCryptoLevel(NetworkManager.CRYPTO_OVERRIDE_REQUIRED);
        }
        core_download.addPeerListener(new DownloadManagerPeerListener() {

            @Override
            public void peerManagerWillBeAdded(PEPeerManager peer_manager) {
                DiskManager disk_manager = peer_manager.getDiskManager();
                DiskManagerPiece[] pieces = disk_manager.getPieces();
                int startPiece = setStartPieceBasedOnMode(testMode, pieces.length);
                for (int i = startPiece; i < pieces.length; i++) {
                    pieces[i].setDone(true);
                }
            }

            @Override
            public void peerManagerAdded(PEPeerManager peer_manager) {
            }

            @Override
            public void peerManagerRemoved(PEPeerManager manager) {
            }

            @Override
            public void peerAdded(PEPeer peer) {
            }

            @Override
            public void peerRemoved(PEPeer peer) {
            }
        });
        speed_download.moveTo(1);
        speed_download.setFlag(Download.FLAG_DISABLE_AUTO_FILE_MOVE, true);
        speed_download.setFlag(Download.FLAG_DISABLE_STOP_AFTER_ALLOC, true);
        core_download.initialize();
        core_download.setForceStart(true);
        TorrentSpeedTestMonitorThread monitor = new TorrentSpeedTestMonitorThread(speed_download);
        monitor.start();
    // The test has now started!!
    } catch (Throwable e) {
        test_completed = true;
        abort("Could not start test", e);
    }
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) Torrent(com.biglybt.pif.torrent.Torrent) TorrentImpl(com.biglybt.pifimpl.local.torrent.TorrentImpl) PEPeer(com.biglybt.core.peer.PEPeer) DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate) DownloadManagerPeerListener(com.biglybt.core.download.DownloadManagerPeerListener) SECertificateListener(com.biglybt.core.security.SECertificateListener) PEPeerManager(com.biglybt.core.peer.PEPeerManager) File(java.io.File) Download(com.biglybt.pif.download.Download)

Example 45 with Download

use of com.biglybt.pif.download.Download 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) {
        List<InetAddress> addresses = inst.getInternalAddresses();
        for (InetAddress address : addresses) {
            String peer_ip = address.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) InetAddress(java.net.InetAddress)

Aggregations

Download (com.biglybt.pif.download.Download)80 DownloadManager (com.biglybt.core.download.DownloadManager)22 Torrent (com.biglybt.pif.torrent.Torrent)17 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)12 File (java.io.File)12 TOTorrent (com.biglybt.core.torrent.TOTorrent)11 PluginInterface (com.biglybt.pif.PluginInterface)11 URL (java.net.URL)10 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)8 PEPeerManager (com.biglybt.core.peer.PEPeerManager)8 List (java.util.List)7 Tag (com.biglybt.core.tag.Tag)6 MenuItem (com.biglybt.pif.ui.menus.MenuItem)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 DownloadException (com.biglybt.pif.download.DownloadException)5 DiskManager (com.biglybt.core.disk.DiskManager)4 DownloadManager (com.biglybt.pif.download.DownloadManager)4 DownloadScrapeResult (com.biglybt.pif.download.DownloadScrapeResult)4 Peer (com.biglybt.pif.peers.Peer)4