From 882f063ab7302f70fdff99c6b7e1fec4a81dc29c Mon Sep 17 00:00:00 2001 From: Maxime Van Hees Date: Thu, 25 May 2023 15:51:22 +0000 Subject: [PATCH] fixed update bug where wrong router_id got used --- src/peer.rs | 2 +- src/router.rs | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/peer.rs b/src/peer.rs index 4fa3027..1123199 100644 --- a/src/peer.rs +++ b/src/peer.rs @@ -184,7 +184,7 @@ impl PeerInner { } Some(packet) = from_routing_data.recv() => { - println!("Sending data packet to peer: {:?}", packet); + // println!("Sending data packet to peer: {:?}", packet); // Send it over the TCP stream if let Err(e) = framed.send(Packet::DataPacket(packet)).await { eprintln!("Error writing to stream: {}", e); diff --git a/src/router.rs b/src/router.rs index dc42b92..24c9021 100644 --- a/src/router.rs +++ b/src/router.rs @@ -250,6 +250,7 @@ impl Router { mut router_control_rx: UnboundedReceiver, ) { while let Some(control_struct) = router_control_rx.recv().await { + println!("received control packet from {:?}", control_struct.src_overlay_ip); match control_struct.control_packet.body.tlv_type { BabelTLVType::Hello => Self::handle_incoming_hello(&self, control_struct), BabelTLVType::IHU => Self::handle_incoming_ihu(&self, control_struct), @@ -303,6 +304,7 @@ impl Router { } => { // upon receiving and update, we should create a mapping that matches an overlay ip to a router id (which is a PublicKey) if let IpAddr::V6(src_overlay_ip) = update.src_overlay_ip { + println!("Adding overlay ip to router id mapping: {:?} -> {:?}", src_overlay_ip, router_id); self.add_dest_pubkey_map_entry(src_overlay_ip, router_id); } @@ -759,20 +761,35 @@ impl RouterInner { for sr in self.selected_routing_table.table.iter() { for peer in self.peer_interfaces.iter() { let peer_link_cost = peer.link_cost(); + + // convert sr.0.prefix to ipv6 addr + if let IpAddr::V6(prefix) = sr.0.prefix { + let og_sender_pubkey_option = self.dest_pubkey_map.get(&prefix); + // if the prefix is not in the dest_pubkey_map, then we use the router_id of the node itself + let og_sender_pubkey = match og_sender_pubkey_option { + Some(pubkey) => *pubkey, + None => self.router_id, + }; - let update = ControlPacket::new_update( - sr.0.plen, - UPDATE_INTERVAL as u16, - self.router_seqno, // updates receive the seqno of the router - if sr.1.metric > u16::MAX - 1 - peer_link_cost { - u16::MAX - 1 - } else { - sr.1.metric + peer_link_cost - }, // the cost of the route is the cost of the route + the cost of the link to the peer - sr.0.prefix, // the prefix of a static route corresponds to the TUN addr of the node - self.router_id, - ); - updates.push((peer.clone(), update)); + + let update = ControlPacket::new_update( + sr.0.plen, + UPDATE_INTERVAL as u16, + self.router_seqno, // updates receive the seqno of the router + if sr.1.metric > u16::MAX - 1 - peer_link_cost { + u16::MAX - 1 + } else { + sr.1.metric + peer_link_cost + }, // the cost of the route is the cost of the route + the cost of the link to the peer + sr.0.prefix, // the prefix of a static route corresponds to the TUN addr of the node + + // we looked for the router_id, which is a public key, in the dest_pubkey_map + // if the router_id is not in the map, then the route came from the node itself + og_sender_pubkey, + ); + println!("\n\n\n\nPropagting route update to: {}\n {:?}\n\n", peer.overlay_ip(), update); + updates.push((peer.clone(), update)); + } } }