nym_sphinx_routing/
lib.rs

1// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use nym_sphinx_types::{Delay, delays};
5use std::time::Duration;
6use thiserror::Error;
7
8#[derive(Debug, Error, Clone, Copy)]
9#[error("the route vector contains {available} nodes while {requested} hops are required")]
10pub struct InvalidNumberOfHops {
11    available: usize,
12    requested: u8,
13}
14
15pub fn generate_hop_delays(average_packet_delay: Duration, num_hops: usize) -> Vec<Delay> {
16    if average_packet_delay.is_zero() {
17        vec![nym_sphinx_types::Delay::new_from_millis(0); num_hops]
18    } else {
19        delays::generate_from_average_duration(num_hops, average_packet_delay)
20    }
21}