Peer

Struct Peer 

Source
pub struct Peer {
    pub id: ProcessUniqueId,
    pub ip: IpAddr,
    pub port: u16,
    pub network: Network,
    /* private fields */
}
Expand description

Node on the network to send and receive messages

It will setup a connection, respond to pings, and store basic properties about the connection, but any real logic to process messages will be handled outside. Network messages received will be published to an observable on the peer’s receiver thread. Messages may be sent via send() from any thread. Once shutdown, the Peer may no longer be used.

Fields§

§id: ProcessUniqueId

Unique id for this connection

§ip: IpAddr

IP address

§port: u16

Port

§network: Network

Network

Implementations§

Source§

impl Peer

Source

pub fn connect( ip: IpAddr, port: u16, network: Network, version: Version, connectable: fn(&Version) -> bool, ) -> Arc<Peer>

Creates a new peer and begins connecting

Source

pub fn send(&self, message: &Message) -> Result<()>

Sends a message to the peer

Source

pub fn disconnect(&self)

Disconects and disables the peer

Source

pub fn connected_event(&self) -> &impl Observable<PeerConnected>

Returns a Single that emits a message when connected

Source

pub fn disconnected_event(&self) -> &impl Observable<PeerDisconnected>

Returns a Single that emits a message when connected

Source

pub fn messages(&self) -> &impl Observable<PeerMessage>

Returns an Observable that emits network messages

Source

pub fn connected(&self) -> bool

Returns whether the peer is connected

Source

pub fn time_delta(&self) -> i64

Returns the time difference in seconds between our time and theirs, which is valid after connecting

Source

pub fn minfee(&self) -> u64

Returns the minimum fee this peer accepts in sats/1000bytes

Source

pub fn sendheaders(&self) -> bool

Returns whether this peer may announce new blocks with headers instead of inv

Source

pub fn sendcmpct(&self) -> bool

Returns whether compact blocks are supported

Source

pub fn version(&self) -> Result<Version>

Gets the version message received during the handshake

Trait Implementations§

Source§

impl Debug for Peer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Peer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Hash for Peer

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Peer

Source§

fn eq(&self, other: &Peer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Peer

Auto Trait Implementations§

§

impl !Freeze for Peer

§

impl RefUnwindSafe for Peer

§

impl Send for Peer

§

impl Sync for Peer

§

impl Unpin for Peer

§

impl UnwindSafe for Peer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.