Skip to content

Commit 712afed

Browse files
authored
Merge pull request #344 from fatedier/dev
bump version to 0.11.0
2 parents 6d81e4c + e29a133 commit 712afed

37 files changed

+870
-205
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ sudo: false
22
language: go
33

44
go:
5-
- 1.7.5
6-
- 1.8
5+
- 1.8.x
76

87
install:
98
- make

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.6
1+
FROM golang:1.8
22

33
COPY . /go/src/github.com/fatedier/frp
44

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ alltest: gotest
4242
clean:
4343
rm -f ./bin/frpc
4444
rm -f ./bin/frps
45-
cd ./test && ./clean_test.sh && cd -
45+
cd ./tests && ./clean_test.sh && cd -
4646

4747
save:
4848
godep save ./...

assets/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?b52826060da73c6b5a10"></script><script type="text/javascript" src="vendor.js?66dfcf2d1c500e900413"></script><script type="text/javascript" src="index.js?ceb589f1be7a87112dbd"></script></body> </html>
1+
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?5217927b66cc446ebfd3"></script><script type="text/javascript" src="vendor.js?66dfcf2d1c500e900413"></script><script type="text/javascript" src="index.js?bf962cded96400bef9a0"></script></body> </html>

assets/static/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/static/manifest.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/statik/statik.go

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

client/control.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,20 @@ func NewControl(svr *Service, pxyCfgs map[string]config.ProxyConf) *Control {
106106
// 7. In controler(): start new reader(), writer(), manager()
107107
// controler() will keep running
108108
func (ctl *Control) Run() error {
109-
err := ctl.login()
110-
if err != nil {
111-
return err
109+
for {
110+
err := ctl.login()
111+
if err != nil {
112+
// if login_fail_exit is true, just exit this program
113+
// otherwise sleep a while and continues relogin to server
114+
if config.ClientCommonCfg.LoginFailExit {
115+
return err
116+
} else {
117+
ctl.Warn("login to server fail: %v", err)
118+
time.Sleep(30 * time.Second)
119+
}
120+
} else {
121+
break
122+
}
112123
}
113124

114125
go ctl.controler()
@@ -166,7 +177,7 @@ func (ctl *Control) NewWorkConn() {
166177

167178
// dispatch this work connection to related proxy
168179
if pxy, ok := ctl.proxies[startMsg.ProxyName]; ok {
169-
workConn.Info("start a new work connection, localAddr: %s remoteAddr: %s", workConn.LocalAddr().String(), workConn.RemoteAddr().String())
180+
workConn.Debug("start a new work connection, localAddr: %s remoteAddr: %s", workConn.LocalAddr().String(), workConn.RemoteAddr().String())
170181
go pxy.InWorkConn(workConn)
171182
} else {
172183
workConn.Close()

client/proxy.go

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/fatedier/frp/models/config"
2525
"github.com/fatedier/frp/models/msg"
26+
"github.com/fatedier/frp/models/plugin"
2627
"github.com/fatedier/frp/models/proto/tcp"
2728
"github.com/fatedier/frp/models/proto/udp"
2829
"github.com/fatedier/frp/utils/errors"
@@ -81,57 +82,84 @@ type BaseProxy struct {
8182
type TcpProxy struct {
8283
BaseProxy
8384

84-
cfg *config.TcpProxyConf
85+
cfg *config.TcpProxyConf
86+
proxyPlugin plugin.Plugin
8587
}
8688

8789
func (pxy *TcpProxy) Run() (err error) {
90+
if pxy.cfg.Plugin != "" {
91+
pxy.proxyPlugin, err = plugin.Create(pxy.cfg.Plugin, pxy.cfg.PluginParams)
92+
if err != nil {
93+
return
94+
}
95+
}
8896
return
8997
}
9098

9199
func (pxy *TcpProxy) Close() {
100+
if pxy.proxyPlugin != nil {
101+
pxy.proxyPlugin.Close()
102+
}
92103
}
93104

94105
func (pxy *TcpProxy) InWorkConn(conn frpNet.Conn) {
95-
defer conn.Close()
96-
HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, &pxy.cfg.BaseProxyConf, conn)
106+
HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn)
97107
}
98108

99109
// HTTP
100110
type HttpProxy struct {
101111
BaseProxy
102112

103-
cfg *config.HttpProxyConf
113+
cfg *config.HttpProxyConf
114+
proxyPlugin plugin.Plugin
104115
}
105116

106117
func (pxy *HttpProxy) Run() (err error) {
118+
if pxy.cfg.Plugin != "" {
119+
pxy.proxyPlugin, err = plugin.Create(pxy.cfg.Plugin, pxy.cfg.PluginParams)
120+
if err != nil {
121+
return
122+
}
123+
}
107124
return
108125
}
109126

110127
func (pxy *HttpProxy) Close() {
128+
if pxy.proxyPlugin != nil {
129+
pxy.proxyPlugin.Close()
130+
}
111131
}
112132

113133
func (pxy *HttpProxy) InWorkConn(conn frpNet.Conn) {
114-
defer conn.Close()
115-
HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, &pxy.cfg.BaseProxyConf, conn)
134+
HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn)
116135
}
117136

118137
// HTTPS
119138
type HttpsProxy struct {
120139
BaseProxy
121140

122-
cfg *config.HttpsProxyConf
141+
cfg *config.HttpsProxyConf
142+
proxyPlugin plugin.Plugin
123143
}
124144

125145
func (pxy *HttpsProxy) Run() (err error) {
146+
if pxy.cfg.Plugin != "" {
147+
pxy.proxyPlugin, err = plugin.Create(pxy.cfg.Plugin, pxy.cfg.PluginParams)
148+
if err != nil {
149+
return
150+
}
151+
}
126152
return
127153
}
128154

129155
func (pxy *HttpsProxy) Close() {
156+
if pxy.proxyPlugin != nil {
157+
pxy.proxyPlugin.Close()
158+
}
130159
}
131160

132161
func (pxy *HttpsProxy) InWorkConn(conn frpNet.Conn) {
133-
defer conn.Close()
134-
HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, &pxy.cfg.BaseProxyConf, conn)
162+
HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn)
135163
}
136164

