long upSpeedSetMax = 0;
long maxUp = 0;
if (hasSelection){
for (int i = 0; i < peers.length; i++) {
PEPeer peer = (PEPeer)peers[i];
try {
int maxul = peer.getStats().getUploadRateLimitBytesPerSecond();
maxUp += maxul * 4;
if (maxul == 0) {
upSpeedUnlimited = true;
}else{
if ( maxul > upSpeedSetMax ){
upSpeedSetMax = maxul;
}
}
if (maxul == -1) {
maxul = 0;
upSpeedDisabled = true;
}
totalUpSpeed += maxul;
int maxdl = peer.getStats().getDownloadRateLimitBytesPerSecond();
maxDown += maxdl * 4;
if (maxdl == 0) {
downSpeedUnlimited = true;
}else{
if ( maxdl > downSpeedSetMax ){
downSpeedSetMax = maxdl;
}
}
if (maxdl == -1) {
maxdl = 0;
downSpeedDisabled = true;
}
totalDownSpeed += maxdl;
} catch (Exception ex) {
Debug.printStackTrace(ex);
}
}
}
if (download_specific) {
final MenuItem block_item = new MenuItem(menu, SWT.CHECK);
PEPeer peer = (PEPeer) tv.getFirstSelectedDataSource();
if ( peer == null || peer.getManager().getDiskManager().getRemainingExcludingDND() > 0 ){
// disallow peer upload blocking when downloading
block_item.setSelection(false);
block_item.setEnabled(false);
}
else {
block_item.setEnabled(true);
block_item.setSelection(peer.isSnubbed());
}
final boolean newSnubbedValue = !peer.isSnubbed();
Messages.setLanguageText(block_item, "PeersView.menu.blockupload");
block_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
public void run(TableRowCore row) {
PEPeer peer = ((PEPeer) row.getDataSource(true));
peer.setSnubbed(newSnubbedValue);
}
});
}
final MenuItem ban_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(ban_item, "PeersView.menu.kickandban");
ban_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
public void run(TableRowCore row) {
PEPeer peer = (PEPeer) row.getDataSource(true);
String msg = MessageText.getString("PeersView.menu.kickandban.reason");
IpFilterManagerFactory.getSingleton().getIPFilter().ban(peer.getIp(),
msg, true );
peer.getManager().removePeer(peer);
}
});
// === advanced menu ===