Skip to content

Commit 100d556

Browse files
authored
support tcp keepalive params (fatedier#2863)
1 parent 452fe25 commit 100d556

File tree

11 files changed

+29
-8
lines changed

11 files changed

+29
-8
lines changed

client/control.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (ctl *Control) connectServer() (conn net.Conn, err error) {
252252
dialOptions = append(dialOptions,
253253
libdial.WithProtocol(protocol),
254254
libdial.WithTimeout(time.Duration(ctl.clientCfg.DialServerTimeout)*time.Second),
255+
libdial.WithKeepAlive(time.Duration(ctl.clientCfg.DialServerKeepAlive)*time.Second),
255256
libdial.WithProxy(proxyType, addr),
256257
libdial.WithProxyAuth(auth),
257258
libdial.WithTLSConfig(tlsConfig),

client/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) {
243243
dialOptions = append(dialOptions,
244244
libdial.WithProtocol(protocol),
245245
libdial.WithTimeout(time.Duration(svr.cfg.DialServerTimeout)*time.Second),
246+
libdial.WithKeepAlive(time.Duration(svr.cfg.DialServerKeepAlive)*time.Second),
246247
libdial.WithProxy(proxyType, addr),
247248
libdial.WithProxyAuth(auth),
248249
libdial.WithTLSConfig(tlsConfig),

conf/frpc_full.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ server_port = 7000
99
# The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds.
1010
# dial_server_timeout = 10
1111

12+
# dial_server_keepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
13+
# If negative, keep-alive probes are disabled.
14+
# dial_server_keepalive = 7200
15+
1216
# 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
1317
# it only works when protocol is tcp
1418
# http_proxy = http://user:[email protected]:8080
@@ -69,7 +73,8 @@ admin_pwd = admin
6973
pool_count = 5
7074

7175
# if tcp stream multiplexing is used, default is true, it must be same with frps
72-
tcp_mux = true
76+
# tcp_mux = true
77+
7378
# specify keep alive interval for tcp mux.
7479
# only valid if tcp_mux is true.
7580
# tcp_mux_keepalive_interval = 60

conf/frps_full.ini

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ oidc_audience =
8686
# By default, this value is false.
8787
oidc_skip_expiry_check = false
8888

89-
9089
# oidc_skip_issuer_check specifies whether to skip checking if the OIDC token's issuer claim matches the issuer specified in OidcIssuer.
9190
# By default, this value is false.
9291
oidc_skip_issuer_check = false
@@ -120,11 +119,16 @@ tls_only = false
120119
subdomain_host = frps.com
121120

122121
# if tcp stream multiplexing is used, default is true
123-
tcp_mux = true
122+
# tcp_mux = true
123+
124124
# specify keep alive interval for tcp mux.
125125
# only valid if tcp_mux is true.
126126
# tcp_mux_keepalive_interval = 60
127127

128+
# tcp_keepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
129+
# If negative, keep-alive probes are disabled.
130+
# tcp_keepalive = 7200
131+
128132
# custom 404 page for HTTP requests
129133
# custom_404_page = /path/to/404.html
130134

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
77
github.com/coreos/go-oidc v2.2.1+incompatible
88
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb
9-
github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9
9+
github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac
1010
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible
1111
github.com/go-playground/validator/v10 v10.6.1
1212
github.com/google/uuid v1.2.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
8888
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
8989
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb h1:wCrNShQidLmvVWn/0PikGmpdP0vtQmnvyRg3ZBEhczw=
9090
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb/go.mod h1:wx3gB6dbIfBRcucp94PI9Bt3I0F2c/MyNEWuhzpWiwk=
91-
github.com/fatedier/golib v0.1.1-0.20220218073251-9509a597216b h1:5r5/G3NFsFK+7svxvxZYA8yy8Ubs4hWIq+QYYMgEBe8=
92-
github.com/fatedier/golib v0.1.1-0.20220218073251-9509a597216b/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo=
93-
github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9 h1:AOGf9Z1ri+3MiyGIAYXe+shEXx6/uVGJlufb6ZfnZls=
94-
github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo=
91+
github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac h1:td1FJwN/oz8+9GldeEm3YdBX0Husc0FSPywLesZxi4w=
92+
github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo=
9593
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible h1:ssXat9YXFvigNge/IkkZvFMn8yeYKFX+uI6wn2mLJ74=
9694
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible/go.mod h1:YpCOaxj7vvMThhIQ9AfTOPW2sfztQR5WDfs7AflSy4s=
9795
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=

pkg/config/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type ClientCommonConf struct {
4040
ServerPort int `ini:"server_port" json:"server_port"`
4141
// The maximum amount of time a dial to server will wait for a connect to complete.
4242
DialServerTimeout int64 `ini:"dial_server_timeout" json:"dial_server_timeout"`
43+
// DialServerKeepAlive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
44+
// If negative, keep-alive probes are disabled.
45+
DialServerKeepAlive int64 `ini:"dial_server_keepalive" json:"dial_server_keepalive"`
4346
// ConnectServerLocalIP specifies the address of the client bind when it connect to server.
4447
// By default, this value is empty.
4548
// this value only use in TCP/Websocket protocol. Not support in KCP protocol.
@@ -163,6 +166,7 @@ func GetDefaultClientConf() ClientCommonConf {
163166
ServerAddr: "0.0.0.0",
164167
ServerPort: 7000,
165168
DialServerTimeout: 10,
169+
DialServerKeepAlive: 7200,
166170
HTTPProxy: os.Getenv("http_proxy"),
167171
LogFile: "console",
168172
LogWay: "console",

pkg/config/client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func Test_LoadClientCommonConf(t *testing.T) {
262262
ServerAddr: "0.0.0.9",
263263
ServerPort: 7009,
264264
DialServerTimeout: 10,
265+
DialServerKeepAlive: 7200,
265266
HTTPProxy: "http://user:[email protected]:8080",
266267
LogFile: "./frpc.log9",
267268
LogWay: "file",

pkg/config/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ type ServerCommonConf struct {
121121
// TCPMuxKeepaliveInterval specifies the keep alive interval for TCP stream multipler.
122122
// If TCPMux is true, heartbeat of application layer is unnecessary because it can only rely on heartbeat in TCPMux.
123123
TCPMuxKeepaliveInterval int64 `ini:"tcp_mux_keepalive_interval" json:"tcp_mux_keepalive_interval"`
124+
// TCPKeepAlive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
125+
// If negative, keep-alive probes are disabled.
126+
TCPKeepAlive int64 `ini:"tcp_keepalive" json:"tcp_keepalive"`
124127
// Custom404Page specifies a path to a custom 404 page to display. If this
125128
// value is "", a default page will be displayed. By default, this value is
126129
// "".
@@ -201,6 +204,7 @@ func GetDefaultServerConf() ServerCommonConf {
201204
SubDomainHost: "",
202205
TCPMux: true,
203206
TCPMuxKeepaliveInterval: 60,
207+
TCPKeepAlive: 7200,
204208
AllowPorts: make(map[int]struct{}),
205209
MaxPoolCount: 5,
206210
MaxPortsPerClient: 0,

pkg/config/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
140140
SubDomainHost: "frps.com",
141141
TCPMux: true,
142142
TCPMuxKeepaliveInterval: 60,
143+
TCPKeepAlive: 7200,
143144
UDPPacketSize: 1509,
144145

145146
HTTPPlugins: map[string]plugin.HTTPPluginOptions{
@@ -191,6 +192,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
191192
DetailedErrorsToClient: true,
192193
TCPMux: true,
193194
TCPMuxKeepaliveInterval: 60,
195+
TCPKeepAlive: 7200,
194196
AllowPorts: make(map[int]struct{}),
195197
MaxPoolCount: 5,
196198
HeartbeatTimeout: 90,

0 commit comments

Comments
 (0)