nakamoto_common/
p2p.rs

1//! P2P-related types
2use std::net;
3
4pub mod peer;
5
6/// Communication domain of a network socket.
7#[derive(Debug, Copy, Clone, Eq, PartialEq)]
8pub enum Domain {
9    /// IPv4.
10    IPV4,
11    /// IPv6.
12    IPV6,
13}
14
15impl Domain {
16    /// All domains.
17    pub fn all() -> Vec<Self> {
18        vec![Self::IPV4, Self::IPV6]
19    }
20
21    /// Returns the domain for `address`.
22    pub const fn for_address(address: &net::SocketAddr) -> Domain {
23        match address {
24            net::SocketAddr::V4(_) => Domain::IPV4,
25            net::SocketAddr::V6(_) => Domain::IPV6,
26        }
27    }
28}