From b367b7828c030b61b231326123be8fc6bdfc4ff7 Mon Sep 17 00:00:00 2001 From: Maxime Van Hees Date: Fri, 12 May 2023 15:10:22 +0000 Subject: [PATCH] leefactor v2 --- src/peer.rs | 9 +++------ src/router.rs | 10 +++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/peer.rs b/src/peer.rs index 493ad32..b55f026 100644 --- a/src/peer.rs +++ b/src/peer.rs @@ -46,8 +46,10 @@ impl Peer { /// Adds 1 to the sequence number of this peer . pub fn increment_hello_seqno(&self) { + println!("current seqno: {}", self.inner.read().unwrap().hello_seqno); // TODO: Validate this works - self.inner.write().unwrap().hello_seqno += 1 + self.inner.write().unwrap().hello_seqno += 1; + println!("after increment seqno: {}", self.inner.read().unwrap().hello_seqno); } pub fn time_last_received_hello(&self) -> tokio::time::Instant { @@ -231,9 +233,4 @@ impl PeerInner { })), } } - - pub fn increase_hello_seqno(&mut self) { - self.hello_seqno = self.hello_seqno + 1; - println!("last hello seqno increasted to {}", self.hello_seqno); - } } diff --git a/src/router.rs b/src/router.rs index 9834786..103f4b1 100644 --- a/src/router.rs +++ b/src/router.rs @@ -233,10 +233,12 @@ impl Router { let peer = router.get_peer_by_ip(update.src_overlay_ip).unwrap(); + + let current_link_cost = peer.link_cost(); let route_entry = RouteEntry::new( source_key, peer.clone(), - peer.link_cost() + metric, + if current_link_cost > u16::MAX - metric - 1 { u16::MAX-1 } else { current_link_cost + metric }, seqno, update.src_overlay_ip, true, @@ -299,7 +301,7 @@ impl Router { // we wait for 10 seconds before we start initializing the routing table entries // possible optimization: only run this when necassary (e.g. when a new peer is added) loop { - tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; + tokio::time::sleep(tokio::time::Duration::from_secs(3)).await; for peer in self.peer_interfaces.lock().unwrap().iter_mut() { // we check for the u16::MAX - 1 value, as this is the value that the link cost is initialized to if peer.link_cost() == (u16::MAX - 1) { @@ -347,7 +349,7 @@ impl Router { pub async fn propagate_routes(self) { loop { // routes are propagated every 10 secs - tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; + tokio::time::sleep(tokio::time::Duration::from_secs(3)).await; let router_table = self.routing_table.lock().unwrap(); let peers = self.peer_interfaces.lock().unwrap(); @@ -363,6 +365,8 @@ impl Router { entry.source.router_id, ); + println!("sending udpate packet"); + if peer.send_control_packet(update).is_err() { println!("route update packet dropped"); }