use of com.biglybt.core.peer.PEPeerStats 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>");
}
use of com.biglybt.core.peer.PEPeerStats in project BiglyBT by BiglySoftware.
the class PeersGraphicView method initialize.
protected void initialize(Composite composite) {
display = composite.getDisplay();
panel = new Canvas(composite, SWT.NO_BACKGROUND);
panel.addListener(SWT.MouseHover, new Listener() {
@Override
public void handleEvent(Event event) {
int x = event.x;
int y = event.y;
String tt = "";
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
if (dm_data.length > 1) {
tt = manager.getDisplayName() + "\r\n";
}
tt += DisplayFormatters.formatDownloadStatus(manager) + ", " + DisplayFormatters.formatPercentFromThousands(manager.getStats().getCompleted());
break;
} else {
PEPeer target = null;
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
target = entry.getKey();
break;
}
}
if (target != null) {
PEPeerStats stats = target.getStats();
String[] details = PeerUtils.getCountryDetails(target);
String dstr = (details == null || details.length < 2) ? "" : (" - " + details[0] + "/" + details[1]);
/*
if ( dm_map.size() > 1 ){
tt = manager.getDisplayName() + "\r\n";
}
*/
tt = target.getIp() + dstr + ", " + DisplayFormatters.formatPercentFromThousands(target.getPercentDoneInThousandNotation()) + "\r\n" + "Up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", " + "Down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate());
break;
}
}
}
}
panel.setToolTipText(tt);
}
});
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent event) {
if (event.button == 3) {
int x = event.x;
int y = event.y;
PEPeer target = null;
DownloadManager target_manager = null;
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
target = entry.getKey();
target_manager = manager;
break;
}
}
if (target != null) {
break;
}
}
}
if (target == null) {
return;
}
Menu menu = panel.getMenu();
if (menu != null && !menu.isDisposed()) {
menu.dispose();
}
menu = new Menu(panel);
PeersViewBase.fillMenu(menu, target, target_manager);
final Point cursorLocation = Display.getCurrent().getCursorLocation();
menu.setLocation(cursorLocation.x, cursorLocation.y);
menu.setVisible(true);
}
}
@Override
public void mouseDoubleClick(MouseEvent event) {
int x = event.x;
int y = event.y;
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, manager);
}
} else {
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
PEPeer target = entry.getKey();
try {
String dm_id = "DMDetails_" + Base32.encode(manager.getTorrent().getHash());
MdiEntry mdi_entry = UIFunctionsManager.getUIFunctions().getMDI().getEntry(dm_id);
if (mdi_entry != null) {
mdi_entry.setDatasource(new Object[] { manager, target });
}
Composite comp = panel.getParent();
while (comp != null) {
if (comp instanceof CTabFolder) {
CTabFolder tf = (CTabFolder) comp;
CTabItem[] items = tf.getItems();
for (CTabItem item : items) {
UISWTViewCore view = (UISWTViewCore) item.getData("TabbedEntry");
UISWTViewEventListener listener = view.getEventListener();
if (listener instanceof UISWTViewEventListenerHolder) {
listener = ((UISWTViewEventListenerHolder) listener).getDelegatedEventListener(view);
}
if (listener instanceof PeersView) {
tf.setSelection(item);
Event ev = new Event();
ev.item = item;
// manual setSelection doesn't file selection event - derp
tf.notifyListeners(SWT.Selection, ev);
((PeersView) listener).selectPeer(target);
return;
}
}
}
comp = comp.getParent();
}
} catch (Throwable e) {
}
break;
}
}
}
}
}
}
});
// without this we get a transient blank when mousing in and out of the tab folder on OSX :(
panel.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
doRefresh();
}
});
}
use of com.biglybt.core.peer.PEPeerStats in project BiglyBT by BiglySoftware.
the class Show method printTorrentDetails.
/**
* prints out the full details of a particular torrent
* @param out
* @param dm
* @param torrentNum
*/
private static void printTorrentDetails(PrintStream out, DownloadManager dm, int torrentNum, List<String> args) {
String name = dm.getDisplayName();
if (name == null)
name = "?";
out.println("> -----");
out.println("Info on Torrent #" + torrentNum + " (" + name + ")");
out.println("- General Info -");
String[] health = { "- no info -", "stopped", "no remote connections", "no tracker", "OK", "ko" };
try {
out.println("Health: " + health[dm.getHealthStatus()]);
} catch (Exception e) {
out.println("Health: " + health[0]);
}
out.println("State: " + Integer.toString(dm.getState()));
if (dm.getState() == DownloadManager.STATE_ERROR)
out.println("Error: " + dm.getErrorDetails());
out.println("Hash: " + TorrentUtils.nicePrintTorrentHash(dm.getTorrent(), true));
out.println("- Torrent file -");
out.println("Torrent Filename: " + dm.getTorrentFileName());
out.println("Saving to: " + dm.getSaveLocation());
out.println("Created By: " + dm.getTorrentCreatedBy());
out.println("Comment: " + dm.getTorrentComment());
Category cat = dm.getDownloadState().getCategory();
if (cat != null) {
out.println("Category: " + cat.getName());
}
List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, dm);
String tags_str;
if (tags.size() == 0) {
tags_str = "None";
} else {
tags_str = "";
for (Tag t : tags) {
tags_str += (tags_str.length() == 0 ? "" : ",") + t.getTagName(true);
}
}
out.println("Tags: " + tags_str);
out.println("- Tracker Info -");
TRTrackerAnnouncer trackerclient = dm.getTrackerClient();
if (trackerclient != null) {
out.println("URL: " + trackerclient.getTrackerURL());
String timestr;
try {
int time = trackerclient.getTimeUntilNextUpdate();
if (time < 0) {
timestr = MessageText.getString("GeneralView.label.updatein.querying");
} else {
int minutes = time / 60;
int seconds = time % 60;
String strSeconds = "" + seconds;
if (seconds < 10) {
// $NON-NLS-1$
strSeconds = "0" + seconds;
}
timestr = minutes + ":" + strSeconds;
}
} catch (Exception e) {
timestr = "unknown";
}
out.println("Time till next Update: " + timestr);
out.println("Status: " + trackerclient.getStatusString());
} else
out.println(" Not available");
out.println("- Files Info -");
DiskManagerFileInfo[] files = dm.getDiskManagerFileInfo();
if (files != null) {
for (int i = 0; i < files.length; i++) {
out.print(((i < 9) ? " " : " ") + Integer.toString(i + 1) + " (");
String tmp = ">";
if (files[i].getPriority() > 0)
tmp = "+";
if (files[i].isSkipped())
tmp = "!";
out.print(tmp + ") ");
if (files[i] != null) {
long fLen = files[i].getLength();
if (fLen > 0) {
DecimalFormat df = new DecimalFormat("000.0%");
out.print(df.format(files[i].getDownloaded() * 1.0 / fLen));
out.println("\t" + files[i].getFile(true).getName());
} else
out.println("Info not available.");
} else
out.println("Info not available.");
}
} else {
out.println(" Info not available.");
}
for (String arg : args) {
arg = arg.toLowerCase();
if (arg.startsWith("pie")) {
out.println("Pieces");
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
PiecePicker picker = pm.getPiecePicker();
PEPiece[] pieces = pm.getPieces();
String line = "";
for (int i = 0; i < pieces.length; i++) {
String str = picker.getPieceString(i);
line += (line.length() == 0 ? (i + " ") : ",") + str;
PEPiece piece = pieces[i];
if (piece != null) {
line += ":" + piece.getString();
}
if ((i + 1) % 10 == 0) {
out.println(line);
line = "";
}
}
if (line.length() > 0) {
out.println(line);
}
}
} else if (arg.startsWith("pee")) {
out.println("Peers");
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
List<PEPeer> peers = pm.getPeers();
out.println("\tConnected to " + peers.size() + " peers");
for (PEPeer peer : peers) {
PEPeerStats stats = peer.getStats();
System.out.println("\t\t" + peer.getIp() + ", in=" + (peer.isIncoming() ? "Y" : "N") + ", prot=" + peer.getProtocol() + ", choked=" + (peer.isChokingMe() ? "Y" : "N") + ", up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate()) + ", in_req=" + peer.getIncomingRequestCount() + ", out_req=" + peer.getOutgoingRequestCount());
}
}
}
}
out.println("> -----");
}
Aggregations