From d5913fc77b562d111d4d1338291b3214df4d61a1 Mon Sep 17 00:00:00 2001 From: fatedier Date: Thu, 7 Apr 2016 19:27:39 +0800 Subject: [PATCH 1/5] all: fix bug when reconnecting --- src/frp/cmd/frpc/control.go | 6 +++++- src/frp/cmd/frps/control.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/frp/cmd/frpc/control.go b/src/frp/cmd/frpc/control.go index 06a4fdae..d1f4fdbf 100644 --- a/src/frp/cmd/frpc/control.go +++ b/src/frp/cmd/frpc/control.go @@ -72,7 +72,10 @@ func msgReader(cli *client.ProxyClient, c *conn.Conn, msgSendChan chan interface log.Info("ProxyName [%s], try to reconnect to frps [%s:%d]...", cli.Name, client.ServerAddr, client.ServerPort) c, err = loginToServer(cli) if err == nil { + close(msgSendChan) + msgSendChan = make(chan interface{}, 1024) go heartbeatSender(c, msgSendChan) + go msgSender(cli, c, msgSendChan) break } @@ -81,6 +84,7 @@ func msgReader(cli *client.ProxyClient, c *conn.Conn, msgSendChan chan interface } time.Sleep(delayTime * time.Second) } + continue } else if err != nil { log.Warn("ProxyName [%s], read from frps error: %v", cli.Name, err) continue @@ -117,7 +121,7 @@ func msgSender(cli *client.ProxyClient, c *conn.Conn, msgSendChan chan interface buf, _ := json.Marshal(msg) err := c.Write(string(buf) + "\n") if err != nil { - log.Warn("ProxyName [%s], write to client error, proxy exit", cli.Name) + log.Warn("ProxyName [%s], write to server error, proxy exit", cli.Name) c.Close() break } diff --git a/src/frp/cmd/frps/control.go b/src/frp/cmd/frps/control.go index 67cd6428..6566cd73 100644 --- a/src/frp/cmd/frps/control.go +++ b/src/frp/cmd/frps/control.go @@ -158,7 +158,7 @@ func msgReader(s *server.ProxyServer, c *conn.Conn, msgSendChan chan interface{} case consts.HeartbeatReq: log.Debug("ProxyName [%s], get heartbeat", s.Name) timer.Reset(time.Duration(server.HeartBeatTimeout) * time.Second) - heartbeatRes := msg.ControlRes{ + heartbeatRes := &msg.ControlRes{ Type: consts.HeartbeatRes, } msgSendChan <- heartbeatRes From 7c3e00ed28d4c67ef41135c996f002a5a529bfa1 Mon Sep 17 00:00:00 2001 From: fatedier Date: Mon, 11 Apr 2016 11:21:35 +0800 Subject: [PATCH 2/5] build: update Makefile to avoid godep warning --- Makefile | 10 +++++----- conf/frpc.ini | 4 ++-- conf/frps.ini | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 4dbf0d99..72bbb120 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ export PATH := $(GOPATH)/bin:$(PATH) -export NEW_GOPATH := $(shell pwd) +export GOPATH := $(shell pwd):$(GOPATH) all: build @@ -9,13 +9,13 @@ godep: @go get github.com/tools/godep fmt: - GOPATH=$(NEW_GOPATH) godep go fmt ./... + godep go fmt ./... frps: - GOPATH=$(NEW_GOPATH) godep go build -o bin/frps ./src/frp/cmd/frps + godep go build -o bin/frps ./src/frp/cmd/frps frpc: - GOPATH=$(NEW_GOPATH) godep go build -o bin/frpc ./src/frp/cmd/frpc + godep go build -o bin/frpc ./src/frp/cmd/frpc test: - @GOPATH=$(NEW_GOPATH) godep go test -v ./... + godep go test -v ./... diff --git a/conf/frpc.ini b/conf/frpc.ini index 2f48a80c..86679e6d 100644 --- a/conf/frpc.ini +++ b/conf/frpc.ini @@ -3,9 +3,9 @@ server_addr = 0.0.0.0 server_port = 7000 # console or real logFile path like ./frpc.log -log_file = console +log_file = ./frpc.log # debug, info, warn, error -log_level = debug +log_level = info # for authentication auth_token = 123 diff --git a/conf/frps.ini b/conf/frps.ini index c410410d..cfb9e7b7 100644 --- a/conf/frps.ini +++ b/conf/frps.ini @@ -3,9 +3,9 @@ bind_addr = 0.0.0.0 bind_port = 7000 # console or real logFile path like ./frps.log -log_file = console +log_file = ./frps.log # debug, info, warn, error -log_level = debug +log_level = info # test1 is the proxy name, client will use this name and auth_token to connect to server [test1] From 0f326449e856117d16431db9e4bf2280007c2fc1 Mon Sep 17 00:00:00 2001 From: fatedier Date: Mon, 11 Apr 2016 11:58:07 +0800 Subject: [PATCH 3/5] build: fix --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 72bbb120..bed17341 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ export PATH := $(GOPATH)/bin:$(PATH) +export OLDGOPATH := $(GOPATH) export GOPATH := $(shell pwd):$(GOPATH) all: build @@ -6,7 +7,8 @@ all: build build: godep fmt frps frpc godep: - @go get github.com/tools/godep + @GOPATH=$(OLDGOPATH) + go get github.com/tools/godep fmt: godep go fmt ./... From fdd743673690c666bdcafbf048c620d4cd80d63c Mon Sep 17 00:00:00 2001 From: fatedier Date: Mon, 11 Apr 2016 12:05:24 +0800 Subject: [PATCH 4/5] build: fix --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bed17341..033a0449 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,7 @@ all: build build: godep fmt frps frpc godep: - @GOPATH=$(OLDGOPATH) - go get github.com/tools/godep + GOPATH=$(OLDGOPATH) go get github.com/tools/godep fmt: godep go fmt ./... From 6874688e075d56dedc7ebcefc0efc8cfa1bbe60e Mon Sep 17 00:00:00 2001 From: fatedier Date: Mon, 11 Apr 2016 17:27:14 +0800 Subject: [PATCH 5/5] build: for cross-compiles --- .gitignore | 1 + Makefile.cross-compiles | 15 +++++++++++++ cross_compiles_package.sh | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 Makefile.cross-compiles create mode 100755 cross_compiles_package.sh diff --git a/.gitignore b/.gitignore index 72c9fd3c..947e2967 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ _testmain.go # Self bin/ +packages/ # Cache *.swp diff --git a/Makefile.cross-compiles b/Makefile.cross-compiles new file mode 100644 index 00000000..fbba88eb --- /dev/null +++ b/Makefile.cross-compiles @@ -0,0 +1,15 @@ +export PATH := $(GOPATH)/bin:$(PATH) +export OLDGOPATH := $(GOPATH) +export GOPATH := $(shell pwd)/Godeps/_workspace:$(shell pwd):$(GOPATH) +export OS_TARGETS=linux windows +export ARCH_TARGETS=386 amd64 + +all: build + +build: godep app + +godep: + GOPATH=$(OLDGOPATH) go get github.com/mitchellh/gox + +app: + gox -os "$(OS_TARGETS)" -arch="$(ARCH_TARGETS)" ./... diff --git a/cross_compiles_package.sh b/cross_compiles_package.sh new file mode 100755 index 00000000..774eb327 --- /dev/null +++ b/cross_compiles_package.sh @@ -0,0 +1,45 @@ +# compile for version +make +if [ $? -ne 0 ]; then + echo "make error" + exit 1 +fi + +frp_version=`./bin/frps --version` +echo "build version: $frp_version" + +# cross_compiles +make -f ./Makefile.cross-compiles + +rm -rf ./packages +mkdir ./packages + +os_all='linux windows' +arch_all='386 amd64' + +for os in $os_all; do + for arch in $arch_all; do + frp_dir_name="frp_${frp_version}_${os}_${arch}" + frp_path="./packages/frp_${frp_version}_${os}_${arch}" + mkdir ${frp_path} + if [ "x${os}" = x"windows" ]; then + mv ./frpc_${os}_${arch}.exe ${frp_path}/frpc.exe + mv ./frps_${os}_${arch}.exe ${frp_path}/frps.exe + else + mv ./frpc_${os}_${arch} ${frp_path}/frpc + mv ./frps_${os}_${arch} ${frp_path}/frps + fi + cp ./LICENSE ${frp_path} + cp ./conf/* ${frp_path} + + # packages + cd ./packages + if [ "x${os}" = x"windows" ]; then + zip -rq ${frp_dir_name}.zip ${frp_dir_name} + else + tar -zcf ${frp_dir_name}.tar.gz ${frp_dir_name} + fi + cd .. + rm -rf ${frp_path} + done +done