#[non_exhaustive]pub struct ConnectionInfo {Show 14 fields
pub id: ConnectionId,
pub listener: Option<ListenerId>,
pub worker: WorkerId,
pub transport: Transport,
pub origin: Origin,
pub local: Endpoint,
pub peer: Endpoint,
pub real_peer: Option<SocketAddr>,
pub proxy: Option<Arc<ProxyFacts>>,
pub peer_credentials: Option<PeerCredentials>,
pub tls: Option<Arc<TlsInfo>>,
pub lane: Lane,
pub gate: GateTag,
pub accepted_at: Instant,
}Expand description
What net-io knows about one connection, built at accept and completed as the handshake reveals more. It holds no heap memory.
§Examples
let info = net_io::ConnectionInfo::for_testing("192.0.2.1:5000".parse().unwrap());
assert_eq!(info.client_addr().unwrap().port(), 5000);
let key = info.client_key(net_io::PrefixPolicy::DEFAULT).unwrap();
assert_eq!(key.to_string(), "192.0.2.1/32");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: ConnectionIdThe connection’s id.
listener: Option<ListenerId>The listener that accepted it, if any.
worker: WorkerIdThe worker that owns it.
transport: TransportThe kind of socket.
origin: OriginHow it came to exist.
local: EndpointOur end.
peer: EndpointThe socket peer, normalized.
real_peer: Option<SocketAddr>The real client from a trusted PROXY header, normalized.
proxy: Option<Arc<ProxyFacts>>Facts copied from a trusted PROXY header (pooled per worker, no allocation after warm-up).
peer_credentials: Option<PeerCredentials>Who is on the other end of a local socket.
tls: Option<Arc<TlsInfo>>TLS facts after the handshake (pooled per worker, no allocation after warm-up).
lane: LaneThe lane the gate assigned.
gate: GateTagThe gate’s tag for this connection.
accepted_at: InstantWhen the connection was accepted or dialed.
Implementations§
Source§impl ConnectionInfo
impl ConnectionInfo
Sourcepub fn client_addr(&self) -> Option<SocketAddr>
pub fn client_addr(&self) -> Option<SocketAddr>
The client address: the real peer from a trusted PROXY header when set, otherwise the IP peer.
Sourcepub fn client_key(&self, policy: PrefixPolicy) -> Option<PrefixKey>
pub fn client_key(&self, policy: PrefixPolicy) -> Option<PrefixKey>
The client address grouped under policy.
Sourcepub fn socket_peer(&self) -> Option<SocketAddr>
pub fn socket_peer(&self) -> Option<SocketAddr>
The socket peer, ignoring any PROXY header.
Sourcepub fn for_testing(peer: SocketAddr) -> ConnectionInfo
pub fn for_testing(peer: SocketAddr) -> ConnectionInfo
A connection fact set attached to no socket, for testing gates and sessions.
The id comes from the process counter, so it never collides with a real connection. Fields are public to adjust.