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 exampleorg.example.Os/stableororg.example.Os/**. The listing holds the collection refs that it selects underostree.summary.collection-map. A selector with no entry lists all collection refs.Noneasks 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
aand a negative!aboth stay, andaanda/bboth stay. - At most
MAX_REF_PATTERNSentries can stay, positive and negative entries of the two lists together. - Over HTTP,
Someof a second selector with no entry goes on the wire as one**entry, and that entry counts toward the limit. ThusMAX_REF_PATTERNSdistinct entries in the first selector andSomeof an empty second selector are refused over HTTP, and accepted over a stream session. - An entry has at most
MAX_REF_ENTRY_LENbytes, with its!counted as one byte. It has at mostMAX_REF_ENTRY_PARTSparts, 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.
impl PullSession
The open of a session over a pair of byte streams, and the calls of the session.
Sourcepub async fn over_stream<R, W>(
input: R,
output: W,
opts: StreamSessionOptions,
) -> Result<PullSession>
pub async fn over_stream<R, W>( input: R, output: W, opts: StreamSessionOptions, ) -> Result<PullSession>
Opens a stream session over a pair of byte streams.
The call is StreamSession::over_stream, and the result is
PullSession::Stream.
§Errors
- The
Errorvariant of the code of anErrormessage from the server. Error::VersionUnsupportedif the server states a version out of1..=PULL_PROTOCOL_VERSION.Error::Protocolif the reply is a message of another kind, or if the codec refuses a frame of the reply.Error::Protocolifagentholds a NUL byte.Error::LimitExceededif thePullHelloframe or a frame of the reply is longer thanMIN_FRAME_LIMIT.Error::Ioif a read or a write of a stream fails.
StreamSession::over_stream gives the conditions in full.
Sourcepub async fn fetch_summary(&self) -> Result<(Option<Vec<u8>>, Option<Vec<u8>>)>
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 reply with a status that is_absent_status accepts, 403,
404, or 410, 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::Fetchover HTTP if a request fails after its retries, or if the remote answers with a status other than 200, 403, 404, and 410. For a stated length over the cap, the inner error of the fetcher isFetchTooLarge. For a 304 reply, the inner error isFetch.Error::Ioover HTTP if the read of a body fails and no refetch applies. If a body grows past the cap, the kind isFileTooLarge, and the call does not fetch the body again.- Each error of
StreamSession::getover a stream session. A stated length over the cap isError::LimitExceeded. - Over a stream session, the error of the session if the read of a
body fails, as
PullBodystates:Error::LimitExceededfor a body over the capError::Protocolfor a body whose length is different from its stated length- the variant of an
Errormessage from the server after the abandon marker Error::Iofor a failed read- the repeat of an earlier failure of the session
Sourcepub async fn fetch_refs(
&self,
refs: &RefSelector,
collections: Option<&RefSelector>,
) -> Result<Option<Vec<u8>>>
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. A 403 and a 410
reply also give None, by the rule of is_absent_status. An ostrya
server answers 403 to a client that it refuses.
§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. It keeps a 403 and a 410 in the same way.
- If the busy server answers 200 in a later round, the call returns
Some. - The call returns
Noneonly if the busy server answers 503 to each retry. It then returnsNoneafter 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::InvalidInputif the entries break a limit of Ref patterns. The call sends no request.Error::InvalidInputover HTTP if the request target is longer than 16 KiB. The call sends no request.Error::Fetchover HTTP if a request fails after its retries, or if the remote answers with a status other than 200, 403, 404, and 410. For a stated length over the cap, the inner error of the fetcher isFetchTooLarge. For a 304 reply, the inner error isFetch.Error::Fetchover HTTP if the server refuses the request. The inner error isHttpStatus. For example, the status is 400 for a pattern that the server refuses, or for acollectionpair 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 overMAX_REF_LISTINGbytes.Error::Ioover HTTP if the read of the body fails and no refetch applies. If the body grows past the cap, the kind isFileTooLarge, and the call does not fetch the body again.- Each error of
StreamSession::list_refsover a stream session. A stated length over the cap isError::LimitExceeded. If the server refuses the listing for its cap, the error is alsoError::LimitExceeded. - Over a stream session, the error of the session if the read of the
body fails, as
fetch_summarylists.
Sourcepub fn max_outstanding(&self) -> usize
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.
Sourcepub async fn finish(self) -> Result<()>
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::InvalidInputif the body of a reply is not read to its end.Error::Transportif the ssh client exited with a failure status and the error of the session isError::Io.
Source§impl PullSession
The open of the session of a pull over ssh or HTTP.
impl PullSession
The open of the session of a pull over ssh or HTTP.
Sourcepub async fn connect(
endpoint: Endpoint,
opts: StreamSessionOptions,
) -> Result<PullSession>
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_outstandingis the request limit of the pull.- A
User-Agententry ofheaderssets the agent. - The call does not apply
check_base_urlto 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
- The errors of
StreamSession::connectfor an ssh endpoint. Error::InvalidInputifoptssetsagentormax_outstandingfor an HTTP endpoint.Error::InvalidInputif the options of an HTTP endpoint name no mirror.Error::InvalidInputfor anEndpoint::S3if the signer refuses its region, or ifoptssets a field.Error::FetchifFetcher::newrefuses the options of an HTTP endpoint or of anEndpoint::S3. An example is an S3 endpoint at anhttp://URL withallow_cleartext_credentialsset tofalse.