Struct bitcoin_peerman::Peer

source ·
pub struct Peer {
Show 20 fields pub id: NodeId, pub misbehavior: Arc<Mutex<PeerMisbehavior>>, pub block_inv_mutex: Arc<Mutex<PeerBlockInv>>, pub starting_height: Atomic<i32>, pub ping_nonce_sent: Atomic<u64>, pub ping_start: Atomic<OffsetDateTime>, pub ping_queued: AtomicBool, pub addrs_to_send: Arc<Mutex<Vec<Address>>>, pub addr_known: Option<RollingBloomFilter>, pub addr_relay_enabled: AtomicBool, pub getaddr_sent: bool, pub addr_send_times_mutex: Arc<Mutex<PeerAddrSendTimes>>, pub wants_addrv2: AtomicBool, pub getaddr_recvd: bool, pub addr_token_bucket: f64, pub addr_token_timestamp: OffsetDateTime, pub addr_rate_limited: Atomic<u64>, pub addr_processed: Atomic<u64>, pub orphan_work_set: PeerOrphans, pub getdata_requests: Arc<Mutex<VecDeque<Inv>>>,
}
Expand description

| Data structure for an individual peer. | This struct is not protected by CS_MAIN | since it does not contain validation-critical | data. | | Memory is owned by shared pointers and | this object is destructed when the refcount | drops to zero. | | Mutexes inside this struct must not | be held when locking m_peer_mutex. | | TODO: move most members from NodeState | to this structure. | | TODO: move remaining application-layer | data members from Node to this structure. |

Fields§

§id: NodeId

| Same id as the Node object for this peer |

§misbehavior: Arc<Mutex<PeerMisbehavior>>

| Protects misbehavior data members |

§block_inv_mutex: Arc<Mutex<PeerBlockInv>>

| Protects block inventory data members |

§starting_height: Atomic<i32>

| This peer’s reported block height when | we connected |

§ping_nonce_sent: Atomic<u64>

| The pong reply we’re expecting, or 0 | if no pong expected. |

§ping_start: Atomic<OffsetDateTime>

| When the last ping was sent, or 0 if no | ping was ever sent |

§ping_queued: AtomicBool

| Whether a ping has been requested by | the user |

§addrs_to_send: Arc<Mutex<Vec<Address>>>

| A vector of addresses to send to the peer, | limited to MAX_ADDR_TO_SEND. |

§addr_known: Option<RollingBloomFilter>

| Probabilistic filter to track recent | addr messages relayed with this peer. | Used to avoid relaying redundant addresses | to this peer. | | We initialize this filter for outbound | peers (other than block-relay-only | connections) or when an inbound peer | sends us an address related message | (ADDR, ADDRV2, GETADDR). | | Presence of this filter must correlate | with m_addr_relay_enabled. |

§addr_relay_enabled: AtomicBool

| Whether we are participating in address | relay with this connection. | | We set this bool to true for outbound | peers (other than block-relay-only | connections), or when an inbound peer | sends us an address related message | (ADDR, ADDRV2, GETADDR). | | We use this bool to decide whether a peer | is eligible for gossiping addr messages. | This avoids relaying to peers that are | unlikely to forward them, effectively | blackholing self announcements. Reasons | peers might support addr relay on the | link include that they connected to | us as a block-relay-only peer or they | are a light client. | | This field must correlate with whether | m_addr_known has been initialized. |

§getaddr_sent: bool

| Whether a getaddr request to this peer | is outstanding. |

§addr_send_times_mutex: Arc<Mutex<PeerAddrSendTimes>>

| Guards address sending timers. |

§wants_addrv2: AtomicBool

| Whether the peer has signaled support | for receiving ADDRv2 (BIP155) messages, | indicating a preference to receive | ADDRv2 instead of ADDR ones. |

§getaddr_recvd: bool

| Whether this peer has already sent us | a getaddr message. |

§addr_token_bucket: f64

| Number of addresses that can be processed | from this peer. Start at 1 to permit self-announcement. |

§addr_token_timestamp: OffsetDateTime

| When m_addr_token_bucket was last | updated |

§addr_rate_limited: Atomic<u64>

| Total number of addresses that were | dropped due to rate limiting. |

§addr_processed: Atomic<u64>

| Total number of addresses that were | processed (excludes rate-limited | ones). |

§orphan_work_set: PeerOrphans§getdata_requests: Arc<Mutex<VecDeque<Inv>>>

| Work queue of items requested by this | peer |

Implementations§

source§

impl Peer

source

pub fn add_address_known(&mut self, addr: &Address)

source

pub fn is_addr_compatible(&self, addr: &Address) -> bool

| Whether the peer supports the address. | For example, a peer that does not implement | BIP155 cannot receive Tor v3 addresses | because it requires | | ADDRv2 (BIP155) encoding. |

source

pub fn push_address( &self, addr: &Address, insecure_rand: &mut FastRandomContext )

source§

impl Peer

source

pub fn new(id: NodeId) -> Self

Auto Trait Implementations§

§

impl !RefUnwindSafe for Peer

§

impl Send for Peer

§

impl Sync for Peer

§

impl Unpin for Peer

§

impl !UnwindSafe for Peer

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, U> CastInto<U> for Twhere U: CastFrom<T>,

§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> StaticUpcast<T> for T

§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V