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
impl PeerStreamReader
Sourcepub fn new(verify: PreambleVerifier) -> Self
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.
Sourcepub fn expecting(self, address: impl Into<String>) -> Self
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.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether the reader has closed the stream. A closed reader yields nothing more, whatever it is fed.
Sourcepub fn feed(&mut self, bytes: &[u8]) -> Vec<StreamEvent>
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.