Skip to content

Commit

Permalink
Add the Miou implementation of happy-eyeballs
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosaure committed Aug 23, 2024
1 parent 65c2d60 commit 40c573b
Show file tree
Hide file tree
Showing 7 changed files with 612 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ freebsd_task:
- opam env

pin_packages_script:
- opam install -y --deps-only -t .
- opam source dns-client
- opam pin add -y -t --with-version=dev happy-eyeballs.opam .
- opam pin add -y -t --with-version=dev happy-eyeballs-lwt.opam .
- opam pin add -y -t --with-version=dev happy-eyeballs-mirage.opam .

build_script:
- opam install -y --deps-only -t dns dns-client dns-client-lwt dns-client-mirage
- opam exec -- dune build -p happy-eyeballs,happy-eyeballs-lwt,happy-eyeballs-mirage,dns,dns-client,dns-client-lwt,dns-client-mirage
- opam exec -- dune build -p happy-eyeballs,happy-eyeballs-lwt,happy-eyeballs-mirage
7 changes: 7 additions & 0 deletions app/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
(modules test)
(package happy-eyeballs-lwt)
(libraries logs.fmt fmt.cli logs.cli fmt.tty cmdliner happy_eyeballs_lwt))

(executable
(name example_with_miou)
(public_name happy_eyeballs_miou_client)
(modules example_with_miou)
(package happy-eyeballs-miou-unix)
(libraries logs.fmt fmt.cli logs.cli logs.threaded fmt.tty happy-eyeballs-miou-unix))
31 changes: 31 additions & 0 deletions app/example_with_miou.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
let reporter ppf =
let report src level ~over k msgf =
let k _ =
over () ;
k () in
let with_metadata header _tags k ppf fmt =
Format.kfprintf k ppf
("%a[%a][%a]: " ^^ fmt ^^ "\n%!")
Logs_fmt.pp_header (level, header)
Fmt.(styled `Cyan int) (Stdlib.Domain.self () :> int)
Fmt.(styled `Magenta string)
(Logs.Src.name src) in
msgf @@ fun ?header ?tags fmt -> with_metadata header tags k ppf fmt in
{ Logs.report }

let () = Fmt_tty.setup_std_outputs ~style_renderer:`Ansi_tty ~utf_8:true ()
let () = Logs.set_reporter (reporter Fmt.stdout)
let () = Logs.set_level ~all:true (Some Logs.Debug)
let () = Logs_threaded.enable ()

let () = Miou_unix.run @@ fun () ->
let daemon, t = Happy_eyeballs_miou_unix.create () in
for _ = 0 to 5 do
match Happy_eyeballs_miou_unix.connect t Sys.argv.(1) [ 80 ] with
| Ok ((ipaddr, port), fd) ->
Logs.info (fun m -> m "Connected to %a:%d" Ipaddr.pp ipaddr port);
Miou_unix.close fd
| Error (`Msg err) ->
Logs.err (fun m -> m "%s" err)
done;
Happy_eyeballs_miou_unix.kill daemon
32 changes: 32 additions & 0 deletions happy-eyeballs-miou-unix.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
opam-version: "2.0"
maintainer: "Robur <[email protected]>"
authors: ["Robur <[email protected]>"]
homepage: "https://github.com/robur-coop/miou-toolkit"
dev-repo: "git+https://github.com/robur-coop/miou-toolkit.git"
bug-reports: "https://github.com/robur-coop/miou-toolkit/issues"
doc: "https://robur-coop.github.io/miou-toolkit/"
license: "ISC"

depends: [
"ocaml" {>= "5.0.0"}
"dune" {>= "2.0.0"}
"happy-eyeballs" {= version}
"miou" {>= "0.2.0"}
"mtime" {>= "2.0.0"}
"duration"
"domain-name"
"ipaddr"
"fmt"
"logs"
]
build: [
["dune" "subst"] {dev}
["dune" "build" "-p" name "-j" jobs]
]

synopsis: "Connecting to a remote host via IP version 4 or 6 using Miou"
description: """
Happy eyeballs is an implementation of RFC 8305 which specifies how to connect
to a remote host using either IP protocol version 4 or IP protocol version 6.
This uses Miou for side effects.
"""
9 changes: 9 additions & 0 deletions miou/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(library
(name happy_eyeballs_miou_unix)
(modules happy_eyeballs_miou_unix)
(public_name happy-eyeballs-miou-unix)
(libraries
miou.unix
mtime.clock.os
ipaddr.unix
happy-eyeballs))
Loading

0 comments on commit 40c573b

Please sign in to comment.