Search in sources :

Example 1 with AEProxySelector

use of com.biglybt.core.proxy.AEProxySelector in project BiglyBT by BiglySoftware.

the class TransferStatsView method refreshGeneral.

private void refreshGeneral() {
    if (stats == null) {
        return;
    }
    int now_prot_down_rate = stats.getProtocolReceiveRate();
    int now_prot_up_rate = stats.getProtocolSendRate();
    int now_total_down_rate = stats.getDataReceiveRate() + now_prot_down_rate;
    int now_total_up_rate = stats.getDataSendRate() + now_prot_up_rate;
    float now_perc_down = (float) (now_prot_down_rate * 100) / (now_total_down_rate == 0 ? 1 : now_total_down_rate);
    float now_perc_up = (float) (now_prot_up_rate * 100) / (now_total_up_rate == 0 ? 1 : now_total_up_rate);
    nowDown.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(now_total_down_rate) + "  (" + DisplayFormatters.formatByteCountToKiBEtcPerSec(now_prot_down_rate) + ", " + formatter.format(now_perc_down) + "%)");
    nowUp.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(now_total_up_rate) + "  (" + DisplayFormatters.formatByteCountToKiBEtcPerSec(now_prot_up_rate) + ", " + formatter.format(now_perc_up) + "%)");
    // /////////////////////////////////////////////////////////////////////
    long session_prot_received = stats.getTotalProtocolBytesReceived();
    long session_prot_sent = stats.getTotalProtocolBytesSent();
    long session_total_received = stats.getTotalDataBytesReceived() + session_prot_received;
    long session_total_sent = stats.getTotalDataBytesSent() + session_prot_sent;
    float session_perc_received = (float) (session_prot_received * 100) / (session_total_received == 0 ? 1 : session_total_received);
    float session_perc_sent = (float) (session_prot_sent * 100) / (session_total_sent == 0 ? 1 : session_total_sent);
    sessionDown.setText(DisplayFormatters.formatByteCountToKiBEtc(session_total_received) + "  (" + DisplayFormatters.formatByteCountToKiBEtc(session_prot_received) + ", " + formatter.format(session_perc_received) + "%)");
    sessionUp.setText(DisplayFormatters.formatByteCountToKiBEtc(session_total_sent) + "  (" + DisplayFormatters.formatByteCountToKiBEtc(session_prot_sent) + ", " + formatter.format(session_perc_sent) + "%)");
    if (totalStats != null) {
        long mark = totalStats.getMarkTime();
        if (mark > 0) {
            Messages.setLanguageText(totalLabel.getWidget(), "SpeedView.stats.total.since", new String[] { new SimpleDateFormat().format(new Date(mark)) });
        } else {
            Messages.setLanguageText(totalLabel.getWidget(), "SpeedView.stats.total");
        }
        long dl_bytes = totalStats.getDownloadedBytes(true);
        long ul_bytes = totalStats.getUploadedBytes(true);
        totalDown.setText(DisplayFormatters.formatByteCountToKiBEtc(dl_bytes));
        totalUp.setText(DisplayFormatters.formatByteCountToKiBEtc(ul_bytes));
        long session_up_time = totalStats.getSessionUpTime();
        long total_up_time = totalStats.getTotalUpTime(true);
        sessionTime.setText(session_up_time == 0 ? "" : DisplayFormatters.formatETA(session_up_time));
        totalTime.setText(total_up_time == 0 ? "" : DisplayFormatters.formatETA(total_up_time));
        long t_ratio_raw = (1000 * ul_bytes / (dl_bytes == 0 ? 1 : dl_bytes));
        long s_ratio_raw = (1000 * session_total_sent / (session_total_received == 0 ? 1 : session_total_received));
        String t_ratio = "";
        String s_ratio = "";
        String partial = String.valueOf(t_ratio_raw % 1000);
        while (partial.length() < 3) {
            partial = "0" + partial;
        }
        t_ratio = (t_ratio_raw / 1000) + "." + partial;
        partial = String.valueOf(s_ratio_raw % 1000);
        while (partial.length() < 3) {
            partial = "0" + partial;
        }
        s_ratio = (s_ratio_raw / 1000) + "." + partial;
        total_ratio.setText(t_ratio);
        session_ratio.setText(s_ratio);
    }
    AEProxySelector proxy_selector = AEProxySelectorFactory.getSelector();
    Proxy proxy = proxy_selector.getActiveProxy();
    socksMore.setEnabled(proxy != null);
    if (Constants.isOSX) {
        socksMore.setForeground(proxy == null ? Colors.light_grey : Colors.blue);
    }
    socksState.setText(proxy == null ? MessageText.getString("label.inactive") : ((InetSocketAddress) proxy.address()).getHostName());
    if (proxy == null) {
        socksCurrent.setText("");
        socksFails.setText("");
    } else {
        long last_con = proxy_selector.getLastConnectionTime();
        long last_fail = proxy_selector.getLastFailTime();
        int total_cons = proxy_selector.getConnectionCount();
        int total_fails = proxy_selector.getFailCount();
        long now = SystemTime.getMonotonousTime();
        long con_ago = now - last_con;
        long fail_ago = now - last_fail;
        String state_str;
        if (last_fail < 0) {
            state_str = "PeerManager.status.ok";
        } else {
            if (fail_ago > 60 * 1000) {
                if (con_ago < fail_ago) {
                    state_str = "PeerManager.status.ok";
                } else {
                    state_str = "SpeedView.stats.unknown";
                }
            } else {
                state_str = "ManagerItem.error";
            }
        }
        socksCurrent.setText(MessageText.getString(state_str) + ", con=" + total_cons);
        long fail_ago_secs = fail_ago / 1000;
        if (fail_ago_secs == 0) {
            fail_ago_secs = 1;
        }
        socksFails.setText(last_fail < 0 ? "" : (DisplayFormatters.formatETA(fail_ago_secs, false) + " " + MessageText.getString("label.ago") + ", tot=" + total_fails));
    }
}
Also used : Proxy(java.net.Proxy) AEProxySelector(com.biglybt.core.proxy.AEProxySelector) InetSocketAddress(java.net.InetSocketAddress) SimpleDateFormat(java.text.SimpleDateFormat) Point(org.eclipse.swt.graphics.Point) TransportStartpoint(com.biglybt.core.networkmanager.TransportStartpoint) Date(java.util.Date)

