diff --git a/client/control.go b/client/control.go index 81aaf7b..ef9a766 100644 --- a/client/control.go +++ b/client/control.go @@ -252,6 +252,7 @@ func (ctl *Control) connectServer() (conn net.Conn, err error) { dialOptions = append(dialOptions, libdial.WithProtocol(protocol), libdial.WithTimeout(time.Duration(ctl.clientCfg.DialServerTimeout)*time.Second), + libdial.WithKeepAlive(time.Duration(ctl.clientCfg.DialServerKeepAlive)*time.Second), libdial.WithProxy(proxyType, addr), libdial.WithProxyAuth(auth), libdial.WithTLSConfig(tlsConfig), diff --git a/client/service.go b/client/service.go index 96ddadf..11e369c 100644 --- a/client/service.go +++ b/client/service.go @@ -243,6 +243,7 @@ func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) { dialOptions = append(dialOptions, libdial.WithProtocol(protocol), libdial.WithTimeout(time.Duration(svr.cfg.DialServerTimeout)*time.Second), + libdial.WithKeepAlive(time.Duration(svr.cfg.DialServerKeepAlive)*time.Second), libdial.WithProxy(proxyType, addr), libdial.WithProxyAuth(auth), libdial.WithTLSConfig(tlsConfig), diff --git a/conf/frpc_full.ini b/conf/frpc_full.ini index 04ede86..913c971 100644 --- a/conf/frpc_full.ini +++ b/conf/frpc_full.ini @@ -9,6 +9,10 @@ server_port = 7000 # The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds. # dial_server_timeout = 10 +# dial_server_keepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps. +# If negative, keep-alive probes are disabled. +# dial_server_keepalive = 7200 + # if you want to connect frps by http proxy or socks5 proxy or ntlm proxy, you can set http_proxy here or in global environment variables # it only works when protocol is tcp # http_proxy = http://user:passwd@192.168.1.128:8080 @@ -69,7 +73,8 @@ admin_pwd = admin pool_count = 5 # if tcp stream multiplexing is used, default is true, it must be same with frps -tcp_mux = true +# tcp_mux = true + # specify keep alive interval for tcp mux. # only valid if tcp_mux is true. # tcp_mux_keepalive_interval = 60 diff --git a/conf/frps_full.ini b/conf/frps_full.ini index e32d37e..fecb8bf 100644 --- a/conf/frps_full.ini +++ b/conf/frps_full.ini @@ -86,7 +86,6 @@ oidc_audience = # By default, this value is false. oidc_skip_expiry_check = false - # oidc_skip_issuer_check specifies whether to skip checking if the OIDC token's issuer claim matches the issuer specified in OidcIssuer. # By default, this value is false. oidc_skip_issuer_check = false @@ -120,11 +119,16 @@ tls_only = false subdomain_host = frps.com # if tcp stream multiplexing is used, default is true -tcp_mux = true +# tcp_mux = true + # specify keep alive interval for tcp mux. # only valid if tcp_mux is true. # tcp_mux_keepalive_interval = 60 +# tcp_keepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps. +# If negative, keep-alive probes are disabled. +# tcp_keepalive = 7200 + # custom 404 page for HTTP requests # custom_404_page = /path/to/404.html diff --git a/go.mod b/go.mod index 98398d5..ea9d6b9 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 github.com/coreos/go-oidc v2.2.1+incompatible github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb - github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9 + github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible github.com/go-playground/validator/v10 v10.6.1 github.com/google/uuid v1.2.0 diff --git a/go.sum b/go.sum index a42b905..cfe79d3 100644 --- a/go.sum +++ b/go.sum @@ -88,10 +88,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb h1:wCrNShQidLmvVWn/0PikGmpdP0vtQmnvyRg3ZBEhczw= github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb/go.mod h1:wx3gB6dbIfBRcucp94PI9Bt3I0F2c/MyNEWuhzpWiwk= -github.com/fatedier/golib v0.1.1-0.20220218073251-9509a597216b h1:5r5/G3NFsFK+7svxvxZYA8yy8Ubs4hWIq+QYYMgEBe8= -github.com/fatedier/golib v0.1.1-0.20220218073251-9509a597216b/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo= -github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9 h1:AOGf9Z1ri+3MiyGIAYXe+shEXx6/uVGJlufb6ZfnZls= -github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo= +github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac h1:td1FJwN/oz8+9GldeEm3YdBX0Husc0FSPywLesZxi4w= +github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo= github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible h1:ssXat9YXFvigNge/IkkZvFMn8yeYKFX+uI6wn2mLJ74= github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible/go.mod h1:YpCOaxj7vvMThhIQ9AfTOPW2sfztQR5WDfs7AflSy4s= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= diff --git a/pkg/config/client.go b/pkg/config/client.go index ce96255..27a47a2 100644 --- a/pkg/config/client.go +++ b/pkg/config/client.go @@ -40,6 +40,9 @@ type ClientCommonConf struct { ServerPort int `ini:"server_port" json:"server_port"` // The maximum amount of time a dial to server will wait for a connect to complete. DialServerTimeout int64 `ini:"dial_server_timeout" json:"dial_server_timeout"` + // DialServerKeepAlive specifies the interval between keep-alive probes for an active network connection between frpc and frps. + // If negative, keep-alive probes are disabled. + DialServerKeepAlive int64 `ini:"dial_server_keepalive" json:"dial_server_keepalive"` // ConnectServerLocalIP specifies the address of the client bind when it connect to server. // By default, this value is empty. // this value only use in TCP/Websocket protocol. Not support in KCP protocol. @@ -163,6 +166,7 @@ func GetDefaultClientConf() ClientCommonConf { ServerAddr: "0.0.0.0", ServerPort: 7000, DialServerTimeout: 10, + DialServerKeepAlive: 7200, HTTPProxy: os.Getenv("http_proxy"), LogFile: "console", LogWay: "console", diff --git a/pkg/config/client_test.go b/pkg/config/client_test.go index a64b9ee..12f1c9e 100644 --- a/pkg/config/client_test.go +++ b/pkg/config/client_test.go @@ -262,6 +262,7 @@ func Test_LoadClientCommonConf(t *testing.T) { ServerAddr: "0.0.0.9", ServerPort: 7009, DialServerTimeout: 10, + DialServerKeepAlive: 7200, HTTPProxy: "http://user:passwd@192.168.1.128:8080", LogFile: "./frpc.log9", LogWay: "file", diff --git a/pkg/config/server.go b/pkg/config/server.go index e4f5a49..cf298f2 100644 --- a/pkg/config/server.go +++ b/pkg/config/server.go @@ -121,6 +121,9 @@ type ServerCommonConf struct { // TCPMuxKeepaliveInterval specifies the keep alive interval for TCP stream multipler. // If TCPMux is true, heartbeat of application layer is unnecessary because it can only rely on heartbeat in TCPMux. TCPMuxKeepaliveInterval int64 `ini:"tcp_mux_keepalive_interval" json:"tcp_mux_keepalive_interval"` + // TCPKeepAlive specifies the interval between keep-alive probes for an active network connection between frpc and frps. + // If negative, keep-alive probes are disabled. + TCPKeepAlive int64 `ini:"tcp_keepalive" json:"tcp_keepalive"` // Custom404Page specifies a path to a custom 404 page to display. If this // value is "", a default page will be displayed. By default, this value is // "". @@ -201,6 +204,7 @@ func GetDefaultServerConf() ServerCommonConf { SubDomainHost: "", TCPMux: true, TCPMuxKeepaliveInterval: 60, + TCPKeepAlive: 7200, AllowPorts: make(map[int]struct{}), MaxPoolCount: 5, MaxPortsPerClient: 0, diff --git a/pkg/config/server_test.go b/pkg/config/server_test.go index bdf20cb..8646ca6 100644 --- a/pkg/config/server_test.go +++ b/pkg/config/server_test.go @@ -140,6 +140,7 @@ func Test_LoadServerCommonConf(t *testing.T) { SubDomainHost: "frps.com", TCPMux: true, TCPMuxKeepaliveInterval: 60, + TCPKeepAlive: 7200, UDPPacketSize: 1509, HTTPPlugins: map[string]plugin.HTTPPluginOptions{ @@ -191,6 +192,7 @@ func Test_LoadServerCommonConf(t *testing.T) { DetailedErrorsToClient: true, TCPMux: true, TCPMuxKeepaliveInterval: 60, + TCPKeepAlive: 7200, AllowPorts: make(map[int]struct{}), MaxPoolCount: 5, HeartbeatTimeout: 90, diff --git a/server/service.go b/server/service.go index c3c4548..ed66329 100644 --- a/server/service.go +++ b/server/service.go @@ -186,6 +186,7 @@ func NewService(cfg config.ServerCommonConf) (svr *Service, err error) { } svr.muxer = mux.NewMux(ln) + svr.muxer.SetKeepAlive(time.Duration(cfg.TCPKeepAlive) * time.Second) go svr.muxer.Serve() ln = svr.muxer.DefaultListener()