pub enum ProtocolVersion {
V0,
V1,
}
Expand description
Protocol version. This can be extracted from the payload of the sync packet and will determine what features a connection supports.
Variants§
Implementations§
Source§impl ProtocolVersion
impl ProtocolVersion
Sourcepub const LATEST: ProtocolVersion = ProtocolVersion::V1
pub const LATEST: ProtocolVersion = ProtocolVersion::V1
The latest protocol version.
Sourcepub fn magic(&self) -> &[u8] ⓘ
pub fn magic(&self) -> &[u8] ⓘ
Magic sent in the sync packet of the USB protocol.
The format is a byte string of the form vsock:0
, where the 0 indicates
protocol version 0, and we expect the reply sync packet to have the
exact same contents. As we version the protocol this may increment.
To document the semantics, let’s say this header were “vsock:3”. The device could reply with a lower number, say “vsock:1”. This is the device requesting a downgrade, and if we accept we send the final sync with “vsock:1”. Otherwise we hang up.
Sourcepub fn from_magic(magic: &[u8]) -> Option<ProtocolVersion>
pub fn from_magic(magic: &[u8]) -> Option<ProtocolVersion>
Derive the protocol version from the magic sent in the sync packet.
Sourcepub fn negotiate(
&self,
host_version: &ProtocolVersion,
) -> Option<ProtocolVersion>
pub fn negotiate( &self, host_version: &ProtocolVersion, ) -> Option<ProtocolVersion>
Given self
is the protocol version the target prefers and
host_version
is the protocol version sent in the magic as the host
connects, find the protocol version that should be sent in the reply
magic and used for the connection. If None
, negotiation has broken
down.
Trait Implementations§
Source§impl Clone for ProtocolVersion
impl Clone for ProtocolVersion
Source§fn clone(&self) -> ProtocolVersion
fn clone(&self) -> ProtocolVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more