feat(netxlite): TLSDialer closes idle connections (#463)
We are proceeding with this plan of every major type being able to close idle connections, which will simplify making DNS resolvers. See https://github.com/ooni/probe/issues/1591.
This commit is contained in:
parent
3caf5800a2
commit
ef9592f75e
@ -228,6 +228,11 @@ type TLSDialer struct {
|
|||||||
TLSHandshaker TLSHandshaker
|
TLSHandshaker TLSHandshaker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseIdleConnection closes idle connections, if any.
|
||||||
|
func (d *TLSDialer) CloseIdleConnection() {
|
||||||
|
d.Dialer.CloseIdleConnections()
|
||||||
|
}
|
||||||
|
|
||||||
// DialTLSContext dials a TLS connection.
|
// DialTLSContext dials a TLS connection.
|
||||||
func (d *TLSDialer) DialTLSContext(ctx context.Context, network, address string) (net.Conn, error) {
|
func (d *TLSDialer) DialTLSContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
host, port, err := net.SplitHostPort(address)
|
host, port, err := net.SplitHostPort(address)
|
||||||
|
@ -278,7 +278,22 @@ func TestTLSHandshakerLoggerFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTLSDialerFailureSplitHostPort(t *testing.T) {
|
func TestTLSDialerCloseIdleConnections(t *testing.T) {
|
||||||
|
var called bool
|
||||||
|
dialer := &TLSDialer{
|
||||||
|
Dialer: &mocks.Dialer{
|
||||||
|
MockCloseIdleConnections: func() {
|
||||||
|
called = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
dialer.CloseIdleConnection()
|
||||||
|
if !called {
|
||||||
|
t.Fatal("not called")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTLSDialerDialTLSContextFailureSplitHostPort(t *testing.T) {
|
||||||
dialer := &TLSDialer{}
|
dialer := &TLSDialer{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
const address = "www.google.com" // missing port
|
const address = "www.google.com" // missing port
|
||||||
@ -291,7 +306,7 @@ func TestTLSDialerFailureSplitHostPort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTLSDialerFailureDialing(t *testing.T) {
|
func TestTLSDialerDialTLSContextFailureDialing(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel() // immediately fail
|
cancel() // immediately fail
|
||||||
dialer := TLSDialer{Dialer: defaultDialer}
|
dialer := TLSDialer{Dialer: defaultDialer}
|
||||||
@ -304,7 +319,7 @@ func TestTLSDialerFailureDialing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTLSDialerFailureHandshaking(t *testing.T) {
|
func TestTLSDialerDialTLSContextFailureHandshaking(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
dialer := TLSDialer{
|
dialer := TLSDialer{
|
||||||
Config: &tls.Config{},
|
Config: &tls.Config{},
|
||||||
@ -328,7 +343,7 @@ func TestTLSDialerFailureHandshaking(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTLSDialerSuccessHandshaking(t *testing.T) {
|
func TestTLSDialerDialTLSContextSuccessHandshaking(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
dialer := TLSDialer{
|
dialer := TLSDialer{
|
||||||
Dialer: &mocks.Dialer{MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
Dialer: &mocks.Dialer{MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user