From d71e94f01d0c4e399bf9e786fbdd206449cbcbcd Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Mon, 13 Nov 2023 11:33:25 +0100 Subject: [PATCH] Fix #54: Enforce hops to have a cost Signed-off-by: Lee Smet --- src/peer.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/peer.rs b/src/peer.rs index 91a2873..e5067e6 100644 --- a/src/peer.rs +++ b/src/peer.rs @@ -18,6 +18,15 @@ use crate::{ /// received. const PACKET_COALESCE_WINDOW: usize = 5; +/// Cost to add to the peer_link_cost for "local processing". +/// +/// The current peer link cost is calculated from a HELLO rtt. This is great to measure link +/// latency, since packets are processed in order. However, on local idle links, this value will +/// likely be 0 since we round down (from the amount of ms it took to process), which does not +/// accurately reflect the fact that there is in fact a cost associated with using a peer, even on +/// these local links. +const PACKET_PROCESSING_COST: u16 = 1; + #[derive(Debug, Clone)] /// A peer represents a directly connected participant in the network. pub struct Peer { @@ -162,7 +171,7 @@ impl Peer { } pub fn link_cost(&self) -> u16 { - self.inner.state.read().unwrap().link_cost + self.inner.state.read().unwrap().link_cost + PACKET_PROCESSING_COST } pub fn set_link_cost(&self, link_cost: u16) {