Skip to main content

PullSession

Enum PullSession 

Source
pub enum PullSession {
    Http(Fetcher),
    Stream(StreamSession),
}
Expand description

The session of a pull: the HTTP fetcher of a remote, or a stream session.

connect opens a session to an Endpoint, and over_stream opens one over a pair of byte streams. The session is Send + Sync. fetch_summary and fetch_refs take &self, so the session stays usable after the read.

To read a raw file of the remote, a caller matches on the variant and uses the call of that variant: Fetcher::fetch for Http, and StreamSession::get for Stream.

§Ref patterns

fetch_refs and StreamSession::list_refs send the entries of two RefSelector values. RefSelector and RefPattern give the pattern language.

  • The first selector selects the local refs by name. In field 0, the listing holds the local refs that it selects, so a selector with no entry lists all local refs.
  • The second selector selects the collection refs by ID/NAME, for example org.example.Os/stable or org.example.Os/**. The listing holds the collection refs that it selects under ostree.summary.collection-map. A selector with no entry lists all collection refs. None asks for no collection ref, and the listing then has the bytes of a listing of the first selector alone.

The server leaves out each ref that the client cannot read. A caller reads the collection refs of a listing with Summary::parse(&listing)?.collection_map() of the ostrya crate.

Each of the two methods sends the entries by these rules, over both transports:

  • In each list, the positive entries come first, then the negative entries, each with its !.
  • The method removes each exact duplicate of one kind in one list and keeps the first appearance, so ["a", "!b", "a"] sends ["a", "!b"]. An entry of the two lists stays in each list.
  • The method removes no entry because another entry covers it. A positive a and a negative !a both stay, and a and a/b both stay.
  • At most MAX_REF_PATTERNS entries can stay, positive and negative entries of the two lists together.
  • Over HTTP, Some of a second selector with no entry goes on the wire as one ** entry, and that entry counts toward the limit. Thus MAX_REF_PATTERNS distinct entries in the first selector and Some of an empty second selector are refused over HTTP, and accepted over a stream session.
  • An entry has at most MAX_REF_ENTRY_LEN bytes, with its ! counted as one byte. It has at most MAX_REF_ENTRY_PARTS parts, and the ! adds no part.

§Reads

fetch_summary and fetch_refs read each body whole into one buffer. The buffer gets the size that the remote states for the body, within the cap of the method. Each read goes into a chunk of at most 128 KiB. Over HTTP, if a body fails in transit, the method fetches it again by the rules of Fetcher::refetching.

Variants§

§

Http(Fetcher)

The fetcher of an HTTP remote.

§

Stream(StreamSession)

A stream session, over ssh or over a pair of byte streams.

Implementations§

Source§

impl PullSession

The open of a session over a pair of byte streams, and the calls of the session.

Source

pub async fn over_stream<R, W>( input: R, output: W, opts: StreamSessionOptions, ) -> Result<PullSession>
where R: AsyncRead + Unpin + Send + 'static, W: AsyncWrite + Unpin + Send + 'static,

Opens a stream session over a pair of byte streams.

The call is StreamSession::over_stream, and the result is PullSession::Stream.

§Errors

StreamSession::over_stream gives the conditions in full.

Source

pub async fn fetch_summary(&self) -> Result<(Option<Vec<u8>>, Option<Vec<u8>>)>

Reads the summary and the summary.sig of the remote.

The call returns the bytes of summary and of summary.sig, in this order. If the remote does not serve a file, the call gives None for that file. Each file has a cap of 64 MiB. The call reads each file by the rules of Reads.

§Order

Over HTTP, the call asks for summary.sig first and for summary second, at Priority::High. This is the order of the ostree command. A 404 reply means that the remote does not serve the file.

Over a stream session, the two Get calls are in flight together, in the same order.

§Errors
  • Error::Fetch over HTTP if a request fails after its retries, or if the remote answers with a status other than 200 and 404. For a stated length over the cap, the inner error of the fetcher is FetchTooLarge. For a 304 reply, the inner error is Fetch.
  • Error::Io over HTTP if the read of a body fails and no refetch applies. If a body grows past the cap, the kind is FileTooLarge, and the call does not fetch the body again.
  • Each error of StreamSession::get over a stream session. A stated length over the cap is Error::LimitExceeded.
  • Over a stream session, the error of the session if the read of a body fails, as PullBody states:
    • Error::LimitExceeded for a body over the cap
    • Error::Protocol for a body whose length is different from its stated length
    • the variant of an Error message from the server after the abandon marker
    • Error::Io for a failed read
    • the repeat of an earlier failure of the session
Source

pub async fn fetch_refs( &self, refs: &RefSelector, collections: Option<&RefSelector>, ) -> Result<Option<Vec<u8>>>

Reads the ref listing of refs and collections from the remote.

The listing is a summary of the local refs that refs selects and of the collection refs that collections selects. None asks for no collection ref. The server builds the listing for this request. The listing has a cap of MAX_REF_LISTING bytes. No signature covers the listing, and the call verifies none.

The call sends the entries of the two selectors by the rules of Ref patterns. It reads the listing by the rules of Reads.

§HTTP

The call sends a GET of _ostrya/refs/v1 under the base URL of each mirror, at Priority::High. Each entry of refs that stays goes into the query as one pattern=VALUE pair. Then each entry of collections that stays goes into the query as one collection=VALUE pair. & separates the pairs. With no entry and with None, the call sends no query. Some of a selector with no entry goes into the query as the one pair collection=**, which selects each collection ref and counts toward the limit of entries.

The value is the entry with each byte outside A-Z, a-z, 0-9, -, ., _, and ~ written as %XX. For example, / is %2F, ! is %21, and * is %2A.

The request target that the call builds, from _ostrya/refs/v1 to the end of the query, is at most 16 KiB. The base path of the mirror comes before it on the wire. An ostrya server over HTTP/2 takes a header list of at most 32 KiB. The other 16 KiB are for the base path and the other header fields.

A 404 reply comes from a remote that serves no ref listing, for example a static file server. The call then returns None.

§Busy server

An ostrya server answers 503 while it builds too many listings. The fetcher retries a 503 with its backoff and does not read Retry-After. If a 503 stays after the retries, the call returns Error::Fetch.

If the mirrors are a static mirror and a busy ostrya server:

  • The fetcher keeps the 404 of the static mirror from the first round, and asks only the busy server again.
  • If the busy server answers 200 in a later round, the call returns Some.
  • The call returns None only if the busy server answers 503 to each retry. It then returns None after the full backoff, because a 404 has priority over a 503.
§Stream session

The call is StreamSession::list_refs, in the pipeline with the get calls. It returns Some with the bytes of the listing.

§Errors
  • Error::InvalidInput if the entries break a limit of Ref patterns. The call sends no request.
  • Error::InvalidInput over HTTP if the request target is longer than 16 KiB. The call sends no request.
  • Error::Fetch over HTTP if a request fails after its retries, or if the remote answers with a status other than 200 and 404. For a stated length over the cap, the inner error of the fetcher is FetchTooLarge. For a 304 reply, the inner error is Fetch.
  • Error::Fetch over HTTP if the server refuses the request. The inner error is HttpStatus. For example, the status is 400 for a pattern that the server refuses, or for a collection pair that a server without collection refs in its listing does not know, and 414 or 431 for a target that is too long for it. A server that stays busy gives 503. An ostrya server gives 500 for a listing over MAX_REF_LISTING bytes.
  • Error::Io over HTTP if the read of the body fails and no refetch applies. If the body grows past the cap, the kind is FileTooLarge, and the call does not fetch the body again.
  • Each error of StreamSession::list_refs over a stream session. A stated length over the cap is Error::LimitExceeded. If the server refuses the listing for its cap, the error is also Error::LimitExceeded.
  • Over a stream session, the error of the session if the read of the body fails, as fetch_summary lists.
Source

pub fn max_outstanding(&self) -> usize

Returns the most requests that the session keeps in flight at one time.

The value is at least 1. For HTTP, it is Fetcher::max_outstanding. For a stream session, it is the StreamSessionOptions::max_outstanding of the open, or 8 if that field is None.

Source

pub async fn finish(self) -> Result<()>

Ends the session.

For HTTP, the call returns Ok(()). For a stream session, it is StreamSession::finish.

§Errors

Over a stream session, the errors of StreamSession::finish:

  • The repeat of the first failure, if the session failed.
  • Error::InvalidInput if the body of a reply is not read to its end.
  • Error::Transport if the ssh client exited with a failure status and the error of the session is Error::Io.
Source§

impl PullSession

The open of the session of a pull over ssh or HTTP.

Source

pub async fn connect( endpoint: Endpoint, opts: StreamSessionOptions, ) -> Result<PullSession>

Opens the session of a pull to endpoint.

For an Endpoint::Ssh, the call is StreamSession::connect with the address, the ssh options, and opts. The result is PullSession::Stream.

For an Endpoint::Http, the call builds the fetcher with Fetcher::new, and the result is PullSession::Http. The call sends no HTTP request.

For an Endpoint::S3, the call builds the fetcher from the options that S3Endpoint::pull_options gives, and the result is PullSession::Http. The fetcher signs each request. The call sends no HTTP request.

Under the tokio backend, the call must run within a runtime that has the IO driver and the time driver enabled, as PushSession::connect states.

§HTTP options

The call gives the options of the endpoint to the fetcher with no change:

  • The options can name one or more mirrors.
  • The fetcher follows redirects up to max_redirects.
  • max_outstanding is the request limit of the pull.
  • A User-Agent entry of headers sets the agent.
  • The call does not apply check_base_url to the mirrors.

The options give the agent and the request limit, so opts must set no field.

With TrustRoots::System, the call reads the trust store of the host by the rule of Fetcher::new. An https:// mirror causes the read. The options that Endpoint::parse gives an http:// address also cause it, because their max_redirects is 10.

§Errors

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