Happy Eyeballs (RFC 8305) connection establishment, I/O-free core
0

Configure Feed

Select the types of activity you want to include in your feed.

17 1 0

Clone this repository

https://git.vm.fail/gazagnaire.org/ocaml-happy-eyeballs https://git.vm.fail/did:plc:j63lzgkixitwp2362woeuymv
ssh://git@git.recoil.org:2222/gazagnaire.org/ocaml-happy-eyeballs ssh://git@git.recoil.org:2222/did:plc:j63lzgkixitwp2362woeuymv

For self-hosted knots, clone URLs may differ based on your setup.


README.md

nox-happy-eyeballs#

Warning. This is a work-in-progress experimental fork of happy-eyeballs. Do not use it in production; use happy-eyeballs instead.

RFC 8305 (Happy Eyeballs v2) describes how to connect to a remote host that may be reachable over several addresses -- IPv4 and IPv6, via DNS A and AAAA records -- when the local host may have connectivity over IPv4 only, IPv6 only, or both. The candidate connections are raced, with a preference for IPv6, so a slow or broken address family never stalls the connection.

  • nox-happy-eyeballs is the I/O-free core (Happy_eyeballs). It is a value passing state machine: it takes time as a parameter, emits actions for an effectful layer to perform (resolve A, resolve AAAA, connect), and consumes the events the layer feeds back (resolved, connected, failed).
  • nox-happy-eyeballs-eio (Happy_eyeballs_eio) drives the core over Eio sockets: the timer and the candidate connections run as fibers, name resolution defaults to Eio.Net.getaddrinfo, and a single connected socket is returned to the caller.

This library has no binary wire format of its own -- it operates on already parsed Ipaddr.t addresses and Domain_name.t host names -- so it needs neither wire nor bytesrw.

Installation#

Install with opam:

$ opam install nox-happy-eyeballs

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install nox-happy-eyeballs

Example#

let connect_example env =
  Eio.Switch.run @@ fun sw ->
  let t =
    Happy_eyeballs_eio.v ~sw ~clock:(Eio.Stdenv.clock env)
      ~net:(Eio.Stdenv.net env) ()
  in
  match Happy_eyeballs_eio.connect t "robur.coop" [ 443 ] with
  | Ok ((ip, port), flow) ->
    Eio.traceln "connected to %a:%d" Ipaddr.pp ip port;
    Eio.Net.close flow
  | Error (`Msg msg) -> Eio.traceln "failed: %s" msg

Derived from robur-coop/happy-eyeballs. Licensed under ISC; see LICENSE.md.