Search in sources :

Example 1 with DownloadManagerPeerListener

use of com.biglybt.core.download.DownloadManagerPeerListener 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 = new File(baseDir, fileName);
        File blankTorrentFile = new File(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);
        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)

Aggregations

DiskManager (com.biglybt.core.disk.DiskManager)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerPeerListener (com.biglybt.core.download.DownloadManagerPeerListener)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 SECertificateListener (com.biglybt.core.security.SECertificateListener)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 Download (com.biglybt.pif.download.Download)1 Torrent (com.biglybt.pif.torrent.Torrent)1 TorrentImpl (com.biglybt.pifimpl.local.torrent.TorrentImpl)1 File (java.io.File)1 URL (java.net.URL)1 X509Certificate (java.security.cert.X509Certificate)1