pub fn random_mix_route<R>(
        &self,
        rng: &mut R,
        num_mix_hops: u8,
    ) -> Result<Vec<SphinxNode>, NymTopologyError>
    where
        // I don't think there's a need for this RNG to be crypto-secure
        R: Rng + ?Sized,
    {
        use rand::seq::SliceRandom;

        if self.mixes.len() < num_mix_hops as usize {
            return Err(NymTopologyError::InvalidNumberOfHopsError);
        }
        let mut route = Vec::with_capacity(num_mix_hops as usize);

        // there is no "layer 0"
        for layer in 1..=num_mix_hops {
            // get all mixes on particular layer
            let layer_mixes = match self.mixes.get(&layer) {
                Some(mixes) => mixes,
                None => return Err(NymTopologyError::NoMixesOnLayerAvailable(layer)),
            };

            // choose a random mix from the above list
            // this can return a 'None' only if slice is empty
            let random_mix = match layer_mixes.choose(rng) {
                Some(random_mix) => random_mix,
                None => return Err(NymTopologyError::NoMixesOnLayerAvailable(layer)),
            };
            route.push(random_mix.into());
        }

        Ok(route)
    }
/// Returns a vec of size of `num_mix_hops` of mixnodes, such that each subsequent node is on
/// next layer, starting from layer 1
Returns a vec of size of `num_mix_hops` of mixnodes, such that each subsequent node is on
next layer, starting from layer 1
Returns a vec of size of ` num_mix_hops ` of mixnodes such that each subsequent node is on next layer starting from layer 1
pub fn random_mix_route<R>(
        &self,
        rng: &mut R,
        num_mix_hops: u8,
    ) -> Result<Vec<SphinxNode>, NymTopologyError>
    where
        // I don't think there's a need for this RNG to be crypto-secure
        R: Rng + ?Sized,
    {
        use rand::seq::SliceRandom;
        if self.mixes.len() < num_mix_hops as usize {
            return Err(NymTopologyError::InvalidNumberOfHopsError);
        }
        let mut route = Vec::with_capacity(num_mix_hops as usize);
        // there is no "layer 0"
        for layer in 1..=num_mix_hops {
            // get all mixes on particular layer
            let layer_mixes = match self.mixes.get(&layer) {
                Some(mixes) => mixes,
                None => return Err(NymTopologyError::NoMixesOnLayerAvailable(layer)),
            };
            // choose a random mix from the above list
            // this can return a 'None' only if slice is empty
            let random_mix = match layer_mixes.choose(rng) {
                Some(random_mix) => random_mix,
                None => return Err(NymTopologyError::NoMixesOnLayerAvailable(layer)),
            };
            route.push(random_mix.into());
        }
        Ok(route)
    }
pub fn random_mix_route < R > ( & self , rng : & mut R , num_mix_hops : u8 , ) -> Result < Vec < SphinxNode > , NymTopologyError > where // I don't think there's a need for this RNG to be crypto-secure R : Rng + ? Sized , { use rand :: seq :: SliceRandom ; if self . mixes . len ( ) < num_mix_hops as usize { return Err ( NymTopologyError :: InvalidNumberOfHopsError ) ; } let mut route = Vec :: with_capacity ( num_mix_hops as usize ) ; // there is no "layer 0" for layer in 1 ..= num_mix_hops { // get all mixes on particular layer let layer_mixes = match self . mixes . get ( & layer ) { Some ( mixes ) => mixes , None => return Err ( NymTopologyError :: NoMixesOnLayerAvailable ( layer ) ) , } ; // choose a random mix from the above list // this can return a 'None' only if slice is empty let random_mix = match layer_mixes . choose ( rng ) { Some ( random_mix ) => random_mix , None => return Err ( NymTopologyError :: NoMixesOnLayerAvailable ( layer ) ) , } ; route . push ( random_mix . into ( ) ) ; } Ok ( route ) }
Returns a vec of size of `num_mix_hops` of mixnodes, such that each subsequent node is on
next layer, starting from layer 1
Returns a vec of size of ` num_mix_hops ` of mixnodes such that each subsequent node is on next layer starting from layer 1
&self
rng
&mut R
num_mix_hops
u8
&self
rng
&mut R
num_mix_hops
u8