ソースを参照

Merge branch 'dev'

fatedier 9 年 前
コミット
2c39719cc0
8 ファイル変更78 行追加12 行削除
  1. 1 0
      .gitignore
  2. 7 6
      Makefile
  3. 15 0
      Makefile.cross-compiles
  4. 2 2
      conf/frpc.ini
  5. 2 2
      conf/frps.ini
  6. 45 0
      cross_compiles_package.sh
  7. 5 1
      src/frp/cmd/frpc/control.go
  8. 1 1
      src/frp/cmd/frps/control.go

+ 1 - 0
.gitignore

@@ -25,6 +25,7 @@ _testmain.go
 
 # Self
 bin/
+packages/
 
 # Cache
 *.swp

+ 7 - 6
Makefile

@@ -1,21 +1,22 @@
 export PATH := $(GOPATH)/bin:$(PATH)
-export NEW_GOPATH := $(shell pwd)
+export OLDGOPATH := $(GOPATH)
+export GOPATH := $(shell pwd):$(GOPATH)
 
 all: build
 
 build: godep fmt frps frpc
 
 godep:
-	@go get github.com/tools/godep
+	GOPATH=$(OLDGOPATH) 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 ./...

+ 15 - 0
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)" ./...

+ 2 - 2
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
 

+ 2 - 2
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]

+ 45 - 0
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

+ 5 - 1
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
 		}

+ 1 - 1
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