1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use priv_prelude::*;

pub struct ImplNode<N> {
    node: N,
    num_hops: u32,
}

/// Add hops between nodes. The will cause the TTL of packets travelling on this connection to
/// decrease by the given amount.
pub fn hops_v4<N>(num_hops: u32, node: N) -> ImplNode<N>
where
    N: Ipv4Node,
{
    ImplNode { node, num_hops }
}

impl<N> Ipv4Node for ImplNode<N>
where
    N: Ipv4Node,
{
    type Output = N::Output;

    fn build(
        self,
        handle: &Handle,
        subnet: SubnetV4,
    ) -> (JoinHandle<N::Output>, Ipv4Plug) {
        let (join_handle, plug) = self.node.build(handle, subnet);
        let plug = plug.with_hops(handle, self.num_hops);
        (join_handle, plug)
    }
}