Example 2 with AEProxySelector

use of com.biglybt.core.proxy.AEProxySelector in project BiglyBT by BiglySoftware.

the class PrivacyView method showSOCKSInfo.

private void showSOCKSInfo() {
    AEProxySelector proxy_selector = AEProxySelectorFactory.getSelector();
    String info = proxy_selector.getInfo();
    TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("proxy.info.title"), null, info, false);
}
Also used : AEProxySelector(com.biglybt.core.proxy.AEProxySelector) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow)

Example 3 with AEProxySelector

use of com.biglybt.core.proxy.AEProxySelector in project BiglyBT by BiglySoftware.

the class PrivacyView method updateVPNSocks.

private void updateVPNSocks() {
    AEProxySelector proxy_selector = AEProxySelectorFactory.getSelector();
    Proxy proxy = proxy_selector.getActiveProxy();
    socks_more.setEnabled(proxy != null);
    if (Constants.isOSX) {
        socks_more.setForeground(proxy == null ? Colors.light_grey : Colors.blue);
    }
    socks_state.setText(proxy == null ? MessageText.getString("label.inactive") : ((InetSocketAddress) proxy.address()).getHostName());
    if (proxy == null) {
        socks_current.setText("");
        socks_fails.setText("");
    } else {
        long last_con = proxy_selector.getLastConnectionTime();
        long last_fail = proxy_selector.getLastFailTime();
        int total_cons = proxy_selector.getConnectionCount();
        int total_fails = proxy_selector.getFailCount();
        long now = SystemTime.getMonotonousTime();
        long con_ago = now - last_con;
        long fail_ago = now - last_fail;
        String state_str;
        if (last_fail < 0) {
            state_str = "PeerManager.status.ok";
        } else {
            if (fail_ago > 60 * 1000) {
                if (con_ago < fail_ago) {
                    state_str = "PeerManager.status.ok";
                } else {
                    state_str = "SpeedView.stats.unknown";
                }
            } else {
                state_str = "ManagerItem.error";
            }
        }
        socks_current.setText(MessageText.getString(state_str) + ", con=" + total_cons);
        long fail_ago_secs = fail_ago / 1000;
        if (fail_ago_secs == 0) {
            fail_ago_secs = 1;
        }
        socks_fails.setText(last_fail < 0 ? "" : (DisplayFormatters.formatETA(fail_ago_secs, false) + " " + MessageText.getString("label.ago") + ", tot=" + total_fails));
    }
    vpn_info.setText(NetworkAdmin.getSingleton().getBindStatus());
}
Also used : Proxy(java.net.Proxy) AEProxySelector(com.biglybt.core.proxy.AEProxySelector) InetSocketAddress(java.net.InetSocketAddress) Point(org.eclipse.swt.graphics.Point)

