diff options
author | Alex Auvolat <alex@adnab.me> | 2024-02-19 17:52:53 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-02-19 18:12:21 +0100 |
commit | 66fe893023a1c296deeb7a4d4c82336c4e34103f (patch) | |
tree | 347a67f2384c8d6118dbf5d17f55c63bac6c02b5 /src/net/peering.rs | |
parent | 6bb34899f225141e65e79fe140b9abca29b39fd6 (diff) | |
download | garage-66fe893023a1c296deeb7a4d4c82336c4e34103f.tar.gz garage-66fe893023a1c296deeb7a4d4c82336c4e34103f.zip |
[networking-fixes] garage_net: retry connecting when new IP is learned
Diffstat (limited to 'src/net/peering.rs')
-rw-r--r-- | src/net/peering.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/net/peering.rs b/src/net/peering.rs index 32199cf8..3f0b2279 100644 --- a/src/net/peering.rs +++ b/src/net/peering.rs @@ -80,6 +80,23 @@ impl PeerInfoInternal { failed_pings: 0, } } + fn add_addr(&mut self, addr: SocketAddr) -> bool { + if !self.all_addrs.contains(&addr) { + self.all_addrs.push(addr); + // If we are learning a new address for this node, + // we want to retry connecting + self.state = match self.state { + PeerConnState::Trying(_) => PeerConnState::Trying(0), + PeerConnState::Waiting(_, _) | PeerConnState::Abandonned => { + PeerConnState::Waiting(0, Instant::now()) + } + x @ (PeerConnState::Ourself | PeerConnState::Connected) => x, + }; + true + } else { + false + } + } } /// Information that the full mesh peering strategy can return about the peers it knows of @@ -465,8 +482,7 @@ impl PeeringManager { let mut changed = false; for (id, addr) in list.iter() { if let Some(kh) = known_hosts.list.get_mut(id) { - if !kh.all_addrs.contains(addr) { - kh.all_addrs.push(*addr); + if kh.add_addr(*addr) { changed = true; } } else { @@ -538,9 +554,7 @@ impl PeeringManager { let mut known_hosts = self.known_hosts.write().unwrap(); if is_incoming { if let Some(host) = known_hosts.list.get_mut(&id) { - if !host.all_addrs.contains(&addr) { - host.all_addrs.push(addr); - } + host.add_addr(addr); } else { known_hosts.list.insert(id, self.new_peer(&id, addr)); } @@ -553,9 +567,7 @@ impl PeeringManager { if let Some(host) = known_hosts.list.get_mut(&id) { host.state = PeerConnState::Connected; host.addr = addr; - if !host.all_addrs.contains(&addr) { - host.all_addrs.push(addr); - } + host.add_addr(addr); } else { known_hosts .list |