Skip to content

Commit 8b80f85

Browse files
committed
autoformat
1 parent 497a56b commit 8b80f85

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

unikernels/resolver/resolver.ml

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module RNG = Mirage_crypto_rng.Fortuna
22
module Hash = Digestif.SHA1
3-
let ( let@ ) finally fn = Fun.protect ~finally fn
43

4+
let ( let@ ) finally fn = Fun.protect ~finally fn
55
let rng () = Mirage_crypto_rng_mkernel.initialize (module RNG)
66
let rng = Mkernel.map rng Mkernel.[]
77
let _5s = Duration.of_sec 5
@@ -102,43 +102,48 @@ let setup_logs =
102102
let nameserver_of_string str =
103103
let ( let* ) = Result.bind in
104104
begin match String.split_on_char ':' str with
105-
| "tls" :: rest ->
105+
| "tls" :: rest -> (
106106
let str = String.concat ":" rest in
107-
( match String.split_on_char '!' str with
108-
| [ nameserver ] ->
109-
let* ipaddr, port = Ipaddr.with_port_of_string ~default:853 nameserver in
107+
match String.split_on_char '!' str with
108+
| [ nameserver ] ->
109+
let* ipaddr, port =
110+
Ipaddr.with_port_of_string ~default:853 nameserver
111+
in
110112
let* authenticator = Ca_certs_nss.authenticator () in
111113
let* tls = Tls.Config.client ~authenticator () in
112114
Ok (`Tcp, `Tls (tls, ipaddr, port))
113-
| nameserver :: opt_hostname :: authenticator ->
114-
let* ipaddr, port = Ipaddr.with_port_of_string ~default:853 nameserver in
115+
| nameserver :: opt_hostname :: authenticator ->
116+
let* ipaddr, port =
117+
Ipaddr.with_port_of_string ~default:853 nameserver
118+
in
115119
let peer_name, data =
116120
match
117121
let* dn = Domain_name.of_string opt_hostname in
118122
Domain_name.host dn
119123
with
120-
| Ok hostname -> Some hostname, String.concat "!" authenticator
121-
| Error _ -> None, String.concat "!" (opt_hostname :: authenticator)
124+
| Ok hostname -> (Some hostname, String.concat "!" authenticator)
125+
| Error _ ->
126+
(None, String.concat "!" (opt_hostname :: authenticator))
122127
in
123-
let* authenticator = match data with
128+
let* authenticator =
129+
match data with
124130
| "" -> Ca_certs_nss.authenticator ()
125131
| data ->
126-
let* a = X509.Authenticator.of_string data in
127-
Ok (a (fun () -> Some (Mirage_ptime.now ())))
132+
let* a = X509.Authenticator.of_string data in
133+
Ok (a (fun () -> Some (Mirage_ptime.now ())))
128134
in
129135
let* tls = Tls.Config.client ~authenticator ?peer_name () in
130136
Ok (`Tcp, `Tls (tls, ipaddr, port))
131-
| [] -> assert false )
132-
| "tcp" :: nameserver ->
137+
| [] -> assert false)
138+
| "tcp" :: nameserver ->
133139
let str = String.concat ":" nameserver in
134140
let* ipaddr, port = Ipaddr.with_port_of_string ~default:53 str in
135141
Ok (`Tcp, `Plaintext (ipaddr, port))
136-
| "udp" :: nameserver ->
142+
| "udp" :: nameserver ->
137143
let str = String.concat ":" nameserver in
138144
let* ipaddr, port = Ipaddr.with_port_of_string ~default:53 str in
139145
Ok (`Udp, `Plaintext (ipaddr, port))
140-
| _ ->
141-
Error (`Msg ("Unable to decode nameserver " ^ str))
146+
| _ -> Error (`Msg ("Unable to decode nameserver " ^ str))
142147
end
143148

144149
let nsec_per_day = Int64.mul 86_400L 1_000_000_000L
@@ -151,7 +156,7 @@ let time () =
151156
let rem_ps = Int64.mul rem_ns ps_per_ns in
152157
Some (Ptime.v (Int64.to_int days, rem_ps))
153158

