Add bridge update

This commit is contained in:
onyinyang 2023-03-23 13:21:04 -04:00
parent 6681289105
commit 93326e24bf
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
1 changed files with 28 additions and 15 deletions

View File

@ -315,23 +315,36 @@ impl BridgeAuth {
// which will include the IP and Port. Then we can replace the original bridge with the updated bridge or else // which will include the IP and Port. Then we can replace the original bridge with the updated bridge or else
// or else just replace the info field. // or else just replace the info field.
pub fn bridge_update(&mut self, bridge: &BridgeLine) -> bool { pub fn bridge_update(&mut self, bridge: &BridgeLine) -> bool {
let mut res: bool = false; //default False to assume that update failed let mut res: bool = false; //default False to assume that update failed
//Needs to be updated since bridge will only match on some fields. //Needs to be updated since bridge will only match on some fields.
let positions = self.bridge_table.reachable.get_key_value(bridge); let reachable_bridges = self.bridge_table.reachable.clone();
if let Some(v) = positions { for reachable_bridge in reachable_bridges {
println!("Bridge v: {:?} has same IP and Port as bridge {:?}.", v.0, bridge); if (reachable_bridge.0.addr == bridge.addr && reachable_bridge.0.port == bridge.port) {
let mut w = *v.0; println!(
w.info = bridge.info; "Bridge from table: {:?} has same IP and Port as bridge {:?}!",
if v.0 == bridge { reachable_bridge.0, bridge
println!("Yay"); );
println!("Now bridge v: {:?} has all fields the same as bridge {:?}.", v.0, bridge); // Search actual table for bridge
}else { let updating_bridge = self
println!("Boo"); .bridge_table
} .reachable
res = true; .get_key_value(&reachable_bridge.0);
if let Some(v) = updating_bridge {
let mut w = *v.0;
w.info = bridge.info;
println!(
"Now bridge v: {:?} matches the passed bridge {:?}?",
v.0, bridge
);
if v.0 == bridge {
println!("Yay");
res = true;
} else {
println!("Boo");
}
}
} }
}
res res
} }