From 72ed22f499b6c8beeebb61cbdf669ec9c1d27639 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 12 Sep 2023 09:33:11 +0200 Subject: [PATCH] refactor(netxlite): use *Netx for creating TLS handshakers This diff is like https://github.com/ooni/probe-cli/commit/50279a7f659d407c2dab6904227083087ae745e7 but uses *Netx to create TLS handshakers. The general idea of this patchset is to ensure we're not using duplicate code for constructing netxlite types, which is good to do now, because we're about to introduce new netxlite types for the network with which we communicate with the OONI backend. Reference issue: https://github.com/ooni/probe/issues/2531 --- internal/netxlite/netx.go | 6 ------ internal/netxlite/tls.go | 10 +++++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/netxlite/netx.go b/internal/netxlite/netx.go index 96cd4a9dd4..23eb9be6e4 100644 --- a/internal/netxlite/netx.go +++ b/internal/netxlite/netx.go @@ -22,12 +22,6 @@ func (netx *Netx) maybeCustomUnderlyingNetwork() *MaybeCustomUnderlyingNetwork { return &MaybeCustomUnderlyingNetwork{netx.Underlying} } -// NewTLSHandshakerStdlib is like [netxlite.NewTLSHandshakerStdlib] but the constructed [model.TLSHandshaker] -// uses the [model.UnderlyingNetwork] configured inside the [Netx] structure. -func (n *Netx) NewTLSHandshakerStdlib(logger model.DebugLogger) model.TLSHandshaker { - return newTLSHandshakerLogger(&tlsHandshakerConfigurable{provider: n.maybeCustomUnderlyingNetwork()}, logger) -} - // NewHTTPTransportStdlib is like [netxlite.NewHTTPTransportStdlib] but the constructed [model.HTTPTransport] // uses the [model.UnderlyingNetwork] configured inside the [Netx] structure. func (n *Netx) NewHTTPTransportStdlib(logger model.DebugLogger) model.HTTPTransport { diff --git a/internal/netxlite/tls.go b/internal/netxlite/tls.go index a8ed747deb..7e31e2a8bd 100644 --- a/internal/netxlite/tls.go +++ b/internal/netxlite/tls.go @@ -163,8 +163,16 @@ var _ TLSConn = &tls.Conn{} // // 3. that we are going to use Mozilla CA if the [tls.Config] // RootCAs field is zero initialized. +func (netx *Netx) NewTLSHandshakerStdlib(logger model.DebugLogger) model.TLSHandshaker { + return newTLSHandshakerLogger( + &tlsHandshakerConfigurable{provider: netx.maybeCustomUnderlyingNetwork()}, logger) +} + +// NewTLSHandshakerStdlib is equivalent to creating an empty [*Netx] +// and calling its NewTLSHandshakerStdlib method. func NewTLSHandshakerStdlib(logger model.DebugLogger) model.TLSHandshaker { - return newTLSHandshakerLogger(&tlsHandshakerConfigurable{}, logger) + netx := &Netx{Underlying: nil} + return netx.NewTLSHandshakerStdlib(logger) } // newTLSHandshakerLogger creates a new tlsHandshakerLogger instance.