pub struct PeerSample { /* private fields */ }Expand description
A list of peers to be exchanged between two nodes.
peaveil builds a PeerSample by drawing a uniformly
random subset of its View and ships
it to a randomly-chosen peer. The recipient merges the
received entries into its own view, deduplicating by
SocketAddr.
Implementations§
Source§impl PeerSample
impl PeerSample
Sourcepub const MAX_ENTRIES: usize
pub const MAX_ENTRIES: usize
Maximum number of entries a single sample can carry.
The wire format uses a 1-byte count field, so a
PeerSample can hold at most 255 entries. In practice
the configured sample_size (default 8) is well under
this; encoding more than 255 entries is a
programmer error.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Returns an empty sample. Useful for “ping” exchanges that test liveness without contributing new peers.
Sourcepub fn from_entries(entries: Vec<PeerEntry>) -> Self
pub fn from_entries(entries: Vec<PeerEntry>) -> Self
Builds a sample from a list of entries. The entries are not validated; the caller is expected to de-duplicate and bound the size before calling.
Sourcepub fn encoded_size(&self) -> usize
pub fn encoded_size(&self) -> usize
Returns the encoded size of this sample, in bytes, when
serialized as a peaveil payload.
Sourcepub fn encode(&self) -> BytesMut
pub fn encode(&self) -> BytesMut
Encodes this sample into a freshly-allocated
BytesMut. The returned buffer is exactly
self.encoded_size() bytes long.
§Panics
Panics if self.len() > Self::MAX_ENTRIES.
Sourcepub fn decode(buf: &[u8]) -> Result<Self, DecodeError>
pub fn decode(buf: &[u8]) -> Result<Self, DecodeError>
Decodes a peaveil payload. Returns Err(_) if the
buffer is too short, has a wrong magic, has a wrong
version, or has a truncated trailing entry. Trailing
bytes after the last declared entry are ignored,
since the on-the-wire format pads the sample with
random bytes to fit the peashape frame size.
Trait Implementations§
Source§impl Clone for PeerSample
impl Clone for PeerSample
Source§fn clone(&self) -> PeerSample
fn clone(&self) -> PeerSample
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PeerSample
impl Debug for PeerSample
Source§impl Default for PeerSample
impl Default for PeerSample
Source§fn default() -> PeerSample
fn default() -> PeerSample
impl Eq for PeerSample
Source§impl PartialEq for PeerSample
impl PartialEq for PeerSample
Source§fn eq(&self, other: &PeerSample) -> bool
fn eq(&self, other: &PeerSample) -> bool
self and other values to be equal, and is used by ==.