Skip to content

ours-transport-api ​

crates/transport-api — the contract between a protocol and the transport under it (VLESS, Trojan over WebSocket, HTTP Upgrade, HTTP, gRPC, XHTTP): the transport turns one connection into the protocol's byte stream, hiding its frames, and the protocol writes and reads bytes and knows nothing about the transport. Protocols and transport modules depend on this crate, not on the transport module, which only owns the point and the transport over QUIC (transport).

Crateours-transport-api, crates/transport-api
Featuresquic — QuicConnection and QuicSession carry ours-quic types (without it QuicConnection is uninhabited); the only one that takes ours-quic

Contents ​

  • ClientTransport::connect gets a connection already opened by the caller and does the client half of the transport; ServerTransport::accept gets a connection accepted by the inbound (with TLS already finished, if the inbound uses it). A transport does not listen, holds no listener and does not do TLS.
  • Setup — what the caller fixes for one outbound/inbound (TLS, REALITY, the server name, the handshake limit, the Connectors a transport dials with on its own); Leg — another server and its TLS options; Request (the server address and early data — the protocol's first write); Connection — the stream and what the transport learned (the peer's address); Incoming — the logical streams of one connection (HTTP/2) and a Driver that drains frames when the last owner has let go; connect_client — how a protocol opens a stream.
  • HANDSHAKE_TIMEOUT (15 s, C.TCPTimeout), GRPC_MAX_MESSAGE_LEN (16 MiB — our limit, the reference has none), forwarded_source (the address from X-Forwarded-For, like badhttp.SourceAddress).
  • variant.rs: Kind<T> — how a transport module builds both sides from its options; decode(node, &KIND) — the shared block decoder, puts a Configured into the entity's blocks; client(blocks, setup, needs) / server(...) — what the protocol calls. Caps::STREAM — a stream per protocol connection; a transport that does not give what is needed is rejected at build time.
  • Quic<L> — the transport over QUIC, the variant QUIC ("quic") of the point transport: dial(services) gives a QuicDialer (dials HTTP/3 through a dialer with TLS options, for an outbound's Connector), listen(listen, transport, services, tls) — a QuicListener (start with a QuicServe per connection, close). L is the inbound's listen options (ours_config::options::ListenOptions): the contract does not name them, the module and the protocol both do.
  • options.rs — the V2Ray*Options of the sing-box form of the transport field.
  • mock.rs — Identity: a transport that changes nothing (for the tests of protocols and of the interface itself).

Dependencies ​

ours-api, ours-clock, ours-codec, ours-json, ours-runtime (the shard of a connection), ours-tls-options (Leg), tokio; with quic — ours-quic. Not ours-config: the crate reads no configuration itself (with quic it comes in through ours-quic, which does) (tests/layers.py, CONFIG_READERS).

Tests ​

tests/identity.rs — a protocol-like exchange over Identity on a real pair of sockets; unit tests in lib.rs, variant.rs.

GPL-3.0-or-later