[networking-fixes] garage_net: retry connecting when new IP is learned
This commit is contained in:
parent
6bb34899f2
commit
66fe893023
1 changed files with 20 additions and 8 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue