Skip to content

Conversation

patrick-ogrady
Copy link
Contributor

@patrick-ogrady patrick-ogrady commented Jun 29, 2025

Related: #1132

Until key confirmation, we don't know if the dialer was in fact the peer. To prevent an adversary from trivially blocking a peer (rate limiting inbound connections by spamming handshake requests), we should wait to reserve a connection to a peer until the handshake is complete.

In an ideal world, we would also check if the dialing peer is already rate limited but governor doesn't expose this capability (and we instead just rely on the handshake rate limiter as an overlay limit which would probably be hit first in most cases anyways).

@patrick-ogrady patrick-ogrady requested a review from Copilot June 29, 2025 21:22
Copilot

This comment was marked as outdated.

debug!(?peer, "verified handshake");

// Check if the peer is listenable
if !tracker
Copy link
Contributor Author

@patrick-ogrady patrick-ogrady Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is extra overhead from messaging the tracker twice per handshake (rather than the once before), however, this is required with the current code to prevent this trivial attack.

@patrick-ogrady patrick-ogrady added this to the v0.0.55 milestone Jun 29, 2025
@patrick-ogrady patrick-ogrady marked this pull request as draft June 29, 2025 22:07
@patrick-ogrady patrick-ogrady marked this pull request as ready for review June 29, 2025 23:44
@patrick-ogrady patrick-ogrady requested a review from Copilot June 30, 2025 01:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR defers reserving a peer connection until after the handshake completes, adding a new listenable predicate and integrating it throughout the tracker and listener logic.

  • Introduce listenable methods in both lookup and discovery records, directories, and mailbox APIs
  • Add Message::Listenable variant & mailbox helpers to query listenability
  • Update listener actor to verify handshake, check listenable, complete handshake, then reserve connection

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
p2p/src/authenticated/lookup/actors/tracker/record.rs Add listenable predicate to peer records
p2p/src/authenticated/lookup/actors/tracker/ingress.rs Add Listenable message & mailbox helper
p2p/src/authenticated/lookup/actors/tracker/directory.rs Implement listenable in directory API
p2p/src/authenticated/lookup/actors/tracker/actor.rs Handle Message::Listenable and add tests
p2p/src/authenticated/lookup/actors/listener.rs Delay reservation until after handshake complete
p2p/src/authenticated/discovery/actors/tracker/{record,ingress,directory,actor}.rs Mirror lookup changes for discovery tracker
p2p/src/authenticated/discovery/actors/listener.rs Delay reservation until after handshake complete
Comments suppressed due to low confidence (3)

p2p/src/authenticated/lookup/actors/tracker/directory.rs:204

  • Add a doc comment explaining when a peer is considered listenable (e.g., allowed and not connected) to match the style of dialable.
    pub fn listenable(&self, peer: &C) -> bool {

p2p/src/authenticated/discovery/actors/tracker/directory.rs:314

  • Consider adding a doc comment here as well to describe the conditions under which a peer is listenable.
    pub fn listenable(&self, peer: &C) -> bool {

p2p/src/authenticated/lookup/actors/tracker/actor.rs:323

  • Relying on a fixed sleep can make tests brittle. Consider using a notification or awaiting an explicit confirmation from the tracker instead of sleep to synchronize test setup.
            context.sleep(Duration::from_millis(10)).await;

danlaine
danlaine previously approved these changes Jun 30, 2025
Copy link
Collaborator

@danlaine danlaine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the comment nits

BrendanChou
BrendanChou previously approved these changes Jun 30, 2025
@patrick-ogrady patrick-ogrady dismissed stale reviews from BrendanChou and danlaine via c41fe5e June 30, 2025 20:03
@patrick-ogrady patrick-ogrady requested a review from danlaine June 30, 2025 20:03
@patrick-ogrady patrick-ogrady merged commit 3da0f82 into main Jun 30, 2025
28 checks passed
@patrick-ogrady patrick-ogrady deleted the delayed-p2p-reservation branch June 30, 2025 20:39
Copy link

codecov bot commented Jun 30, 2025

Codecov Report

Attention: Patch coverage is 97.97297% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.17%. Comparing base (fcdf0ab) to head (c41fe5e).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
p2p/src/authenticated/lookup/actors/listener.rs 81.81% 2 Missing ⚠️
p2p/src/authenticated/discovery/actors/listener.rs 90.00% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #1170      +/-   ##
==========================================
+ Coverage   91.09%   91.17%   +0.07%     
==========================================
  Files         216      216              
  Lines       57779    57889     +110     
==========================================
+ Hits        52634    52780     +146     
+ Misses       5145     5109      -36     
Files with missing lines Coverage Δ
...rc/authenticated/discovery/actors/tracker/actor.rs 98.03% <100.00%> (+0.06%) ⬆️
...uthenticated/discovery/actors/tracker/directory.rs 88.54% <100.00%> (+0.15%) ⬆️
.../authenticated/discovery/actors/tracker/ingress.rs 87.95% <100.00%> (+1.65%) ⬆️
...c/authenticated/discovery/actors/tracker/record.rs 96.88% <100.00%> (+0.01%) ⬆️
...p/src/authenticated/lookup/actors/tracker/actor.rs 97.22% <100.00%> (+0.32%) ⬆️
...c/authenticated/lookup/actors/tracker/directory.rs 92.30% <100.00%> (+0.20%) ⬆️
...src/authenticated/lookup/actors/tracker/ingress.rs 85.29% <100.00%> (+2.53%) ⬆️
.../src/authenticated/lookup/actors/tracker/record.rs 98.03% <100.00%> (+0.02%) ⬆️
p2p/src/authenticated/discovery/actors/listener.rs 87.23% <90.00%> (+0.87%) ⬆️
p2p/src/authenticated/lookup/actors/listener.rs 87.23% <81.81%> (+0.87%) ⬆️

... and 11 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fcdf0ab...c41fe5e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants