pub struct P2P { /* private fields */ }Expand description
The main struct coordinating all P2P activity.
Implementations§
Source§impl P2P
impl P2P
Sourcepub fn set_height(&self, block_height: u32)
pub fn set_height(&self, block_height: u32)
Set the latest block height to advertise to peers.
Sourcepub fn shutdown(&self) -> Result<(), Error>
pub fn shutdown(&self) -> Result<(), Error>
Shut down the p2p operation. Any subsequent call will be a no-op.
Sourcepub fn add_peer<S: IntoMioTcpStream>(
&self,
conn: S,
peer_type: PeerType,
) -> Result<PeerId, Error>
pub fn add_peer<S: IntoMioTcpStream>( &self, conn: S, peer_type: PeerType, ) -> Result<PeerId, Error>
Add a new peer from an opened TCP stream.
Sourcepub fn connect_peer(&self, addr: SocketAddr) -> Result<PeerId, Error>
pub fn connect_peer(&self, addr: SocketAddr) -> Result<PeerId, Error>
Connect to the given peer.
Sourcepub fn ban_peer(&self, peer: PeerId) -> Result<(), Error>
pub fn ban_peer(&self, peer: PeerId) -> Result<(), Error>
Disconnect the peer and don’t reconnect to it.
Sourcepub fn nb_connected_peers(&self) -> usize
pub fn nb_connected_peers(&self) -> usize
The number of connected peers.
Sourcepub fn peer_version(
&self,
peer: PeerId,
) -> Result<Option<VersionMessage>, Error>
pub fn peer_version( &self, peer: PeerId, ) -> Result<Option<VersionMessage>, Error>
Get the peer’s version message.
Sourcepub fn send_message(
&self,
peer: PeerId,
msg: NetworkMessage,
) -> Result<(), Error>
pub fn send_message( &self, peer: PeerId, msg: NetworkMessage, ) -> Result<(), Error>
Send a message to the given peer.
Sourcepub fn broadcast_message(&self, msg: NetworkMessage) -> Result<(), Error>
pub fn broadcast_message(&self, msg: NetworkMessage) -> Result<(), Error>
Broadcast the message to all peers.
Sourcepub fn queue_inventory(&self, peer: PeerId, inv: Inventory) -> Result<(), Error>
pub fn queue_inventory(&self, peer: PeerId, inv: Inventory) -> Result<(), Error>
Add an inventory item to send to the peer. They are trickled with randomized intervals.
Blocks are not queued up, but sent immediatelly.
Don’t use this to send inv messages directly, f.e. when replying to mempool.
Just use send_message for that.
Auto Trait Implementations§
impl !Freeze for P2P
impl RefUnwindSafe for P2P
impl Send for P2P
impl Sync for P2P
impl Unpin for P2P
impl UnwindSafe for P2P
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