feat(netxlite): introduce wrapping constructors (#507)
This diff has been extracted from https://github.com/ooni/probe-cli/pull/506. In it, we introduce wrapping constructors for types and we update the docs. These new constructures are used by the code in https://github.com/ooni/probe-cli/pull/506. In itself, this work is part of https://github.com/ooni/probe/issues/1733.
This commit is contained in:
parent
985c1ba761
commit
741a8bc4c2
3 changed files with 45 additions and 25 deletions
|
|
@ -19,8 +19,14 @@ type Dialer interface {
|
|||
CloseIdleConnections()
|
||||
}
|
||||
|
||||
// NewDialerWithResolver creates a new Dialer. The returned Dialer
|
||||
// has the following properties:
|
||||
// NewDialerWithResolver is a convenience factory that calls
|
||||
// WrapDialer for a stdlib dialer type.
|
||||
func NewDialerWithResolver(logger Logger, resolver Resolver) Dialer {
|
||||
return WrapDialer(logger, resolver, &dialerSystem{})
|
||||
}
|
||||
|
||||
// WrapDialer creates a new Dialer that wraps the given
|
||||
// Dialer. The returned Dialer has the following properties:
|
||||
//
|
||||
// 1. logs events using the given logger;
|
||||
//
|
||||
|
|
@ -45,12 +51,12 @@ type Dialer interface {
|
|||
// 6. if a dialer wraps a resolver, the dialer will forward
|
||||
// the CloseIdleConnection call to its resolver (which is
|
||||
// instrumental to manage a DoH resolver connections properly).
|
||||
func NewDialerWithResolver(logger Logger, resolver Resolver) Dialer {
|
||||
func WrapDialer(logger Logger, resolver Resolver, dialer Dialer) Dialer {
|
||||
return &dialerLogger{
|
||||
Dialer: &dialerResolver{
|
||||
Dialer: &dialerLogger{
|
||||
Dialer: &dialerErrWrapper{
|
||||
Dialer: &dialerSystem{},
|
||||
Dialer: dialer,
|
||||
},
|
||||
Logger: logger,
|
||||
operationSuffix: "_address",
|
||||
|
|
|
|||
Loading…
Reference in a new issue