Skip to main content

SmartProtocol

Struct SmartProtocol 

Source
pub struct SmartProtocol<R, A>{
    pub transport_protocol: TransportProtocol,
    pub capabilities: Vec<Capability>,
    pub side_band: Option<SideBand>,
    pub command_list: Vec<RefCommand>,
    pub wire_hash_kind: HashKind,
    pub local_hash_kind: HashKind,
    pub zero_id: String,
    /* private fields */
}
Expand description

Smart Git Protocol implementation

This struct handles the Git smart protocol operations for both HTTP and SSH transports. It uses trait abstractions to decouple from specific business logic implementations.

Fields§

§transport_protocol: TransportProtocol§capabilities: Vec<Capability>§side_band: Option<SideBand>§command_list: Vec<RefCommand>§wire_hash_kind: HashKind§local_hash_kind: HashKind§zero_id: String

Implementations§

Source§

impl<R, A> SmartProtocol<R, A>

Source

pub fn set_wire_hash_kind(&mut self, kind: HashKind)

Set the wire hash kind (sha1, sha256 or blake3) and the matching zero ID.

The wire kind must equal the repository’s format (RepositoryAccess::object_hash_kind) and local_hash_kind: every protocol operation re-checks the three with SmartProtocol::ensure_hash_kind_consistency and fails closed on a divergence, so this setter cannot be used to serve a repository under another object format.

Source

pub fn new( transport_protocol: TransportProtocol, repo_storage: R, auth_service: A, ) -> Self

Create a new SmartProtocol instance.

The local and wire hash kinds (and the zero ID) are bound to the repository’s own object format, RepositoryAccess::object_hash_kind() — which defaults to the thread-local kind for implementors that do not override it — so a SHA-1, SHA-256 or BLAKE3 (git-internal / Libra extension) repository advertises and accepts exactly its own object-format. Nothing is inferred from ID widths.

Source

pub fn ensure_hash_kind_consistency(&self) -> Result<(), ProtocolError>

Verify that the repository object format, the local kind bound at construction and the negotiated wire kind agree (ADR-GI-B3-03).

Every protocol operation calls this before touching refs, objects or pack bytes. A divergence — a wire object-format that differs from the repository, a SmartProtocol::set_wire_hash_kind override, or a RepositoryAccess whose kind changed after construction — is a diagnosable InvalidRequest naming all three kinds; there is no fallback to another format.

Source

pub async fn authenticate_http( &self, headers: &HashMap<String, String>, ) -> Result<(), ProtocolError>

Authenticate an HTTP request using the injected auth service

Source

pub async fn authenticate_ssh( &self, username: &str, public_key: &[u8], ) -> Result<(), ProtocolError>

Authenticate an SSH session using username and public key

Source

pub fn set_transport_protocol(&mut self, protocol: TransportProtocol)

Set transport protocol (Http, Ssh, etc.)

Source

pub async fn git_info_refs( &self, service_type: ServiceType, ) -> Result<BytesMut, ProtocolError>

Get git info refs for the repository, with explicit service type

Source

pub async fn git_upload_pack( &mut self, upload_request: Bytes, ) -> Result<(ReceiverStream<Result<Vec<u8>, ProtocolError>>, BytesMut), ProtocolError>

Handle git-upload-pack request.

The returned pack stream carries Result items: a failure inside the pack producer (encoder error, object of another format) arrives as an Err item so the transport can report it, instead of an EOF that looks like a truncated pack.

Source

pub fn parse_receive_pack_commands( &mut self, protocol_bytes: Bytes, ) -> Result<(), ProtocolError>

Parse receive-pack commands from protocol bytes.

Fails closed (InvalidRequest) on an object-format capability that is unknown or differs from the repository, and on any command whose IDs are not raw lowercase hex of the wire kind; command_list then holds the commands parsed so far.

Source

pub async fn git_receive_pack_stream( &mut self, data_stream: ProtocolStream, ) -> Result<Bytes, ProtocolError>

Handle git receive-pack operation (push)

Source

pub fn build_side_band_format( &self, from_bytes: BytesMut, length: usize, ) -> BytesMut

Builds the packet data in the sideband format if the SideBand/64k capability is enabled.

Source

pub fn parse_capabilities(&mut self, cap_str: &str) -> Result<(), ProtocolError>

Parse the capability list of the first pkt-line of a request.

object-format=<name> goes through the single HashKind parser (GC-02) as an exact lowercase value (GC-13): sha1 and sha256 are the standard Git formats, blake3 is the git-internal / Libra extension. An unknown or non-canonical value, or a known value that differs from the repository’s format, is a diagnosable InvalidRequest (fail-closed: no warn-and-ignore, no fallback); the wire kind and zero ID are only updated on success. Other capabilities are recorded as before.

Source

pub fn parse_ref_command( &self, pkt_line: &mut Bytes, ) -> Result<RefCommand, ProtocolError>

Parse a reference command (<old-id> <new-id> <ref-name>) from a pkt-line.

Both IDs must be raw lowercase hex of the wire kind (the zero ID included): a wrong width (for example a 40-hex SHA-1 ID on a BLAKE3 wire), non-hex characters, a tagged ID or a missing ref name is a diagnosable InvalidRequest.

Auto Trait Implementations§

§

impl<R, A> Freeze for SmartProtocol<R, A>
where R: Freeze, A: Freeze,

§

impl<R, A> RefUnwindSafe for SmartProtocol<R, A>

§

impl<R, A> Send for SmartProtocol<R, A>

§

impl<R, A> Sync for SmartProtocol<R, A>

§

impl<R, A> Unpin for SmartProtocol<R, A>
where R: Unpin, A: Unpin,

§

impl<R, A> UnsafeUnpin for SmartProtocol<R, A>
where R: UnsafeUnpin, A: UnsafeUnpin,

§

impl<R, A> UnwindSafe for SmartProtocol<R, A>
where R: UnwindSafe, A: UnwindSafe,

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

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

Source§

fn value_size(&self) -> usize

The size of this value in bytes, excluding allocated data. Read more
Source§

fn value_size_sum_iter<'item>(iterator: impl Iterator<Item = &'item T>) -> usize
where T: 'item,

The total sum of the sizes of all values in the given iterator, in bytes. This is default-implemented by computing ValueSize::value_size on every element and summing them. For Sized types, a more potentially efficient implementation using Iterator::count is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more
Source§

fn value_size_sum_exact_size_iter<'item>( iterator: impl ExactSizeIterator<Item = &'item T>, ) -> usize
where T: 'item,

The total sum of the sizes of all values in the given exact-size-iterator, in bytes. This is default-implemented by using ValueSize::value_size_sum_iter. For Sized types, a usually more efficient implementation using ExactSizeIterator::len is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more
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