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
impl Peers
pub fn new( store: PeerStore, adapter: Arc<dyn ChainAdapter>, config: P2PConfig ) -> Peers
sourcepub fn add_connected(&self, peer: Arc<Peer>) -> Result<(), Error>
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.
sourcepub fn add_banned(
&self,
addr: PeerAddr,
ban_reason: ReasonForBan
) -> Result<(), Error>
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
sourcepub fn is_known(&self, addr: PeerAddr) -> Result<bool, Error>
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.
sourcepub fn connected_peers(&self) -> Vec<Arc<Peer>>
pub fn connected_peers(&self) -> Vec<Arc<Peer>>
Get vec of peers we are currently connected to.
sourcepub fn outgoing_connected_peers(&self) -> Vec<Arc<Peer>>
pub fn outgoing_connected_peers(&self) -> Vec<Arc<Peer>>
Get vec of peers we currently have an outgoing connection with.
sourcepub fn incoming_connected_peers(&self) -> Vec<Arc<Peer>>
pub fn incoming_connected_peers(&self) -> Vec<Arc<Peer>>
Get vec of peers we currently have an incoming connection with.
sourcepub fn get_connected_peer(&self, addr: PeerAddr) -> Option<Arc<Peer>>
pub fn get_connected_peer(&self, addr: PeerAddr) -> Option<Arc<Peer>>
Get a peer we’re connected to by address.
sourcepub fn peer_count(&self) -> u32
pub fn peer_count(&self) -> u32
Number of peers currently connected to.
sourcepub fn peer_outbound_count(&self) -> u32
pub fn peer_outbound_count(&self) -> u32
Number of outbound peers currently connected to.
sourcepub fn peer_inbound_count(&self) -> u32
pub fn peer_inbound_count(&self) -> u32
Number of inbound peers currently connected to.
pub fn more_work_peers(&self) -> Result<Vec<Arc<Peer>>, Error>
pub fn more_or_same_work_peers(&self) -> Result<usize, Error>
sourcepub fn more_work_peer(&self) -> Option<Arc<Peer>>
pub fn more_work_peer(&self) -> Option<Arc<Peer>>
Returns single random peer with more work than us.
sourcepub fn most_work_peers(&self) -> Vec<Arc<Peer>>
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.
sourcepub fn most_work_peer(&self) -> Option<Arc<Peer>>
pub fn most_work_peer(&self) -> Option<Arc<Peer>>
Returns single random peer with the most worked branch, showing the highest total difficulty.
pub fn is_banned(&self, peer_addr: PeerAddr) -> bool
sourcepub fn ban_peer(
&self,
peer_addr: PeerAddr,
ban_reason: ReasonForBan
) -> Result<(), Error>
pub fn ban_peer( &self, peer_addr: PeerAddr, ban_reason: ReasonForBan ) -> Result<(), Error>
Ban a peer, disconnecting it if we’re currently connected
sourcepub fn disconnect_peer(&self, peer_addr: PeerAddr) -> Result<(), Error>
pub fn disconnect_peer(&self, peer_addr: PeerAddr) -> Result<(), Error>
Ban a peer, disconnecting it if we’re currently connected
sourcepub fn unban_peer(&self, peer_addr: PeerAddr) -> Result<(), Error>
pub fn unban_peer(&self, peer_addr: PeerAddr) -> Result<(), Error>
Unban a peer, checks if it exists and banned then unban
sourcepub fn broadcast_compact_block(&self, b: &CompactBlock)
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.
sourcepub fn broadcast_header(&self, bh: &BlockHeader)
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.
sourcepub fn broadcast_transaction(&self, tx: &Transaction)
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.
sourcepub fn check_all(&self, total_difficulty: Difficulty, height: u64)
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.
sourcepub fn find_peers(
&self,
state: State,
cap: Capabilities,
count: usize
) -> Vec<PeerData>
pub fn find_peers( &self, state: State, cap: Capabilities, count: usize ) -> Vec<PeerData>
Find peers in store (not necessarily connected) and return their data
sourcepub fn get_peer(&self, peer_addr: PeerAddr) -> Result<PeerData, Error>
pub fn get_peer(&self, peer_addr: PeerAddr) -> Result<PeerData, Error>
Get peer in store by address
sourcepub fn exists_peer(&self, peer_addr: PeerAddr) -> Result<bool, Error>
pub fn exists_peer(&self, peer_addr: PeerAddr) -> Result<bool, Error>
Whether we’ve already seen a peer with the provided address
sourcepub fn save_peer(&self, p: &PeerData) -> Result<(), Error>
pub fn save_peer(&self, p: &PeerData) -> Result<(), Error>
Saves updated information about a peer
sourcepub fn update_state(
&self,
peer_addr: PeerAddr,
new_state: State
) -> Result<(), Error>
pub fn update_state( &self, peer_addr: PeerAddr, new_state: State ) -> Result<(), Error>
Updates the state of a peer in store
sourcepub fn clean_peers(&self, max_inbound_count: usize, max_outbound_count: usize)
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.
pub fn stop(&self)
sourcepub fn enough_outbound_peers(&self) -> bool
pub fn enough_outbound_peers(&self) -> bool
We have enough outbound connected peers
sourcepub fn remove_expired(&self)
pub fn remove_expired(&self)
Removes those peers that seem to have expired
Trait Implementations§
source§impl ChainAdapter for Peers
impl ChainAdapter for Peers
source§fn total_difficulty(&self) -> Result<Difficulty, Error>
fn total_difficulty(&self) -> Result<Difficulty, Error>
fn get_transaction(&self, kernel_hash: Hash) -> Option<Transaction>
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>
fn transaction_received( &self, tx: Transaction, stem: bool ) -> Result<bool, Error>
source§fn block_received(
&self,
b: Block,
peer_info: &PeerInfo,
opts: Options
) -> Result<bool, Error>
fn block_received( &self, b: Block, peer_info: &PeerInfo, opts: Options ) -> Result<bool, Error>
fn compact_block_received( &self, cb: CompactBlock, peer_info: &PeerInfo ) -> Result<bool, Error>
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>
fn headers_received( &self, headers: &[BlockHeader], peer_info: &PeerInfo ) -> Result<bool, Error>
source§fn locate_headers(
&self,
hs: &[Hash],
offset: &u8
) -> Result<Vec<BlockHeader>, Error>
fn locate_headers( &self, hs: &[Hash], offset: &u8 ) -> Result<Vec<BlockHeader>, Error>
fn kernel_data_read(&self) -> Result<File, Error>
fn kernel_data_write(&self, reader: &mut dyn Read) -> Result<bool, Error>
source§fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead>
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead>
source§fn txhashset_archive_header(&self) -> Result<BlockHeader, Error>
fn txhashset_archive_header(&self) -> Result<BlockHeader, Error>
source§fn txhashset_receive_ready(&self) -> bool
fn txhashset_receive_ready(&self) -> bool
source§fn txhashset_write(
&self,
h: Hash,
txhashset_data: File,
peer_info: &PeerInfo
) -> Result<bool, Error>
fn txhashset_write( &self, h: Hash, txhashset_data: File, peer_info: &PeerInfo ) -> Result<bool, Error>
source§fn txhashset_download_update(
&self,
start_time: DateTime<Utc>,
downloaded_size: u64,
total_size: u64
) -> bool
fn txhashset_download_update( &self, start_time: DateTime<Utc>, downloaded_size: u64, total_size: u64 ) -> bool
source§fn get_tmp_dir(&self) -> PathBuf
fn get_tmp_dir(&self) -> PathBuf
source§fn get_tmpfile_pathname(&self, tmpfile_name: String) -> PathBuf
fn get_tmpfile_pathname(&self, tmpfile_name: String) -> PathBuf
source§impl NetAdapter for Peers
impl NetAdapter for Peers
source§fn find_peer_addrs(&self, capab: Capabilities) -> Vec<PeerAddr>
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>)
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
)
fn peer_difficulty( &self, addr: PeerAddr, diff: Difficulty, height: u64, local_timestamp: i64 )
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> 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
§impl<T> SafeBorrow<T> for Twhere
T: ?Sized,
impl<T> SafeBorrow<T> for Twhere
T: ?Sized,
§fn borrow_replacement(ptr: &T) -> &T
fn borrow_replacement(ptr: &T) -> &T
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