mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
(1)新增心跳检测发送间隔和超时时间的配置
This commit is contained in:
parent
5d6f37aa82
commit
04c26d1c31
@ -11,16 +11,16 @@ import (
|
|||||||
|
|
||||||
// common config
|
// common config
|
||||||
var (
|
var (
|
||||||
ServerAddr string = "0.0.0.0"
|
ServerAddr string = "0.0.0.0"
|
||||||
ServerPort int64 = 7000
|
ServerPort int64 = 7000
|
||||||
LogFile string = "./frpc.log"
|
LogFile string = "./frpc.log"
|
||||||
LogLevel string = "warn"
|
LogLevel string = "warn"
|
||||||
LogWay string = "file"
|
LogWay string = "file"
|
||||||
|
HeartBeatInterval int64 = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
var ProxyClients map[string]*models.ProxyClient = make(map[string]*models.ProxyClient)
|
var ProxyClients map[string]*models.ProxyClient = make(map[string]*models.ProxyClient)
|
||||||
|
|
||||||
|
|
||||||
func LoadConf(confFile string) (err error) {
|
func LoadConf(confFile string) (err error) {
|
||||||
var tmpStr string
|
var tmpStr string
|
||||||
var ok bool
|
var ok bool
|
||||||
@ -56,6 +56,11 @@ func LoadConf(confFile string) (err error) {
|
|||||||
LogWay = tmpStr
|
LogWay = tmpStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmpStr, ok = conf.Get("common", "heartbeat_interval")
|
||||||
|
if ok {
|
||||||
|
HeartBeatInterval, _ = strconv.ParseInt(tmpStr, 10, 64)
|
||||||
|
}
|
||||||
|
|
||||||
// servers
|
// servers
|
||||||
for name, section := range conf {
|
for name, section := range conf {
|
||||||
if name != "common" {
|
if name != "common" {
|
||||||
|
@ -11,10 +11,6 @@ import (
|
|||||||
"frp/pkg/utils/log"
|
"frp/pkg/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
heartbeatDuration = 2 //心跳检测时间间隔,单位秒
|
|
||||||
)
|
|
||||||
|
|
||||||
var isHeartBeatContinue bool = true
|
var isHeartBeatContinue bool = true
|
||||||
|
|
||||||
func ControlProcess(cli *models.ProxyClient, wait *sync.WaitGroup) {
|
func ControlProcess(cli *models.ProxyClient, wait *sync.WaitGroup) {
|
||||||
@ -114,7 +110,7 @@ func loginToServer(cli *models.ProxyClient) (connection *conn.Conn) {
|
|||||||
func startHeartBeat(con *conn.Conn) {
|
func startHeartBeat(con *conn.Conn) {
|
||||||
isHeartBeatContinue = true
|
isHeartBeatContinue = true
|
||||||
for {
|
for {
|
||||||
time.Sleep(heartbeatDuration * time.Second)
|
time.Sleep(time.Duration(HeartBeatInterval) * time.Second)
|
||||||
if isHeartBeatContinue { // 把isHeartBeatContinue放在这里是为了防止SIGPIPE
|
if isHeartBeatContinue { // 把isHeartBeatContinue放在这里是为了防止SIGPIPE
|
||||||
err := con.Write("\r\n")
|
err := con.Write("\r\n")
|
||||||
//log.Debug("send heart beat to server!")
|
//log.Debug("send heart beat to server!")
|
||||||
|
@ -11,16 +11,16 @@ import (
|
|||||||
|
|
||||||
// common config
|
// common config
|
||||||
var (
|
var (
|
||||||
BindAddr string = "0.0.0.0"
|
BindAddr string = "0.0.0.0"
|
||||||
BindPort int64 = 9527
|
BindPort int64 = 9527
|
||||||
LogFile string = "./frps.log"
|
LogFile string = "./frps.log"
|
||||||
LogLevel string = "warn"
|
LogLevel string = "warn"
|
||||||
LogWay string = "file"
|
LogWay string = "file"
|
||||||
|
HeartBeatTimeout int64 = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
var ProxyServers map[string]*models.ProxyServer = make(map[string]*models.ProxyServer)
|
var ProxyServers map[string]*models.ProxyServer = make(map[string]*models.ProxyServer)
|
||||||
|
|
||||||
|
|
||||||
func LoadConf(confFile string) (err error) {
|
func LoadConf(confFile string) (err error) {
|
||||||
var tmpStr string
|
var tmpStr string
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -151,7 +151,7 @@ func readControlMsgFromClient(server *models.ProxyServer, c *conn.Conn) {
|
|||||||
isContinueRead = false
|
isContinueRead = false
|
||||||
server.StopWaitUserConn()
|
server.StopWaitUserConn()
|
||||||
}
|
}
|
||||||
timer := time.AfterFunc(10*time.Second, f)
|
timer := time.AfterFunc(time.Duration(HeartBeatTimeout)*time.Second, f)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
|
|
||||||
for isContinueRead {
|
for isContinueRead {
|
||||||
@ -169,7 +169,7 @@ func readControlMsgFromClient(server *models.ProxyServer, c *conn.Conn) {
|
|||||||
|
|
||||||
if content == "\r\n" {
|
if content == "\r\n" {
|
||||||
log.Debug("receive hearbeat:%s", content)
|
log.Debug("receive hearbeat:%s", content)
|
||||||
timer.Reset(10 * time.Second)
|
timer.Reset(time.Duration(HeartBeatTimeout) * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,9 @@ log_file = ./frpc.log
|
|||||||
# debug, info, warn, error
|
# debug, info, warn, error
|
||||||
log_level = info
|
log_level = info
|
||||||
# file, console
|
# file, console
|
||||||
log_way = file
|
log_way = console
|
||||||
|
# 心跳检测时间间隔,单位秒,默认为2
|
||||||
|
heartbeat_interval = 2
|
||||||
|
|
||||||
# test1即为name
|
# test1即为name
|
||||||
[test1]
|
[test1]
|
||||||
|
@ -6,7 +6,9 @@ log_file = ./frps.log
|
|||||||
# debug, info, warn, error
|
# debug, info, warn, error
|
||||||
log_level = info
|
log_level = info
|
||||||
# file, console
|
# file, console
|
||||||
log_way = file
|
log_way = console
|
||||||
|
# 心跳检测超时时间,单位秒,默认为30
|
||||||
|
heartbeat_timeout = 30
|
||||||
|
|
||||||
# test1即为name
|
# test1即为name
|
||||||
[test1]
|
[test1]
|
||||||
|
Loading…
Reference in New Issue
Block a user