Skip to content

Commit

Permalink
refactor(netxlite): use *Netx for creating TLS handshakers (#1252)
Browse files Browse the repository at this point in the history
This diff is like
50279a7
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: ooni/probe#2531
  • Loading branch information
bassosimone authored Sep 12, 2023
1 parent 50279a7 commit f36432c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 0 additions & 6 deletions internal/netxlite/netx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion internal/netxlite/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,18 @@ 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.
Expand Down

0 comments on commit f36432c

Please sign in to comment.