Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
企猫商务
frp
提交
a2f1897a
F
frp
项目概览
企猫商务
/
frp
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
frp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a2f1897a
编写于
2月 26, 2016
作者:
H
Hurricanezwf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add heartbeat echo from server to client
上级
b2ca78fa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
83 addition
and
13 deletion
+83
-13
src/frp/cmd/frpc/control.go
src/frp/cmd/frpc/control.go
+47
-9
src/frp/cmd/frps/control.go
src/frp/cmd/frps/control.go
+25
-4
src/frp/models/client/config.go
src/frp/models/client/config.go
+1
-0
src/frp/models/consts/consts.go
src/frp/models/consts/consts.go
+10
-0
未找到文件。
src/frp/cmd/frpc/control.go
浏览文件 @
a2f1897a
...
...
@@ -14,6 +14,9 @@ import (
"frp/utils/log"
)
var
connection
*
conn
.
Conn
=
nil
var
heartBeatTimer
*
time
.
Timer
=
nil
func
ControlProcess
(
cli
*
client
.
ProxyClient
,
wait
*
sync
.
WaitGroup
)
{
defer
wait
.
Done
()
...
...
@@ -22,12 +25,13 @@ func ControlProcess(cli *client.ProxyClient, wait *sync.WaitGroup) {
log
.
Error
(
"ProxyName [%s], connect to server failed!"
,
cli
.
Name
)
return
}
defer
c
.
Close
()
connection
=
c
defer
connection
.
Close
()
for
{
// ignore response content now
_
,
err
:=
c
.
ReadLine
()
if
err
==
io
.
EOF
{
content
,
err
:=
connection
.
ReadLine
()
if
err
==
io
.
EOF
||
nil
==
connection
||
connection
.
IsClosed
()
{
log
.
Debug
(
"ProxyName [%s], server close this control conn"
,
cli
.
Name
)
var
sleepTime
time
.
Duration
=
1
...
...
@@ -36,8 +40,8 @@ func ControlProcess(cli *client.ProxyClient, wait *sync.WaitGroup) {
log
.
Debug
(
"ProxyName [%s], try to reconnect to server[%s:%d]..."
,
cli
.
Name
,
client
.
ServerAddr
,
client
.
ServerPort
)
tmpConn
,
err
:=
loginToServer
(
cli
)
if
err
==
nil
{
c
.
Close
()
c
=
tmpConn
c
onnection
.
Close
()
c
onnection
=
tmpConn
break
}
...
...
@@ -52,6 +56,21 @@ func ControlProcess(cli *client.ProxyClient, wait *sync.WaitGroup) {
continue
}
clientCtlRes
:=
&
msg
.
ClientCtlRes
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
content
),
clientCtlRes
);
err
!=
nil
{
log
.
Warn
(
"Parse err: %v : %s"
,
err
,
content
)
continue
}
if
consts
.
SCHeartBeatRes
==
clientCtlRes
.
GeneralRes
.
Code
{
if
heartBeatTimer
!=
nil
{
log
.
Debug
(
"Client rcv heartbeat response"
)
heartBeatTimer
.
Reset
(
time
.
Duration
(
client
.
HeartBeatTimeout
)
*
time
.
Second
)
}
else
{
log
.
Error
(
"heartBeatTimer is nil"
)
}
continue
}
cli
.
StartTunnel
(
client
.
ServerAddr
,
client
.
ServerPort
)
}
}
...
...
@@ -100,18 +119,37 @@ func loginToServer(cli *client.ProxyClient) (c *conn.Conn, err error) {
}
func
startHeartBeat
(
c
*
conn
.
Conn
)
{
f
:=
func
()
{
log
.
Error
(
"HeartBeat timeout!"
)
if
c
!=
nil
{
c
.
Close
()
}
}
heartBeatTimer
=
time
.
AfterFunc
(
time
.
Duration
(
client
.
HeartBeatTimeout
)
*
time
.
Second
,
f
)
defer
heartBeatTimer
.
Stop
()
clientCtlReq
:=
&
msg
.
ClientCtlReq
{
Type
:
consts
.
CSHeartBeatReq
,
ProxyName
:
""
,
Passwd
:
""
,
}
request
,
err
:=
json
.
Marshal
(
clientCtlReq
)
if
err
!=
nil
{
log
.
Warn
(
"Serialize clientCtlReq err! Err: %v"
,
err
)
}
log
.
Debug
(
"Start to send heartbeat"
)
for
{
time
.
Sleep
(
time
.
Duration
(
client
.
HeartBeatInterval
)
*
time
.
Second
)
if
!
c
.
IsClosed
()
{
err
:=
c
.
Write
(
"
\n
"
)
if
c
!=
nil
&&
!
c
.
IsClosed
()
{
err
=
c
.
Write
(
string
(
request
)
+
"
\n
"
)
if
err
!=
nil
{
log
.
Error
(
"Send hearbeat to server failed! Err:%
s"
,
err
.
Error
()
)
log
.
Error
(
"Send hearbeat to server failed! Err:%
v"
,
err
)
continue
}
}
else
{
break
}
}
log
.
Debug
(
"
h
eartbeat exit"
)
log
.
Debug
(
"
H
eartbeat exit"
)
}
src/frp/cmd/frps/control.go
浏览文件 @
a2f1897a
...
...
@@ -162,13 +162,13 @@ func readControlMsgFromClient(s *server.ProxyServer, c *conn.Conn) {
defer
timer
.
Stop
()
for
isContinueRead
{
_
,
err
:=
c
.
ReadLine
()
content
,
err
:=
c
.
ReadLine
()
if
err
!=
nil
{
if
err
==
io
.
EOF
{
log
.
Warn
(
"ProxyName [%s], client is dead!"
,
s
.
Name
)
s
.
Close
()
break
}
else
if
c
.
IsClosed
()
{
}
else
if
nil
==
c
||
c
.
IsClosed
()
{
log
.
Warn
(
"ProxyName [%s], client connection is closed"
,
s
.
Name
)
break
}
...
...
@@ -176,8 +176,29 @@ func readControlMsgFromClient(s *server.ProxyServer, c *conn.Conn) {
log
.
Error
(
"ProxyName [%s], read error: %v"
,
s
.
Name
,
err
)
continue
}
log
.
Debug
(
"ProxyName [%s], get heartbeat"
,
s
.
Name
)
timer
.
Reset
(
time
.
Duration
(
server
.
HeartBeatTimeout
)
*
time
.
Second
)
clientCtlReq
:=
&
msg
.
ClientCtlReq
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
content
),
clientCtlReq
);
err
!=
nil
{
log
.
Warn
(
"Parse err: %v : %s"
,
err
,
content
)
continue
}
if
consts
.
CSHeartBeatReq
==
clientCtlReq
.
Type
{
log
.
Debug
(
"ProxyName [%s], get heartbeat"
,
s
.
Name
)
timer
.
Reset
(
time
.
Duration
(
server
.
HeartBeatTimeout
)
*
time
.
Second
)
clientCtlRes
:=
&
msg
.
ClientCtlRes
{}
clientCtlRes
.
GeneralRes
.
Code
=
consts
.
SCHeartBeatRes
response
,
err
:=
json
.
Marshal
(
clientCtlRes
)
if
err
!=
nil
{
log
.
Warn
(
"Serialize ClientCtlRes err! err: %v"
,
err
)
continue
}
err
=
c
.
Write
(
string
(
response
)
+
"
\n
"
)
if
err
!=
nil
{
log
.
Error
(
"Send heartbeat response to client failed! Err:%v"
,
err
)
continue
}
}
}
}
src/frp/models/client/config.go
浏览文件 @
a2f1897a
...
...
@@ -15,6 +15,7 @@ var (
LogLevel
string
=
"warn"
LogWay
string
=
"file"
HeartBeatInterval
int64
=
5
HeartBeatTimeout
int64
=
30
)
var
ProxyClients
map
[
string
]
*
ProxyClient
=
make
(
map
[
string
]
*
ProxyClient
)
...
...
src/frp/models/consts/consts.go
浏览文件 @
a2f1897a
...
...
@@ -11,3 +11,13 @@ const (
CtlConn
=
iota
WorkConn
)
// msg from client to server
const
(
CSHeartBeatReq
=
1
)
// msg from server to client
const
(
SCHeartBeatRes
=
100
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录