1// Copyright 2024 New Vector Ltd.
2// Copyright 2022-2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
67#![deny(rustdoc::missing_crate_level_docs)]
8#![allow(clippy::module_name_repetitions)]
910//! An utility crate to build flexible [`hyper`] listeners, with optional TLS
11//! and proxy protocol support.
1213use self::{maybe_tls::TlsStreamInfo, proxy_protocol::ProxyProtocolV1Info};
1415pub mod maybe_tls;
16pub mod proxy_protocol;
17pub mod rewind;
18pub mod server;
19pub mod unix_or_tcp;
2021#[derive(Debug, Clone)]
22pub struct ConnectionInfo {
23 tls: Option<TlsStreamInfo>,
24 proxy: Option<ProxyProtocolV1Info>,
25 net_peer_addr: Option<std::net::SocketAddr>,
26}
2728impl ConnectionInfo {
29/// Returns informations about the TLS connection. Returns [`None`] if the
30 /// connection was not TLS.
31#[must_use]
32pub fn get_tls_ref(&self) -> Option<&TlsStreamInfo> {
33self.tls.as_ref()
34 }
3536/// Returns informations about the proxy protocol connection. Returns
37 /// [`None`] if the connection was not using the proxy protocol.
38#[must_use]
39pub fn get_proxy_ref(&self) -> Option<&ProxyProtocolV1Info> {
40self.proxy.as_ref()
41 }
4243/// Returns the remote peer address. Returns [`None`] if the connection was
44 /// established via a UNIX domain socket.
45#[must_use]
46pub fn get_peer_addr(&self) -> Option<std::net::SocketAddr> {
47self.net_peer_addr
48 }
49}