diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index 8d2437c30..d05831c03 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -875,8 +875,6 @@ impl DiscoveryPeer { #[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct LanPeers { - // #[serde(default)] - // pub peers: String, pub peers: Vec, } diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..05dfa3270 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.62.0" diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rs index db087aa68..8da1937a7 100644 --- a/src/rendezvous_mediator.rs +++ b/src/rendezvous_mediator.rs @@ -750,31 +750,16 @@ async fn handle_received_peers(mut rx: UnboundedReceiver) loop { tokio::select! { data = rx.recv() => match data { - Some(peer) => { + Some(mut peer) => { let in_response_set = !response_set.insert(peer.id.clone()); - let mut pre_found = false; - // Try find and update peer - for peer1 in &mut peers { - if peer1.is_same_peer(&peer) { - if in_response_set { - // Merge ip_mac and update other infos - peer1.ip_mac.extend(peer.ip_mac.clone()); - peer1.hostname = peer.hostname.clone(); - peer1.platform = peer.platform.clone(); - peer1.online = true; - } else { - // Update all peer infos - *peer1 = peer.clone(); - } - pre_found = true; - break + if let Some(pos) = peers.iter().position(|x| x.is_same_peer(&peer) ) { + let peer1 = peers.remove(pos); + if in_response_set { + peer.ip_mac.extend(peer1.ip_mac); + peer.online = true; } } - // Push if not found - if !pre_found { - peers.push(peer); - } - + peers.insert(0, peer); if last_write_time.elapsed().as_millis() > 300 { config::LanPeers::store(&peers); last_write_time = Instant::now();