aboutsummaryrefslogtreecommitdiff
path: root/p2p/src/discovery
diff options
context:
space:
mode:
Diffstat (limited to 'p2p/src/discovery')
-rw-r--r--p2p/src/discovery/lookup.rs10
-rw-r--r--p2p/src/discovery/refresh.rs4
2 files changed, 8 insertions, 6 deletions
diff --git a/p2p/src/discovery/lookup.rs b/p2p/src/discovery/lookup.rs
index 52aa339..0138068 100644
--- a/p2p/src/discovery/lookup.rs
+++ b/p2p/src/discovery/lookup.rs
@@ -140,11 +140,12 @@ impl LookupService {
}
}
+ let mut table = self.table.lock().await;
for peer in peer_buffer.iter() {
- let mut table = self.table.lock().await;
let result = table.add_entry(peer.clone().into());
trace!("Add entry {:?}", result);
}
+ drop(table);
self.monitor
.notify(&DiscoveryEvent::LookupSucceeded(endpoint.clone(), peer_buffer.len()).into())
@@ -164,10 +165,12 @@ impl LookupService {
for _ in 0..2 {
let peer_id = PeerID::random();
let peers = self.connect(&peer_id, endpoint.clone()).await?;
+
+ let table = self.table.lock().await;
for peer in peers {
if random_peers.contains(&peer)
|| peer.peer_id == self.id
- || self.table.lock().await.contains_key(&peer.peer_id.0)
+ || table.contains_key(&peer.peer_id.0)
{
continue;
}
@@ -343,8 +346,9 @@ impl LookupService {
trace!("Send Peers msg");
let table = self.table.lock().await;
let entries = table.closest_entries(&peer_id.0, MAX_PEERS_IN_PEERSMSG);
- let peers: Vec<PeerMsg> = entries.into_iter().map(|e| e.into()).collect();
drop(table);
+
+ let peers: Vec<PeerMsg> = entries.into_iter().map(|e| e.into()).collect();
io_codec.write(NetMsgCmd::Peers, &PeersMsg(peers)).await?;
Ok(())
}
diff --git a/p2p/src/discovery/refresh.rs b/p2p/src/discovery/refresh.rs
index a708261..1ced266 100644
--- a/p2p/src/discovery/refresh.rs
+++ b/p2p/src/discovery/refresh.rs
@@ -130,14 +130,12 @@ impl RefreshService {
.notify(&DiscoveryEvent::RefreshStarted.into())
.await;
- let table = self.table.lock().await;
let mut entries: Vec<BucketEntry> = vec![];
- for bucket in table.iter() {
+ for bucket in self.table.lock().await.iter() {
for entry in bucket.random_iter(8) {
entries.push(entry.clone())
}
}
- drop(table);
self.clone().do_refresh(&entries).await;
}