rust-libp2p icon indicating copy to clipboard operation
rust-libp2p copied to clipboard

feat(Transport::Dial): PortUse policy yielded for Outbound Connections

Open momoshell opened this issue 2 months ago • 0 comments

Description

For quite some time, I've observed that behaviors used in production were deteriorating over time. Specifically, KAD queries started failing, nodes remained stuck in kad::Mode::Client, and Autonat repeatedly failed to confirm external addresses, often stuck with a single check per PeerID.

Inspection revealed that the Identify protocol was returning addresses with ephemeral ports. As a result, all behaviors attempted to dial discovered peers on these ephemeral ports, leading to failed outbound connections.

This was happening because the Transport::Dial future lacked a way to notify NetworkBehaviour implementations about which PortUse policy was ultimately applied while creating outbound connections.

This PR aims to address this by enabling this promise to yield this data, allowing behaviors to respond appropriately based on the PortUse policy in use.

Fixes #5820 Should help with related paritytech/polkadot-sdk#7207

Notes & open questions

Huge thanks and shoutout to @dmitry-markin —without his insights into the problem, I wouldn't have been able to start on this.

This PR is large and contains many changes, but I've done my best to organize it. Since each commit addresses a separate crate, I suggest reviewing it commit-by-commit for the clearest path through the changes. 🙏

I'd appreciate an extra set of eyes on all changes, but I'm specifically looking for a thorough review of the modifications to priv_client within the Relay crate, as I have some unease about them.

I will keep this as a draft until I add some additional tests in the following days.

Change checklist

  • [x] I have performed a self-review of my own code
  • [x] I have made corresponding changes to the documentation
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] A changelog entry has been made in the appropriate crates

momoshell avatar Oct 23 '25 18:10 momoshell