use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.
the class ClientStatsView method addPeer.
protected void addPeer(PEPeer peer) {
byte[] bloomId;
long now = SystemTime.getCurrentTime();
// Bloom Filter is based on the first 8 bytes of peer id + ip address
// This captures more duplicates than peer id because most clients
// randomize their peer id on restart. IP address, however, changes
// less often.
byte[] address = null;
byte[] peerId = peer.getId();
InetAddress ip = peer.getAlternativeIPv6();
if (ip == null) {
try {
ip = AddressUtils.getByName(peer.getIp());
address = ip.getAddress();
} catch (Throwable e) {
String ipString = peer.getIp();
if (ipString != null) {
address = ByteFormatter.intToByteArray(ipString.hashCode());
}
}
} else {
address = ip.getAddress();
}
if (address == null) {
bloomId = peerId;
} else {
bloomId = new byte[8 + address.length];
System.arraycopy(peerId, 0, bloomId, 0, 8);
System.arraycopy(address, 0, bloomId, 8, address.length);
}
synchronized (mapData) {
// break on month.. assume user didn't last use this on the same month in a different year
calendar.setTimeInMillis(now);
int thisMonth = calendar.get(Calendar.MONTH);
if (thisMonth != lastAddMonth) {
if (lastAddMonth == 0) {
lastAddMonth = thisMonth;
} else {
String s = new SimpleDateFormat("yyyy-MM").format(new Date(lastAdd));
String filename = CONFIG_FILE_ARCHIVE.replace("%1", s);
save(filename);
lastAddMonth = thisMonth;
lastAdd = 0;
bloomFilter = BloomFilterFactory.createRotating(BloomFilterFactory.createAddOnly(BLOOMFILTER_SIZE), 2);
bloomFilterPeerId = BloomFilterFactory.createRotating(BloomFilterFactory.createAddOnly(BLOOMFILTER_PEERID_SIZE), 2);
overall = new ClientStatsOverall();
mapData.clear();
if (tv != null) {
tv.removeAllTableRows();
}
totalTime = 0;
startedListeningOn = 0;
}
}
String id = getID(peer);
ClientStatsDataSource stat;
stat = mapData.get(id);
boolean needNew = stat == null;
if (needNew) {
stat = new ClientStatsDataSource();
stat.overall = overall;
stat.client = id;
mapData.put(id, stat);
}
boolean inBloomFilter = bloomFilter.contains(bloomId) || bloomFilterPeerId.contains(peerId);
if (!inBloomFilter) {
bloomFilter.add(bloomId);
bloomFilterPeerId.add(peerId);
lastAdd = now;
synchronized (overall) {
overall.count++;
}
stat.count++;
}
stat.current++;
long existingBytesReceived = peer.getStats().getTotalDataBytesReceived();
long existingBytesSent = peer.getStats().getTotalDataBytesSent();
long existingBytesDiscarded = peer.getStats().getTotalBytesDiscarded();
if (existingBytesReceived > 0) {
stat.bytesReceived -= existingBytesReceived;
if (stat.bytesReceived < 0) {
stat.bytesReceived = 0;
}
}
if (existingBytesSent > 0) {
stat.bytesSent -= existingBytesSent;
if (stat.bytesSent < 0) {
stat.bytesSent = 0;
}
}
if (existingBytesDiscarded > 0) {
stat.bytesDiscarded -= existingBytesDiscarded;
if (stat.bytesDiscarded < 0) {
stat.bytesDiscarded = 0;
}
}
if (peer instanceof PEPeerTransport) {
PeerItem identity = ((PEPeerTransport) peer).getPeerItemIdentity();
if (identity != null) {
String network = identity.getNetwork();
if (network != null) {
Map<String, Object> map = stat.perNetworkStats.get(network);
if (map == null) {
map = new HashMap<>();
stat.perNetworkStats.put(network, map);
}
if (!inBloomFilter) {
long count = MapUtils.getMapLong(map, "count", 0);
map.put("count", count + 1);
}
if (existingBytesReceived > 0) {
long bytesReceived = MapUtils.getMapLong(map, "bytesReceived", 0);
bytesReceived -= existingBytesReceived;
if (bytesReceived < 0) {
bytesReceived = 0;
}
map.put("bytesReceived", bytesReceived);
}
if (existingBytesSent > 0) {
long bytesSent = MapUtils.getMapLong(map, "bytesSent", 0);
bytesSent -= existingBytesSent;
if (bytesSent < 0) {
bytesSent = 0;
}
map.put("bytesSent", bytesSent);
}
if (existingBytesDiscarded > 0) {
long bytesDiscarded = MapUtils.getMapLong(map, "bytesDiscarded", 0);
bytesDiscarded -= existingBytesDiscarded;
if (bytesDiscarded < 0) {
bytesDiscarded = 0;
}
map.put("bytesDiscarded", bytesDiscarded);
}
}
}
}
if (tv != null) {
if (needNew) {
tv.addDataSource(stat);
} else {
TableRowCore row = tv.getRow(stat);
if (row != null) {
row.invalidate();
}
}
}
}
}
use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.
the class ClientStatsView method peerRemoved.
@Override
public void peerRemoved(PEPeer peer) {
synchronized (mapData) {
ClientStatsDataSource stat = mapData.get(getID(peer));
if (stat != null) {
stat.current--;
String network = null;
if (peer instanceof PEPeerTransport) {
PeerItem identity = ((PEPeerTransport) peer).getPeerItemIdentity();
if (identity != null) {
network = identity.getNetwork();
}
}
stat.bytesReceived += peer.getStats().getTotalDataBytesReceived();
stat.bytesSent += peer.getStats().getTotalDataBytesSent();
stat.bytesDiscarded += peer.getStats().getTotalBytesDiscarded();
if (network != null) {
Map<String, Object> map = stat.perNetworkStats.get(network);
if (map == null) {
map = new HashMap<>();
stat.perNetworkStats.put(network, map);
}
long bytesReceived = MapUtils.getMapLong(map, "bytesReceived", 0);
map.put("bytesReceived", bytesReceived + peer.getStats().getTotalDataBytesReceived());
long bytesSent = MapUtils.getMapLong(map, "bytesSent", 0);
map.put("bytesSent", bytesSent + peer.getStats().getTotalDataBytesSent());
long bytesDiscarded = MapUtils.getMapLong(map, "bytesDiscarded", 0);
map.put("bytesDiscarded", bytesDiscarded + peer.getStats().getTotalBytesDiscarded());
}
if (tv != null) {
TableRowCore row = tv.getRow(stat);
if (row != null) {
row.invalidate();
}
}
}
}
}
use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.
the class ClientStatsView method tableViewTabInitComplete.
@Override
public void tableViewTabInitComplete() {
Composite cTV = (Composite) parent.getChildren()[0];
Composite cBottom = new Composite(parent, SWT.None);
FormData fd;
fd = Utils.getFilledFormData();
fd.bottom = new FormAttachment(cBottom);
Utils.setLayoutData(cTV, fd);
fd = Utils.getFilledFormData();
fd.top = null;
Utils.setLayoutData(cBottom, fd);
cBottom.setLayout(new FormLayout());
Button btnCopy = new Button(cBottom, SWT.PUSH);
Utils.setLayoutData(btnCopy, new FormData());
btnCopy.setText("Copy");
btnCopy.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
TableRowCore[] rows = tv.getRows();
StringBuilder sb = new StringBuilder();
sb.append(new SimpleDateFormat("MMM yyyy").format(new Date()));
sb.append("\n");
sb.append("Hits,Client,Bytes Sent,Bytes Received,Bad Bytes\n");
for (TableRowCore row : rows) {
ClientStatsDataSource stat = (ClientStatsDataSource) row.getDataSource();
if (stat == null) {
continue;
}
sb.append(stat.count);
sb.append(",");
sb.append(stat.client.replaceAll(",", ""));
sb.append(",");
sb.append(stat.bytesSent);
sb.append(",");
sb.append(stat.bytesReceived);
sb.append(",");
sb.append(stat.bytesDiscarded);
sb.append("\n");
}
ClipboardCopy.copyToClipBoard(sb.toString());
}
});
Button btnCopyShort = new Button(cBottom, SWT.PUSH);
Utils.setLayoutData(btnCopyShort, new FormData());
btnCopyShort.setText("Copy > 1%");
btnCopyShort.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
StringBuilder sb = new StringBuilder();
sb.append(new SimpleDateFormat("MMM ''yy").format(new Date()));
sb.append("] ");
sb.append(overall.count);
sb.append(": ");
ClientStatsDataSource[] stats;
synchronized (mapData) {
stats = mapData.values().toArray(new ClientStatsDataSource[0]);
}
Arrays.sort(stats, new Comparator<ClientStatsDataSource>() {
@Override
public int compare(ClientStatsDataSource o1, ClientStatsDataSource o2) {
if (o1.count == o2.count) {
return 0;
}
return o1.count > o2.count ? -1 : 1;
}
});
boolean first = true;
for (ClientStatsDataSource stat : stats) {
int pct = (int) (stat.count * 1000 / overall.count);
if (pct < 10) {
continue;
}
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(DisplayFormatters.formatPercentFromThousands(pct));
sb.append(" ");
sb.append(stat.client);
}
Arrays.sort(stats, new Comparator<ClientStatsDataSource>() {
@Override
public int compare(ClientStatsDataSource o1, ClientStatsDataSource o2) {
float v1 = (float) o1.bytesReceived / o1.count;
float v2 = (float) o2.bytesReceived / o2.count;
if (v1 == v2) {
return 0;
}
return v1 > v2 ? -1 : 1;
}
});
int top = 5;
first = true;
sb.append("\nBest Seeders (");
long total = 0;
for (ClientStatsDataSource stat : stats) {
total += stat.bytesReceived;
}
sb.append(DisplayFormatters.formatByteCountToKiBEtc(total, false, true, 0));
sb.append(" Downloaded): ");
for (ClientStatsDataSource stat : stats) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(DisplayFormatters.formatByteCountToKiBEtc(stat.bytesReceived / stat.count, false, true, 0));
sb.append(" per ");
sb.append(stat.client);
sb.append("(x");
sb.append(stat.count);
sb.append(")");
if (--top <= 0) {
break;
}
}
Arrays.sort(stats, new Comparator<ClientStatsDataSource>() {
@Override
public int compare(ClientStatsDataSource o1, ClientStatsDataSource o2) {
float v1 = (float) o1.bytesDiscarded / o1.count;
float v2 = (float) o2.bytesDiscarded / o2.count;
if (v1 == v2) {
return 0;
}
return v1 > v2 ? -1 : 1;
}
});
top = 5;
first = true;
sb.append("\nMost Discarded (");
total = 0;
for (ClientStatsDataSource stat : stats) {
total += stat.bytesDiscarded;
}
sb.append(DisplayFormatters.formatByteCountToKiBEtc(total, false, true, 0));
sb.append(" Discarded): ");
for (ClientStatsDataSource stat : stats) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(DisplayFormatters.formatByteCountToKiBEtc(stat.bytesDiscarded / stat.count, false, true, 0));
sb.append(" per ");
sb.append(stat.client);
sb.append("(x");
sb.append(stat.count);
sb.append(")");
if (--top <= 0) {
break;
}
}
Arrays.sort(stats, new Comparator<ClientStatsDataSource>() {
@Override
public int compare(ClientStatsDataSource o1, ClientStatsDataSource o2) {
float v1 = (float) o1.bytesSent / o1.count;
float v2 = (float) o2.bytesSent / o2.count;
if (v1 == v2) {
return 0;
}
return v1 > v2 ? -1 : 1;
}
});
top = 5;
first = true;
sb.append("\nMost Fed (");
total = 0;
for (ClientStatsDataSource stat : stats) {
total += stat.bytesSent;
}
sb.append(DisplayFormatters.formatByteCountToKiBEtc(total, false, true, 0));
sb.append(" Sent): ");
for (ClientStatsDataSource stat : stats) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(DisplayFormatters.formatByteCountToKiBEtc(stat.bytesSent / stat.count, false, true, 0));
sb.append(" per ");
sb.append(stat.client);
sb.append("(x");
sb.append(stat.count);
sb.append(")");
if (--top <= 0) {
break;
}
}
ClipboardCopy.copyToClipBoard(sb.toString());
}
});
fd = new FormData();
fd.left = new FormAttachment(btnCopy, 5);
Utils.setLayoutData(btnCopyShort, fd);
}
use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.
the class ColumnStream method noIconForYou.
private boolean noIconForYou(Object ds, TableCell cell) {
if (ds instanceof FilesView.FilesViewTreeNode) {
if (!((FilesView.FilesViewTreeNode) ds).isLeaf()) {
return (true);
}
}
if (!(ds instanceof DownloadManager)) {
return false;
}
if (!(cell instanceof TableCellCore)) {
return false;
}
DownloadManager dm = (DownloadManager) ds;
TableRowCore rowCore = ((TableCellCore) cell).getTableRowCore();
return rowCore != null && (dm.getNumFileInfos() > 1 && rowCore.isExpanded());
}
use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.
the class ColumnThumbAndName method cellMouseTrigger.
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE || event.eventType == TableRowMouseEvent.EVENT_MOUSEDOWN) {
TableRow row = event.cell.getTableRow();
if (row == null) {
return;
}
Object data = row.getData(ID_EXPANDOHITAREA);
if (data instanceof Rectangle) {
Rectangle hitArea = (Rectangle) data;
boolean inExpando = hitArea.contains(event.x, event.y);
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE) {
((TableCellCore) event.cell).setCursorID(inExpando ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW);
} else if (inExpando) {
// mousedown
if (row instanceof TableRowCore) {
TableRowCore rowCore = (TableRowCore) row;
rowCore.setExpanded(!rowCore.isExpanded());
}
}
}
}
}
Aggregations