pub enum Protocol {
Ping {
client_timestamp: UtcTimestamp,
nonce: u8,
},
PingReply {
client_timestamp: UtcTimestamp,
nonce: u8,
server_start_timestamp: UtcTimestamp,
server_transmit_timestamp: UtcTimestamp,
},
}
Expand description
The set of possible QCMP commands.
Variants§
Ping
Fields
client_timestamp: UtcTimestamp
The timestamp from when the client sent the packet.
The initation of a ping command to send to a Quilkin proxy to measure latency.
PingReply
Fields
client_timestamp: UtcTimestamp
The timestamp from when the client sent the ping packet.
server_start_timestamp: UtcTimestamp
The timestamp from when the server received the ping packet.
server_transmit_timestamp: UtcTimestamp
The timestamp from when the server sent the reply.
The reply from a Quilkin proxy from a Self::Ping
command. Can be
used with Protocol::round_trip_delay
to measure latency between
two machines.
Implementations§
source§impl Protocol
impl Protocol
sourcepub fn ping() -> Self
pub fn ping() -> Self
Creates a Self::Ping
with a random nonce, should be sent
as soon as possible from creation to maintain accuracy.
sourcepub fn ping_with_nonce(nonce: u8) -> Self
pub fn ping_with_nonce(nonce: u8) -> Self
Creates a Self::Ping
with a user-specified nonce, should be sent
as soon as possible from creation to maintain accuracy.
sourcepub fn ping_reply(
nonce: u8,
client_timestamp: UtcTimestamp,
server_start_timestamp: UtcTimestamp
) -> Self
pub fn ping_reply( nonce: u8, client_timestamp: UtcTimestamp, server_start_timestamp: UtcTimestamp ) -> Self
Creates a Self::PingReply
from the client and server start timestamp.
It’s recommended to transmit as as soon as possible from creation to
keep the start and transmit times as accurate as possible.
sourcepub fn encode<'buf>(&self, buffer: &'buf mut QcmpPacket) -> &'buf [u8] ⓘ
pub fn encode<'buf>(&self, buffer: &'buf mut QcmpPacket) -> &'buf [u8] ⓘ
Encodes the protocol command into a buffer of bytes for network transmission.
sourcepub fn round_trip_delay(
&self,
client_response_timestamp: UtcTimestamp
) -> Option<DurationNanos>
pub fn round_trip_delay( &self, client_response_timestamp: UtcTimestamp ) -> Option<DurationNanos>
If the command is Protocol::PingReply
, with client_response_timestamp
measures the roundtrip delay between the client machine, and the Quilkin
proxy, using the same algorithm as Network Time Protocol (NTP).
sourcepub fn distance(
&self,
client_response_timestamp: UtcTimestamp
) -> Option<DistanceMeasure>
pub fn distance( &self, client_response_timestamp: UtcTimestamp ) -> Option<DistanceMeasure>
If the command is Protocol::PingReply
, with client_response_timestamp
returns the time between the client -> server, and the server -> client.
sourcepub fn parse(input: &[u8]) -> Result<Option<Self>, Error>
pub fn parse(input: &[u8]) -> Result<Option<Self>, Error>
Parses the provided input, and attempts to parse it as a Protocol
packet.
Returns None
if the magic number is not present, and thus is not a
QCMP packet, and returning Err
when it was detected as a QCMP packet,
but there was an error in parsing the payload.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Protocol
impl Send for Protocol
impl Sync for Protocol
impl Unpin for Protocol
impl UnwindSafe for Protocol
Blanket Implementations§
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request