mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
lint by golangci-lint (#3080)
This commit is contained in:
@@ -23,32 +23,30 @@ import (
|
||||
gnet "github.com/fatedier/golib/net"
|
||||
)
|
||||
|
||||
var (
|
||||
FRPTLSHeadByte = 0x17
|
||||
)
|
||||
var FRPTLSHeadByte = 0x17
|
||||
|
||||
func CheckAndEnableTLSServerConnWithTimeout(
|
||||
c net.Conn, tlsConfig *tls.Config, tlsOnly bool, timeout time.Duration,
|
||||
) (out net.Conn, isTLS bool, custom bool, err error) {
|
||||
|
||||
sc, r := gnet.NewSharedConnSize(c, 2)
|
||||
buf := make([]byte, 1)
|
||||
var n int
|
||||
c.SetReadDeadline(time.Now().Add(timeout))
|
||||
_ = c.SetReadDeadline(time.Now().Add(timeout))
|
||||
n, err = r.Read(buf)
|
||||
c.SetReadDeadline(time.Time{})
|
||||
_ = c.SetReadDeadline(time.Time{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if n == 1 && int(buf[0]) == FRPTLSHeadByte {
|
||||
switch {
|
||||
case n == 1 && int(buf[0]) == FRPTLSHeadByte:
|
||||
out = tls.Server(c, tlsConfig)
|
||||
isTLS = true
|
||||
custom = true
|
||||
} else if n == 1 && int(buf[0]) == 0x16 {
|
||||
case n == 1 && int(buf[0]) == 0x16:
|
||||
out = tls.Server(sc, tlsConfig)
|
||||
isTLS = true
|
||||
} else {
|
||||
default:
|
||||
if tlsOnly {
|
||||
err = fmt.Errorf("non-TLS connection received on a TlsOnly server")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user