add read timeout for TLS check operation

This commit is contained in:
fatedier
2019-07-12 16:53:21 +08:00
parent fd336a5503
commit 17cc0735d1
3 changed files with 22 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ package net
import (
"crypto/tls"
"net"
"time"
gnet "github.com/fatedier/golib/net"
)
@@ -31,10 +32,17 @@ func WrapTLSClientConn(c net.Conn, tlsConfig *tls.Config) (out Conn) {
return
}
func CheckAndEnableTLSServerConn(c net.Conn, tlsConfig *tls.Config) (out Conn) {
sc, r := gnet.NewSharedConnSize(c, 1)
func CheckAndEnableTLSServerConnWithTimeout(c net.Conn, tlsConfig *tls.Config, timeout time.Duration) (out Conn, err error) {
sc, r := gnet.NewSharedConnSize(c, 2)
buf := make([]byte, 1)
n, _ := r.Read(buf)
var n int
c.SetReadDeadline(time.Now().Add(timeout))
n, err = r.Read(buf)
c.SetReadDeadline(time.Time{})
if err != nil {
return
}
if n == 1 && int(buf[0]) == FRP_TLS_HEAD_BYTE {
out = WrapConn(tls.Server(c, tlsConfig))
} else {

View File

@@ -19,7 +19,7 @@ import (
"strings"
)
var version string = "0.27.0"
var version string = "0.27.1"
func Full() string {
return version