robur-coop / happy-eyeballs

An implementation of happy eyeballs (RFC 8305) in OCaml with lwt
ISC License
22 stars 4 forks source link

Add the Miou implementation of happy-eyeballs #41

Closed dinosaure closed 3 weeks ago

dinosaure commented 4 months ago

This implementation provide an happy-eyeballs implementation with Miou with the idea proposed in #38 (with a protection to avoid to inject multiple a time a DNS resolver). This implementation is able to provide what is needed for dns-client then and handle UDP, TCP and TLS DNS resolution (the last one with tls-miou available here mirleft/ocaml-tls#494).

I tested the implementation with httpcats and see if I was able to resolve domain-names with UDP, TCP and TLS. Minor some timeout on uncensoreddns (used for TLS), everything seems to work.

The idea of this implementation is to launch a task in parallel which will care about its internal state and how to connect sockets to a given IP address. The daemon tries multiple connections and take the first one connected - other sub-tasks are cancelled and their file-descriptors are properly closed. The daemon works with a internal queue which aggregate user's actions and events from sub-tasks (when a socket is connected, we fill this queue with such event). The daemon can be suspended a certain amount of times (when happy-eyeballs returns `Act) or suspended as long as nothing (user's actions or events) appears (when happy-eyeballs returns `Suspend). Finally, the transfer of the file-descriptor is done via an atomic value. The user initiate a busy-loop and receive an error (if the happy-eyeballs say so) or the socket connected.

A documentation was written to explain the purpose of inject_resolver and to precise that the user must kill the daemon at the end of the process.

dinosaure commented 4 months ago

I added a new patch which takes the advantages of Miou_unix.Ownership and ensure that, in any situation, we don't leak file-descriptors. I added some comments to explain how Miou handles file-descriptors and cancellation.

dinosaure commented 3 months ago

Actually, happy-eyeballs-miou-unix requires dns to have the Transport.S interface. Since my previous work, we can: 1) keep the PR as is 2) defer all the implementation directly into mirage/ocaml-dns#352

dinosaure commented 3 months ago

I re-implemented happy-eyeballs with Miou (and no pin are required) to reflect the recent change made on the package and ocaml-dns. I think this PR is good to review and merge now.

dinosaure commented 3 weeks ago

Ok, we are done on this side. I checked that we don't have a file-descriptor leak. The Miou.Ownership design works like a charm and I improved this version by the deletion of a busy-waiting loop and replace it directly by Miou.Computation which take the advantage of the low-level API of Miou (inspired by picos). A little program is provided: happy-eyeballs-miou-unix.connect which can helps us to see how the library works via logs.