trevrpc/channel

A connection to a TrevRPC server, which reconnects on its own: native QUIC, QMux over TLS where UDP is blocked, or whichever connects first.

Types

A channel: the process that keeps the connection.

pub type Channel
pub type Config {
  Config(
    host: String,
    port: Int,
    tcp_port: option.Option(Int),
    transport: Transport,
    server_name: option.Option(String),
    ca_file: option.Option(String),
    verify: Bool,
    max_frame_size: option.Option(Int),
    connect_timeout: option.Option(Int),
    idle_timeout: option.Option(Int),
    min_quic_connections: option.Option(Int),
    max_quic_connections: option.Option(Int),
    connection_metadata: dict.Dict(String, BitArray),
    validator: option.Option(
      fn(String) -> option.Option(
        fn(dynamic.Dynamic, BitArray) -> Result(
          Nil,
          status.Status,
        ),
      ),
    ),
  )
}

Constructors

  • Config(
      host: String,
      port: Int,
      tcp_port: option.Option(Int),
      transport: Transport,
      server_name: option.Option(String),
      ca_file: option.Option(String),
      verify: Bool,
      max_frame_size: option.Option(Int),
      connect_timeout: option.Option(Int),
      idle_timeout: option.Option(Int),
      min_quic_connections: option.Option(Int),
      max_quic_connections: option.Option(Int),
      connection_metadata: dict.Dict(String, BitArray),
      validator: option.Option(
        fn(String) -> option.Option(
          fn(dynamic.Dynamic, BitArray) -> Result(Nil, status.Status),
        ),
      ),
    )

    Arguments

    tcp_port

    The server’s TCP listener, by default on the QUIC port number.

    server_name

    The name the server’s certificate must have, by default host.

    ca_file

    A PEM file of the certificates to trust, which may be the server’s own self-signed one; the system’s without.

    min_quic_connections

    How many QUIC connections the channel keeps open and spreads its calls over, by default one; QMux over TLS always uses one.

    max_quic_connections

    How many QUIC connections the channel’s pool grows to under load, by default the schedulers online, from one to four.

    connection_metadata

    Request metadata every call carries, such as a bearer token, sent once per connection instead of in every call; none when empty. See set_connection_metadata.

    validator

    Checks the request messages of calls before they are sent: see trevrpc/validator.

pub type Transport {
  Auto
  Quic
  Tcp
}

Constructors

  • Auto

    QUIC, racing QMux over TLS once QUIC has not connected after a delay.

  • Quic
  • Tcp

    QMux over TLS.

Values

pub fn close(channel: Channel) -> Nil

Closes the channel, ending its calls.

pub fn config(host: String, port: Int) -> Config

A channel to host and port, with every other option at its default.

pub fn connect(
  config: Config,
  timeout: Int,
) -> Result(Channel, status.Status)

Starts a channel, linked to the calling process, and waits up to timeout milliseconds for it to connect. The channel closes when that process exits.

pub fn set_connection_metadata(
  channel: Channel,
  metadata: dict.Dict(String, BitArray),
) -> Result(Nil, status.Status)

Replaces the channel’s connection metadata: request metadata every call carries, which crosses each connection in its first calls, until the server confirms it stored it, and is referred to by ID after that. The server merges it into each call’s metadata, the call’s own entry winning for a name both have. Calls that start afterwards carry the new metadata, and calls in flight keep theirs. Empty metadata removes it.

✨ Search Document