154-
let _8_8_8_8 = `Udp, `Plaintext (Ipaddr.of_string_exn "8.8.8.8", 53)
159+
let _8_8_8_8 = (`Udp, `Plaintext (Ipaddr.of_string_exn "8.8.8.8", 53))
155160

156161
let uncensoreddns_org =
157162
let ipaddr = Ipaddr.of_string_exn "89.233.43.71" in
@@ -169,22 +174,31 @@ let nameservers =
169174
let doc = "A DNS nameserver." in
170175
let parser = nameserver_of_string in
171176
let pp ppf (proto, nameserver) =
172-
match proto, nameserver with
173-
| `Udp, `Plaintext (ipaddr, port) -> Fmt.pf ppf "udp:%a:%d" Ipaddr.pp ipaddr port
174-
| `Tcp, `Plaintext (ipaddr, port) -> Fmt.pf ppf "tcp:%a:%d" Ipaddr.pp ipaddr port
175-
| `Tcp, `Tls (_, ipaddr, port) -> Fmt.pf ppf "tls:%a:%d" Ipaddr.pp ipaddr port
176-
| `Udp, _ -> assert false in
177+
match (proto, nameserver) with
178+
| `Udp, `Plaintext (ipaddr, port) ->
179+
Fmt.pf ppf "udp:%a:%d" Ipaddr.pp ipaddr port
180+
| `Tcp, `Plaintext (ipaddr, port) ->
181+
Fmt.pf ppf "tcp:%a:%d" Ipaddr.pp ipaddr port
182+
| `Tcp, `Tls (_, ipaddr, port) ->
183+
Fmt.pf ppf "tls:%a:%d" Ipaddr.pp ipaddr port
184+
| `Udp, _ -> assert false
185+
in
177186
let open Arg in
178-
value & opt_all (conv (parser, pp)) [ uncensoreddns_org ] & info [ "n"; "nameserver" ] ~doc ~docv:"NAMESERVER"
187+
value
188+
& opt_all (conv (parser, pp)) [ uncensoreddns_org ]
189+
& info [ "n"; "nameserver" ] ~doc ~docv:"NAMESERVER"
179190

180191
let setup_nameservers nameservers =
181192
let fn = function
182193
| `Udp, ns -> Either.Left ns
183-
| `Tcp, ns -> Either.Right ns in
194+
| `Tcp, ns -> Either.Right ns
195+
in
184196
match List.partition_map fn nameservers with
185-
| [], nss -> `Tcp, nss
186-
| nss, [] -> `Udp, nss
187-
| _ -> Fmt.failwith "It is impossible to mix multiple nameservers over TCP and UDP"
197+
| [], nss -> (`Tcp, nss)
198+
| nss, [] -> (`Udp, nss)
199+
| _ ->
200+
Fmt.failwith
201+
"It is impossible to mix multiple nameservers over TCP and UDP"
188202

189203
let setup_nameservers =
190204
let open Term in
@@ -195,15 +209,13 @@ let host =
195209
let parser s = Result.bind (Domain_name.of_string s) Domain_name.host in
196210
let robur_coop = Domain_name.(host_exn (of_string_exn "robur.coop")) in
197211
let open Arg in
198-
value & opt (conv (parser, Domain_name.pp)) robur_coop & info [ "host" ] ~doc ~docv:"HOST"
212+
value
213+
& opt (conv (parser, Domain_name.pp)) robur_coop
214+
& info [ "host" ] ~doc ~docv:"HOST"
199215

200216
let term =
201217
let open Term in
202-
const run
203-
$ setup_logs
204-
$ Mnet_cli.setup
205-
$ setup_nameservers
206-
$ host
218+
const run $ setup_logs $ Mnet_cli.setup $ setup_nameservers $ host
207219

208220
let cmd =
209221
let info = Cmd.info "dns" in

0 commit comments

Comments
 (0)