Skip to content

Commit

Permalink
fix: re-establish bond on ping
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Oct 22, 2024
1 parent 8bfbd97 commit 083d236
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,23 @@ impl Discv4Service {

let old_enr = match self.kbuckets.entry(&key) {
kbucket::Entry::Present(mut entry, _) => {
is_proven = entry.value().has_endpoint_proof;
if entry.value().is_expired() {
// If no communication with the sender has occurred within the last 12h, a ping
// should be sent in addition to pong in order to receive an endpoint proof.
needs_bond = true;
} else {
is_proven = entry.value().has_endpoint_proof;
}
entry.value_mut().update_with_enr(ping.enr_sq)
}
kbucket::Entry::Pending(mut entry, _) => {
is_proven = entry.value().has_endpoint_proof;
if entry.value().is_expired() {
// If no communication with the sender has occurred within the last 12h, a ping
// should be sent in addition to pong in order to receive an endpoint proof.
needs_bond = true;
} else {
is_proven = entry.value().has_endpoint_proof;
}
entry.value().update_with_enr(ping.enr_sq)
}
kbucket::Entry::Absent(entry) => {
Expand Down Expand Up @@ -1223,7 +1235,7 @@ impl Discv4Service {
self.update_on_pong(node, pong.enr_sq);
}
PingReason::EstablishBond => {
// nothing to do here
self.update_on_pong(node, pong.enr_sq);
}
PingReason::RePing => {
self.update_on_reping(node, pong.enr_sq);
Expand Down Expand Up @@ -2268,8 +2280,7 @@ impl NodeEntry {
enum PingReason {
/// Initial ping to a previously unknown peer that was inserted into the table.
InitialInsert,
/// Initial ping to a previously unknown peer that didn't fit into the table. But we still want
/// to establish a bond.
/// A ping to a peer to establish a bond (endpoint proof).
EstablishBond,
/// Re-ping a peer.
RePing,
Expand Down

0 comments on commit 083d236

Please sign in to comment.