Struct vivaldi_nc::network_coordinate::NetworkCoordinate
source · pub struct NetworkCoordinate<const N: usize> { /* private fields */ }Implementations§
source§impl<const N: usize> NetworkCoordinate<N>
impl<const N: usize> NetworkCoordinate<N>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new random NetworkCoordinate
Example
use vivaldi_nc::NetworkCoordinate;
// create a new 3-dimensional random NC
let a: NetworkCoordinate<3> = NetworkCoordinate::new();
// print the NC
println!("Our new NC is: {:#?}", a);sourcepub fn estimated_rtt(&self, rhs: &Self) -> Duration
pub fn estimated_rtt(&self, rhs: &Self) -> Duration
Given another Vivaldi NetworkCoordinate, estimate the round trip time (ie ping) between them.
This is done by computing the height vector distance between between the two coordinates. Vivaldi uses this distance as a representation of estimated round trip time.
Parameters
rhs: the other coordinate
Returns
- the estimated round trip time as a
Duration
Example
use vivaldi_nc::NetworkCoordinate;
// create some 2-dimensional NCs for the sake of this example. These will just be random
// NCs. In a real usecase these would have meaningful values.
let a: NetworkCoordinate<2> = NetworkCoordinate::new();
let b: NetworkCoordinate<2> = NetworkCoordinate::new();
// get the estimated RTT, convert to milliseconds, and print
println!("Estimated RTT: {}", a.estimated_rtt(&b).as_millis());sourcepub fn update(&mut self, rhs: &Self, rtt: Duration) -> &Self
pub fn update(&mut self, rhs: &Self, rtt: Duration) -> &Self
Given another Vivaldi NetworkCoordinate, adjust our coordinateto better represent the actual round
trip time (aka distance) between us.
Parameters
rhs: the other coordinatertt: the measured round trip time betweenselfandrhs
Returns
- a reference to
self
Example
use std::time::Duration;
use vivaldi_nc::NetworkCoordinate;
// We always have our own NC:
let mut local: NetworkCoordinate<2> = NetworkCoordinate::new();
// Assume we received a NC from a remote node:
let remote: NetworkCoordinate<2> = NetworkCoordinate::new();
// And we measured the RTT between us and the remote node:
let rtt = Duration::from_millis(100);
// Now we can update our NC to adjust our position relative to the remote node:
local.update(&remote, rtt);Trait Implementations§
source§impl<const N: usize> Clone for NetworkCoordinate<N>
impl<const N: usize> Clone for NetworkCoordinate<N>
source§fn clone(&self) -> NetworkCoordinate<N>
fn clone(&self) -> NetworkCoordinate<N>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<const N: usize> Debug for NetworkCoordinate<N>
impl<const N: usize> Debug for NetworkCoordinate<N>
source§impl<const N: usize> Default for NetworkCoordinate<N>
impl<const N: usize> Default for NetworkCoordinate<N>
source§impl<'de, const N: usize> Deserialize<'de> for NetworkCoordinate<N>
impl<'de, const N: usize> Deserialize<'de> for NetworkCoordinate<N>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more