Mercurial > core / rust/lib/net/src/connection.rs
changeset 698: |
96958d3eb5b0 |
parent: |
0ccbbd142694
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
4 net::{IpAddr, SocketAddr}, 7 #[derive(PartialEq, Hash, Eq, Clone, PartialOrd, Ord, Debug, Copy)] 14 pub fn from_str(string: &str) -> Option<Self> { 15 match string.to_ascii_uppercase().as_str() { 16 "TCP" => Some(Protocol::Tcp), 17 "UDP" => Some(Protocol::Udp), 23 impl fmt::Display for Protocol { 24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 26 Protocol::Tcp => write!(f, "tcp"), 27 Protocol::Udp => write!(f, "udp"), 32 #[derive(Clone, Ord, PartialOrd, PartialEq, Eq, Hash, Debug, Copy)] 38 #[derive(PartialEq, Hash, Eq, Clone, PartialOrd, Ord, Debug, Copy)] 39 pub struct LocalSocket { 42 pub protocol: Protocol, 45 #[derive(PartialEq, Hash, Eq, Clone, PartialOrd, Ord, Debug, Copy)] 46 pub struct Connection { 47 pub local_socket: LocalSocket, 48 pub remote_socket: Socket, 51 pub fn display_ip_or_host( 53 ip_to_host: &HashMap<IpAddr, String>, 55 match ip_to_host.get(&ip) { 56 Some(host) => host.clone(), 57 None => ip.to_string(), 61 pub fn display_connection_string( 62 connection: &Connection, 63 ip_to_host: &HashMap<IpAddr, String>, 67 "<{}>:{} => {}:{} ({})", 69 connection.local_socket.port, 70 display_ip_or_host(connection.remote_socket.ip, ip_to_host), 71 connection.remote_socket.port, 72 connection.local_socket.protocol, 78 remote_socket: SocketAddr, 84 remote_socket: Socket { 85 ip: remote_socket.ip(), 86 port: remote_socket.port(), 88 local_socket: LocalSocket { 97 /// DL/UL stats for network interfaces 99 pub struct ConnectionInfo { 100 pub interface_name: String, 101 pub total_bytes_downloaded: u128, 102 pub total_bytes_uploaded: u128,