pub struct TrustedPeer {
pub address: AddrV2,
pub port: Option<u16>,
pub known_services: ServiceFlags,
}Expand description
A peer on the Bitcoin P2P network
§Building peers
use std::net::{IpAddr, Ipv4Addr};
use kyoto::{TrustedPeer, ServiceFlags, AddrV2};
let local_host = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
let mut trusted = TrustedPeer::from_ip(local_host);
// Optionally set the known services of the peer later.
trusted.set_services(ServiceFlags::P2P_V2);
let local_host = Ipv4Addr::new(0, 0, 0, 0);
// Or construct a trusted peer directly.
let trusted = TrustedPeer::new(AddrV2::Ipv4(local_host), None, ServiceFlags::P2P_V2);
// Or implicitly with `into`
let local_host = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
let trusted: TrustedPeer = (local_host, None).into();Fields§
§address: AddrV2The IP address of the remote node to connect to.
port: Option<u16>The port to establish a TCP connection. If none is provided, the typical Bitcoin Core port is used as the default.
known_services: ServiceFlagsThe services this peer is known to offer before starting the node.
Implementations§
Source§impl TrustedPeer
impl TrustedPeer
Sourcepub fn new(address: AddrV2, port: Option<u16>, services: ServiceFlags) -> Self
pub fn new(address: AddrV2, port: Option<u16>, services: ServiceFlags) -> Self
Create a new trusted peer.
Sourcepub fn from_ip(ip_addr: impl Into<IpAddr>) -> Self
pub fn from_ip(ip_addr: impl Into<IpAddr>) -> Self
Create a new trusted peer using the default port for the network.
Sourcepub fn from_socket_addr(socket_addr: impl Into<SocketAddr>) -> Self
pub fn from_socket_addr(socket_addr: impl Into<SocketAddr>) -> Self
Create a new peer from a known address and port.
Sourcepub fn services(&self) -> ServiceFlags
pub fn services(&self) -> ServiceFlags
The services this peer is known to offer.
Sourcepub fn set_services(&mut self, services: ServiceFlags)
pub fn set_services(&mut self, services: ServiceFlags)
Set the known services for this trusted peer.
Trait Implementations§
Source§impl Clone for TrustedPeer
impl Clone for TrustedPeer
Source§fn clone(&self) -> TrustedPeer
fn clone(&self) -> TrustedPeer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TrustedPeer
impl Debug for TrustedPeer
Source§impl From<IpAddr> for TrustedPeer
impl From<IpAddr> for TrustedPeer
Source§impl From<SocketAddr> for TrustedPeer
impl From<SocketAddr> for TrustedPeer
Source§fn from(value: SocketAddr) -> Self
fn from(value: SocketAddr) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for TrustedPeer
impl RefUnwindSafe for TrustedPeer
impl Send for TrustedPeer
impl Sync for TrustedPeer
impl Unpin for TrustedPeer
impl UnwindSafe for TrustedPeer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more