aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-03-21 10:50:44 +0100
committerAlex Auvolat <alex@adnab.me>2024-03-21 10:50:44 +0100
commit3844110cd03210a1600d57db1aab53e41cf4815f (patch)
tree3deae99e0651b66e6d12f8e3336dca9016e23ecc
parent961b4f9af36a7fb5d3a661ac19e8f2c168bb48ae (diff)
downloadgarage-net-fixes.tar.gz
garage-net-fixes.zip
[net-fixes] netapp peer exchange: send only currently connected addressnet-fixes
-rw-r--r--src/net/peering.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/net/peering.rs b/src/net/peering.rs
index 0b4fec9e..b4271231 100644
--- a/src/net/peering.rs
+++ b/src/net/peering.rs
@@ -43,7 +43,7 @@ impl Message for PingMessage {
#[derive(Serialize, Deserialize)]
struct PeerListMessage {
- pub list: Vec<(NodeID, Vec<SocketAddr>)>,
+ pub list: Vec<(NodeID, SocketAddr)>,
}
impl Message for PeerListMessage {
@@ -185,11 +185,13 @@ impl KnownHosts {
}
self.hash = hash_state.finalize();
}
- fn connected_peers_vec(&self) -> Vec<(NodeID, Vec<SocketAddr>)> {
+ fn connected_peers_vec(&self) -> Vec<(NodeID, SocketAddr)> {
self.list
.iter()
- .filter(|(_, peer)| peer.state.is_up())
- .map(|(id, peer)| (*id, peer.known_addrs.clone()))
+ .filter_map(|(id, peer)| match peer.state {
+ PeerConnState::Connected { addr } => Some((*id, addr)),
+ _ => None,
+ })
.collect::<Vec<_>>()
}
}
@@ -468,20 +470,18 @@ impl PeeringManager {
}
}
- fn handle_peer_list(&self, list: &[(NodeID, Vec<SocketAddr>)]) {
+ fn handle_peer_list(&self, list: &[(NodeID, SocketAddr)]) {
let mut known_hosts = self.known_hosts.write().unwrap();
let mut changed = false;
- for (id, addrs) in list.iter() {
- for addr in addrs.iter() {
- if let Some(kh) = known_hosts.list.get_mut(id) {
- if kh.add_addr(*addr) {
- changed = true;
- }
- } else {
- known_hosts.list.insert(*id, self.new_peer(id, *addr));
+ for (id, addr) in list.iter() {
+ if let Some(kh) = known_hosts.list.get_mut(id) {
+ if kh.add_addr(*addr) {
changed = true;
}
+ } else {
+ known_hosts.list.insert(*id, self.new_peer(id, *addr));
+ changed = true;
}
}