Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
企猫商务
frp
提交
d1935193
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 搜索 >>
未验证
提交
d1935193
编写于
5月 07, 2020
作者:
T
Tank
提交者:
GitHub
5月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: Support user specify udp packet size in config (#1794)
上级
7266154d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
43 addition
and
8 deletion
+43
-8
client/proxy/proxy.go
client/proxy/proxy.go
+2
-2
client/visitor.go
client/visitor.go
+1
-1
conf/frpc_full.ini
conf/frpc_full.ini
+5
-0
conf/frps_full.ini
conf/frps_full.ini
+5
-0
models/config/client_common.go
models/config/client_common.go
+12
-0
models/config/server_common.go
models/config/server_common.go
+13
-0
models/proto/udp/udp.go
models/proto/udp/udp.go
+4
-4
server/proxy/udp.go
server/proxy/udp.go
+1
-1
未找到文件。
client/proxy/proxy.go
浏览文件 @
d1935193
...
...
@@ -543,7 +543,7 @@ func (pxy *UdpProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
go
workConnSenderFn
(
pxy
.
workConn
,
pxy
.
sendCh
)
go
workConnReaderFn
(
pxy
.
workConn
,
pxy
.
readCh
)
go
heartbeatFn
(
pxy
.
workConn
,
pxy
.
sendCh
)
udp
.
Forwarder
(
pxy
.
localAddr
,
pxy
.
readCh
,
pxy
.
sendCh
)
udp
.
Forwarder
(
pxy
.
localAddr
,
pxy
.
readCh
,
pxy
.
sendCh
,
int
(
pxy
.
clientCfg
.
UdpPacketSize
)
)
}
type
SudpProxy
struct
{
...
...
@@ -688,7 +688,7 @@ func (pxy *SudpProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
go
workConnReaderFn
(
workConn
,
readCh
)
go
heartbeatFn
(
workConn
,
sendCh
)
udp
.
Forwarder
(
pxy
.
localAddr
,
readCh
,
sendCh
)
udp
.
Forwarder
(
pxy
.
localAddr
,
readCh
,
sendCh
,
int
(
pxy
.
clientCfg
.
UdpPacketSize
)
)
}
// Common handler for tcp work connections.
...
...
client/visitor.go
浏览文件 @
d1935193
...
...
@@ -369,7 +369,7 @@ func (sv *SudpVisitor) Run() (err error) {
xl
.
Info
(
"sudp start to work"
)
go
sv
.
dispatcher
()
go
udp
.
ForwardUserConn
(
sv
.
udpConn
,
sv
.
readCh
,
sv
.
sendCh
)
go
udp
.
ForwardUserConn
(
sv
.
udpConn
,
sv
.
readCh
,
sv
.
sendCh
,
int
(
sv
.
ctl
.
clientCfg
.
UdpPacketSize
)
)
return
}
...
...
conf/frpc_full.ini
浏览文件 @
d1935193
...
...
@@ -68,6 +68,11 @@ tls_enable = true
meta_var1
=
123
meta_var2
=
234
# specify udp packet size, unit is byte. If not set, the default value is 1500.
# This parameter should be same between client and server.
# It affects the udp and sudp proxy.
udp_packet_size
=
1500
# 'ssh' is the unique proxy name
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
[ssh]
...
...
conf/frps_full.ini
浏览文件 @
d1935193
...
...
@@ -113,6 +113,11 @@ tcp_mux = true
# custom 404 page for HTTP requests
# custom_404_page = /path/to/404.html
# specify udp packet size, unit is byte. If not set, the default value is 1500.
# This parameter should be same between client and server.
# It affects the udp and sudp proxy.
udp_packet_size
=
1500
[plugin.user-manager]
addr
=
127.0.0.1:9000
path
=
/handler
...
...
models/config/client_common.go
浏览文件 @
d1935193
...
...
@@ -116,6 +116,9 @@ type ClientCommonConf struct {
HeartBeatTimeout
int64
`json:"heartbeat_timeout"`
// Client meta info
Metas
map
[
string
]
string
`json:"metas"`
// UdpPacketSize specifies the udp packet size
// By default, this value is 1500
UdpPacketSize
int64
`json:"udp_packet_size"`
}
// GetDefaultClientConf returns a client configuration with default values.
...
...
@@ -145,6 +148,7 @@ func GetDefaultClientConf() ClientCommonConf {
HeartBeatInterval
:
30
,
HeartBeatTimeout
:
90
,
Metas
:
make
(
map
[
string
]
string
),
UdpPacketSize
:
1500
,
}
}
...
...
@@ -298,6 +302,14 @@ func UnmarshalClientConfFromIni(content string) (cfg ClientCommonConf, err error
cfg
.
Metas
[
strings
.
TrimPrefix
(
k
,
"meta_"
)]
=
v
}
}
if
tmpStr
,
ok
=
conf
.
Get
(
"common"
,
"udp_packet_size"
);
ok
{
if
v
,
err
=
strconv
.
ParseInt
(
tmpStr
,
10
,
64
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Parse conf error: invalid udp_packet_size"
)
return
}
else
{
cfg
.
UdpPacketSize
=
v
}
}
return
}
...
...
models/config/server_common.go
浏览文件 @
d1935193
...
...
@@ -145,6 +145,9 @@ type ServerCommonConf struct {
UserConnTimeout
int64
`json:"user_conn_timeout"`
// HTTPPlugins specify the server plugins support HTTP protocol.
HTTPPlugins
map
[
string
]
plugin
.
HTTPPluginOptions
`json:"http_plugins"`
// UdpPacketSize specifies the udp packet size
// By default, this value is 1500
UdpPacketSize
int64
`json:"udp_packet_size"`
}
// GetDefaultServerConf returns a server configuration with reasonable
...
...
@@ -182,6 +185,7 @@ func GetDefaultServerConf() ServerCommonConf {
UserConnTimeout
:
10
,
Custom404Page
:
""
,
HTTPPlugins
:
make
(
map
[
string
]
plugin
.
HTTPPluginOptions
),
UdpPacketSize
:
1500
,
}
}
...
...
@@ -416,6 +420,15 @@ func UnmarshalServerConfFromIni(content string) (cfg ServerCommonConf, err error
}
else
{
cfg
.
TlsOnly
=
false
}
if
tmpStr
,
ok
=
conf
.
Get
(
"common"
,
"udp_packet_size"
);
ok
{
if
v
,
err
=
strconv
.
ParseInt
(
tmpStr
,
10
,
64
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Parse conf error: invalid udp_packet_size"
)
return
}
else
{
cfg
.
UdpPacketSize
=
v
}
}
return
}
...
...
models/proto/udp/udp.go
浏览文件 @
d1935193
...
...
@@ -39,7 +39,7 @@ func GetContent(m *msg.UdpPacket) (buf []byte, err error) {
return
}
func
ForwardUserConn
(
udpConn
*
net
.
UDPConn
,
readCh
<-
chan
*
msg
.
UdpPacket
,
sendCh
chan
<-
*
msg
.
UdpPacket
)
{
func
ForwardUserConn
(
udpConn
*
net
.
UDPConn
,
readCh
<-
chan
*
msg
.
UdpPacket
,
sendCh
chan
<-
*
msg
.
UdpPacket
,
bufSize
int
)
{
// read
go
func
()
{
for
udpMsg
:=
range
readCh
{
...
...
@@ -52,7 +52,7 @@ func ForwardUserConn(udpConn *net.UDPConn, readCh <-chan *msg.UdpPacket, sendCh
}()
// write
buf
:=
pool
.
GetBuf
(
1500
)
buf
:=
pool
.
GetBuf
(
bufSize
)
defer
pool
.
PutBuf
(
buf
)
for
{
n
,
remoteAddr
,
err
:=
udpConn
.
ReadFromUDP
(
buf
)
...
...
@@ -69,7 +69,7 @@ func ForwardUserConn(udpConn *net.UDPConn, readCh <-chan *msg.UdpPacket, sendCh
}
}
func
Forwarder
(
dstAddr
*
net
.
UDPAddr
,
readCh
<-
chan
*
msg
.
UdpPacket
,
sendCh
chan
<-
msg
.
Message
)
{
func
Forwarder
(
dstAddr
*
net
.
UDPAddr
,
readCh
<-
chan
*
msg
.
UdpPacket
,
sendCh
chan
<-
msg
.
Message
,
bufSize
int
)
{
var
(
mu
sync
.
RWMutex
)
...
...
@@ -85,7 +85,7 @@ func Forwarder(dstAddr *net.UDPAddr, readCh <-chan *msg.UdpPacket, sendCh chan<-
udpConn
.
Close
()
}()
buf
:=
pool
.
GetBuf
(
1500
)
buf
:=
pool
.
GetBuf
(
bufSize
)
for
{
udpConn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
30
*
time
.
Second
))
n
,
_
,
err
:=
udpConn
.
ReadFromUDP
(
buf
)
...
...
server/proxy/udp.go
浏览文件 @
d1935193
...
...
@@ -196,7 +196,7 @@ func (pxy *UdpProxy) Run() (remoteAddr string, err error) {
// Response will be wrapped to be forwarded by work connection to server.
// Close readCh and sendCh at the end.
go
func
()
{
udp
.
ForwardUserConn
(
udpConn
,
pxy
.
readCh
,
pxy
.
sendCh
)
udp
.
ForwardUserConn
(
udpConn
,
pxy
.
readCh
,
pxy
.
sendCh
,
int
(
pxy
.
serverCfg
.
UdpPacketSize
)
)
pxy
.
Close
()
}()
return
remoteAddr
,
nil
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录