Skip to content

Commit

Permalink
Revert "Merge pull request #395 from CraigFe/avoid-initialise-time-ef…
Browse files Browse the repository at this point in the history
…fects"

This reverts commit 6cf2ec8, reversing
changes made to a2f91d0.
  • Loading branch information
dinosaure committed Aug 6, 2021
1 parent 959f57a commit d1d00ef
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
5 changes: 0 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
## Unreleased

* change the type of `Conduit_lwt_tls.X509.default_authenticator` and
`Conduit_lwt_unix.default_ctx` to be lazy, avoiding various side-effects
(system interactions, logging) due to constructing these values at
initialisation time. (@craigfe, #395)

* Add missing `ipaddr-sexp` dependency on conduit-async (#385 @anmonteiro)

## v4.0.0 (2021-04-15)
Expand Down
7 changes: 3 additions & 4 deletions src/conduit-lwt-unix/conduit_lwt_tls.real.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ module X509 = struct
type authenticator = X509.Authenticator.t

let default_authenticator =
lazy
(match Ca_certs.authenticator () with
| Ok a -> a
| Error (`Msg msg) -> failwith msg)
match Ca_certs.authenticator () with
| Ok a -> a
| Error (`Msg msg) -> failwith msg
end

module Client = struct
Expand Down
2 changes: 1 addition & 1 deletion src/conduit-lwt-unix/conduit_lwt_tls.real.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module X509 : sig

type authenticator = X509.Authenticator.t

val default_authenticator : authenticator Lazy.t
val default_authenticator : authenticator
end

module Client : sig
Expand Down
14 changes: 6 additions & 8 deletions src/conduit-lwt-unix/conduit_lwt_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,14 @@ let flow_of_fd fd sa =
TCP { fd; ip = Ipaddr_unix.of_inet_addr ip; port }

let default_ctx =
lazy
{
src = None;
tls_own_key = `None;
tls_authenticator = Lazy.force Conduit_lwt_tls.X509.default_authenticator;
}
{
src = None;
tls_own_key = `None;
tls_authenticator = Conduit_lwt_tls.X509.default_authenticator;
}

let init ?src ?(tls_own_key = `None)
?(tls_authenticator = Lazy.force Conduit_lwt_tls.X509.default_authenticator)
() =
?(tls_authenticator = Conduit_lwt_tls.X509.default_authenticator) () =
match src with
| None -> Lwt.return { src = None; tls_own_key; tls_authenticator }
| Some host -> (
Expand Down
2 changes: 1 addition & 1 deletion src/conduit-lwt-unix/conduit_lwt_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type ctx [@@deriving sexp_of]

(** {2 Connection and listening} *)

val default_ctx : ctx Lazy.t
val default_ctx : ctx
(** Default context that listens on all source addresses with no TLS certificate
associated with the Conduit *)

Expand Down
2 changes: 1 addition & 1 deletion tests/conduit-lwt-unix/cdtest_tls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let perform () =
let client =
`TLS (`Hostname "", `IP Ipaddr.(V6 V6.localhost), `Port port)
in
Conduit_lwt_unix.(connect ~ctx:(Lazy.force default_ctx) client)
Conduit_lwt_unix.(connect ~ctx:default_ctx client)
>>= fun (_flow, ic, oc) ->
Lwt_log.notice "Connected!" >>= fun () ->
Lwt_io.write oc "hello" >>= fun () ->
Expand Down

0 comments on commit d1d00ef

Please sign in to comment.