leefactor v2

This commit is contained in:
Maxime Van Hees
2023-05-12 15:10:22 +00:00
parent fc9a1647b1
commit b367b7828c
2 changed files with 10 additions and 9 deletions
+3 -6
View File
@@ -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);
}
}
+7 -3
View File
@@ -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");
}