From 50279a7f659d407c2dab6904227083087ae745e7 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 12 Sep 2023 09:25:52 +0200 Subject: [PATCH] refactor(netxlite): use *Netx for creating QUIC dialers (#1251) This diff is like https://github.com/ooni/probe-cli/commit/8a5edc22e3fde71e412715e6f96797376252b0ce but here we use *Netx to create QUIC dialers. While there, recognize that `WrapQUICDialer` could become a private function. 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 | 11 ----------- internal/netxlite/quic.go | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/internal/netxlite/netx.go b/internal/netxlite/netx.go index eca345633f..96cd4a9dd4 100644 --- a/internal/netxlite/netx.go +++ b/internal/netxlite/netx.go @@ -22,17 +22,6 @@ func (netx *Netx) maybeCustomUnderlyingNetwork() *MaybeCustomUnderlyingNetwork { return &MaybeCustomUnderlyingNetwork{netx.Underlying} } -// NewQUICDialerWithResolver is like [netxlite.NewQUICDialerWithResolver] but the constructed -// [model.QUICDialer] uses the [model.UnderlyingNetwork] configured inside the [Netx] structure. -func (n *Netx) NewQUICDialerWithResolver(listener model.UDPListener, logger model.DebugLogger, - resolver model.Resolver, wrappers ...model.QUICDialerWrapper) (outDialer model.QUICDialer) { - baseDialer := &quicDialerQUICGo{ - UDPListener: listener, - provider: n.maybeCustomUnderlyingNetwork(), - } - return WrapQUICDialer(logger, resolver, baseDialer, wrappers...) -} - // 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 { diff --git a/internal/netxlite/quic.go b/internal/netxlite/quic.go index a1fb7d6656..674da6b10f 100644 --- a/internal/netxlite/quic.go +++ b/internal/netxlite/quic.go @@ -30,20 +30,29 @@ import ( // // Please, note that this fuunction will just ignore any nil wrapper. // -// Unlike the dialer returned by WrapDialer, this dialer MAY attempt +// Unlike the dialer returned by NewDialerWithResolver, this dialer MAY attempt // happy eyeballs, perform parallel dial attempts, and return an error // that aggregates all the errors that occurred. -func NewQUICDialerWithResolver(listener model.UDPListener, logger model.DebugLogger, +func (netx *Netx) NewQUICDialerWithResolver(listener model.UDPListener, logger model.DebugLogger, resolver model.Resolver, wrappers ...model.QUICDialerWrapper) (outDialer model.QUICDialer) { baseDialer := &quicDialerQUICGo{ UDPListener: listener, + provider: netx.maybeCustomUnderlyingNetwork(), } - return WrapQUICDialer(logger, resolver, baseDialer, wrappers...) + return wrapQUICDialer(logger, resolver, baseDialer, wrappers...) +} + +// NewQUICDialerWithResolver is equivalent to creating an empty [*Netx] +// and calling its NewQUICDialerWithResolver method. +func NewQUICDialerWithResolver(listener model.UDPListener, logger model.DebugLogger, + resolver model.Resolver, wrappers ...model.QUICDialerWrapper) (outDialer model.QUICDialer) { + netx := &Netx{Underlying: nil} + return netx.NewQUICDialerWithResolver(listener, logger, resolver, wrappers...) } -// WrapQUICDialer is similar to NewQUICDialerWithResolver except that it takes as +// wrapQUICDialer is similar to NewQUICDialerWithResolver except that it takes as // input an already constructed [model.QUICDialer] instead of creating one. -func WrapQUICDialer(logger model.DebugLogger, resolver model.Resolver, +func wrapQUICDialer(logger model.DebugLogger, resolver model.Resolver, baseDialer model.QUICDialer, wrappers ...model.QUICDialerWrapper) (outDialer model.QUICDialer) { outDialer = &quicDialerErrWrapper{ QUICDialer: &quicDialerHandshakeCompleter{