aboutsummaryrefslogtreecommitdiff
path: root/src/peering
diff options
context:
space:
mode:
Diffstat (limited to 'src/peering')
-rw-r--r--src/peering/fullmesh.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs
index 22657dd..5b73f4e 100644
--- a/src/peering/fullmesh.rs
+++ b/src/peering/fullmesh.rs
@@ -391,12 +391,19 @@ impl FullMeshPeeringStrategy {
fn handle_peer_list(&self, list: &[(NodeID, SocketAddr)]) {
let mut known_hosts = self.known_hosts.write().unwrap();
+
+ let mut changed = false;
for (id, addr) in list.iter() {
if !known_hosts.list.contains_key(id) {
known_hosts.list.insert(*id, self.new_peer(id, *addr));
+ changed = true;
}
}
- self.update_public_peer_list(&known_hosts);
+
+ if changed {
+ known_hosts.update_hash();
+ self.update_public_peer_list(&known_hosts);
+ }
}
async fn try_connect(self: Arc<Self>, id: NodeID, addr: SocketAddr) {
@@ -422,18 +429,20 @@ impl FullMeshPeeringStrategy {
async fn on_connected(self: Arc<Self>, id: NodeID, addr: SocketAddr, is_incoming: bool) {
if is_incoming {
- if !self.known_hosts.read().unwrap().list.contains_key(&id) {
- self.known_hosts
- .write()
- .unwrap()
+ let mut known_hosts = self.known_hosts.write().unwrap();
+ if !known_hosts.list.contains_key(&id) {
+ known_hosts
.list
.insert(id, self.new_peer(&id, addr));
+ known_hosts.update_hash();
+ self.update_public_peer_list(&known_hosts);
}
} else {
info!("Successfully connected to {} at {}", hex::encode(&id), addr);
let mut known_hosts = self.known_hosts.write().unwrap();
if let Some(host) = known_hosts.list.get_mut(&id) {
host.state = PeerConnState::Connected;
+ host.addr = addr;
known_hosts.update_hash();
self.update_public_peer_list(&known_hosts);
}