Struct stack_epic_p2p::Peers

source ·
pub struct Peers {
    pub adapter: Arc<dyn ChainAdapter>,
    /* private fields */
}

Fields§

§adapter: Arc<dyn ChainAdapter>

Implementations§

source§

impl Peers

source

pub fn new( store: PeerStore, adapter: Arc<dyn ChainAdapter>, config: P2PConfig ) -> Peers

source

pub fn add_connected(&self, peer: Arc<Peer>) -> Result<(), Error>

Adds the peer to our internal peer mapping. Note that the peer is still returned so the server can run it.

source

pub fn add_banned( &self, addr: PeerAddr, ban_reason: ReasonForBan ) -> Result<(), Error>

Add a peer as banned to block future connections, usually due to failed handshake

source

pub fn is_known(&self, addr: PeerAddr) -> Result<bool, Error>

Check if this peer address is already known (are we already connected to it)? We try to get the read lock but if we experience contention and this attempt fails then return an error allowing the caller to decide how best to handle this.

source

pub fn connected_peers(&self) -> Vec<Arc<Peer>>

Get vec of peers we are currently connected to.

source

pub fn outgoing_connected_peers(&self) -> Vec<Arc<Peer>>

Get vec of peers we currently have an outgoing connection with.

source

pub fn incoming_connected_peers(&self) -> Vec<Arc<Peer>>

Get vec of peers we currently have an incoming connection with.

source

pub fn get_connected_peer(&self, addr: PeerAddr) -> Option<Arc<Peer>>

Get a peer we’re connected to by address.

source

pub fn peer_count(&self) -> u32

Number of peers currently connected to.

source

pub fn peer_outbound_count(&self) -> u32

Number of outbound peers currently connected to.

source

pub fn peer_inbound_count(&self) -> u32

Number of inbound peers currently connected to.

source

pub fn more_work_peers(&self) -> Result<Vec<Arc<Peer>>, Error>

source

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

source

pub fn more_work_peer(&self) -> Option<Arc<Peer>>

Returns single random peer with more work than us.

source

pub fn most_work_peers(&self) -> Vec<Arc<Peer>>

Return vec of connected peers that currently have the most worked branch, showing the highest total difficulty.

source

pub fn most_work_peer(&self) -> Option<Arc<Peer>>

Returns single random peer with the most worked branch, showing the highest total difficulty.

source

pub fn is_banned(&self, peer_addr: PeerAddr) -> bool

source

pub fn ban_peer( &self, peer_addr: PeerAddr, ban_reason: ReasonForBan ) -> Result<(), Error>

Ban a peer, disconnecting it if we’re currently connected

source

pub fn disconnect_peer(&self, peer_addr: PeerAddr) -> Result<(), Error>

Ban a peer, disconnecting it if we’re currently connected

source

pub fn unban_peer(&self, peer_addr: PeerAddr) -> Result<(), Error>

Unban a peer, checks if it exists and banned then unban

source

pub fn broadcast_compact_block(&self, b: &CompactBlock)

Broadcast a compact block to all our connected peers. This is only used when initially broadcasting a newly mined block.

source

pub fn broadcast_header(&self, bh: &BlockHeader)

Broadcast a block header to all our connected peers. A peer implementation may drop the broadcast request if it knows the remote peer already has the header.

source

pub fn broadcast_transaction(&self, tx: &Transaction)

Broadcasts the provided transaction to all our connected peers. A peer implementation may drop the broadcast request if it knows the remote peer already has the transaction.

source

pub fn check_all(&self, total_difficulty: Difficulty, height: u64)

Ping all our connected peers. Always automatically expects a pong back or disconnects. This acts as a liveness test.

source

pub fn all_peers(&self) -> Vec<PeerData>

All peer information we have in storage

source

pub fn find_peers( &self, state: State, cap: Capabilities, count: usize ) -> Vec<PeerData>

Find peers in store (not necessarily connected) and return their data

source

pub fn get_peer(&self, peer_addr: PeerAddr) -> Result<PeerData, Error>

Get peer in store by address

source

pub fn exists_peer(&self, peer_addr: PeerAddr) -> Result<bool, Error>

Whether we’ve already seen a peer with the provided address

source

pub fn save_peer(&self, p: &PeerData) -> Result<(), Error>

Saves updated information about a peer

source

pub fn update_state( &self, peer_addr: PeerAddr, new_state: State ) -> Result<(), Error>

Updates the state of a peer in store

source

pub fn clean_peers(&self, max_inbound_count: usize, max_outbound_count: usize)

