Skip to content

Capability-based transport decoupling and modular packaging - #1259

Closed
asmit27rai wants to merge 7 commits into
libp2p:mainfrom
asmit27rai:feat/pg
Closed

asmit27rai wants to merge 7 commits into
libp2p:mainfrom
asmit27rai:feat/pg

Conversation

@asmit27rai

@asmit27rai asmit27rai commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR decouples the QUIC transport from the core library and introduces
a provider-based architecture that allows transports, security protocols,
and stream muxers to be discovered and composed dynamically at runtime.

Motivation

Previously, the core imported QUIC classes directly, meaning aioquic
was a hard dependency even for users who only needed TCP. Transport
selection was also rigid — the upgrade pipeline didn't know whether a
transport already handled security or muxing, so it couldn't skip
redundant steps.

What changed

Capability protocols — TransportCapabilities, ConnectionCapabilities,
and NeedsSetup are runtime-checkable protocols that let any transport
declare what it provides (security, muxing) without the core importing
concrete classes.

Requirement decorators — @requires_connection(ISecureConn) and
@after_connection(ISecureConn) let protocol handlers and muxer classes
express ordering constraints. check_connection_requirements() validates
them at stream-open time, and TransportUpgrader verifies muxer ordering
before negotiation.

Provider abstractions — TransportProvider, SecurityProvider, and
MuxerProvider wrap existing transport/security/muxer implementations
behind a uniform interface. ProviderRegistry stores them and supports
bulk registration from legacy option dicts.

Connection resolver — ConnectionResolver is a pull-based stack
builder. Given a multiaddr and peer ID, it picks the right transport,
applies security and muxer upgrades in order, and skips layers the
transport already provides. If one path fails, it falls back to the next
registered transport.

Capability-aware registry queries — TransportRegistry gained methods
like transport_provides_security() and get_self_upgrading_protocols()
so callers can inspect transport capabilities without instantiating them.

Entry-point discovery — discover_and_register() scans
libp2p.transports, libp2p.security, and libp2p.muxers entry-point
groups. Each built-in component ships a _create_*_provider() factory.
Third-party packages can register their own providers by declaring
entry points in their pyproject.toml.

Modular packaging — pyproject.toml now defines optional dependency
groups (quic, noise, tls, secio, yamux, mplex, defaults).
Conditional import guards (_HAS_QUIC, _HAS_NOISE, etc.) let the
library load cleanly when extras are missing. create_yamux_muxer_option()
and the security transport setup in new_swarm() check availability
before including components.

Testing

  • 180 new tests across 6 test files
  • All 180 pass; full suite shows no regressions (2272 passed, 14 skipped)

Breaking changes

None. All changes are additive and opt-in. Existing code using the fixed
TransportUpgrader pipeline continues to work without modification.

Discussion : #1204

Issue : #395

@asmit27rai
asmit27rai marked this pull request as draft March 2, 2026 18:21
@acul71

acul71 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Closing this large draft (CI fully red, heavy conflicts). A focused capabilities approach can be proposed later as a fresh PR against current main if needed for #395.

@acul71 acul71 closed this Sep 9, 2026
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