P2P

Struct P2P 

Source
pub struct P2P { /* private fields */ }
Expand description

The main struct coordinating all P2P activity.

Implementations§

Source§

impl P2P

Source

pub fn new(config: Config) -> Result<Arc<P2P>, Error>

Instantiate a P2P coordinator.

Source

pub fn config(&self) -> &Config

Get the configuration of the P2P instance.

Source

pub fn set_height(&self, block_height: u32)

Set the latest block height to advertise to peers.

Source

pub fn shutdown(&self) -> Result<(), Error>

Shut down the p2p operation. Any subsequent call will be a no-op.

Source

pub fn add_peer<S: IntoMioTcpStream>( &self, conn: S, peer_type: PeerType, ) -> Result<PeerId, Error>

Add a new peer from an opened TCP stream.

Source

pub fn connect_peer(&self, addr: SocketAddr) -> Result<PeerId, Error>

Connect to the given peer.

Source

pub fn disconnect_peer(&self, peer: PeerId) -> Result<(), Error>

Disconnect the given peer.

Source

pub fn ban_peer(&self, peer: PeerId) -> Result<(), Error>

Disconnect the peer and don’t reconnect to it.

Source

pub fn nb_connected_peers(&self) -> usize

The number of connected peers.

Source

pub fn peer_version( &self, peer: PeerId, ) -> Result<Option<VersionMessage>, Error>

Get the peer’s version message.

Source

pub fn send_message( &self, peer: PeerId, msg: NetworkMessage, ) -> Result<(), Error>

Send a message to the given peer.

Source

pub fn broadcast_message(&self, msg: NetworkMessage) -> Result<(), Error>

Broadcast the message to all peers.

Source

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.

Source

pub fn broadcast_inventory(&self, inv: Inventory) -> Result<(), Error>

Broadcast an inventory item to all peers. They are tricled with randomized intervals.

Blocks are not queued up, but sent immediatelly.

Source

pub fn add_listener<L: Listener + 'static>( &self, listener: L, ) -> Result<(), Error>

Add a new listener.

See the documentation on the Listener trait to see what common types implement this trait.

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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V