diff --git a/.travis.yml b/.travis.yml index 51c2421c4b806a749142debd63f24f93a58b71d0..ff656e79b8e259206023c3265dbc996a8dc2b7e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ sudo: false language: go go: - - 1.8.x - - 1.9.x + - 1.10.x install: - make diff --git a/Makefile b/Makefile index 63927f9b90084593962035067c4cc6dcf14ec961..b91b33487807809856605d59b365048d9bdd1a05 100644 --- a/Makefile +++ b/Makefile @@ -15,12 +15,7 @@ file: go generate ./assets/... fmt: - go fmt ./assets/... - go fmt ./client/... - go fmt ./cmd/... - go fmt ./models/... - go fmt ./server/... - go fmt ./utils/... + go fmt ./... frps: go build -o bin/frps ./cmd/frps diff --git a/Makefile.cross-compiles b/Makefile.cross-compiles index 086d8b692438141c77d58d2d63e25629b46949c5..c5dda4d457be0b12bcb1b9657c01f71a1d54ee47 100644 --- a/Makefile.cross-compiles +++ b/Makefile.cross-compiles @@ -9,6 +9,10 @@ build: app app: env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frpc_darwin_amd64 ./cmd/frpc env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frps_darwin_amd64 ./cmd/frps + env CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frpc_freebsd_386 ./cmd/frpc + env CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frps_freebsd_386 ./cmd/frps + env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frpc_freebsd_amd64 ./cmd/frpc + env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frps_freebsd_amd64 ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_386 ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_386 ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_amd64 ./cmd/frpc @@ -23,10 +27,10 @@ app: env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mips64 ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_mips64le ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mips64le ./cmd/frps - env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_mips ./cmd/frpc - env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mips ./cmd/frps - env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_mipsle ./cmd/frpc - env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mipsle ./cmd/frps + env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_mips ./cmd/frpc + env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mips ./cmd/frps + env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_mipsle ./cmd/frpc + env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mipsle ./cmd/frps temp: env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_amd64 ./cmd/frps diff --git a/cmd/frpc/main.go b/cmd/frpc/main.go index 51eb53ca66cf7be13f8c54739474da52b40d8fb4..845f4f744baaa3bb4e6694debbf2db019eb74b8e 100644 --- a/cmd/frpc/main.go +++ b/cmd/frpc/main.go @@ -86,7 +86,7 @@ func main() { if args["reload"] != nil { if args["reload"].(bool) { if err = CmdReload(); err != nil { - fmt.Printf("frps reload error: %v\n", err) + fmt.Printf("frpc reload error: %v\n", err) os.Exit(1) } else { fmt.Printf("reload success\n") diff --git a/conf/frpc_full.ini b/conf/frpc_full.ini index 1204b2662a9cce37d9fec0534ff97b95bb3b259c..4bec160b7cb1383ff2cd9085150c733156b79d7f 100644 --- a/conf/frpc_full.ini +++ b/conf/frpc_full.ini @@ -73,7 +73,7 @@ local_port = 22 # if remote_port is 0, frps will assgin a random port for you remote_port = 0 -# if you want tp expose multiple ports, add 'range:' prefix to the section name +# if you want to expose multiple ports, add 'range:' prefix to the section name # frpc will generate multiple proxies such as 'tcp_port_6010', 'tcp_port_6011' and so on. [range:tcp_port] type = tcp diff --git a/models/config/proxy.go b/models/config/proxy.go index b506c43572a3b06ba4565ad572d28fcdc871fd7f..49835c3f80e4bc046143e5fb5246ac3af2998363 100644 --- a/models/config/proxy.go +++ b/models/config/proxy.go @@ -788,7 +788,7 @@ func ParseRangeSection(name string, section ini.Section) (sections map[string]in return } if len(localPorts) == 0 { - err = fmt.Errorf("Parse conf error: range section [%s] local_port and remote_port is necessary") + err = fmt.Errorf("Parse conf error: range section [%s] local_port and remote_port is necessary", name) return } diff --git a/models/proto/udp/udp.go b/models/proto/udp/udp.go index fe548f1e106022ff8a4661d79aa7dfaf9a9a5de3..15ecb9c44d271f74ba81aa45741104c0f726674e 100644 --- a/models/proto/udp/udp.go +++ b/models/proto/udp/udp.go @@ -82,6 +82,7 @@ func Forwarder(dstAddr *net.UDPAddr, readCh <-chan *msg.UdpPacket, sendCh chan<- mu.Lock() delete(udpConnMap, addr) mu.Unlock() + udpConn.Close() }() buf := pool.GetBuf(1500) diff --git a/package.sh b/package.sh index a5c55f1e1f11706d2a6ef51919d6e6025374abb9..65d1446e76a25e6ea7bdf663adca6510f12ba369 100755 --- a/package.sh +++ b/package.sh @@ -14,7 +14,7 @@ make -f ./Makefile.cross-compiles rm -rf ./packages mkdir ./packages -os_all='linux windows darwin' +os_all='linux windows darwin freebsd' arch_all='386 amd64 arm mips64 mips64le mips mipsle' for os in $os_all; do diff --git a/server/control.go b/server/control.go index dbb99ad9e9fee2628c7bc8762e053037a944bd2b..d7938e7a36de2877d03ab113379732c7ac5323d4 100644 --- a/server/control.go +++ b/server/control.go @@ -265,13 +265,14 @@ func (ctl *Control) stoper() { ctl.conn.Close() ctl.readerShutdown.WaitDone() + ctl.mu.Lock() + defer ctl.mu.Unlock() + close(ctl.workConnCh) for workConn := range ctl.workConnCh { workConn.Close() } - ctl.mu.Lock() - defer ctl.mu.Unlock() for _, pxy := range ctl.proxies { pxy.Close() ctl.svr.DelProxy(pxy.GetName()) @@ -303,6 +304,7 @@ func (ctl *Control) manager() { if time.Since(ctl.lastPing) > time.Duration(config.ServerCommonCfg.HeartBeatTimeout)*time.Second { ctl.conn.Warn("heartbeat timeout") ctl.allShutdown.Start() + return } case rawMsg, ok := <-ctl.readCh: if !ok { diff --git a/utils/net/conn.go b/utils/net/conn.go index 78319cc7d87182a761b3c40abfb02266d4f36cfc..b18773312a1d5d75074dfacf963b35cbd9c2573e 100644 --- a/utils/net/conn.go +++ b/utils/net/conn.go @@ -21,6 +21,7 @@ import ( "io" "net" "sync" + "sync/atomic" "time" "github.com/fatedier/frp/utils/log" @@ -178,6 +179,7 @@ func (sc *SharedConn) WriteBuff(buffer []byte) (err error) { type StatsConn struct { Conn + closed int64 // 1 means closed totalRead int64 totalWrite int64 statsFunc func(totalRead, totalWrite int64) @@ -203,9 +205,12 @@ func (statsConn *StatsConn) Write(p []byte) (n int, err error) { } func (statsConn *StatsConn) Close() (err error) { - err = statsConn.Conn.Close() - if statsConn.statsFunc != nil { - statsConn.statsFunc(statsConn.totalRead, statsConn.totalWrite) + old := atomic.SwapInt64(&statsConn.closed, 1) + if old != 1 { + err = statsConn.Conn.Close() + if statsConn.statsFunc != nil { + statsConn.statsFunc(statsConn.totalRead, statsConn.totalWrite) + } } return } diff --git a/utils/version/version.go b/utils/version/version.go index 4a086114017719e11f7ce10cd534408c49957cc2..5c901e7d3d559799bca50b2d9f965c9786c6ef53 100644 --- a/utils/version/version.go +++ b/utils/version/version.go @@ -19,7 +19,7 @@ import ( "strings" ) -var version string = "0.16.0" +var version string = "0.16.1" func Full() string { return version diff --git a/utils/vhost/https.go b/utils/vhost/https.go index a1a064596afb085bea8e6524171077d3894cd255..a6ef55db6e0462e27d0b13ded4a4af7cf8e5ab4b 100644 --- a/utils/vhost/https.go +++ b/utils/vhost/https.go @@ -108,7 +108,7 @@ func readHandshake(rd io.Reader) (host string, err error) { return } if len(data) < 2 { - err = fmt.Errorf("readHandshake: extension dataLen[%d] is too short") + err = fmt.Errorf("readHandshake: extension dataLen[%d] is too short", len(data)) return }