pub enum ProtocolVersion {
V0,
V1,
V2(u32),
}Expand description
Protocol version. This can be extracted from the payload of the sync packet and will determine what features a connection supports.
Variants§
V0
Protocol version 0
V1
Protocol version 1
V2(u32)
Protocol version 2 with a random 32-bit integer nonce
Implementations§
Source§impl ProtocolVersion
impl ProtocolVersion
Sourcepub const LATEST: ProtocolVersion
pub const LATEST: ProtocolVersion
The latest protocol version.
Sourcepub fn magic(&self) -> Vec<u8> ⓘ
pub fn magic(&self) -> Vec<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.
In version 2, the format is vsock:2:<nonce> where <nonce> is a random
32-bit unsigned integer (in hexadecimal).
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more