Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ impl ConfigBuilder {
self.config.executor = Some(Box::<crate::executor::TokioExecutor>::default());
};

// If enr-update is set to false, then it is non-intuitive for discv5 to revoke ENR details
// when determining NAT status. So we will not do this.
if self.config.enr_update {
self.config.auto_nat_listen_duration = None;
}

assert!(self.config.incoming_bucket_limit <= MAX_NODES_PER_BUCKET);

self.config.clone()
Expand Down
14 changes: 10 additions & 4 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,11 @@ impl Service {
return;
}

// We are configured to ignore ENR updates, we therefore ignore PONGs.
if self.ip_votes.is_none() {
return;
}

// Only count votes that are from peers we have contacted.
let key: kbucket::Key<NodeId> = node_id.into();
let is_connected_and_outgoing = matches!(
Expand All @@ -896,7 +901,7 @@ impl Service {
if status.is_connected() && !status.is_incoming());

// Check to make sure this is an outgoing peer vote, otherwise if we need the vote due to a
// lack of minority, we accept it.
// lack of majority, we accept it.
if !(is_connected_and_outgoing | self.require_more_ip_votes(socket.is_ipv6())) {
return;
}
Expand Down Expand Up @@ -1617,15 +1622,16 @@ impl Service {
let Some(ip_votes) = self.ip_votes.as_mut() else {
return false;
};

// Here we check the number of non-expired votes, rather than the majority. As if the
// local router is not SNAT'd we can have many votes but none for the same port and we
// therefore do excessive pinging.
match (ip_votes.has_minimum_threshold(), is_ipv6) {
// We don't have enough ipv4 votes, but this is an IPv4-only node.
// We don't have enough ipv4 votes, and this is an IPv4-only node.
((false, true), false) |
// We don't have enough ipv6 votes, but this is an IPv6 node.
// We don't have enough ipv6 votes, and this is an IPv6 node.
((true, false), true) |
// We don't have enough ipv6 or ipv4 nodes, ping this peer.
// We don't have enough ipv6 or ipv4 nodes, permit this peer's pong.
((false, false), _,) => true,
// We have enough votes do nothing.
((_, _), _,) => false,
Expand Down
Loading