Skip to content

Commit

Permalink
Merge pull request #415 from reynir/resolver
Browse files Browse the repository at this point in the history
Delay parsing of nameservers
  • Loading branch information
dinosaure authored Oct 8, 2022
2 parents 5c10995 + 515617f commit e5421ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
21 changes: 17 additions & 4 deletions src/conduit-mirage/resolver_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,34 @@ struct
| Ok addr -> `TCP (Ipaddr.V4 addr, port)

let register ?nameservers s res =
let ( let* ) = Result.bind in
(* DNS stub resolver *)
let nameservers = Option.map (fun ns -> (`Tcp, ns)) nameservers in
let* nameservers =
Option.fold ~none:(Ok None)
~some:(fun nameservers ->
List.fold_left
(fun acc ns ->
let* acc = acc in
let* ns = DNS.nameserver_of_string ns in
Ok (ns :: acc))
(Ok []) nameservers
|> Result.map Option.some)
nameservers
|> Result.map (Option.map (fun io -> (`Tcp, io)))
in
let dns = DNS.create ?nameservers s in
let f = dns_stub_resolver dns in
Resolver_lwt.add_rewrite ~host:"" ~f res;
let service = Resolver_lwt.(service res ++ static_service) in
Resolver_lwt.set_service ~f:service res;
let vchan_tld = ".xen" in
let vchan_res = vchan_resolver ~tld:vchan_tld in
Resolver_lwt.add_rewrite ~host:vchan_tld ~f:vchan_res res
Resolver_lwt.add_rewrite ~host:vchan_tld ~f:vchan_res res;
Ok ()

let v ?nameservers stack =
let res = Resolver_lwt.init () in
register ?nameservers stack res;
res
register ?nameservers stack res |> Result.map (fun () -> res)

type t = Resolver_lwt.t
end
11 changes: 3 additions & 8 deletions src/conduit-mirage/resolver_mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ module Make
(S : Tcpip.Stack.V4V6) : sig
include S

val v :
?nameservers:
[ `Plaintext of Ipaddr.t * int
| `Tls of Tls.Config.client * Ipaddr.t * int ]
list ->
S.t ->
t
(** [v ~nameservers stack ()] TODO *)
val v : ?nameservers:string list -> S.t -> (t, [> `Msg of string ]) result
(** [v ~nameservers stack ()] TODO. An error is returned if any of the
nameserver specifications do not parse. *)
end

0 comments on commit e5421ab

Please sign in to comment.