Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
企猫商务
frp
提交
bd1e9a30
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 搜索 >>
提交
bd1e9a30
编写于
12月 05, 2017
作者:
F
fatedier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update doc and fix vistor -> visitor
上级
92fff5c1
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
308 addition
and
202 deletion
+308
-202
README.md
README.md
+53
-3
README_zh.md
README_zh.md
+58
-2
client/admin_api.go
client/admin_api.go
+2
-2
client/control.go
client/control.go
+47
-47
client/proxy.go
client/proxy.go
+5
-5
client/service.go
client/service.go
+2
-2
client/visitor.go
client/visitor.go
+49
-49
cmd/frpc/main.go
cmd/frpc/main.go
+2
-2
conf/frpc_full.ini
conf/frpc_full.ini
+10
-10
models/config/proxy.go
models/config/proxy.go
+11
-11
models/msg/msg.go
models/msg/msg.go
+26
-26
server/manager.go
server/manager.go
+16
-16
server/nathole.go
server/nathole.go
+14
-14
server/proxy.go
server/proxy.go
+2
-2
server/service.go
server/service.go
+11
-11
未找到文件。
README.md
浏览文件 @
bd1e9a30
...
@@ -11,6 +11,7 @@ frp is a fast reverse proxy to help you expose a local server behind a NAT or fi
...
@@ -11,6 +11,7 @@ frp is a fast reverse proxy to help you expose a local server behind a NAT or fi
## Table of Contents
## Table of Contents
<!-- vim-markdown-toc GFM -->
<!-- vim-markdown-toc GFM -->
*
[
What can I do with frp?
](
#what-can-i-do-with-frp
)
*
[
What can I do with frp?
](
#what-can-i-do-with-frp
)
*
[
Status
](
#status
)
*
[
Status
](
#status
)
*
[
Architecture
](
#architecture
)
*
[
Architecture
](
#architecture
)
...
@@ -20,6 +21,7 @@ frp is a fast reverse proxy to help you expose a local server behind a NAT or fi
...
@@ -20,6 +21,7 @@ frp is a fast reverse proxy to help you expose a local server behind a NAT or fi
*
[
Forward DNS query request
](
#forward-dns-query-request
)
*
[
Forward DNS query request
](
#forward-dns-query-request
)
*
[
Forward unix domain socket
](
#forward-unix-domain-socket
)
*
[
Forward unix domain socket
](
#forward-unix-domain-socket
)
*
[
Expose your service in security
](
#expose-your-service-in-security
)
*
[
Expose your service in security
](
#expose-your-service-in-security
)
*
[
P2P Mode
](
#p2p-mode
)
*
[
Connect website through frpc's network
](
#connect-website-through-frpcs-network
)
*
[
Connect website through frpc's network
](
#connect-website-through-frpcs-network
)
*
[
Features
](
#features
)
*
[
Features
](
#features
)
*
[
Configuration File
](
#configuration-file
)
*
[
Configuration File
](
#configuration-file
)
...
@@ -242,9 +244,9 @@ Configure frps same as above.
...
@@ -242,9 +244,9 @@ Configure frps same as above.
server_addr
=
x.x.x.x
server_addr
=
x.x.x.x
server_port
=
7000
server_port
=
7000
[secret_ssh_vistor]
[secret_ssh_vis
i
tor]
type
=
stcp
type
=
stcp
role
=
vistor
role
=
vis
i
tor
server_name
=
secret_ssh
server_name
=
secret_ssh
sk
=
abcdefg
sk
=
abcdefg
bind_addr
=
127.0.0.1
bind_addr
=
127.0.0.1
...
@@ -255,6 +257,54 @@ Configure frps same as above.
...
@@ -255,6 +257,54 @@ Configure frps same as above.
`ssh -oPort=6000 test@127.0.0.1`
`ssh -oPort=6000 test@127.0.0.1`
### P2P Mode
**xtcp**
is designed for transmitting a large amount of data directly between two client.
Now it can't penetrate all types of NAT devices. You can try
**stcp**
if
**xtcp**
doesn't work.
1.
Configure a udp port for xtcp:
```
ini
bind_udp_port
=
7001
```
2.
Start frpc, forward ssh port and
`remote_port`
is useless:
```
ini
# frpc.ini
[common]
server_addr
=
x.x.x.x
server_port
=
7000
[p2p_ssh]
type
=
xtcp
sk
=
abcdefg
local_ip
=
127.0.0.1
local_port
=
22
```
3.
Start another frpc in which you want to connect this ssh server:
```
ini
# frpc.ini
[common]
server_addr
=
x.x.x.x
server_port
=
7000
[p2p_ssh_visitor]
type
=
xtcp
role
=
visitor
server_name
=
p2p_ssh
sk
=
abcdefg
bind_addr
=
127.0.0.1
bind_port
=
6000
```
4.
Connect to server in LAN by ssh assuming that username is test:
`ssh -oPort=6000 test@127.0.0.1`
### Connect website through frpc's network
### Connect website through frpc's network
Configure frps same as above.
Configure frps same as above.
...
@@ -550,7 +600,7 @@ plugin_http_passwd = abc
...
@@ -550,7 +600,7 @@ plugin_http_passwd = abc
*
Direct reverse proxy, like haproxy.
*
Direct reverse proxy, like haproxy.
*
Load balance to different service in frpc.
*
Load balance to different service in frpc.
*
Frpc can directly be a webserver for static files.
*
Frpc can directly be a webserver for static files.
*
P2p communicate by mak
e
udp hole to penetrate NAT.
*
P2p communicate by mak
ing
udp hole to penetrate NAT.
*
kubernetes ingress support.
*
kubernetes ingress support.
...
...
README_zh.md
浏览文件 @
bd1e9a30
...
@@ -9,6 +9,7 @@ frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp
...
@@ -9,6 +9,7 @@ frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp
## 目录
## 目录
<!-- vim-markdown-toc GFM -->
<!-- vim-markdown-toc GFM -->
*
[
frp 的作用
](
#frp-的作用
)
*
[
frp 的作用
](
#frp-的作用
)
*
[
开发状态
](
#开发状态
)
*
[
开发状态
](
#开发状态
)
*
[
架构
](
#架构
)
*
[
架构
](
#架构
)
...
@@ -18,6 +19,7 @@ frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp
...
@@ -18,6 +19,7 @@ frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp
*
[
转发 DNS 查询请求
](
#转发-dns-查询请求
)
*
[
转发 DNS 查询请求
](
#转发-dns-查询请求
)
*
[
转发 Unix域套接字
](
#转发-unix域套接字
)
*
[
转发 Unix域套接字
](
#转发-unix域套接字
)
*
[
安全地暴露内网服务
](
#安全地暴露内网服务
)
*
[
安全地暴露内网服务
](
#安全地暴露内网服务
)
*
[
点对点内网穿透
](
#点对点内网穿透
)
*
[
通过 frpc 所在机器访问外网
](
#通过-frpc-所在机器访问外网
)
*
[
通过 frpc 所在机器访问外网
](
#通过-frpc-所在机器访问外网
)
*
[
功能说明
](
#功能说明
)
*
[
功能说明
](
#功能说明
)
*
[
配置文件
](
#配置文件
)
*
[
配置文件
](
#配置文件
)
...
@@ -246,10 +248,10 @@ frps 的部署步骤同上。
...
@@ -246,10 +248,10 @@ frps 的部署步骤同上。
server_addr
=
x.x.x.x
server_addr
=
x.x.x.x
server_port
=
7000
server_port
=
7000
[secret_ssh_vistor]
[secret_ssh_vis
i
tor]
type
=
stcp
type
=
stcp
# stcp 的访问者
# stcp 的访问者
role
=
vistor
role
=
vis
i
tor
# 要访问的 stcp 代理的名字
# 要访问的 stcp 代理的名字
server_name
=
secret_ssh
server_name
=
secret_ssh
sk
=
abcdefg
sk
=
abcdefg
...
@@ -262,6 +264,60 @@ frps 的部署步骤同上。
...
@@ -262,6 +264,60 @@ frps 的部署步骤同上。
`ssh -oPort=6000 test@127.0.0.1`
`ssh -oPort=6000 test@127.0.0.1`
### 点对点内网穿透
frp 提供了一种新的代理类型
**xtcp**
用于应对在希望传输大量数据且流量不经过服务器的场景。
使用方式同
**stcp**
类似,需要在两边都部署上 frpc 用于建立直接的连接。
目前处于开发的初级阶段,并不能穿透所有类型的 NAT 设备,所以穿透成功率较低。穿透失败时可以尝试
**stcp**
的方式。
1.
frps 除正常配置外需要额外配置一个 udp 端口用于支持该类型的客户端:
```
ini
bind_udp_port
=
7001
```
2.
启动 frpc,转发内网的 ssh 服务,配置如下,不需要指定远程端口:
```
ini
# frpc.ini
[common]
server_addr
=
x.x.x.x
server_port
=
7000
[p2p_ssh]
type
=
xtcp
# 只有 sk 一致的用户才能访问到此服务
sk
=
abcdefg
local_ip
=
127.0.0.1
local_port
=
22
```
3.
在要访问这个服务的机器上启动另外一个 frpc,配置如下:
```
ini
# frpc.ini
[common]
server_addr
=
x.x.x.x
server_port
=
7000
[p2p_ssh_visitor]
type
=
xtcp
# xtcp 的访问者
role
=
visitor
# 要访问的 xtcp 代理的名字
server_name
=
p2p_ssh
sk
=
abcdefg
# 绑定本地端口用于访问 ssh 服务
bind_addr
=
127.0.0.1
bind_port
=
6000
```
4.
通过 ssh 访问内网机器,假设用户名为 test:
`ssh -oPort=6000 test@127.0.0.1`
### 通过 frpc 所在机器访问外网
### 通过 frpc 所在机器访问外网
frpc 内置了 http proxy 和 socks5 插件,可以使其他机器通过 frpc 的网络访问互联网。
frpc 内置了 http proxy 和 socks5 插件,可以使其他机器通过 frpc 的网络访问互联网。
...
...
client/admin_api.go
浏览文件 @
bd1e9a30
...
@@ -64,7 +64,7 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request, _ httprout
...
@@ -64,7 +64,7 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request, _ httprout
return
return
}
}
pxyCfgs
,
vistorCfgs
,
err
:=
config
.
LoadProxyConfFromFile
(
config
.
ClientCommonCfg
.
User
,
conf
,
newCommonCfg
.
Start
)
pxyCfgs
,
vis
i
torCfgs
,
err
:=
config
.
LoadProxyConfFromFile
(
config
.
ClientCommonCfg
.
User
,
conf
,
newCommonCfg
.
Start
)
if
err
!=
nil
{
if
err
!=
nil
{
res
.
Code
=
3
res
.
Code
=
3
res
.
Msg
=
err
.
Error
()
res
.
Msg
=
err
.
Error
()
...
@@ -72,7 +72,7 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request, _ httprout
...
@@ -72,7 +72,7 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request, _ httprout
return
return
}
}
svr
.
ctl
.
reloadConf
(
pxyCfgs
,
vistorCfgs
)
svr
.
ctl
.
reloadConf
(
pxyCfgs
,
vis
i
torCfgs
)
log
.
Info
(
"success reload conf"
)
log
.
Info
(
"success reload conf"
)
return
return
}
}
client/control.go
浏览文件 @
bd1e9a30
...
@@ -49,11 +49,11 @@ type Control struct {
...
@@ -49,11 +49,11 @@ type Control struct {
// proxies
// proxies
proxies
map
[
string
]
Proxy
proxies
map
[
string
]
Proxy
// vistor configures
// vis
i
tor configures
vistorCfgs
map
[
string
]
config
.
ProxyConf
vis
i
torCfgs
map
[
string
]
config
.
ProxyConf
// vistors
// vis
i
tors
vis
tors
map
[
string
]
Vis
tor
vis
itors
map
[
string
]
Visi
tor
// control connection
// control connection
conn
frpNet
.
Conn
conn
frpNet
.
Conn
...
@@ -84,7 +84,7 @@ type Control struct {
...
@@ -84,7 +84,7 @@ type Control struct {
log
.
Logger
log
.
Logger
}
}
func
NewControl
(
svr
*
Service
,
pxyCfgs
map
[
string
]
config
.
ProxyConf
,
vistorCfgs
map
[
string
]
config
.
ProxyConf
)
*
Control
{
func
NewControl
(
svr
*
Service
,
pxyCfgs
map
[
string
]
config
.
ProxyConf
,
vis
i
torCfgs
map
[
string
]
config
.
ProxyConf
)
*
Control
{
loginMsg
:=
&
msg
.
Login
{
loginMsg
:=
&
msg
.
Login
{
Arch
:
runtime
.
GOARCH
,
Arch
:
runtime
.
GOARCH
,
Os
:
runtime
.
GOOS
,
Os
:
runtime
.
GOOS
,
...
@@ -93,16 +93,16 @@ func NewControl(svr *Service, pxyCfgs map[string]config.ProxyConf, vistorCfgs ma
...
@@ -93,16 +93,16 @@ func NewControl(svr *Service, pxyCfgs map[string]config.ProxyConf, vistorCfgs ma
Version
:
version
.
Full
(),
Version
:
version
.
Full
(),
}
}
return
&
Control
{
return
&
Control
{
svr
:
svr
,
svr
:
svr
,
loginMsg
:
loginMsg
,
loginMsg
:
loginMsg
,
pxyCfgs
:
pxyCfgs
,
pxyCfgs
:
pxyCfgs
,
vis
torCfgs
:
vis
torCfgs
,
vis
itorCfgs
:
visi
torCfgs
,
proxies
:
make
(
map
[
string
]
Proxy
),
proxies
:
make
(
map
[
string
]
Proxy
),
vis
tors
:
make
(
map
[
string
]
Vis
tor
),
vis
itors
:
make
(
map
[
string
]
Visi
tor
),
sendCh
:
make
(
chan
msg
.
Message
,
10
),
sendCh
:
make
(
chan
msg
.
Message
,
10
),
readCh
:
make
(
chan
msg
.
Message
,
10
),
readCh
:
make
(
chan
msg
.
Message
,
10
),
closedCh
:
make
(
chan
int
),
closedCh
:
make
(
chan
int
),
Logger
:
log
.
NewPrefixLogger
(
""
),
Logger
:
log
.
NewPrefixLogger
(
""
),
}
}
}
}
...
@@ -137,16 +137,16 @@ func (ctl *Control) Run() (err error) {
...
@@ -137,16 +137,16 @@ func (ctl *Control) Run() (err error) {
go
ctl
.
writer
()
go
ctl
.
writer
()
go
ctl
.
reader
()
go
ctl
.
reader
()
// start all local vistors
// start all local vis
i
tors
for
_
,
cfg
:=
range
ctl
.
vistorCfgs
{
for
_
,
cfg
:=
range
ctl
.
vis
i
torCfgs
{
vis
tor
:=
NewVis
tor
(
ctl
,
cfg
)
vis
itor
:=
NewVisi
tor
(
ctl
,
cfg
)
err
=
vistor
.
Run
()
err
=
vis
i
tor
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
vistor
.
Warn
(
"start error: %v"
,
err
)
vis
i
tor
.
Warn
(
"start error: %v"
,
err
)
continue
continue
}
}
ctl
.
vis
tors
[
cfg
.
GetName
()]
=
vis
tor
ctl
.
vis
itors
[
cfg
.
GetName
()]
=
visi
tor
vis
tor
.
Info
(
"start vis
tor success"
)
vis
itor
.
Info
(
"start visi
tor success"
)
}
}
// send NewProxy message for all configured proxies
// send NewProxy message for all configured proxies
...
@@ -441,17 +441,17 @@ func (ctl *Control) controler() {
...
@@ -441,17 +441,17 @@ func (ctl *Control) controler() {
}
}
}
}
for
_
,
cfg
:=
range
ctl
.
vistorCfgs
{
for
_
,
cfg
:=
range
ctl
.
vis
i
torCfgs
{
if
_
,
exist
:=
ctl
.
vistors
[
cfg
.
GetName
()];
!
exist
{
if
_
,
exist
:=
ctl
.
vis
i
tors
[
cfg
.
GetName
()];
!
exist
{
ctl
.
Info
(
"try to start vistor [%s]"
,
cfg
.
GetName
())
ctl
.
Info
(
"try to start vis
i
tor [%s]"
,
cfg
.
GetName
())
vis
tor
:=
NewVis
tor
(
ctl
,
cfg
)
vis
itor
:=
NewVisi
tor
(
ctl
,
cfg
)
err
=
vistor
.
Run
()
err
=
vis
i
tor
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
vistor
.
Warn
(
"start error: %v"
,
err
)
vis
i
tor
.
Warn
(
"start error: %v"
,
err
)
continue
continue
}
}
ctl
.
vis
tors
[
cfg
.
GetName
()]
=
vis
tor
ctl
.
vis
itors
[
cfg
.
GetName
()]
=
visi
tor
vis
tor
.
Info
(
"start vis
tor success"
)
vis
itor
.
Info
(
"start visi
tor success"
)
}
}
}
}
ctl
.
mu
.
RUnlock
()
ctl
.
mu
.
RUnlock
()
...
@@ -549,7 +549,7 @@ func (ctl *Control) getProxyConf(name string) (conf config.ProxyConf, ok bool) {
...
@@ -549,7 +549,7 @@ func (ctl *Control) getProxyConf(name string) (conf config.ProxyConf, ok bool) {
return
return
}
}
func
(
ctl
*
Control
)
reloadConf
(
pxyCfgs
map
[
string
]
config
.
ProxyConf
,
vistorCfgs
map
[
string
]
config
.
ProxyConf
)
{
func
(
ctl
*
Control
)
reloadConf
(
pxyCfgs
map
[
string
]
config
.
ProxyConf
,
vis
i
torCfgs
map
[
string
]
config
.
ProxyConf
)
{
ctl
.
mu
.
Lock
()
ctl
.
mu
.
Lock
()
defer
ctl
.
mu
.
Unlock
()
defer
ctl
.
mu
.
Unlock
()
...
@@ -588,35 +588,35 @@ func (ctl *Control) reloadConf(pxyCfgs map[string]config.ProxyConf, vistorCfgs m
...
@@ -588,35 +588,35 @@ func (ctl *Control) reloadConf(pxyCfgs map[string]config.ProxyConf, vistorCfgs m
}
}
ctl
.
Info
(
"proxy added: %v"
,
addedPxyNames
)
ctl
.
Info
(
"proxy added: %v"
,
addedPxyNames
)
removedVistorName
:=
make
([]
string
,
0
)
removedVis
i
torName
:=
make
([]
string
,
0
)
for
name
,
oldVis
torCfg
:=
range
ctl
.
vis
torCfgs
{
for
name
,
oldVis
itorCfg
:=
range
ctl
.
visi
torCfgs
{
del
:=
false
del
:=
false
cfg
,
ok
:=
vistorCfgs
[
name
]
cfg
,
ok
:=
vis
i
torCfgs
[
name
]
if
!
ok
{
if
!
ok
{
del
=
true
del
=
true
}
else
{
}
else
{
if
!
oldVistorCfg
.
Compare
(
cfg
)
{
if
!
oldVis
i
torCfg
.
Compare
(
cfg
)
{
del
=
true
del
=
true
}
}
}
}
if
del
{
if
del
{
removedVis
torName
=
append
(
removedVis
torName
,
name
)
removedVis
itorName
=
append
(
removedVisi
torName
,
name
)
delete
(
ctl
.
vistorCfgs
,
name
)
delete
(
ctl
.
vis
i
torCfgs
,
name
)
if
vis
tor
,
ok
:=
ctl
.
vis
tors
[
name
];
ok
{
if
vis
itor
,
ok
:=
ctl
.
visi
tors
[
name
];
ok
{
vistor
.
Close
()
vis
i
tor
.
Close
()
}
}
delete
(
ctl
.
vistors
,
name
)
delete
(
ctl
.
vis
i
tors
,
name
)
}
}
}
}
ctl
.
Info
(
"vis
tor removed: %v"
,
removedVis
torName
)
ctl
.
Info
(
"vis
itor removed: %v"
,
removedVisi
torName
)
addedVistorName
:=
make
([]
string
,
0
)
addedVis
i
torName
:=
make
([]
string
,
0
)
for
name
,
vis
torCfg
:=
range
vis
torCfgs
{
for
name
,
vis
itorCfg
:=
range
visi
torCfgs
{
if
_
,
ok
:=
ctl
.
vistorCfgs
[
name
];
!
ok
{
if
_
,
ok
:=
ctl
.
vis
i
torCfgs
[
name
];
!
ok
{
ctl
.
vis
torCfgs
[
name
]
=
vis
torCfg
ctl
.
vis
itorCfgs
[
name
]
=
visi
torCfg
addedVis
torName
=
append
(
addedVis
torName
,
name
)
addedVis
itorName
=
append
(
addedVisi
torName
,
name
)
}
}
}
}
ctl
.
Info
(
"vis
tor added: %v"
,
addedVis
torName
)
ctl
.
Info
(
"vis
itor added: %v"
,
addedVisi
torName
)
}
}
client/proxy.go
浏览文件 @
bd1e9a30
...
@@ -273,23 +273,23 @@ func (pxy *XtcpProxy) InWorkConn(conn frpNet.Conn) {
...
@@ -273,23 +273,23 @@ func (pxy *XtcpProxy) InWorkConn(conn frpNet.Conn) {
clientConn
.
Close
()
clientConn
.
Close
()
pxy
.
Trace
(
"get natHoleRespMsg, sid [%s], client address [%s]"
,
natHoleRespMsg
.
Sid
,
natHoleRespMsg
.
ClientAddr
)
pxy
.
Trace
(
"get natHoleRespMsg, sid [%s], client address [%s]"
,
natHoleRespMsg
.
Sid
,
natHoleRespMsg
.
ClientAddr
)
// Send sid to vistor udp address.
// Send sid to vis
i
tor udp address.
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
laddr
,
_
:=
net
.
ResolveUDPAddr
(
"udp"
,
clientConn
.
LocalAddr
()
.
String
())
laddr
,
_
:=
net
.
ResolveUDPAddr
(
"udp"
,
clientConn
.
LocalAddr
()
.
String
())
daddr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
natHoleRespMsg
.
VistorAddr
)
daddr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
natHoleRespMsg
.
Vis
i
torAddr
)
if
err
!=
nil
{
if
err
!=
nil
{
pxy
.
Error
(
"resolve vistor udp address error: %v"
,
err
)
pxy
.
Error
(
"resolve vis
i
tor udp address error: %v"
,
err
)
return
return
}
}
lConn
,
err
:=
net
.
DialUDP
(
"udp"
,
laddr
,
daddr
)
lConn
,
err
:=
net
.
DialUDP
(
"udp"
,
laddr
,
daddr
)
if
err
!=
nil
{
if
err
!=
nil
{
pxy
.
Error
(
"dial vistor udp address error: %v"
,
err
)
pxy
.
Error
(
"dial vis
i
tor udp address error: %v"
,
err
)
return
return
}
}
lConn
.
Write
([]
byte
(
natHoleRespMsg
.
Sid
))
lConn
.
Write
([]
byte
(
natHoleRespMsg
.
Sid
))
kcpConn
,
err
:=
frpNet
.
NewKcpConnFromUdp
(
lConn
,
true
,
natHoleRespMsg
.
VistorAddr
)
kcpConn
,
err
:=
frpNet
.
NewKcpConnFromUdp
(
lConn
,
true
,
natHoleRespMsg
.
Vis
i
torAddr
)
if
err
!=
nil
{
if
err
!=
nil
{
pxy
.
Error
(
"create kcp connection from udp connection error: %v"
,
err
)
pxy
.
Error
(
"create kcp connection from udp connection error: %v"
,
err
)
return
return
...
...
client/service.go
浏览文件 @
bd1e9a30
...
@@ -26,11 +26,11 @@ type Service struct {
...
@@ -26,11 +26,11 @@ type Service struct {
closedCh
chan
int
closedCh
chan
int
}
}
func
NewService
(
pxyCfgs
map
[
string
]
config
.
ProxyConf
,
vistorCfgs
map
[
string
]
config
.
ProxyConf
)
(
svr
*
Service
)
{
func
NewService
(
pxyCfgs
map
[
string
]
config
.
ProxyConf
,
vis
i
torCfgs
map
[
string
]
config
.
ProxyConf
)
(
svr
*
Service
)
{
svr
=
&
Service
{
svr
=
&
Service
{
closedCh
:
make
(
chan
int
),
closedCh
:
make
(
chan
int
),
}
}
ctl
:=
NewControl
(
svr
,
pxyCfgs
,
vistorCfgs
)
ctl
:=
NewControl
(
svr
,
pxyCfgs
,
vis
i
torCfgs
)
svr
.
ctl
=
ctl
svr
.
ctl
=
ctl
return
return
}
}
...
...
client/vistor.go
→
client/vis
i
tor.go
浏览文件 @
bd1e9a30
...
@@ -35,34 +35,34 @@ import (
...
@@ -35,34 +35,34 @@ import (
"github.com/fatedier/frp/utils/util"
"github.com/fatedier/frp/utils/util"
)
)
// Vistor is used for forward traffics from local port tot remote service.
// Vis
i
tor is used for forward traffics from local port tot remote service.
type
Vistor
interface
{
type
Vis
i
tor
interface
{
Run
()
error
Run
()
error
Close
()
Close
()
log
.
Logger
log
.
Logger
}
}
func
NewVis
tor
(
ctl
*
Control
,
pxyConf
config
.
ProxyConf
)
(
vistor
Vis
tor
)
{
func
NewVis
itor
(
ctl
*
Control
,
pxyConf
config
.
ProxyConf
)
(
visitor
Visi
tor
)
{
baseVis
tor
:=
BaseVis
tor
{
baseVis
itor
:=
BaseVisi
tor
{
ctl
:
ctl
,
ctl
:
ctl
,
Logger
:
log
.
NewPrefixLogger
(
pxyConf
.
GetName
()),
Logger
:
log
.
NewPrefixLogger
(
pxyConf
.
GetName
()),
}
}
switch
cfg
:=
pxyConf
.
(
type
)
{
switch
cfg
:=
pxyConf
.
(
type
)
{
case
*
config
.
StcpProxyConf
:
case
*
config
.
StcpProxyConf
:
vis
tor
=
&
StcpVis
tor
{
vis
itor
=
&
StcpVisi
tor
{
BaseVis
tor
:
baseVis
tor
,
BaseVis
itor
:
baseVisi
tor
,
cfg
:
cfg
,
cfg
:
cfg
,
}
}
case
*
config
.
XtcpProxyConf
:
case
*
config
.
XtcpProxyConf
:
vis
tor
=
&
XtcpVis
tor
{
vis
itor
=
&
XtcpVisi
tor
{
BaseVis
tor
:
baseVis
tor
,
BaseVis
itor
:
baseVisi
tor
,
cfg
:
cfg
,
cfg
:
cfg
,
}
}
}
}
return
return
}
}
type
BaseVistor
struct
{
type
BaseVis
i
tor
struct
{
ctl
*
Control
ctl
*
Control
l
frpNet
.
Listener
l
frpNet
.
Listener
closed
bool
closed
bool
...
@@ -70,13 +70,13 @@ type BaseVistor struct {
...
@@ -70,13 +70,13 @@ type BaseVistor struct {
log
.
Logger
log
.
Logger
}
}
type
StcpVistor
struct
{
type
StcpVis
i
tor
struct
{
BaseVistor
BaseVis
i
tor
cfg
*
config
.
StcpProxyConf
cfg
*
config
.
StcpProxyConf
}
}
func
(
sv
*
StcpVistor
)
Run
()
(
err
error
)
{
func
(
sv
*
StcpVis
i
tor
)
Run
()
(
err
error
)
{
sv
.
l
,
err
=
frpNet
.
ListenTcp
(
sv
.
cfg
.
BindAddr
,
int64
(
sv
.
cfg
.
BindPort
))
sv
.
l
,
err
=
frpNet
.
ListenTcp
(
sv
.
cfg
.
BindAddr
,
int64
(
sv
.
cfg
.
BindPort
))
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -86,11 +86,11 @@ func (sv *StcpVistor) Run() (err error) {
...
@@ -86,11 +86,11 @@ func (sv *StcpVistor) Run() (err error) {
return
return
}
}
func
(
sv
*
StcpVistor
)
Close
()
{
func
(
sv
*
StcpVis
i
tor
)
Close
()
{
sv
.
l
.
Close
()
sv
.
l
.
Close
()
}
}
func
(
sv
*
StcpVistor
)
worker
()
{
func
(
sv
*
StcpVis
i
tor
)
worker
()
{
for
{
for
{
conn
,
err
:=
sv
.
l
.
Accept
()
conn
,
err
:=
sv
.
l
.
Accept
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -102,46 +102,46 @@ func (sv *StcpVistor) worker() {
...
@@ -102,46 +102,46 @@ func (sv *StcpVistor) worker() {
}
}
}
}
func
(
sv
*
StcpVistor
)
handleConn
(
userConn
frpNet
.
Conn
)
{
func
(
sv
*
StcpVis
i
tor
)
handleConn
(
userConn
frpNet
.
Conn
)
{
defer
userConn
.
Close
()
defer
userConn
.
Close
()
sv
.
Debug
(
"get a new stcp user connection"
)
sv
.
Debug
(
"get a new stcp user connection"
)
vistorConn
,
err
:=
sv
.
ctl
.
connectServer
()
vis
i
torConn
,
err
:=
sv
.
ctl
.
connectServer
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
defer
vistorConn
.
Close
()
defer
vis
i
torConn
.
Close
()
now
:=
time
.
Now
()
.
Unix
()
now
:=
time
.
Now
()
.
Unix
()
newVis
torConnMsg
:=
&
msg
.
NewVis
torConn
{
newVis
itorConnMsg
:=
&
msg
.
NewVisi
torConn
{
ProxyName
:
sv
.
cfg
.
ServerName
,
ProxyName
:
sv
.
cfg
.
ServerName
,
SignKey
:
util
.
GetAuthKey
(
sv
.
cfg
.
Sk
,
now
),
SignKey
:
util
.
GetAuthKey
(
sv
.
cfg
.
Sk
,
now
),
Timestamp
:
now
,
Timestamp
:
now
,
UseEncryption
:
sv
.
cfg
.
UseEncryption
,
UseEncryption
:
sv
.
cfg
.
UseEncryption
,
UseCompression
:
sv
.
cfg
.
UseCompression
,
UseCompression
:
sv
.
cfg
.
UseCompression
,
}
}
err
=
msg
.
WriteMsg
(
vis
torConn
,
newVis
torConnMsg
)
err
=
msg
.
WriteMsg
(
vis
itorConn
,
newVisi
torConnMsg
)
if
err
!=
nil
{
if
err
!=
nil
{
sv
.
Warn
(
"send newVistorConnMsg to server error: %v"
,
err
)
sv
.
Warn
(
"send newVis
i
torConnMsg to server error: %v"
,
err
)
return
return
}
}
var
newVis
torConnRespMsg
msg
.
NewVis
torConnResp
var
newVis
itorConnRespMsg
msg
.
NewVisi
torConnResp
vistorConn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
10
*
time
.
Second
))
vis
i
torConn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
10
*
time
.
Second
))
err
=
msg
.
ReadMsgInto
(
vis
torConn
,
&
newVis
torConnRespMsg
)
err
=
msg
.
ReadMsgInto
(
vis
itorConn
,
&
newVisi
torConnRespMsg
)
if
err
!=
nil
{
if
err
!=
nil
{
sv
.
Warn
(
"get newVistorConnRespMsg error: %v"
,
err
)
sv
.
Warn
(
"get newVis
i
torConnRespMsg error: %v"
,
err
)
return
return
}
}
vistorConn
.
SetReadDeadline
(
time
.
Time
{})
vis
i
torConn
.
SetReadDeadline
(
time
.
Time
{})
if
newVistorConnRespMsg
.
Error
!=
""
{
if
newVis
i
torConnRespMsg
.
Error
!=
""
{
sv
.
Warn
(
"start new vis
tor connection error: %s"
,
newVis
torConnRespMsg
.
Error
)
sv
.
Warn
(
"start new vis
itor connection error: %s"
,
newVisi
torConnRespMsg
.
Error
)
return
return
}
}
var
remote
io
.
ReadWriteCloser
var
remote
io
.
ReadWriteCloser
remote
=
vistorConn
remote
=
vis
i
torConn
if
sv
.
cfg
.
UseEncryption
{
if
sv
.
cfg
.
UseEncryption
{
remote
,
err
=
frpIo
.
WithEncryption
(
remote
,
[]
byte
(
sv
.
cfg
.
Sk
))
remote
,
err
=
frpIo
.
WithEncryption
(
remote
,
[]
byte
(
sv
.
cfg
.
Sk
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -157,13 +157,13 @@ func (sv *StcpVistor) handleConn(userConn frpNet.Conn) {
...
@@ -157,13 +157,13 @@ func (sv *StcpVistor) handleConn(userConn frpNet.Conn) {
frpIo
.
Join
(
userConn
,
remote
)
frpIo
.
Join
(
userConn
,
remote
)
}
}
type
XtcpVistor
struct
{
type
XtcpVis
i
tor
struct
{
BaseVistor
BaseVis
i
tor
cfg
*
config
.
XtcpProxyConf
cfg
*
config
.
XtcpProxyConf
}
}
func
(
sv
*
XtcpVistor
)
Run
()
(
err
error
)
{
func
(
sv
*
XtcpVis
i
tor
)
Run
()
(
err
error
)
{
sv
.
l
,
err
=
frpNet
.
ListenTcp
(
sv
.
cfg
.
BindAddr
,
int64
(
sv
.
cfg
.
BindPort
))
sv
.
l
,
err
=
frpNet
.
ListenTcp
(
sv
.
cfg
.
BindAddr
,
int64
(
sv
.
cfg
.
BindPort
))
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -173,11 +173,11 @@ func (sv *XtcpVistor) Run() (err error) {
...
@@ -173,11 +173,11 @@ func (sv *XtcpVistor) Run() (err error) {
return
return
}
}
func
(
sv
*
XtcpVistor
)
Close
()
{
func
(
sv
*
XtcpVis
i
tor
)
Close
()
{
sv
.
l
.
Close
()
sv
.
l
.
Close
()
}
}
func
(
sv
*
XtcpVistor
)
worker
()
{
func
(
sv
*
XtcpVis
i
tor
)
worker
()
{
for
{
for
{
conn
,
err
:=
sv
.
l
.
Accept
()
conn
,
err
:=
sv
.
l
.
Accept
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -189,7 +189,7 @@ func (sv *XtcpVistor) worker() {
...
@@ -189,7 +189,7 @@ func (sv *XtcpVistor) worker() {
}
}
}
}
func
(
sv
*
XtcpVistor
)
handleConn
(
userConn
frpNet
.
Conn
)
{
func
(
sv
*
XtcpVis
i
tor
)
handleConn
(
userConn
frpNet
.
Conn
)
{
defer
userConn
.
Close
()
defer
userConn
.
Close
()
sv
.
Debug
(
"get a new xtcp user connection"
)
sv
.
Debug
(
"get a new xtcp user connection"
)
...
@@ -200,26 +200,26 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
...
@@ -200,26 +200,26 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
raddr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
raddr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
fmt
.
Sprintf
(
"%s:%d"
,
config
.
ClientCommonCfg
.
ServerAddr
,
config
.
ClientCommonCfg
.
ServerUdpPort
))
fmt
.
Sprintf
(
"%s:%d"
,
config
.
ClientCommonCfg
.
ServerAddr
,
config
.
ClientCommonCfg
.
ServerUdpPort
))
vistorConn
,
err
:=
net
.
DialUDP
(
"udp"
,
nil
,
raddr
)
vis
i
torConn
,
err
:=
net
.
DialUDP
(
"udp"
,
nil
,
raddr
)
defer
vistorConn
.
Close
()
defer
vis
i
torConn
.
Close
()
now
:=
time
.
Now
()
.
Unix
()
now
:=
time
.
Now
()
.
Unix
()
natHoleVis
torMsg
:=
&
msg
.
NatHoleVis
tor
{
natHoleVis
itorMsg
:=
&
msg
.
NatHoleVisi
tor
{
ProxyName
:
sv
.
cfg
.
ServerName
,
ProxyName
:
sv
.
cfg
.
ServerName
,
SignKey
:
util
.
GetAuthKey
(
sv
.
cfg
.
Sk
,
now
),
SignKey
:
util
.
GetAuthKey
(
sv
.
cfg
.
Sk
,
now
),
Timestamp
:
now
,
Timestamp
:
now
,
}
}
err
=
msg
.
WriteMsg
(
vis
torConn
,
natHoleVis
torMsg
)
err
=
msg
.
WriteMsg
(
vis
itorConn
,
natHoleVisi
torMsg
)
if
err
!=
nil
{
if
err
!=
nil
{
sv
.
Warn
(
"send natHoleVistorMsg to server error: %v"
,
err
)
sv
.
Warn
(
"send natHoleVis
i
torMsg to server error: %v"
,
err
)
return
return
}
}
// Wait for client address at most 10 seconds.
// Wait for client address at most 10 seconds.
var
natHoleRespMsg
msg
.
NatHoleResp
var
natHoleRespMsg
msg
.
NatHoleResp
vistorConn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
10
*
time
.
Second
))
vis
i
torConn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
10
*
time
.
Second
))
buf
:=
pool
.
GetBuf
(
1024
)
buf
:=
pool
.
GetBuf
(
1024
)
n
,
err
:=
vistorConn
.
Read
(
buf
)
n
,
err
:=
vis
i
torConn
.
Read
(
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
sv
.
Warn
(
"get natHoleRespMsg error: %v"
,
err
)
sv
.
Warn
(
"get natHoleRespMsg error: %v"
,
err
)
return
return
...
@@ -230,13 +230,13 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
...
@@ -230,13 +230,13 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
sv
.
Warn
(
"get natHoleRespMsg error: %v"
,
err
)
sv
.
Warn
(
"get natHoleRespMsg error: %v"
,
err
)
return
return
}
}
vistorConn
.
SetReadDeadline
(
time
.
Time
{})
vis
i
torConn
.
SetReadDeadline
(
time
.
Time
{})
pool
.
PutBuf
(
buf
)
pool
.
PutBuf
(
buf
)
sv
.
Trace
(
"get natHoleRespMsg, sid [%s], client address [%s]"
,
natHoleRespMsg
.
Sid
,
natHoleRespMsg
.
ClientAddr
)
sv
.
Trace
(
"get natHoleRespMsg, sid [%s], client address [%s]"
,
natHoleRespMsg
.
Sid
,
natHoleRespMsg
.
ClientAddr
)
// Close vistorConn, so we can use it's local address.
// Close vis
i
torConn, so we can use it's local address.
vistorConn
.
Close
()
vis
i
torConn
.
Close
()
// Send detect message.
// Send detect message.
array
:=
strings
.
Split
(
natHoleRespMsg
.
ClientAddr
,
":"
)
array
:=
strings
.
Split
(
natHoleRespMsg
.
ClientAddr
,
":"
)
...
@@ -244,7 +244,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
...
@@ -244,7 +244,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
sv
.
Error
(
"get natHoleResp client address error: %s"
,
natHoleRespMsg
.
ClientAddr
)
sv
.
Error
(
"get natHoleResp client address error: %s"
,
natHoleRespMsg
.
ClientAddr
)
return
return
}
}
laddr
,
_
:=
net
.
ResolveUDPAddr
(
"udp"
,
vistorConn
.
LocalAddr
()
.
String
())
laddr
,
_
:=
net
.
ResolveUDPAddr
(
"udp"
,
vis
i
torConn
.
LocalAddr
()
.
String
())
/*
/*
for i := 1000; i < 65000; i++ {
for i := 1000; i < 65000; i++ {
sv.sendDetectMsg(array[0], int64(i), laddr, "a")
sv.sendDetectMsg(array[0], int64(i), laddr, "a")
...
@@ -258,7 +258,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
...
@@ -258,7 +258,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
sv
.
sendDetectMsg
(
array
[
0
],
int64
(
port
),
laddr
,
[]
byte
(
natHoleRespMsg
.
Sid
))
sv
.
sendDetectMsg
(
array
[
0
],
int64
(
port
),
laddr
,
[]
byte
(
natHoleRespMsg
.
Sid
))
sv
.
Trace
(
"send all detect msg done"
)
sv
.
Trace
(
"send all detect msg done"
)
// Listen for vistorConn's address and wait for client connection.
// Listen for vis
i
torConn's address and wait for client connection.
lConn
,
_
:=
net
.
ListenUDP
(
"udp"
,
laddr
)
lConn
,
_
:=
net
.
ListenUDP
(
"udp"
,
laddr
)
lConn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
5
*
time
.
Second
))
lConn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
5
*
time
.
Second
))
sidBuf
:=
pool
.
GetBuf
(
1024
)
sidBuf
:=
pool
.
GetBuf
(
1024
)
...
@@ -298,7 +298,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
...
@@ -298,7 +298,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
sv
.
Debug
(
"join connections closed"
)
sv
.
Debug
(
"join connections closed"
)
}
}
func
(
sv
*
XtcpVistor
)
sendDetectMsg
(
addr
string
,
port
int64
,
laddr
*
net
.
UDPAddr
,
content
[]
byte
)
(
err
error
)
{
func
(
sv
*
XtcpVis
i
tor
)
sendDetectMsg
(
addr
string
,
port
int64
,
laddr
*
net
.
UDPAddr
,
content
[]
byte
)
(
err
error
)
{
daddr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
fmt
.
Sprintf
(
"%s:%d"
,
addr
,
port
))
daddr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
fmt
.
Sprintf
(
"%s:%d"
,
addr
,
port
))
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
cmd/frpc/main.go
浏览文件 @
bd1e9a30
...
@@ -156,7 +156,7 @@ func main() {
...
@@ -156,7 +156,7 @@ func main() {
}
}
}
}
pxyCfgs
,
vistorCfgs
,
err
:=
config
.
LoadProxyConfFromFile
(
config
.
ClientCommonCfg
.
User
,
conf
,
config
.
ClientCommonCfg
.
Start
)
pxyCfgs
,
vis
i
torCfgs
,
err
:=
config
.
LoadProxyConfFromFile
(
config
.
ClientCommonCfg
.
User
,
conf
,
config
.
ClientCommonCfg
.
Start
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
...
@@ -165,7 +165,7 @@ func main() {
...
@@ -165,7 +165,7 @@ func main() {
log
.
InitLog
(
config
.
ClientCommonCfg
.
LogWay
,
config
.
ClientCommonCfg
.
LogFile
,
log
.
InitLog
(
config
.
ClientCommonCfg
.
LogWay
,
config
.
ClientCommonCfg
.
LogFile
,
config
.
ClientCommonCfg
.
LogLevel
,
config
.
ClientCommonCfg
.
LogMaxDays
)
config
.
ClientCommonCfg
.
LogLevel
,
config
.
ClientCommonCfg
.
LogMaxDays
)
svr
:=
client
.
NewService
(
pxyCfgs
,
vistorCfgs
)
svr
:=
client
.
NewService
(
pxyCfgs
,
vis
i
torCfgs
)
// Capture the exit signal if we use kcp.
// Capture the exit signal if we use kcp.
if
config
.
ClientCommonCfg
.
Protocol
==
"kcp"
{
if
config
.
ClientCommonCfg
.
Protocol
==
"kcp"
{
...
...
conf/frpc_full.ini
浏览文件 @
bd1e9a30
...
@@ -119,24 +119,24 @@ plugin_http_passwd = abc
...
@@ -119,24 +119,24 @@ plugin_http_passwd = abc
[secret_tcp]
[secret_tcp]
# If the type is secret tcp, remote_port is useless
# If the type is secret tcp, remote_port is useless
# Who want to connect local port should deploy another frpc with stcp proxy and role is vistor
# Who want to connect local port should deploy another frpc with stcp proxy and role is vis
i
tor
type
=
stcp
type
=
stcp
# sk used for authentication for vistors
# sk used for authentication for vis
i
tors
sk
=
abcdefg
sk
=
abcdefg
local_ip
=
127.0.0.1
local_ip
=
127.0.0.1
local_port
=
22
local_port
=
22
use_encryption
=
false
use_encryption
=
false
use_compression
=
false
use_compression
=
false
# user of frpc should be same in both stcp server and stcp vistor
# user of frpc should be same in both stcp server and stcp vis
i
tor
[secret_tcp_vistor]
[secret_tcp_vis
i
tor]
# frpc role vistor -> frps -> frpc role server
# frpc role vis
i
tor -> frps -> frpc role server
role
=
vistor
role
=
vis
i
tor
type
=
stcp
type
=
stcp
# the server name you want to vistor
# the server name you want to vis
i
tor
server_name
=
secret_tcp
server_name
=
secret_tcp
sk
=
abcdefg
sk
=
abcdefg
# connect this address to vistor stcp server
# connect this address to vis
i
tor stcp server
bind_addr
=
127.0.0.1
bind_addr
=
127.0.0.1
bind_port
=
9000
bind_port
=
9000
use_encryption
=
false
use_encryption
=
false
...
@@ -150,8 +150,8 @@ local_port = 22
...
@@ -150,8 +150,8 @@ local_port = 22
use_encryption
=
false
use_encryption
=
false
use_compression
=
false
use_compression
=
false
[p2p_tcp_vistor]
[p2p_tcp_vis
i
tor]
role
=
vistor
role
=
vis
i
tor
type
=
xtcp
type
=
xtcp
server_name
=
p2p_tcp
server_name
=
p2p_tcp
sk
=
abcdefg
sk
=
abcdefg
...
...
models/config/proxy.go
浏览文件 @
bd1e9a30
...
@@ -595,7 +595,7 @@ type StcpProxyConf struct {
...
@@ -595,7 +595,7 @@ type StcpProxyConf struct {
LocalSvrConf
LocalSvrConf
PluginConf
PluginConf
// used in role vistor
// used in role vis
i
tor
ServerName
string
`json:"server_name"`
ServerName
string
`json:"server_name"`
BindAddr
string
`json:"bind_addr"`
BindAddr
string
`json:"bind_addr"`
BindPort
int
`json:"bind_port"`
BindPort
int
`json:"bind_port"`
...
@@ -632,7 +632,7 @@ func (cfg *StcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
...
@@ -632,7 +632,7 @@ func (cfg *StcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
}
}
tmpStr
:=
section
[
"role"
]
tmpStr
:=
section
[
"role"
]
if
tmpStr
==
"server"
||
tmpStr
==
"vistor"
{
if
tmpStr
==
"server"
||
tmpStr
==
"vis
i
tor"
{
cfg
.
Role
=
tmpStr
cfg
.
Role
=
tmpStr
}
else
{
}
else
{
cfg
.
Role
=
"server"
cfg
.
Role
=
"server"
...
@@ -640,7 +640,7 @@ func (cfg *StcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
...
@@ -640,7 +640,7 @@ func (cfg *StcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
cfg
.
Sk
=
section
[
"sk"
]
cfg
.
Sk
=
section
[
"sk"
]
if
tmpStr
==
"vistor"
{
if
tmpStr
==
"vis
i
tor"
{
prefix
:=
section
[
"prefix"
]
prefix
:=
section
[
"prefix"
]
cfg
.
ServerName
=
prefix
+
section
[
"server_name"
]
cfg
.
ServerName
=
prefix
+
section
[
"server_name"
]
if
cfg
.
BindAddr
=
section
[
"bind_addr"
];
cfg
.
BindAddr
==
""
{
if
cfg
.
BindAddr
=
section
[
"bind_addr"
];
cfg
.
BindAddr
==
""
{
...
@@ -684,7 +684,7 @@ type XtcpProxyConf struct {
...
@@ -684,7 +684,7 @@ type XtcpProxyConf struct {
LocalSvrConf
LocalSvrConf
PluginConf
PluginConf
// used in role vistor
// used in role vis
i
tor
ServerName
string
`json:"server_name"`
ServerName
string
`json:"server_name"`
BindAddr
string
`json:"bind_addr"`
BindAddr
string
`json:"bind_addr"`
BindPort
int
`json:"bind_port"`
BindPort
int
`json:"bind_port"`
...
@@ -721,7 +721,7 @@ func (cfg *XtcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
...
@@ -721,7 +721,7 @@ func (cfg *XtcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
}
}
tmpStr
:=
section
[
"role"
]
tmpStr
:=
section
[
"role"
]
if
tmpStr
==
"server"
||
tmpStr
==
"vistor"
{
if
tmpStr
==
"server"
||
tmpStr
==
"vis
i
tor"
{
cfg
.
Role
=
tmpStr
cfg
.
Role
=
tmpStr
}
else
{
}
else
{
cfg
.
Role
=
"server"
cfg
.
Role
=
"server"
...
@@ -729,7 +729,7 @@ func (cfg *XtcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
...
@@ -729,7 +729,7 @@ func (cfg *XtcpProxyConf) LoadFromFile(name string, section ini.Section) (err er
cfg
.
Sk
=
section
[
"sk"
]
cfg
.
Sk
=
section
[
"sk"
]
if
tmpStr
==
"vistor"
{
if
tmpStr
==
"vis
i
tor"
{
prefix
:=
section
[
"prefix"
]
prefix
:=
section
[
"prefix"
]
cfg
.
ServerName
=
prefix
+
section
[
"server_name"
]
cfg
.
ServerName
=
prefix
+
section
[
"server_name"
]
if
cfg
.
BindAddr
=
section
[
"bind_addr"
];
cfg
.
BindAddr
==
""
{
if
cfg
.
BindAddr
=
section
[
"bind_addr"
];
cfg
.
BindAddr
==
""
{
...
@@ -765,7 +765,7 @@ func (cfg *XtcpProxyConf) Check() (err error) {
...
@@ -765,7 +765,7 @@ func (cfg *XtcpProxyConf) Check() (err error) {
// if len(startProxy) is 0, start all
// if len(startProxy) is 0, start all
// otherwise just start proxies in startProxy map
// otherwise just start proxies in startProxy map
func
LoadProxyConfFromFile
(
prefix
string
,
conf
ini
.
File
,
startProxy
map
[
string
]
struct
{})
(
func
LoadProxyConfFromFile
(
prefix
string
,
conf
ini
.
File
,
startProxy
map
[
string
]
struct
{})
(
proxyConfs
map
[
string
]
ProxyConf
,
vistorConfs
map
[
string
]
ProxyConf
,
err
error
)
{
proxyConfs
map
[
string
]
ProxyConf
,
vis
i
torConfs
map
[
string
]
ProxyConf
,
err
error
)
{
if
prefix
!=
""
{
if
prefix
!=
""
{
prefix
+=
"."
prefix
+=
"."
...
@@ -776,7 +776,7 @@ func LoadProxyConfFromFile(prefix string, conf ini.File, startProxy map[string]s
...
@@ -776,7 +776,7 @@ func LoadProxyConfFromFile(prefix string, conf ini.File, startProxy map[string]s
startAll
=
false
startAll
=
false
}
}
proxyConfs
=
make
(
map
[
string
]
ProxyConf
)
proxyConfs
=
make
(
map
[
string
]
ProxyConf
)
vistorConfs
=
make
(
map
[
string
]
ProxyConf
)
vis
i
torConfs
=
make
(
map
[
string
]
ProxyConf
)
for
name
,
section
:=
range
conf
{
for
name
,
section
:=
range
conf
{
_
,
shouldStart
:=
startProxy
[
name
]
_
,
shouldStart
:=
startProxy
[
name
]
if
name
!=
"common"
&&
(
startAll
||
shouldStart
)
{
if
name
!=
"common"
&&
(
startAll
||
shouldStart
)
{
...
@@ -784,12 +784,12 @@ func LoadProxyConfFromFile(prefix string, conf ini.File, startProxy map[string]s
...
@@ -784,12 +784,12 @@ func LoadProxyConfFromFile(prefix string, conf ini.File, startProxy map[string]s
section
[
"prefix"
]
=
prefix
section
[
"prefix"
]
=
prefix
cfg
,
err
:=
NewProxyConfFromFile
(
name
,
section
)
cfg
,
err
:=
NewProxyConfFromFile
(
name
,
section
)
if
err
!=
nil
{
if
err
!=
nil
{
return
proxyConfs
,
vistorConfs
,
err
return
proxyConfs
,
vis
i
torConfs
,
err
}
}
role
:=
section
[
"role"
]
role
:=
section
[
"role"
]
if
role
==
"vistor"
{
if
role
==
"vis
i
tor"
{
vistorConfs
[
prefix
+
name
]
=
cfg
vis
i
torConfs
[
prefix
+
name
]
=
cfg
}
else
{
}
else
{
proxyConfs
[
prefix
+
name
]
=
cfg
proxyConfs
[
prefix
+
name
]
=
cfg
}
}
...
...
models/msg/msg.go
浏览文件 @
bd1e9a30
...
@@ -20,23 +20,23 @@ import (
...
@@ -20,23 +20,23 @@ import (
)
)
const
(
const
(
TypeLogin
=
'o'
TypeLogin
=
'o'
TypeLoginResp
=
'1'
TypeLoginResp
=
'1'
TypeNewProxy
=
'p'
TypeNewProxy
=
'p'
TypeNewProxyResp
=
'2'
TypeNewProxyResp
=
'2'
TypeCloseProxy
=
'c'
TypeCloseProxy
=
'c'
TypeNewWorkConn
=
'w'
TypeNewWorkConn
=
'w'
TypeReqWorkConn
=
'r'
TypeReqWorkConn
=
'r'
TypeStartWorkConn
=
's'
TypeStartWorkConn
=
's'
TypeNewVistorConn
=
'v'
TypeNewVis
i
torConn
=
'v'
TypeNewVistorConnResp
=
'3'
TypeNewVis
i
torConnResp
=
'3'
TypePing
=
'h'
TypePing
=
'h'
TypePong
=
'4'
TypePong
=
'4'
TypeUdpPacket
=
'u'
TypeUdpPacket
=
'u'
TypeNatHoleVistor
=
'i'
TypeNatHoleVis
i
tor
=
'i'
TypeNatHoleClient
=
'n'
TypeNatHoleClient
=
'n'
TypeNatHoleResp
=
'm'
TypeNatHoleResp
=
'm'
TypeNatHoleSid
=
'5'
TypeNatHoleSid
=
'5'
)
)
var
(
var
(
...
@@ -56,12 +56,12 @@ func init() {
...
@@ -56,12 +56,12 @@ func init() {
TypeMap
[
TypeNewWorkConn
]
=
reflect
.
TypeOf
(
NewWorkConn
{})
TypeMap
[
TypeNewWorkConn
]
=
reflect
.
TypeOf
(
NewWorkConn
{})
TypeMap
[
TypeReqWorkConn
]
=
reflect
.
TypeOf
(
ReqWorkConn
{})
TypeMap
[
TypeReqWorkConn
]
=
reflect
.
TypeOf
(
ReqWorkConn
{})
TypeMap
[
TypeStartWorkConn
]
=
reflect
.
TypeOf
(
StartWorkConn
{})
TypeMap
[
TypeStartWorkConn
]
=
reflect
.
TypeOf
(
StartWorkConn
{})
TypeMap
[
TypeNewVis
torConn
]
=
reflect
.
TypeOf
(
NewVis
torConn
{})
TypeMap
[
TypeNewVis
itorConn
]
=
reflect
.
TypeOf
(
NewVisi
torConn
{})
TypeMap
[
TypeNewVis
torConnResp
]
=
reflect
.
TypeOf
(
NewVis
torConnResp
{})
TypeMap
[
TypeNewVis
itorConnResp
]
=
reflect
.
TypeOf
(
NewVisi
torConnResp
{})
TypeMap
[
TypePing
]
=
reflect
.
TypeOf
(
Ping
{})
TypeMap
[
TypePing
]
=
reflect
.
TypeOf
(
Ping
{})
TypeMap
[
TypePong
]
=
reflect
.
TypeOf
(
Pong
{})
TypeMap
[
TypePong
]
=
reflect
.
TypeOf
(
Pong
{})
TypeMap
[
TypeUdpPacket
]
=
reflect
.
TypeOf
(
UdpPacket
{})
TypeMap
[
TypeUdpPacket
]
=
reflect
.
TypeOf
(
UdpPacket
{})
TypeMap
[
TypeNatHoleVis
tor
]
=
reflect
.
TypeOf
(
NatHoleVis
tor
{})
TypeMap
[
TypeNatHoleVis
itor
]
=
reflect
.
TypeOf
(
NatHoleVisi
tor
{})
TypeMap
[
TypeNatHoleClient
]
=
reflect
.
TypeOf
(
NatHoleClient
{})
TypeMap
[
TypeNatHoleClient
]
=
reflect
.
TypeOf
(
NatHoleClient
{})
TypeMap
[
TypeNatHoleResp
]
=
reflect
.
TypeOf
(
NatHoleResp
{})
TypeMap
[
TypeNatHoleResp
]
=
reflect
.
TypeOf
(
NatHoleResp
{})
TypeMap
[
TypeNatHoleSid
]
=
reflect
.
TypeOf
(
NatHoleSid
{})
TypeMap
[
TypeNatHoleSid
]
=
reflect
.
TypeOf
(
NatHoleSid
{})
...
@@ -138,7 +138,7 @@ type StartWorkConn struct {
...
@@ -138,7 +138,7 @@ type StartWorkConn struct {
ProxyName
string
`json:"proxy_name"`
ProxyName
string
`json:"proxy_name"`
}
}
type
NewVistorConn
struct
{
type
NewVis
i
torConn
struct
{
ProxyName
string
`json:"proxy_name"`
ProxyName
string
`json:"proxy_name"`
SignKey
string
`json:"sign_key"`
SignKey
string
`json:"sign_key"`
Timestamp
int64
`json:"timestamp"`
Timestamp
int64
`json:"timestamp"`
...
@@ -146,7 +146,7 @@ type NewVistorConn struct {
...
@@ -146,7 +146,7 @@ type NewVistorConn struct {
UseCompression
bool
`json:"use_compression"`
UseCompression
bool
`json:"use_compression"`
}
}
type
NewVistorConnResp
struct
{
type
NewVis
i
torConnResp
struct
{
ProxyName
string
`json:"proxy_name"`
ProxyName
string
`json:"proxy_name"`
Error
string
`json:"error"`
Error
string
`json:"error"`
}
}
...
@@ -163,7 +163,7 @@ type UdpPacket struct {
...
@@ -163,7 +163,7 @@ type UdpPacket struct {
RemoteAddr
*
net
.
UDPAddr
`json:"r"`
RemoteAddr
*
net
.
UDPAddr
`json:"r"`
}
}
type
NatHoleVistor
struct
{
type
NatHoleVis
i
tor
struct
{
ProxyName
string
`json:"proxy_name"`
ProxyName
string
`json:"proxy_name"`
SignKey
string
`json:"sign_key"`
SignKey
string
`json:"sign_key"`
Timestamp
int64
`json:"timestamp"`
Timestamp
int64
`json:"timestamp"`
...
@@ -175,9 +175,9 @@ type NatHoleClient struct {
...
@@ -175,9 +175,9 @@ type NatHoleClient struct {
}
}
type
NatHoleResp
struct
{
type
NatHoleResp
struct
{
Sid
string
`json:"sid"`
Sid
string
`json:"sid"`
Vis
torAddr
string
`json:"vis
tor_addr"`
Vis
itorAddr
string
`json:"visi
tor_addr"`
ClientAddr
string
`json:"client_addr"`
ClientAddr
string
`json:"client_addr"`
}
}
type
NatHoleSid
struct
{
type
NatHoleSid
struct
{
...
...
server/manager.go
浏览文件 @
bd1e9a30
...
@@ -93,46 +93,46 @@ func (pm *ProxyManager) GetByName(name string) (pxy Proxy, ok bool) {
...
@@ -93,46 +93,46 @@ func (pm *ProxyManager) GetByName(name string) (pxy Proxy, ok bool) {
return
return
}
}
// Manager for vistor listeners.
// Manager for vis
i
tor listeners.
type
VistorManager
struct
{
type
Vis
i
torManager
struct
{
vistorListeners
map
[
string
]
*
frpNet
.
CustomListener
vis
i
torListeners
map
[
string
]
*
frpNet
.
CustomListener
skMap
map
[
string
]
string
skMap
map
[
string
]
string
mu
sync
.
RWMutex
mu
sync
.
RWMutex
}
}
func
NewVis
torManager
()
*
Vis
torManager
{
func
NewVis
itorManager
()
*
Visi
torManager
{
return
&
VistorManager
{
return
&
Vis
i
torManager
{
vistorListeners
:
make
(
map
[
string
]
*
frpNet
.
CustomListener
),
vis
i
torListeners
:
make
(
map
[
string
]
*
frpNet
.
CustomListener
),
skMap
:
make
(
map
[
string
]
string
),
skMap
:
make
(
map
[
string
]
string
),
}
}
}
}
func
(
vm
*
VistorManager
)
Listen
(
name
string
,
sk
string
)
(
l
*
frpNet
.
CustomListener
,
err
error
)
{
func
(
vm
*
Vis
i
torManager
)
Listen
(
name
string
,
sk
string
)
(
l
*
frpNet
.
CustomListener
,
err
error
)
{
vm
.
mu
.
Lock
()
vm
.
mu
.
Lock
()
defer
vm
.
mu
.
Unlock
()
defer
vm
.
mu
.
Unlock
()
if
_
,
ok
:=
vm
.
vistorListeners
[
name
];
ok
{
if
_
,
ok
:=
vm
.
vis
i
torListeners
[
name
];
ok
{
err
=
fmt
.
Errorf
(
"custom listener for [%s] is repeated"
,
name
)
err
=
fmt
.
Errorf
(
"custom listener for [%s] is repeated"
,
name
)
return
return
}
}
l
=
frpNet
.
NewCustomListener
()
l
=
frpNet
.
NewCustomListener
()
vm
.
vistorListeners
[
name
]
=
l
vm
.
vis
i
torListeners
[
name
]
=
l
vm
.
skMap
[
name
]
=
sk
vm
.
skMap
[
name
]
=
sk
return
return
}
}
func
(
vm
*
VistorManager
)
NewConn
(
name
string
,
conn
frpNet
.
Conn
,
timestamp
int64
,
signKey
string
,
func
(
vm
*
Vis
i
torManager
)
NewConn
(
name
string
,
conn
frpNet
.
Conn
,
timestamp
int64
,
signKey
string
,
useEncryption
bool
,
useCompression
bool
)
(
err
error
)
{
useEncryption
bool
,
useCompression
bool
)
(
err
error
)
{
vm
.
mu
.
RLock
()
vm
.
mu
.
RLock
()
defer
vm
.
mu
.
RUnlock
()
defer
vm
.
mu
.
RUnlock
()
if
l
,
ok
:=
vm
.
vistorListeners
[
name
];
ok
{
if
l
,
ok
:=
vm
.
vis
i
torListeners
[
name
];
ok
{
var
sk
string
var
sk
string
if
sk
=
vm
.
skMap
[
name
];
util
.
GetAuthKey
(
sk
,
timestamp
)
!=
signKey
{
if
sk
=
vm
.
skMap
[
name
];
util
.
GetAuthKey
(
sk
,
timestamp
)
!=
signKey
{
err
=
fmt
.
Errorf
(
"vistor connection of [%s] auth failed"
,
name
)
err
=
fmt
.
Errorf
(
"vis
i
tor connection of [%s] auth failed"
,
name
)
return
return
}
}
...
@@ -154,10 +154,10 @@ func (vm *VistorManager) NewConn(name string, conn frpNet.Conn, timestamp int64,
...
@@ -154,10 +154,10 @@ func (vm *VistorManager) NewConn(name string, conn frpNet.Conn, timestamp int64,
return
return
}
}
func
(
vm
*
VistorManager
)
CloseListener
(
name
string
)
{
func
(
vm
*
Vis
i
torManager
)
CloseListener
(
name
string
)
{
vm
.
mu
.
Lock
()
vm
.
mu
.
Lock
()
defer
vm
.
mu
.
Unlock
()
defer
vm
.
mu
.
Unlock
()
delete
(
vm
.
vistorListeners
,
name
)
delete
(
vm
.
vis
i
torListeners
,
name
)
delete
(
vm
.
skMap
,
name
)
delete
(
vm
.
skMap
,
name
)
}
}
server/nathole.go
浏览文件 @
bd1e9a30
...
@@ -78,8 +78,8 @@ func (nc *NatHoleController) Run() {
...
@@ -78,8 +78,8 @@ func (nc *NatHoleController) Run() {
}
}
switch
m
:=
rawMsg
.
(
type
)
{
switch
m
:=
rawMsg
.
(
type
)
{
case
*
msg
.
NatHoleVistor
:
case
*
msg
.
NatHoleVis
i
tor
:
go
nc
.
HandleVistor
(
m
,
raddr
)
go
nc
.
HandleVis
i
tor
(
m
,
raddr
)
case
*
msg
.
NatHoleClient
:
case
*
msg
.
NatHoleClient
:
go
nc
.
HandleClient
(
m
,
raddr
)
go
nc
.
HandleClient
(
m
,
raddr
)
default
:
default
:
...
@@ -96,12 +96,12 @@ func (nc *NatHoleController) GenSid() string {
...
@@ -96,12 +96,12 @@ func (nc *NatHoleController) GenSid() string {
return
fmt
.
Sprintf
(
"%d%s"
,
t
,
id
)
return
fmt
.
Sprintf
(
"%d%s"
,
t
,
id
)
}
}
func
(
nc
*
NatHoleController
)
HandleVis
tor
(
m
*
msg
.
NatHoleVis
tor
,
raddr
*
net
.
UDPAddr
)
{
func
(
nc
*
NatHoleController
)
HandleVis
itor
(
m
*
msg
.
NatHoleVisi
tor
,
raddr
*
net
.
UDPAddr
)
{
sid
:=
nc
.
GenSid
()
sid
:=
nc
.
GenSid
()
session
:=
&
NatHoleSession
{
session
:=
&
NatHoleSession
{
Sid
:
sid
,
Sid
:
sid
,
VistorAddr
:
raddr
,
Vis
i
torAddr
:
raddr
,
NotifyCh
:
make
(
chan
struct
{},
0
),
NotifyCh
:
make
(
chan
struct
{},
0
),
}
}
nc
.
mu
.
Lock
()
nc
.
mu
.
Lock
()
clientCfg
,
ok
:=
nc
.
clientCfgs
[
m
.
ProxyName
]
clientCfg
,
ok
:=
nc
.
clientCfgs
[
m
.
ProxyName
]
...
@@ -111,7 +111,7 @@ func (nc *NatHoleController) HandleVistor(m *msg.NatHoleVistor, raddr *net.UDPAd
...
@@ -111,7 +111,7 @@ func (nc *NatHoleController) HandleVistor(m *msg.NatHoleVistor, raddr *net.UDPAd
}
}
nc
.
sessions
[
sid
]
=
session
nc
.
sessions
[
sid
]
=
session
nc
.
mu
.
Unlock
()
nc
.
mu
.
Unlock
()
log
.
Trace
(
"handle vistor message, sid [%s]"
,
sid
)
log
.
Trace
(
"handle vis
i
tor message, sid [%s]"
,
sid
)
defer
func
()
{
defer
func
()
{
nc
.
mu
.
Lock
()
nc
.
mu
.
Lock
()
...
@@ -130,7 +130,7 @@ func (nc *NatHoleController) HandleVistor(m *msg.NatHoleVistor, raddr *net.UDPAd
...
@@ -130,7 +130,7 @@ func (nc *NatHoleController) HandleVistor(m *msg.NatHoleVistor, raddr *net.UDPAd
select
{
select
{
case
<-
session
.
NotifyCh
:
case
<-
session
.
NotifyCh
:
resp
:=
nc
.
GenNatHoleResponse
(
raddr
,
session
)
resp
:=
nc
.
GenNatHoleResponse
(
raddr
,
session
)
log
.
Trace
(
"send nat hole response to vistor"
)
log
.
Trace
(
"send nat hole response to vis
i
tor"
)
nc
.
listener
.
WriteToUDP
(
resp
,
raddr
)
nc
.
listener
.
WriteToUDP
(
resp
,
raddr
)
case
<-
time
.
After
(
time
.
Duration
(
NatHoleTimeout
)
*
time
.
Second
)
:
case
<-
time
.
After
(
time
.
Duration
(
NatHoleTimeout
)
*
time
.
Second
)
:
return
return
...
@@ -155,9 +155,9 @@ func (nc *NatHoleController) HandleClient(m *msg.NatHoleClient, raddr *net.UDPAd
...
@@ -155,9 +155,9 @@ func (nc *NatHoleController) HandleClient(m *msg.NatHoleClient, raddr *net.UDPAd
func
(
nc
*
NatHoleController
)
GenNatHoleResponse
(
raddr
*
net
.
UDPAddr
,
session
*
NatHoleSession
)
[]
byte
{
func
(
nc
*
NatHoleController
)
GenNatHoleResponse
(
raddr
*
net
.
UDPAddr
,
session
*
NatHoleSession
)
[]
byte
{
m
:=
&
msg
.
NatHoleResp
{
m
:=
&
msg
.
NatHoleResp
{
Sid
:
session
.
Sid
,
Sid
:
session
.
Sid
,
Vis
torAddr
:
session
.
Vis
torAddr
.
String
(),
Vis
itorAddr
:
session
.
Visi
torAddr
.
String
(),
ClientAddr
:
session
.
ClientAddr
.
String
(),
ClientAddr
:
session
.
ClientAddr
.
String
(),
}
}
b
:=
bytes
.
NewBuffer
(
nil
)
b
:=
bytes
.
NewBuffer
(
nil
)
err
:=
msg
.
WriteMsg
(
b
,
m
)
err
:=
msg
.
WriteMsg
(
b
,
m
)
...
@@ -168,9 +168,9 @@ func (nc *NatHoleController) GenNatHoleResponse(raddr *net.UDPAddr, session *Nat
...
@@ -168,9 +168,9 @@ func (nc *NatHoleController) GenNatHoleResponse(raddr *net.UDPAddr, session *Nat
}
}
type
NatHoleSession
struct
{
type
NatHoleSession
struct
{
Sid
string
Sid
string
VistorAddr
*
net
.
UDPAddr
Vis
i
torAddr
*
net
.
UDPAddr
ClientAddr
*
net
.
UDPAddr
ClientAddr
*
net
.
UDPAddr
NotifyCh
chan
struct
{}
NotifyCh
chan
struct
{}
}
}
...
...
server/proxy.go
浏览文件 @
bd1e9a30
...
@@ -290,7 +290,7 @@ type StcpProxy struct {
...
@@ -290,7 +290,7 @@ type StcpProxy struct {
}
}
func
(
pxy
*
StcpProxy
)
Run
()
error
{
func
(
pxy
*
StcpProxy
)
Run
()
error
{
listener
,
err
:=
pxy
.
ctl
.
svr
.
vistorManager
.
Listen
(
pxy
.
GetName
(),
pxy
.
cfg
.
Sk
)
listener
,
err
:=
pxy
.
ctl
.
svr
.
vis
i
torManager
.
Listen
(
pxy
.
GetName
(),
pxy
.
cfg
.
Sk
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -308,7 +308,7 @@ func (pxy *StcpProxy) GetConf() config.ProxyConf {
...
@@ -308,7 +308,7 @@ func (pxy *StcpProxy) GetConf() config.ProxyConf {
func
(
pxy
*
StcpProxy
)
Close
()
{
func
(
pxy
*
StcpProxy
)
Close
()
{
pxy
.
BaseProxy
.
Close
()
pxy
.
BaseProxy
.
Close
()
pxy
.
ctl
.
svr
.
vistorManager
.
CloseListener
(
pxy
.
GetName
())
pxy
.
ctl
.
svr
.
vis
i
torManager
.
CloseListener
(
pxy
.
GetName
())
}
}
type
XtcpProxy
struct
{
type
XtcpProxy
struct
{
...
...
server/service.go
浏览文件 @
bd1e9a30
...
@@ -56,8 +56,8 @@ type Service struct {
...
@@ -56,8 +56,8 @@ type Service struct {
// Manage all proxies.
// Manage all proxies.
pxyManager
*
ProxyManager
pxyManager
*
ProxyManager
// Manage all vistor listeners.
// Manage all vis
i
tor listeners.
vis
torManager
*
Vis
torManager
vis
itorManager
*
Visi
torManager
// Controller for nat hole connections.
// Controller for nat hole connections.
natHoleController
*
NatHoleController
natHoleController
*
NatHoleController
...
@@ -65,9 +65,9 @@ type Service struct {
...
@@ -65,9 +65,9 @@ type Service struct {
func
NewService
()
(
svr
*
Service
,
err
error
)
{
func
NewService
()
(
svr
*
Service
,
err
error
)
{
svr
=
&
Service
{
svr
=
&
Service
{
ctlManager
:
NewControlManager
(),
ctlManager
:
NewControlManager
(),
pxyManager
:
NewProxyManager
(),
pxyManager
:
NewProxyManager
(),
vis
torManager
:
NewVis
torManager
(),
vis
itorManager
:
NewVisi
torManager
(),
}
}
cfg
:=
config
.
ServerCommonCfg
cfg
:=
config
.
ServerCommonCfg
...
@@ -200,16 +200,16 @@ func (svr *Service) HandleListener(l frpNet.Listener) {
...
@@ -200,16 +200,16 @@ func (svr *Service) HandleListener(l frpNet.Listener) {
}
}
case
*
msg
.
NewWorkConn
:
case
*
msg
.
NewWorkConn
:
svr
.
RegisterWorkConn
(
conn
,
m
)
svr
.
RegisterWorkConn
(
conn
,
m
)
case
*
msg
.
NewVistorConn
:
case
*
msg
.
NewVis
i
torConn
:
if
err
=
svr
.
RegisterVistorConn
(
conn
,
m
);
err
!=
nil
{
if
err
=
svr
.
RegisterVis
i
torConn
(
conn
,
m
);
err
!=
nil
{
conn
.
Warn
(
"%v"
,
err
)
conn
.
Warn
(
"%v"
,
err
)
msg
.
WriteMsg
(
conn
,
&
msg
.
NewVistorConnResp
{
msg
.
WriteMsg
(
conn
,
&
msg
.
NewVis
i
torConnResp
{
ProxyName
:
m
.
ProxyName
,
ProxyName
:
m
.
ProxyName
,
Error
:
err
.
Error
(),
Error
:
err
.
Error
(),
})
})
conn
.
Close
()
conn
.
Close
()
}
else
{
}
else
{
msg
.
WriteMsg
(
conn
,
&
msg
.
NewVistorConnResp
{
msg
.
WriteMsg
(
conn
,
&
msg
.
NewVis
i
torConnResp
{
ProxyName
:
m
.
ProxyName
,
ProxyName
:
m
.
ProxyName
,
Error
:
""
,
Error
:
""
,
})
})
...
@@ -300,8 +300,8 @@ func (svr *Service) RegisterWorkConn(workConn frpNet.Conn, newMsg *msg.NewWorkCo
...
@@ -300,8 +300,8 @@ func (svr *Service) RegisterWorkConn(workConn frpNet.Conn, newMsg *msg.NewWorkCo
return
return
}
}
func
(
svr
*
Service
)
RegisterVis
torConn
(
vistorConn
frpNet
.
Conn
,
newMsg
*
msg
.
NewVis
torConn
)
error
{
func
(
svr
*
Service
)
RegisterVis
itorConn
(
visitorConn
frpNet
.
Conn
,
newMsg
*
msg
.
NewVisi
torConn
)
error
{
return
svr
.
vis
torManager
.
NewConn
(
newMsg
.
ProxyName
,
vis
torConn
,
newMsg
.
Timestamp
,
newMsg
.
SignKey
,
return
svr
.
vis
itorManager
.
NewConn
(
newMsg
.
ProxyName
,
visi
torConn
,
newMsg
.
Timestamp
,
newMsg
.
SignKey
,
newMsg
.
UseEncryption
,
newMsg
.
UseCompression
)
newMsg
.
UseEncryption
,
newMsg
.
UseCompression
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录