Skip to content

Commit

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

0 comments on commit 50279a7

Please sign in to comment.