pub struct SmartProtocol<R, A>where
R: RepositoryAccess,
A: AuthenticationService,{
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: StringImplementations§
Source§impl<R, A> SmartProtocol<R, A>where
R: RepositoryAccess,
A: AuthenticationService,
impl<R, A> SmartProtocol<R, A>where
R: RepositoryAccess,
A: AuthenticationService,
Sourcepub fn set_wire_hash_kind(&mut self, kind: HashKind)
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.
Sourcepub fn new(
transport_protocol: TransportProtocol,
repo_storage: R,
auth_service: A,
) -> Self
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.
Sourcepub fn ensure_hash_kind_consistency(&self) -> Result<(), ProtocolError>
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.
Sourcepub async fn authenticate_http(
&self,
headers: &HashMap<String, String>,
) -> Result<(), ProtocolError>
pub async fn authenticate_http( &self, headers: &HashMap<String, String>, ) -> Result<(), ProtocolError>
Authenticate an HTTP request using the injected auth service
Sourcepub async fn authenticate_ssh(
&self,
username: &str,
public_key: &[u8],
) -> Result<(), ProtocolError>
pub async fn authenticate_ssh( &self, username: &str, public_key: &[u8], ) -> Result<(), ProtocolError>
Authenticate an SSH session using username and public key
Sourcepub fn set_transport_protocol(&mut self, protocol: TransportProtocol)
pub fn set_transport_protocol(&mut self, protocol: TransportProtocol)
Set transport protocol (Http, Ssh, etc.)
Sourcepub async fn git_info_refs(
&self,
service_type: ServiceType,
) -> Result<BytesMut, ProtocolError>
pub async fn git_info_refs( &self, service_type: ServiceType, ) -> Result<BytesMut, ProtocolError>
Get git info refs for the repository, with explicit service type
Sourcepub async fn git_upload_pack(
&mut self,
upload_request: Bytes,
) -> Result<(ReceiverStream<Result<Vec<u8>, ProtocolError>>, BytesMut), ProtocolError>
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.
Sourcepub fn parse_receive_pack_commands(
&mut self,
protocol_bytes: Bytes,
) -> Result<(), ProtocolError>
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.
Sourcepub async fn git_receive_pack_stream(
&mut self,
data_stream: ProtocolStream,
) -> Result<Bytes, ProtocolError>
pub async fn git_receive_pack_stream( &mut self, data_stream: ProtocolStream, ) -> Result<Bytes, ProtocolError>
Handle git receive-pack operation (push)
Sourcepub fn build_side_band_format(
&self,
from_bytes: BytesMut,
length: usize,
) -> BytesMut
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.
Sourcepub fn parse_capabilities(&mut self, cap_str: &str) -> Result<(), ProtocolError>
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.
Sourcepub fn parse_ref_command(
&self,
pkt_line: &mut Bytes,
) -> Result<RefCommand, ProtocolError>
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>
impl<R, A> RefUnwindSafe for SmartProtocol<R, A>where
R: RefUnwindSafe,
A: RefUnwindSafe,
impl<R, A> Send for SmartProtocol<R, A>
impl<R, A> Sync for SmartProtocol<R, A>
impl<R, A> Unpin for SmartProtocol<R, A>
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.