137165
// UDP
@@ -240,14 +268,13 @@ func (pxy *UdpProxy) InWorkConn(conn frpNet.Conn) {
240268
}
241269

242270
// Common handler for tcp work connections.
243-
func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, baseInfo *config.BaseProxyConf, workConn frpNet.Conn) {
244-
localConn, err := frpNet.ConnectTcpServer(fmt.Sprintf("%s:%d", localInfo.LocalIp, localInfo.LocalPort))
245-
if err != nil {
246-
workConn.Error("connect to local service [%s:%d] error: %v", localInfo.LocalIp, localInfo.LocalPort, err)
247-
return
248-
}
271+
func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, proxyPlugin plugin.Plugin,
272+
baseInfo *config.BaseProxyConf, workConn frpNet.Conn) {
249273

250-
var remote io.ReadWriteCloser
274+
var (
275+
remote io.ReadWriteCloser
276+
err error
277+
)
251278
remote = workConn
252279
if baseInfo.UseEncryption {
253280
remote, err = tcp.WithEncryption(remote, []byte(config.ClientCommonCfg.PrivilegeToken))
@@ -259,8 +286,23 @@ func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, baseInfo *config.Ba
259286
if baseInfo.UseCompression {
260287
remote = tcp.WithCompression(remote)
261288
}
262-
workConn.Debug("join connections, localConn(l[%s] r[%s]) workConn(l[%s] r[%s])", localConn.LocalAddr().String(),
263-
localConn.RemoteAddr().String(), workConn.LocalAddr().String(), workConn.RemoteAddr().String())
264-
tcp.Join(localConn, remote)
265-
workConn.Debug("join connections closed")
289+
290+
if proxyPlugin != nil {
291+
// if plugin is set, let plugin handle connections first
292+
workConn.Debug("handle by plugin: %s", proxyPlugin.Name())
293+
proxyPlugin.Handle(remote)
294+
workConn.Debug("handle by plugin finished")
295+
return
296+
} else {
297+
localConn, err := frpNet.ConnectTcpServer(fmt.Sprintf("%s:%d", localInfo.LocalIp, localInfo.LocalPort))
298+
if err != nil {
299+
workConn.Error("connect to local service [%s:%d] error: %v", localInfo.LocalIp, localInfo.LocalPort, err)
300+
return
301+
}
302+
303+
workConn.Debug("join connections, localConn(l[%s] r[%s]) workConn(l[%s] r[%s])", localConn.LocalAddr().String(),
304+
localConn.RemoteAddr().String(), workConn.LocalAddr().String(), workConn.RemoteAddr().String())
305+
tcp.Join(localConn, remote)
306+
workConn.Debug("join connections closed")
307+
}
266308
}

cmd/frpc/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Options:
4646
--log-level=<log_level> set log level: debug, info, warn, error
4747
--server-addr=<server_addr> addr which frps is listening for, example: 0.0.0.0:7000
4848
-h --help show this screen
49-
--version show version
49+
-v --version show version
5050
`
5151

5252
func main() {
@@ -106,7 +106,7 @@ func main() {
106106
}
107107
}
108108

109-
pxyCfgs, err := config.LoadProxyConfFromFile(conf)
109+
pxyCfgs, err := config.LoadProxyConfFromFile(config.ClientCommonCfg.User, conf, config.ClientCommonCfg.Start)
110110
if err != nil {
111111
fmt.Println(err)
112112
os.Exit(1)

0 commit comments

Comments
 (0)