Iterate over the peer list and prune all peers we have lost connection to or have been deemed problematic. Also avoid connected peer count getting too high.

source

pub fn stop(&self)

source

pub fn enough_outbound_peers(&self) -> bool

We have enough outbound connected peers

source

pub fn remove_expired(&self)

Removes those peers that seem to have expired

Trait Implementations§

source§

impl ChainAdapter for Peers

source§

fn total_difficulty(&self) -> Result<Difficulty, Error>

Current total difficulty on our chain
source§

fn total_height(&self) -> Result<u64, Error>

Current total height
source§

fn total_header_height(&self) -> Result<u64, Error>

Current total header height
source§

fn get_transaction(&self, kernel_hash: Hash) -> Option<Transaction>

source§

fn tx_kernel_received( &self, kernel_hash: Hash, peer_info: &PeerInfo ) -> Result<bool, Error>

source§

fn transaction_received( &self, tx: Transaction, stem: bool ) -> Result<bool, Error>

A valid transaction has been received from one of our peers
source§

fn block_received( &self, b: Block, peer_info: &PeerInfo, opts: Options ) -> Result<bool, Error>

A block has been received from one of our peers. Returns true if the block could be handled properly and is not deemed defective by the chain. Returning false means the block will never be valid and may result in the peer being banned.
source§

fn compact_block_received( &self, cb: CompactBlock, peer_info: &PeerInfo ) -> Result<bool, Error>

source§

fn header_received( &self, bh: BlockHeader, peer_info: &PeerInfo ) -> Result<bool, Error>

source§

fn headers_received( &self, headers: &[BlockHeader], peer_info: &PeerInfo ) -> Result<bool, Error>

A set of block header has been received, typically in response to a block header request.
source§

fn locate_headers( &self, hs: &[Hash], offset: &u8 ) -> Result<Vec<BlockHeader>, Error>

Finds a list of block headers based on the provided locator. Tries to identify the common chain and gets the headers that follow it immediately.
source§

fn get_block(&self, h: Hash) -> Option<Block>

Gets a full block by its hash.
source§

fn kernel_data_read(&self) -> Result<File, Error>

source§

fn kernel_data_write(&self, reader: &mut dyn Read) -> Result<bool, Error>

source§

fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead>

Provides a reading view into the current txhashset state as well as the required indexes for a consumer to rewind to a consistant state at the provided block hash.
source§

fn txhashset_archive_header(&self) -> Result<BlockHeader, Error>

Header of the txhashset archive currently being served to peers.
source§

fn txhashset_receive_ready(&self) -> bool

Whether the node is ready to accept a new txhashset. If this isn’t the case, the archive is provided without being requested and likely an attack attempt. This should be checked before downloading the whole state data.
source§

fn txhashset_write( &self, h: Hash, txhashset_data: File, peer_info: &PeerInfo ) -> Result<bool, Error>

Writes a reading view on a txhashset state that’s been provided to us. If we’re willing to accept that new state, the data stream will be read as a zip file, unzipped and the resulting state files should be rewound to the provided indexes.
source§

fn txhashset_download_update( &self, start_time: DateTime<Utc>, downloaded_size: u64, total_size: u64 ) -> bool

Update txhashset downloading progress
source§

fn get_tmp_dir(&self) -> PathBuf

Get the Epic specific tmp dir
source§

fn get_tmpfile_pathname(&self, tmpfile_name: String) -> PathBuf

Get a tmp file path in above specific tmp dir (create tmp dir if not exist) Delete file if tmp file already exists
source§

impl NetAdapter for Peers

source§

fn find_peer_addrs(&self, capab: Capabilities) -> Vec<PeerAddr>

Find good peers we know with the provided capability and return their addresses.

source§

fn peer_addrs_received(&self, peer_addrs: Vec<PeerAddr>)

A list of peers has been received from one of our peers.

source§

fn peer_difficulty( &self, addr: PeerAddr, diff: Difficulty, height: u64, local_timestamp: i64 )

Heard total_difficulty from a connected peer (via ping/pong).
source§

fn is_banned(&self, addr: PeerAddr) -> bool

Is this peer currently banned?

Auto Trait Implementations§

§

impl !RefUnwindSafe for Peers

§

impl Send for Peers

§

impl Sync for Peers

§

impl Unpin for Peers

§

impl !UnwindSafe for Peers

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.

§

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

§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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

impl<T> Erased for T

§

impl<T> UnsafeAny for T
where T: Any,