feat(net/peer): add peer with udp socket (#9156)

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
Delweng
2024-06-29 17:02:09 +08:00
committed by GitHub
parent 57c4f7e570
commit b93e70c429
10 changed files with 221 additions and 88 deletions

View File

@ -92,6 +92,17 @@ impl NodeRecord {
Self { address: addr.ip(), tcp_port: addr.port(), udp_port: addr.port(), id }
}
/// Creates a new record from an ip address and ports.
pub fn new_with_ports(
ip_addr: IpAddr,
tcp_port: u16,
udp_port: Option<u16>,
id: PeerId,
) -> Self {
let udp_port = udp_port.unwrap_or(tcp_port);
Self { address: ip_addr, tcp_port, udp_port, id }
}
/// The TCP socket address of this node
#[must_use]
pub const fn tcp_addr(&self) -> SocketAddr {