Example 4 with AEProxySelector

use of com.biglybt.core.proxy.AEProxySelector in project BiglyBT by BiglySoftware.

the class PrivacyView method updatePeersEtc.

private void updatePeersEtc(final DownloadManager dm) {
    final PEPeerManager pm;
    if (dm != null) {
        pm = dm.getPeerManager();
    } else {
        pm = null;
    }
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            if (peer_info == null || peer_info.isDisposed()) {
                return;
            }
            if (pm == null) {
                peer_info.setText(dm == null ? "" : MessageText.getString("privacy.view.dl.not.running"));
            } else {
                AEProxySelector proxy_selector = AEProxySelectorFactory.getSelector();
                Proxy proxy = proxy_selector.getActiveProxy();
                boolean socks_bad_incoming = false;
                List<PEPeer> peers = pm.getPeers();
                String[] all_nets = AENetworkClassifier.AT_NETWORKS;
                int[] counts = new int[all_nets.length];
                int incoming = 0;
                int outgoing = 0;
                int outgoing_connected = 0;
                for (PEPeer peer : peers) {
                    String net = PeerUtils.getNetwork(peer);
                    for (int i = 0; i < all_nets.length; i++) {
                        if (all_nets[i] == net) {
                            counts[i]++;
                            break;
                        }
                    }
                    boolean is_incoming = peer.isIncoming();
                    if (is_incoming) {
                        incoming++;
                    } else {
                        outgoing++;
                        if (peer.getPeerState() == PEPeer.TRANSFERING) {
                            outgoing_connected++;
                        }
                    }
                    if (proxy != null) {
                        if (is_incoming) {
                            if (!peer.isLANLocal()) {
                                try {
                                    if (InetAddress.getByAddress(HostNameToIPResolver.hostAddressToBytes(peer.getIp())).isLoopbackAddress()) {
                                        continue;
                                    }
                                } catch (Throwable e) {
                                }
                                socks_bad_incoming = true;
                                break;
                            }
                        }
                    }
                }
                String str = "";
                for (int i = 0; i < all_nets.length; i++) {
                    int num = counts[i];
                    if (num > 0) {
                        str += (str.length() == 0 ? "" : ", ") + all_nets[i] + "=" + num;
                    }
                }
                if (str.length() == 0) {
                    str = MessageText.getString("privacy.view.no.peers");
                } else {
                    str += ", " + MessageText.getString("label.incoming") + "=" + incoming + ", " + MessageText.getString("label.outgoing") + "=" + outgoing_connected + "/" + outgoing;
                }
                if (socks_bad_incoming) {
                    str += " (" + MessageText.getString("privacy.view.non.local.peer") + ")";
                }
                peer_info.setText(str);
            }
            updateVPNSocks();
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Proxy(java.net.Proxy) PEPeer(com.biglybt.core.peer.PEPeer) AEProxySelector(com.biglybt.core.proxy.AEProxySelector) PEPeerManager(com.biglybt.core.peer.PEPeerManager) List(java.util.List)

Example 5 with AEProxySelector

use of com.biglybt.core.proxy.AEProxySelector in project BiglyBT by BiglySoftware.

the class TransferStatsView method showSOCKSInfo.

private void showSOCKSInfo() {
    AEProxySelector proxy_selector = AEProxySelectorFactory.getSelector();
    String info = proxy_selector.getInfo();
    TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("proxy.info.title"), null, info, false);
}
Also used : AEProxySelector(com.biglybt.core.proxy.AEProxySelector) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow)

Aggregations

AEProxySelector (com.biglybt.core.proxy.AEProxySelector)5 Proxy (java.net.Proxy)3 TextViewerWindow (com.biglybt.ui.swt.TextViewerWindow)2 InetSocketAddress (java.net.InetSocketAddress)2 Point (org.eclipse.swt.graphics.Point)2 TransportStartpoint (com.biglybt.core.networkmanager.TransportStartpoint)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 AERunnable (com.biglybt.core.util.AERunnable)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1