Skip to content

refactor: move PeerNetwork onto the PeerTransport trait - #7925

Open
rob-stacks wants to merge 1 commit into
stacks-network:mainfrom
rob-stacks:feat/p2p-use-peer-transport
Open

rob-stacks wants to merge 1 commit into
stacks-network:mainfrom
rob-stacks:feat/p2p-use-peer-transport

Conversation

@rob-stacks

Copy link
Copy Markdown
Contributor

Description

Second step of making the p2p network's transport replaceable.

#7864 added the PeerTransport trait and TcpTransport; this PR makes PeerNetwork actually use them.

Until now, PeerNetwork owned every peer's TCP socket and called mio directly to bind, connect, accept and close. After this PR it only deals with connection IDs and byte streams, and everything socket-related lives in TcpTransport. The original TCP code is removed from p2p.rs, so the diff is mostly deletions.

The node's behavior doesn't change: it still uses plain TCP, with no consensus, wire-format or configuration changes. The only new hook is PeerNetwork::set_transport(), which lets a caller pick another transport before binding; nothing calls it yet. The next PR uses it to add an in-memory transport for tests.

@brice-stacks brice-stacks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the PeerNetwork transport-abstraction refactor.

No open issues 🎉

What changed in this PR

Moves PeerNetwork onto the PeerTransport abstraction introduced in #7864, preparing for replaceable transports while retaining TCP as the default.

Changes:

  • Delegates connection lifecycle, polling, and stream ownership to the transport.
  • Adds a pre-bind set_transport() hook and a stream-return reminder.
  • Adapts disconnect tests and documents the refactor.
File Description
stackslib/​src/​net/​transport/​mod.rs Adds must_use guidance for borrowed streams.
stackslib/​src/​net/​tests/​neighbors.rs Simulates disconnects through transport-owned streams.
stackslib/​src/​net/​p2p.rs Replaces direct TCP handling with transport delegation.
changelog.d/​p2p-transport-trait.changed Records the refactor and intended unchanged TCP behavior.

Review effort: Balanced

@rob-stacks
rob-stacks added this pull request to the merge queue Dec 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 4, 2026

This branch has not been deployed

No deployments
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.

4 participants