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
impl Peer
Sourcepub fn connect(
ip: IpAddr,
port: u16,
network: Network,
version: Version,
connectable: fn(&Version) -> bool,
) -> Arc<Peer>
pub fn connect( ip: IpAddr, port: u16, network: Network, version: Version, connectable: fn(&Version) -> bool, ) -> Arc<Peer>
Creates a new peer and begins connecting
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Disconects and disables the peer
Sourcepub fn connected_event(&self) -> &impl Observable<PeerConnected>
pub fn connected_event(&self) -> &impl Observable<PeerConnected>
Returns a Single that emits a message when connected
Sourcepub fn disconnected_event(&self) -> &impl Observable<PeerDisconnected>
pub fn disconnected_event(&self) -> &impl Observable<PeerDisconnected>
Returns a Single that emits a message when connected
Sourcepub fn messages(&self) -> &impl Observable<PeerMessage>
pub fn messages(&self) -> &impl Observable<PeerMessage>
Returns an Observable that emits network messages
Sourcepub fn time_delta(&self) -> i64
pub fn time_delta(&self) -> i64
Returns the time difference in seconds between our time and theirs, which is valid after connecting
Sourcepub fn sendheaders(&self) -> bool
pub fn sendheaders(&self) -> bool
Returns whether this peer may announce new blocks with headers instead of inv