mirror of
https://github.com/status-im/consul.git
synced 2025-01-18 17:52:17 +00:00
snapshot: add TLS support to HalfCloser interface (#6216)
Calls net.TCPConn.CloseWrite or mtls.Conn.CloseWrite, which was added in https://go-review.googlesource.com/c/go/+/31318/
This commit is contained in:
parent
8241787e92
commit
61206fdf42
@ -2,6 +2,7 @@ package pool
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -257,11 +258,8 @@ func (p *ConnPool) acquire(dc string, addr net.Addr, version int, useTLS bool) (
|
|||||||
return nil, fmt.Errorf("rpc error: lead thread didn't get connection")
|
return nil, fmt.Errorf("rpc error: lead thread didn't get connection")
|
||||||
}
|
}
|
||||||
|
|
||||||
// HalfCloser is an interface that exposes a TCP half-close. We need this
|
// HalfCloser is an interface that exposes a TCP half-close without exposing
|
||||||
// because we want to expose the raw TCP connection underlying a TLS one in a
|
// the underlying TLS or raw TCP connection.
|
||||||
// way that's hard to screw up and use for anything else. There's a change
|
|
||||||
// brewing that will allow us to use the TLS connection for this instead -
|
|
||||||
// https://go-review.googlesource.com/#/c/25159/.
|
|
||||||
type HalfCloser interface {
|
type HalfCloser interface {
|
||||||
CloseWrite() error
|
CloseWrite() error
|
||||||
}
|
}
|
||||||
@ -296,11 +294,13 @@ func DialTimeoutWithRPCType(dc string, addr net.Addr, src *net.TCPAddr, timeout
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cast to TCPConn
|
|
||||||
var hc HalfCloser
|
var hc HalfCloser
|
||||||
|
|
||||||
if tcp, ok := conn.(*net.TCPConn); ok {
|
if tcp, ok := conn.(*net.TCPConn); ok {
|
||||||
tcp.SetKeepAlive(true)
|
tcp.SetKeepAlive(true)
|
||||||
tcp.SetNoDelay(true)
|
tcp.SetNoDelay(true)
|
||||||
|
|
||||||
|
// Expose TCPConn CloseWrite method on HalfCloser
|
||||||
hc = tcp
|
hc = tcp
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,6 +319,11 @@ func DialTimeoutWithRPCType(dc string, addr net.Addr, src *net.TCPAddr, timeout
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
conn = tlsConn
|
conn = tlsConn
|
||||||
|
|
||||||
|
// If this is a tls.Conn, expose HalfCloser to caller
|
||||||
|
if tlsConn, ok := conn.(*tls.Conn); ok {
|
||||||
|
hc = tlsConn
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn, hc, nil
|
return conn, hc, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user