Skip to content

Commit fb711f6

Browse files
committed
Merge tag '3.1.0.0.6' into feat/nix_build_shell
2 parents c533237 + 037f020 commit fb711f6

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

stackslib/src/net/p2p.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ pub struct DropPeer {
450450
pub reason: DropReason,
451451
/// The address of the peer to drop
452452
pub address: PeerAddress,
453+
/// The port of the peer to drop
454+
pub port: u16,
453455
/// The subsystem source that is dropping the peer
454456
pub source: DropSource,
455457
}
@@ -459,6 +461,7 @@ impl From<&DropNeighbor> for DropPeer {
459461
DropPeer {
460462
reason: drop_neighbor.reason.clone(),
461463
address: drop_neighbor.key.addrbytes,
464+
port: drop_neighbor.key.port,
462465
source: drop_neighbor.source.clone(),
463466
}
464467
}
@@ -1739,6 +1742,7 @@ impl PeerNetwork {
17391742

17401743
disconnect.push(DropPeer {
17411744
address: neighbor_key.addrbytes,
1745+
port: neighbor_key.port,
17421746
reason: DropReason::BannedConnection,
17431747
source: DropSource::PeerNetwork,
17441748
});
@@ -2087,14 +2091,15 @@ impl PeerNetwork {
20872091
pub fn deregister_peer(&mut self, peer: DropPeer) {
20882092
let reason = peer.reason;
20892093
debug!(
2090-
"{:?}: Disconnect peer {}",
2094+
"{:?}: Disconnect peer {}:{}",
20912095
&self.local_peer,
2092-
peer.address.pretty_print()
2096+
peer.address.pretty_print(),
2097+
peer.port,
20932098
);
20942099

20952100
let mut nk_remove = vec![];
20962101
for (neighbor_key, event_id) in self.events.iter() {
2097-
if neighbor_key.addrbytes == peer.address {
2102+
if neighbor_key.addrbytes == peer.address && neighbor_key.port == peer.port {
20982103
let pubkh = self
20992104
.get_p2p_convo(*event_id)
21002105
.and_then(|convo| convo.get_public_key_hash())
@@ -2166,6 +2171,7 @@ impl PeerNetwork {
21662171
reason,
21672172
address: neighbor.addrbytes,
21682173
source,
2174+
port: neighbor.port,
21692175
});
21702176
}
21712177

@@ -2187,6 +2193,7 @@ impl PeerNetwork {
21872193
reason,
21882194
address: neighbor.addrbytes,
21892195
source,
2196+
port: neighbor.port,
21902197
});
21912198
}
21922199
}
@@ -2466,6 +2473,7 @@ impl PeerNetwork {
24662473
if let Some(convo) = convo {
24672474
to_remove.push(DropPeer {
24682475
address: convo.peer_addrbytes,
2476+
port: convo.peer_port,
24692477
reason: DropReason::BrokenConnection(format!("Connection failed: {e}")),
24702478
source: if ibd {
24712479
DropSource::PeerNetworkInboundReadySocket
@@ -2487,6 +2495,7 @@ impl PeerNetwork {
24872495
if let Some(convo) = convo {
24882496
to_remove.push(DropPeer {
24892497
address: convo.peer_addrbytes,
2498+
port: convo.peer_port,
24902499
reason: DropReason::DeadConnection("Connection is no longer alive".into()),
24912500
source: if ibd {
24922501
DropSource::PeerNetworkInboundReadySocket
@@ -2598,6 +2607,7 @@ impl PeerNetwork {
25982607
);
25992608
to_remove.push(DropPeer {
26002609
address: peer.nk.addrbytes,
2610+
port: peer.nk.port,
26012611
reason: DropReason::Unresponsive {
26022612
timeout: self.connection_opts.timeout,
26032613
last_seen: peer.timestamp,
@@ -2629,6 +2639,7 @@ impl PeerNetwork {
26292639

26302640
to_remove.push(DropPeer {
26312641
address: convo.peer_addrbytes,
2642+
port: convo.peer_port,
26322643
reason: DropReason::Unresponsive {
26332644
timeout: self.connection_opts.timeout,
26342645
last_seen: convo.peer_heartbeat.into(),
@@ -2651,6 +2662,7 @@ impl PeerNetwork {
26512662

26522663
to_remove.push(DropPeer {
26532664
address: convo.peer_addrbytes,
2665+
port: convo.peer_port,
26542666
reason: DropReason::Unresponsive {
26552667
timeout: self.connection_opts.timeout,
26562668
last_seen: convo.instantiated,
@@ -2846,6 +2858,7 @@ impl PeerNetwork {
28462858
if let Some(peer) = self.peers.get(event_id) {
28472859
broken.push(DropPeer {
28482860
address: peer.peer_addrbytes,
2861+
port: peer.peer_port,
28492862
reason: DropReason::BrokenConnection(format!(
28502863
"Relay handle broken: {e}"
28512864
)),
@@ -2984,14 +2997,15 @@ impl PeerNetwork {
29842997

29852998
/// Disconnect from all peers
29862999
fn disconnect_all(&mut self, reason: DropReason, source: DropSource) {
2987-
let addresses: Vec<_> = self
3000+
let address_port_pairs: Vec<_> = self
29883001
.peers
29893002
.values()
2990-
.map(|convo| convo.peer_addrbytes)
3003+
.map(|convo| (convo.peer_addrbytes, convo.peer_port))
29913004
.collect();
2992-
for address in addresses {
3005+
for (address, port) in address_port_pairs {
29933006
self.deregister_peer(DropPeer {
29943007
address,
3008+
port,
29953009
reason: reason.clone(),
29963010
source: source.clone(),
29973011
});

0 commit comments

Comments
 (0)