Skip to main content

serve

Function serve 

Source
pub async fn serve<T, F>(
    channel: &mut PeerChannel,
    offering: &Offering,
    trust: &T,
    versions: &dyn DirectoryVersions,
    on_ack: F,
) -> Result<ServeReport, PeeringError>
Expand description

Serve offering to the channel’s verified peer until it says it is done.

Reads the peer’s opening offer first when the caller has not (PeerChannel::receive_offer) and sets it aside, then sends the listing, then answers each request in turn:

  • Every request is authorized first against the trust trust pins now (PeerSession::authorize): a peer revoked, or gone from the directory, since the handshake is refused and the session ends — as it does when trust cannot produce current trust (fail closed).
  • A ranged pull is answered only for an offered address, with at most MAX_RANGE bytes in data frames of at most MAX_DATA_FRAME.
  • An acknowledgement is taken only when it names the verified peer as the delegate and an offered address; then on_ack decides it. Its refusal is reported to the peer and the session goes on.
  • The wait for each request is the channel’s I/O timeout plus the largest unacknowledged offered artifact at MIN_PERSIST_RATE: the peer verifies and persists a pulled artifact before it acknowledges it, and that takes longer than one frame’s timeout for a large artifact on slow storage.

§Errors

The PeeringError that ended the session: an authorization refusal, a malformed or unexpected frame, a timeout, or the channel failing.