garage_net: retry connecting when new IP is learned #724

Merged
lx merged 2 commits from networking-fixes into main 2024-02-19 17:37:02 +00:00
Showing only changes of commit 66fe893023 - Show all commits

View file

@ -80,6 +80,23 @@ impl PeerInfoInternal {
failed_pings: 0, 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 /// 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; let mut changed = false;
for (id, addr) in list.iter() { for (id, addr) in list.iter() {
if let Some(kh) = known_hosts.list.get_mut(id) { if let Some(kh) = known_hosts.list.get_mut(id) {
if !kh.all_addrs.contains(addr) { if kh.add_addr(*addr) {
kh.all_addrs.push(*addr);
changed = true; changed = true;
} }
} else { } else {
@ -538,9 +554,7 @@ impl PeeringManager {
let mut known_hosts = self.known_hosts.write().unwrap(); let mut known_hosts = self.known_hosts.write().unwrap();
if is_incoming { if is_incoming {
if let Some(host) = known_hosts.list.get_mut(&id) { if let Some(host) = known_hosts.list.get_mut(&id) {
if !host.all_addrs.contains(&addr) { host.add_addr(addr);
host.all_addrs.push(addr);
}
} else { } else {
known_hosts.list.insert(id, self.new_peer(&id, addr)); 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) { if let Some(host) = known_hosts.list.get_mut(&id) {
host.state = PeerConnState::Connected; host.state = PeerConnState::Connected;
host.addr = addr; host.addr = addr;
if !host.all_addrs.contains(&addr) { host.add_addr(addr);
host.all_addrs.push(addr);
}
} else { } else {
known_hosts known_hosts
.list .list