Skip to main content

PeerStreamReader

Struct PeerStreamReader 

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

The receiving side of one direction of a peer stream.

Feed it the bytes each socket read returned, in order, and act on the events it yields. It holds at most one incomplete frame between calls, whose prefix has already passed the bounds, so memory per stream is bounded by the caller’s read buffer plus one body.

One reader is one direction of one stream. It has no view of other streams, so the chapter’s one-announced-stream-per-address rule (a second stream proving an address already announced is refused or supersedes the first, and either way the core sees one announcement and one loss) is the host’s, which is the only place that can see both streams.

Implementations§

Source§

impl PeerStreamReader

Source

pub fn new(verify: PreambleVerifier) -> Self

A reader for a stream with no claim about who is at the other end: an inbound connection, or a peer-list entry naming only a host and port. The derived address is the peer’s id, and there is nothing to compare.

Source

pub fn expecting(self, address: impl Into<String>) -> Self

Requires the preamble to prove exactly address, the chapter’s fourth step, for a stream opened toward a known address. A mismatch closes the stream with CloseReason::AddressMismatch. The announced address is still the derived one; the claim is a hint about whom to expect, never a name to announce.

Source

pub fn peer(&self) -> Option<&str>

The address this stream proved, once it has.

Source

pub fn is_closed(&self) -> bool

Whether the reader has closed the stream. A closed reader yields nothing more, whatever it is fed.

Source

pub fn feed(&mut self, bytes: &[u8]) -> Vec<StreamEvent>

Feeds the bytes one read returned and yields every event they complete.

Frames are yielded in stream order. A StreamEvent::Closed is terminal and always last: frames decoded before the fault are still delivered, because they arrived on a stream whose peer was proved, and nothing after it ever is.

Trait Implementations§

Source§

impl Debug for PeerStreamReader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more