nquic

Hex.pmCI

Pure Erlang QUIC transport for Erlang/OTP 27+.

Getting started

{deps, [{nquic, "1.0.0"}]}.

Client

{ok, Ctx0} = nquic:connect("example.com", 443, #{tls => #{alpn => [<<"h3">>]}}),
{ok, Sid, Ctx1} = nquic_lib:open_stream(Ctx0, #{type => bidi}),
{ok, Ctx2} = nquic_lib:send_fin(Ctx1, Sid, <<"Hello, QUIC!">>),
{ok, Body, true, Ctx3} = nquic_lib:recv(Ctx2, Sid),
{ok, _Ctx4} = nquic_lib:close(Ctx3).

connect/3 and accept/1,2 return an opaque t:nquic:ctx/0 owned by the calling process. After the handshake the owner is the connection and drives it through nquic_lib. There is no message hop to a connection process: stream operations are pure functions threading the ctx() through.

Server

{ok, Listener} = nquic:listen(4433, #{
    tls => #{
        certfile => "server.pem",
        keyfile => "server.key",
        alpn => [<<"h3">>]
    }
}),
{ok, Ctx0} = nquic:accept(Listener),
{ok, Ctx1} = nquic_lib:takeover(Ctx0),
owner_loop(Ctx1).

The owner must run a loop that ingests inbound packets and services timers, or the connection stalls. See the nquic_lib module docs for the full owner-liveness contract; test/support/nquic_ctx_driver.erl is the faithful reference loop.

Features

Documentation

nquic on HexDocs

License

Apache License 2.0