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);
}
}
Aggregations