Skip to content

[S2] Generic Transport trait + Host.openStream public API #211

Description

@ch4r10t33r

Architectural follow-up surfaced by the spec-compliance audit. Two related gaps blocking new transports + new application protocols.

1. No generic Transport interface

src/transport/quic_runtime.zig:80 hardcodes the 13 supported protocol ids and bakes the QUIC drive loop into the runtime. To add WebTransport, /wss, or WebRTC the embedder has to either:

  • write a parallel transport that re-implements the lifecycle hook contract by hand, OR
  • edit quic_runtime.zig itself.

CommandDispatchHook (swarm.zig:107) gives a per-command interception path but not a transport interface.

2. No Host.openStream(peer, protocol_id) → Stream API

host.zig exposes publish / subscribe / sendRequest only. Custom protocols outside gossipsub + req/resp + identify/ping can't be opened through the public API — application has to intercept via CommandDispatchHook and reach into transport internals.

Acceptance

  • Define pub const Transport = struct { dial: fn ... , listen: fn ..., lifecycle: Lifecycle } in src/transport.zig
  • Refactor QuicRuntime to consume Transport instead of being one
  • Host owns a list of registered transports keyed by multiaddr prefix (/quic-v1, /ws, /wss, ...)
  • Host.openStream(peer, protocol_id) → !*Stream public API delegating to the multistream-select layer
  • Host owns a ProtocolRegistry mapping multistream id → inbound handler; built-in protocols register through it instead of being hardcoded

This unblocks #94 (/wss/WebTransport/WebRTC follow-up), #207 (mDNS) integration shape, and #209 (rendezvous).

Severity: S2 — large refactor, but it's the bottleneck for almost every "add a transport / protocol" item.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions