pub struct NetworkCoordinate<const N: usize> { /* private fields */ }

Implementations§

source§

impl<const N: usize> NetworkCoordinate<N>

source

pub fn new() -> Self

Creates a new random NetworkCoordinate

Example
use vivaldi_nc::network_coordinate::NetworkCoordinate;

// create a new 3-dimensional random NC
let a: NetworkCoordinate<3> = NetworkCoordinate::new();

// print the NC
println!("Our new NC is: {:#?}", a);
source

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::network_coordinate::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());
source

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 coordinate
  • rtt: the measured round trip time between self and rhs
Returns
  • a reference to self
Example
use std::time::Duration;
use vivaldi_nc::network_coordinate::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> Debug for NetworkCoordinate<N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const N: usize> Default for NetworkCoordinate<N>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, const N: usize> Deserialize<'de> for NetworkCoordinate<N>

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
    __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<const N: usize> Serialize for NetworkCoordinate<N>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where
    __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<const N: usize> RefUnwindSafe for NetworkCoordinate<N>

§

impl<const N: usize> Send for NetworkCoordinate<N>

§

impl<const N: usize> Sync for NetworkCoordinate<N>

§

impl<const N: usize> Unpin for NetworkCoordinate<N>

§

impl<const N: usize> UnwindSafe for NetworkCoordinate<N>

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere
    T: for<'de> Deserialize<'de>,