Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns-client-mirage udp #322

Merged
merged 15 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions client/dns_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module type S = sig
val rng : int -> Cstruct.t
val clock : unit -> int64

val connect : t -> (context, [> `Msg of string ]) result io
val connect : t -> (Dns.proto * context, [> `Msg of string ]) result io
val send_recv : context -> Cstruct.t -> (Cstruct.t, [> `Msg of string ]) result io
val close : context -> unit io

Expand Down Expand Up @@ -222,8 +222,8 @@ struct
}

(* TODO eventually use Auto, and retry without on FormErr *)
let create ?(size = 32) ?(edns = `None) ?nameservers ?(timeout = Duration.of_sec 5) stack =
{ cache = Dns_cache.empty size ;
let create ?(cache_size = 32) ?(edns = `None) ?nameservers ?(timeout = Duration.of_sec 5) stack =
{ cache = Dns_cache.empty cache_size ;
transport = Transport.create ?nameservers ~timeout stack ;
edns ;
}
Expand Down Expand Up @@ -254,12 +254,11 @@ struct
| Error _ -> Error (`Msg "")

let get_raw_reply t query_type name =
let proto, _ = Transport.nameservers t.transport in
Transport.connect t.transport >>| fun (proto, socket) ->
Log.debug (fun m -> m "Connected to NS.");
let tx, state =
Pure.make_query Transport.rng proto ~dnssec:true t.edns name query_type
in
Transport.connect t.transport >>| fun socket ->
Log.debug (fun m -> m "Connected to NS.");
(Transport.send_recv socket tx >>| fun recv_buffer ->
Log.debug (fun m -> m "Read @[<v>%d bytes@]"
(Cstruct.length recv_buffer)) ;
Expand All @@ -285,12 +284,11 @@ struct
| Ok _ as ok -> Transport.lift ok
| Error ((`No_data _ | `No_domain _) as nod) -> Error nod |> Transport.lift
| Error `Msg _ ->
let proto, _ = Transport.nameservers t.transport in
Transport.connect t.transport >>| fun (proto, socket) ->
Log.debug (fun m -> m "Connected to NS.");
let tx, state =
Pure.make_query Transport.rng proto t.edns name query_type
in
Transport.connect t.transport >>| fun socket ->
Log.debug (fun m -> m "Connected to NS.");
(Transport.send_recv socket tx >>| fun recv_buffer ->
Log.debug (fun m -> m "Read @[<v>%d bytes@]"
(Cstruct.length recv_buffer)) ;
Expand Down
13 changes: 7 additions & 6 deletions client/dns_client.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ module type S = sig
val clock : unit -> int64
(** [clock t] is the monotonic clock. *)

val connect : t -> (context, [> `Msg of string ]) result io
(** [connect addr] is a new connection ([context]) to [addr], or an error. *)
val connect : t -> (Dns.proto * context, [> `Msg of string ]) result io
(** [connect t] is a new connection ([context]) to [t], or an error. *)

val send_recv : context -> Cstruct.t -> (Cstruct.t, [> `Msg of string ]) result io
(** [send_recv context buffer] sends [buffer] to the [context] upstream, and
Expand All @@ -67,12 +67,13 @@ sig

type t

val create : ?size:int -> ?edns:[ `None | `Auto | `Manual of Dns.Edns.t ] ->
val create : ?cache_size:int ->
?edns:[ `None | `Auto | `Manual of Dns.Edns.t ] ->
?nameservers:(Dns.proto * T.io_addr list) -> ?timeout:int64 ->
T.stack -> t
(** [create ~size ~edns ~nameservers ~timeout stack] creates the state of the
DNS client. We use [timeout] (ns, default 5s) as a time budget for connect
and request timeouts. To specify a timeout, use
(** [create ~cache_size ~edns ~nameservers ~timeout stack] creates the state
of the DNS client. We use [timeout] (ns, default 5s) as a time budget for
connect and request timeouts. To specify a timeout, use
[create ~timeout:(Duration.of_sec 3)]. Whether or not to use
{{:https://tools.ietf.org/html/rfc6891}EDNS} in queries is controlled
by [~edns] (defaults to [`None]): if [None], no EDNS will be present,
Expand Down
2 changes: 1 addition & 1 deletion lwt/client/dns_client_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ module Transport : Dns_client.S

let connect t =
connect_via_tcp_to_ns t >|= function
| Ok () -> Ok t
| Ok () -> Ok (`Tcp, t)
| Error `Msg msg -> Error (`Msg msg)
end

Expand Down
Loading