Skip to content

Commit

Permalink
Merge pull request #4812 from driftluo/revert-unnecessary-operations
Browse files Browse the repository at this point in the history
revert: revert unnecessary operations
  • Loading branch information
zhangsoledad authored Feb 20, 2025
2 parents 0c8434c + b598e36 commit b05727c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
22 changes: 4 additions & 18 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ pub struct NetworkState {
pub(crate) peer_store: Mutex<PeerStore>,
/// Node listened addresses
pub(crate) listened_addrs: RwLock<Vec<Multiaddr>>,
dialing_addrs: RwLock<HashMap<PeerId, (Instant, Multiaddr)>>,
pub(crate) pending_dns_addrs: RwLock<HashMap<PeerId, Multiaddr>>,
dialing_addrs: RwLock<HashMap<PeerId, Instant>>,
/// Node public addresses,
/// includes manually public addrs and remote peer observed addrs
public_addrs: RwLock<HashSet<Multiaddr>>,
Expand Down Expand Up @@ -136,7 +135,6 @@ impl NetworkState {
bootnodes,
peer_registry: RwLock::new(peer_registry),
dialing_addrs: RwLock::new(HashMap::default()),
pending_dns_addrs: RwLock::new(HashMap::default()),
public_addrs: RwLock::new(public_addrs),
listened_addrs: RwLock::new(Vec::new()),
pending_observed_addrs: RwLock::new(HashSet::default()),
Expand Down Expand Up @@ -408,7 +406,7 @@ impl NetworkState {
return false;
}

if let Some((dial_started, _)) = self.dialing_addrs.read().get(peer_id) {
if let Some(dial_started) = self.dialing_addrs.read().get(peer_id) {
trace!(
"Do not send repeated dial commands to network service: {:?}, {}",
peer_id,
Expand Down Expand Up @@ -440,15 +438,7 @@ impl NetworkState {

pub(crate) fn dial_success(&self, addr: &Multiaddr) {
if let Some(peer_id) = extract_peer_id(addr) {
if let Some(dial_addr) = self.dialing_addrs.write().remove(&peer_id).map(|a| a.1) {
let has_dns = dial_addr
.iter()
.any(|p| matches!(p, Protocol::Dns4(_) | Protocol::Dns6(_)));

if &dial_addr != addr && has_dns {
self.pending_dns_addrs.write().insert(peer_id, dial_addr);
}
}
self.dialing_addrs.write().remove(&peer_id);
}
}

Expand Down Expand Up @@ -478,7 +468,7 @@ impl NetworkState {
p2p_control.dial(addr.clone(), target)?;
self.dialing_addrs.write().insert(
extract_peer_id(&addr).expect("verified addr"),
(Instant::now(), addr),
Instant::now(),
);
Ok(())
}
Expand Down Expand Up @@ -819,10 +809,6 @@ impl ServiceHandle for EventHandler {
peer_store.remove_disconnected_peer(&session_context.address);
});
}
self.network_state
.pending_dns_addrs
.write()
.remove(&extract_peer_id(&session_context.address).expect("must have peerid"));
}
_ => {
info!("p2p service event: {:?}", event);
Expand Down
7 changes: 0 additions & 7 deletions network/src/protocols/identify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,15 +457,8 @@ impl Callback for IdentifyCallback {
// and if set it to peer store, it will be broadcast to the entire network,
// but this is an unverified address
if renew {
let dns_addr = self.network_state.pending_dns_addrs.write().remove(
&extract_peer_id(&context.session.address).expect("must have peerid"),
);
self.network_state.with_peer_store_mut(|peer_store| {
peer_store.add_outbound_addr(context.session.address.clone(), flags);
if let Some(dns) = dns_addr {
// mark dns address connected time
peer_store.add_outbound_addr(dns, flags);
}
});
}

Expand Down

0 comments on commit b05727c

Please sign in to comment.