use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class DownloadManagerStatsImpl method timerTick.
protected void timerTick(int tick_count) {
if (tick_count % 15 == 0) {
checkShareRatioProgress();
}
if (!history_retention_required) {
return;
}
PEPeerManager pm = download_manager.getPeerManager();
if (pm == null) {
return;
}
PEPeerManagerStats stats = pm.getStats();
long send_rate = stats.getDataSendRate() + stats.getProtocolSendRate();
long receive_rate = stats.getDataReceiveRate() + stats.getProtocolReceiveRate();
long peer_swarm_average = getTotalAveragePerPeer();
long entry = ((((send_rate - 1 + HISTORY_DIV / 2) / HISTORY_DIV) << 42) & 0x7ffffc0000000000L) | ((((receive_rate - 1 + HISTORY_DIV / 2) / HISTORY_DIV) << 21) & 0x000003ffffe00000L) | ((((peer_swarm_average - 1 + HISTORY_DIV / 2) / HISTORY_DIV)) & 0x00000000001fffffL);
synchronized (this) {
if (history != null) {
history[history_pos++] = entry;
if (history_pos == HISTORY_MAX_SECS) {
history_pos = 0;
history_wrapped = true;
}
}
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class DownloadManagerStatsImpl method getTimeSinceLastDataReceivedInSeconds.
@Override
public int getTimeSinceLastDataReceivedInSeconds() {
PEPeerManager pm = download_manager.getPeerManager();
int res = saved_SecondsSinceDownload;
if (pm != null) {
int current = pm.getStats().getTimeSinceLastDataReceivedInSeconds();
if (current >= 0) {
// activity this session, use this value
res = current;
} else {
if (res >= 0) {
long now = SystemTime.getCurrentTime();
long elapsed = now - pm.getTimeStarted(false);
if (elapsed < 0) {
elapsed = 0;
}
res += elapsed / 1000;
}
}
}
return (res);
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class DownloadManagerStatsImpl method getAvailWentBadTime.
@Override
public long getAvailWentBadTime() {
PEPeerManager pm = download_manager.getPeerManager();
if (pm != null) {
long bad_time = pm.getAvailWentBadTime();
if (bad_time > 0) {
return (bad_time);
}
if (pm.getMinAvailability() >= 1.0) {
return (0);
}
}
DownloadManagerState state = download_manager.getDownloadState();
return (state.getLongAttribute(DownloadManagerState.AT_AVAIL_BAD_TIME));
}
use of com.biglybt.core.peer.PEPeerManager 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);
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class StatsWriterImpl method writeSupport.
protected void writeSupport() {
writeLineRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
boolean export_peer_stats = COConfigurationManager.getBooleanParameter("Stats Export Peer Details");
boolean export_file_stats = COConfigurationManager.getBooleanParameter("Stats Export File Details");
String xsl = COConfigurationManager.getStringParameter("Stats XSL File");
if (xsl.length() > 0) {
writeLineRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + xsl + "\"?>");
}
writeLineRaw("<STATS>");
GlobalManager global = core.getGlobalManager();
try {
indent();
writeTag("AZUREUS_VERSION", Constants.AZUREUS_VERSION);
writeLineRaw("<GLOBAL>");
try {
indent();
GlobalManagerStats gm_stats = global.getStats();
writeRawCookedAverageTag("DOWNLOAD_SPEED", gm_stats.getDataReceiveRate() + gm_stats.getProtocolReceiveRate());
writeRawCookedAverageTag("UPLOAD_SPEED", gm_stats.getDataSendRate() + gm_stats.getProtocolSendRate());
} finally {
exdent();
}
writeLineRaw("</GLOBAL>");
writeLineRaw("<DOWNLOADS>");
try {
indent();
List _dms = global.getDownloadManagers();
DownloadManager[] dms = new DownloadManager[_dms.size()];
// sort by position, downloads then seeders
_dms.toArray(dms);
Arrays.sort(dms, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
DownloadManager d1 = (DownloadManager) o1;
DownloadManager d2 = (DownloadManager) o2;
int d1_index = d1.getPosition();
int d2_index = d2.getPosition();
if (d1.isDownloadComplete(false)) {
d1_index += 1000000;
}
if (d2.isDownloadComplete(false)) {
d2_index += 1000000;
}
return (d1_index - d2_index);
}
});
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = (DownloadManager) dms[i];
DownloadManagerStats dm_stats = dm.getStats();
writeLineRaw("<DOWNLOAD>");
try {
indent();
writeLineRaw("<TORRENT>");
// torrent can be null if broken torrent!
TOTorrent torrent = dm.getTorrent();
try {
indent();
writeTag("NAME", dm.getDisplayName());
writeTag("TORRENT_FILE", dm.getTorrentFileName());
if (torrent != null) {
writeTag("HASH", TorrentUtils.nicePrintTorrentHash(torrent, true));
writeRawCookedTag("SIZE", torrent.getSize());
writeTag("PIECE_LENGTH", torrent.getPieceLength());
writeTag("PIECE_COUNT", torrent.getNumberOfPieces());
writeTag("FILE_COUNT", torrent.getFiles().length);
writeTag("COMMENT", dm.getTorrentComment());
writeTag("CREATED_BY", dm.getTorrentCreatedBy());
writeTag("CREATION_DATE", torrent.getCreationDate());
}
} finally {
exdent();
}
writeLineRaw("</TORRENT>");
writeTag("DOWNLOAD_STATUS", DisplayFormatters.formatDownloadStatusDefaultLocale(dm));
writeTag("DOWNLOAD_DIR", dm.getSaveLocation().toString());
if (torrent != null) {
if (torrent.isSimpleTorrent()) {
writeTag("TARGET_FILE", dm.getSaveLocation().toString());
} else {
writeTag("TARGET_DIR", dm.getSaveLocation().toString());
}
}
writeTag("TRACKER_STATUS", dm.getTrackerStatus());
writeTag("COMPLETED", dm_stats.getCompleted());
writeTag("NON_DND_COMPLETED", dm.isDownloadComplete(false));
writeRawCookedTag("DOWNLOADED", dm_stats.getTotalDataBytesReceived());
writeRawCookedTag("UPLOADED", dm_stats.getTotalDataBytesSent());
writeRawCookedTag("DISCARDED", dm_stats.getDiscarded());
writeRawCookedAverageTag("DOWNLOAD_SPEED", dm_stats.getDataReceiveRate());
writeRawCookedAverageTag("UPLOAD_SPEED", dm_stats.getDataSendRate());
writeRawCookedAverageTag("TOTAL_SPEED", dm_stats.getTotalAverage());
writeRawCookedAverageTag("DOWNLOAD_SPEED_SMOOTH", dm_stats.getSmoothedDataReceiveRate());
writeRawCookedAverageTag("UPLOAD_SPEED_SMOOTH", dm_stats.getSmoothedDataSendRate());
writeTag("ELAPSED", dm_stats.getElapsedTime());
writeTag("ETA", DisplayFormatters.formatETA(dm_stats.getSmoothedETA()));
writeTag("HASH_FAILS", dm_stats.getHashFailCount());
writeTag("SHARE_RATIO", dm_stats.getShareRatio());
writeTag("TOTAL_SEEDS", dm.getNbSeeds());
writeTag("TOTAL_LEECHERS", dm.getNbPeers());
if (export_file_stats) {
try {
writeLineRaw("<FILES>");
indent();
DiskManagerFileInfo[] files = dm.getDiskManagerFileInfo();
for (int j = 0; j < files.length; j++) {
DiskManagerFileInfo file = files[j];
try {
writeLineRaw("<FILE>");
indent();
writeTag("NAME", file.getTorrentFile().getRelativePath());
writeTag("DND", file.isSkipped());
writeRawCookedTag("SIZE", file.getLength());
writeRawCookedTag("DOWNLOADED", file.getDownloaded());
} finally {
exdent();
writeLineRaw("</FILE>");
}
}
} finally {
exdent();
writeLineRaw("</FILES>");
}
}
if (export_peer_stats) {
try {
writeLineRaw("<PEERS>");
indent();
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
List peers = pm.getPeers();
for (int j = 0; j < peers.size(); j++) {
PEPeer peer = (PEPeer) peers.get(j);
PEPeerStats peer_stats = peer.getStats();
byte[] id = peer.getId();
if (id == null) {
continue;
}
try {
String peer_id = PeerClassifier.getPrintablePeerID(id);
peer_id = escapeXML(peer_id);
String type = escapeXML(peer.getClient());
writeLineRaw("<PEER hex_id=\"" + ByteFormatter.encodeString(id) + "\" printable_id=\"" + peer_id + "\" type=\"" + type + "\">");
indent();
writeTag("IP", peer.getIp());
writeTag("IS_SEED", peer.isSeed());
writeRawCookedTag("DOWNLOADED", peer_stats.getTotalDataBytesReceived());
writeRawCookedTag("UPLOADED", peer_stats.getTotalDataBytesSent());
writeRawCookedAverageTag("DOWNLOAD_SPEED", peer_stats.getDataReceiveRate());
writeRawCookedAverageTag("UPLOAD_SPEED", peer_stats.getDataSendRate());
} catch (Throwable e) {
Debug.printStackTrace(e);
} finally {
exdent();
writeLineRaw("</PEER>");
}
}
}
} finally {
exdent();
writeLineRaw("</PEERS>");
}
}
} finally {
exdent();
}
writeLineRaw("</DOWNLOAD>");
}
} finally {
exdent();
}
writeLineRaw("</DOWNLOADS>");
} finally {
exdent();
}
writeLineRaw("</STATS>");
}
Aggregations