Search in sources :

Example 1 with TransportStartpoint

use of com.biglybt.core.networkmanager.TransportStartpoint in project BiglyBT by BiglySoftware.

the class TransferStatsView method refreshConnectionPanel.

private void refreshConnectionPanel() {
    if (global_manager == null) {
        return;
    }
    int total_connections = 0;
    int total_con_queued = 0;
    int total_con_blocked = 0;
    int total_con_unchoked = 0;
    int total_data_queued = 0;
    int total_in = 0;
    List<DownloadManager> dms = global_manager.getDownloadManagers();
    for (DownloadManager dm : dms) {
        PEPeerManager pm = dm.getPeerManager();
        if (pm != null) {
            total_data_queued += pm.getBytesQueuedForUpload();
            total_connections += pm.getNbPeers() + pm.getNbSeeds();
            total_con_queued += pm.getNbPeersWithUploadQueued();
            total_con_blocked += pm.getNbPeersWithUploadBlocked();
            total_con_unchoked += pm.getNbPeersUnchoked();
            total_in += pm.getNbRemoteTCPConnections() + pm.getNbRemoteUDPConnections() + pm.getNbRemoteUTPConnections();
        }
    }
    connection_label.setText(MessageText.getString("SpeedView.stats.con_details", new String[] { String.valueOf(total_connections) + "[" + MessageText.getString("label.in").toLowerCase() + ":" + total_in + "]", String.valueOf(total_con_unchoked), String.valueOf(total_con_queued), String.valueOf(total_con_blocked) }));
    connection_graphic.addIntsValue(new int[] { total_connections, total_con_unchoked, total_con_queued, total_con_blocked });
    upload_label.setText(MessageText.getString("SpeedView.stats.upload_details", new String[] { DisplayFormatters.formatByteCountToKiBEtc(total_data_queued) }));
    upload_graphic.addIntValue(total_data_queued);
    upload_graphic.refresh(false);
    connection_graphic.refresh(false);
    if (con_folder.getSelectionIndex() == 1) {
        long now = SystemTime.getMonotonousTime();
        if (now - last_route_update >= 2 * 1000) {
            last_route_update = now;
            NetworkAdmin na = NetworkAdmin.getSingleton();
            Map<InetAddress, String> ip_to_name_map = new HashMap<>();
            Map<String, RouteInfo> name_to_route_map = new HashMap<>();
            RouteInfo udp_info = null;
            RouteInfo unknown_info = null;
            List<PRUDPPacketHandler> udp_handlers = PRUDPPacketHandlerFactory.getHandlers();
            InetAddress udp_bind_ip = null;
            for (PRUDPPacketHandler handler : udp_handlers) {
                if (handler.hasPrimordialHandler()) {
                    udp_bind_ip = handler.getBindIP();
                    if (udp_bind_ip != null) {
                        if (udp_bind_ip.isAnyLocalAddress()) {
                            udp_bind_ip = null;
                        }
                    }
                }
            }
            for (DownloadManager dm : dms) {
                PEPeerManager pm = dm.getPeerManager();
                if (pm != null) {
                    List<PEPeer> peers = pm.getPeers();
                    for (PEPeer p : peers) {
                        NetworkConnection nc = PluginCoreUtils.unwrap(p.getPluginConnection());
                        boolean done = false;
                        if (nc != null) {
                            Transport transport = nc.getTransport();
                            if (transport != null) {
                                InetSocketAddress notional_address = nc.getEndpoint().getNotionalAddress();
                                String ip = AddressUtils.getHostAddress(notional_address);
                                String network = AENetworkClassifier.categoriseAddress(ip);
                                if (network == AENetworkClassifier.AT_PUBLIC) {
                                    if (transport.isTCP()) {
                                        TransportStartpoint start = transport.getTransportStartpoint();
                                        if (start != null) {
                                            InetSocketAddress socket_address = start.getProtocolStartpoint().getAddress();
                                            if (socket_address != null) {
                                                InetAddress address = socket_address.getAddress();
                                                String name;
                                                if (address.isAnyLocalAddress()) {
                                                    name = "* (TCP)";
                                                } else {
                                                    name = ip_to_name_map.get(address);
                                                }
                                                if (name == null) {
                                                    name = na.classifyRoute(address);
                                                    ip_to_name_map.put(address, name);
                                                }
                                                if (transport.isSOCKS()) {
                                                    name += " (SOCKS)";
                                                }
                                                RouteInfo info = name_to_route_map.get(name);
                                                if (info == null) {
                                                    info = new RouteInfo(name);
                                                    name_to_route_map.put(name, info);
                                                    route_last_seen.put(name, now);
                                                }
                                                info.update(p);
                                                done = true;
                                            }
                                        }
                                    } else {
                                        if (udp_bind_ip != null) {
                                            RouteInfo info;
                                            String name = ip_to_name_map.get(udp_bind_ip);
                                            if (name == null) {
                                                name = na.classifyRoute(udp_bind_ip);
                                                ip_to_name_map.put(udp_bind_ip, name);
                                                info = name_to_route_map.get(name);
                                                route_last_seen.put(name, now);
                                                if (info == null) {
                                                    info = new RouteInfo(name);
                                                    name_to_route_map.put(name, info);
                                                }
                                            } else {
                                                info = name_to_route_map.get(name);
                                            }
                                            info.update(p);
                                            done = true;
                                        } else {
                                            if (udp_info == null) {
                                                udp_info = new RouteInfo("* (UDP)");
                                                name_to_route_map.put(udp_info.getName(), udp_info);
                                                route_last_seen.put(udp_info.getName(), now);
                                            }
                                            udp_info.update(p);
                                            done = true;
                                        }
                                    }
                                } else {
                                    RouteInfo info = name_to_route_map.get(network);
                                    if (info == null) {
                                        info = new RouteInfo(network);
                                        name_to_route_map.put(network, info);
                                        route_last_seen.put(network, now);
                                    }
                                    info.update(p);
                                    done = true;
                                }
                            }
                        }
                        if (!done) {
                            if (unknown_info == null) {
                                unknown_info = new RouteInfo("Pending");
                                name_to_route_map.put(unknown_info.getName(), unknown_info);
                                route_last_seen.put(unknown_info.getName(), now);
                            }
                            unknown_info.update(p);
                        }
                    }
                }
            }
            List<RouteInfo> rows = new ArrayList<>();
            Iterator<Map.Entry<String, Long>> it = route_last_seen.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Long> entry = it.next();
                long when = entry.getValue();
                if (now - when > 60 * 1000) {
                    it.remove();
                } else if (when != now) {
                    rows.add(new RouteInfo(entry.getKey()));
                }
            }
            rows.addAll(name_to_route_map.values());
            Collections.sort(rows, new Comparator<RouteInfo>() {

                @Override
                public int compare(RouteInfo o1, RouteInfo o2) {
                    String n1 = o1.getName();
                    String n2 = o2.getName();
                    // wildcard and pending to the bottom
                    if (n1.startsWith("*") || n1.equals("Pending")) {
                        n1 = "zzzz" + n1;
                    }
                    if (n2.startsWith("*") || n2.equals("Pending")) {
                        n2 = "zzzz" + n2;
                    }
                    return (n1.compareTo(n2));
                }
            });
            buildRouteComponent(rows.size());
            for (int i = 0; i < rows.size(); i++) {
                RouteInfo info = rows.get(i);
                route_labels[i][0].setText(info.getName());
                route_labels[i][1].setText(info.getIncomingString());
                route_labels[i][2].setText(info.getOutgoingString());
            }
            buildRouteComponent(rows.size());
        }
    }
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) DownloadManager(com.biglybt.core.download.DownloadManager) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) TransportStartpoint(com.biglybt.core.networkmanager.TransportStartpoint) NetworkConnection(com.biglybt.core.networkmanager.NetworkConnection) Point(org.eclipse.swt.graphics.Point) TransportStartpoint(com.biglybt.core.networkmanager.TransportStartpoint) PRUDPPacketHandler(com.biglybt.net.udp.uc.PRUDPPacketHandler) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Transport(com.biglybt.core.networkmanager.Transport) InetAddress(java.net.InetAddress) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)1 NetworkConnection (com.biglybt.core.networkmanager.NetworkConnection)1 Transport (com.biglybt.core.networkmanager.Transport)1 TransportStartpoint (com.biglybt.core.networkmanager.TransportStartpoint)1 NetworkAdmin (com.biglybt.core.networkmanager.admin.NetworkAdmin)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 PRUDPPacketHandler (com.biglybt.net.udp.uc.PRUDPPacketHandler)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Point (org.eclipse.swt.graphics.Point)1