mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
Use go fmt before build
This commit is contained in:
parent
bdcdafd768
commit
fa9356936b
5
Makefile
5
Makefile
@ -2,12 +2,15 @@ export PATH := $(GOPATH)/bin:$(PATH)
|
|||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
build: godep frps frpc
|
build: godep fmt frps frpc
|
||||||
|
|
||||||
godep:
|
godep:
|
||||||
@go get github.com/tools/godep
|
@go get github.com/tools/godep
|
||||||
godep restore
|
godep restore
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
@godep go fmt ./...
|
||||||
|
|
||||||
frps:
|
frps:
|
||||||
godep go build -o bin/frps ./cmd/frps
|
godep go build -o bin/frps ./cmd/frps
|
||||||
|
|
||||||
|
@ -11,16 +11,15 @@ import (
|
|||||||
|
|
||||||
// common config
|
// common config
|
||||||
var (
|
var (
|
||||||
ServerAddr string = "0.0.0.0"
|
ServerAddr string = "0.0.0.0"
|
||||||
ServerPort int64 = 7000
|
ServerPort int64 = 7000
|
||||||
LogFile string = "./frpc.log"
|
LogFile string = "./frpc.log"
|
||||||
LogLevel string = "warn"
|
LogLevel string = "warn"
|
||||||
LogWay string = "file"
|
LogWay string = "file"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ProxyClients map[string]*models.ProxyClient = make(map[string]*models.ProxyClient)
|
var ProxyClients map[string]*models.ProxyClient = make(map[string]*models.ProxyClient)
|
||||||
|
|
||||||
|
|
||||||
func LoadConf(confFile string) (err error) {
|
func LoadConf(confFile string) (err error) {
|
||||||
var tmpStr string
|
var tmpStr string
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/models"
|
"github.com/fatedier/frp/pkg/models"
|
||||||
"github.com/fatedier/frp/pkg/utils/conn"
|
"github.com/fatedier/frp/pkg/utils/conn"
|
||||||
@ -22,9 +22,9 @@ func ControlProcess(cli *models.ProxyClient, wait *sync.WaitGroup) {
|
|||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
req := &models.ClientCtlReq{
|
req := &models.ClientCtlReq{
|
||||||
Type: models.ControlConn,
|
Type: models.ControlConn,
|
||||||
ProxyName: cli.Name,
|
ProxyName: cli.Name,
|
||||||
Passwd: cli.Passwd,
|
Passwd: cli.Passwd,
|
||||||
}
|
}
|
||||||
buf, _ := json.Marshal(req)
|
buf, _ := json.Marshal(req)
|
||||||
err = c.Write(string(buf) + "\n")
|
err = c.Write(string(buf) + "\n")
|
||||||
|
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/utils/log"
|
"github.com/fatedier/frp/pkg/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,16 +11,15 @@ import (
|
|||||||
|
|
||||||
// common config
|
// common config
|
||||||
var (
|
var (
|
||||||
BindAddr string = "0.0.0.0"
|
BindAddr string = "0.0.0.0"
|
||||||
BindPort int64 = 9527
|
BindPort int64 = 9527
|
||||||
LogFile string = "./frps.log"
|
LogFile string = "./frps.log"
|
||||||
LogLevel string = "warn"
|
LogLevel string = "warn"
|
||||||
LogWay string = "file"
|
LogWay string = "file"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ProxyServers map[string]*models.ProxyServer = make(map[string]*models.ProxyServer)
|
var ProxyServers map[string]*models.ProxyServer = make(map[string]*models.ProxyServer)
|
||||||
|
|
||||||
|
|
||||||
func LoadConf(confFile string) (err error) {
|
func LoadConf(confFile string) (err error) {
|
||||||
var tmpStr string
|
var tmpStr string
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/utils/log"
|
|
||||||
"github.com/fatedier/frp/pkg/utils/conn"
|
|
||||||
"github.com/fatedier/frp/pkg/models"
|
"github.com/fatedier/frp/pkg/models"
|
||||||
|
"github.com/fatedier/frp/pkg/utils/conn"
|
||||||
|
"github.com/fatedier/frp/pkg/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProcessControlConn(l *conn.Listener) {
|
func ProcessControlConn(l *conn.Listener) {
|
||||||
@ -41,7 +41,7 @@ func controlWorker(c *conn.Conn) {
|
|||||||
clientCtlRes.Code = 1
|
clientCtlRes.Code = 1
|
||||||
clientCtlRes.Msg = msg
|
clientCtlRes.Msg = msg
|
||||||
}
|
}
|
||||||
|
|
||||||
if needRes {
|
if needRes {
|
||||||
buf, _ := json.Marshal(clientCtlRes)
|
buf, _ := json.Marshal(clientCtlRes)
|
||||||
err = c.Write(string(buf) + "\n")
|
err = c.Write(string(buf) + "\n")
|
||||||
@ -49,7 +49,7 @@ func controlWorker(c *conn.Conn) {
|
|||||||
log.Warn("Write error, %v", err)
|
log.Warn("Write error, %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// work conn, just return
|
// work conn, just return
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func checkProxy(req *models.ClientCtlReq, c *conn.Conn) (succ bool, msg string,
|
|||||||
log.Warn(msg)
|
log.Warn(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// control conn
|
// control conn
|
||||||
if req.Type == models.ControlConn {
|
if req.Type == models.ControlConn {
|
||||||
if server.Status != models.Idle {
|
if server.Status != models.Idle {
|
||||||
@ -115,7 +115,7 @@ func checkProxy(req *models.ClientCtlReq, c *conn.Conn) (succ bool, msg string,
|
|||||||
|
|
||||||
log.Info("ProxyName [%s], start proxy success", req.ProxyName)
|
log.Info("ProxyName [%s], start proxy success", req.ProxyName)
|
||||||
} else if req.Type == models.WorkConn {
|
} else if req.Type == models.WorkConn {
|
||||||
// work conn
|
// work conn
|
||||||
needRes = false
|
needRes = false
|
||||||
if server.Status != models.Working {
|
if server.Status != models.Working {
|
||||||
log.Warn("ProxyName [%s], is not working when it gets one new work conn", req.ProxyName)
|
log.Warn("ProxyName [%s], is not working when it gets one new work conn", req.ProxyName)
|
||||||
|
@ -3,8 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/utils/log"
|
|
||||||
"github.com/fatedier/frp/pkg/utils/conn"
|
"github.com/fatedier/frp/pkg/utils/conn"
|
||||||
|
"github.com/fatedier/frp/pkg/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ProxyClient struct {
|
type ProxyClient struct {
|
||||||
Name string
|
Name string
|
||||||
Passwd string
|
Passwd string
|
||||||
LocalPort int64
|
LocalPort int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProxyClient) GetLocalConn() (c *conn.Conn, err error) {
|
func (p *ProxyClient) GetLocalConn() (c *conn.Conn, err error) {
|
||||||
@ -24,7 +24,7 @@ func (p *ProxyClient) GetLocalConn() (c *conn.Conn, err error) {
|
|||||||
|
|
||||||
func (p *ProxyClient) GetRemoteConn(addr string, port int64) (c *conn.Conn, err error) {
|
func (p *ProxyClient) GetRemoteConn(addr string, port int64) (c *conn.Conn, err error) {
|
||||||
c = &conn.Conn{}
|
c = &conn.Conn{}
|
||||||
defer func(){
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
@ -37,9 +37,9 @@ func (p *ProxyClient) GetRemoteConn(addr string, port int64) (c *conn.Conn, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := &ClientCtlReq{
|
req := &ClientCtlReq{
|
||||||
Type: WorkConn,
|
Type: WorkConn,
|
||||||
ProxyName: p.Name,
|
ProxyName: p.Name,
|
||||||
Passwd: p.Passwd,
|
Passwd: p.Passwd,
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, _ := json.Marshal(req)
|
buf, _ := json.Marshal(req)
|
||||||
@ -64,7 +64,7 @@ func (p *ProxyClient) StartTunnel(serverAddr string, serverPort int64) (err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", localConn.GetLocalAddr(), localConn.GetRemoteAddr(),
|
log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", localConn.GetLocalAddr(), localConn.GetRemoteAddr(),
|
||||||
remoteConn.GetLocalAddr(), remoteConn.GetRemoteAddr())
|
remoteConn.GetLocalAddr(), remoteConn.GetRemoteAddr())
|
||||||
go conn.Join(localConn, remoteConn)
|
go conn.Join(localConn, remoteConn)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type GeneralRes struct {
|
type GeneralRes struct {
|
||||||
Code int64 `json:"code"`
|
Code int64 `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// type
|
// type
|
||||||
@ -12,16 +12,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ClientCtlReq struct {
|
type ClientCtlReq struct {
|
||||||
Type int64 `json:"type"`
|
Type int64 `json:"type"`
|
||||||
ProxyName string `json:"proxy_name"`
|
ProxyName string `json:"proxy_name"`
|
||||||
Passwd string `json:"passwd"`
|
Passwd string `json:"passwd"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientCtlRes struct {
|
type ClientCtlRes struct {
|
||||||
GeneralRes
|
GeneralRes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type ServerCtlReq struct {
|
type ServerCtlReq struct {
|
||||||
Type int64 `json:"type"`
|
Type int64 `json:"type"`
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/utils/conn"
|
"github.com/fatedier/frp/pkg/utils/conn"
|
||||||
"github.com/fatedier/frp/pkg/utils/log"
|
"github.com/fatedier/frp/pkg/utils/log"
|
||||||
@ -14,17 +14,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ProxyServer struct {
|
type ProxyServer struct {
|
||||||
Name string
|
Name string
|
||||||
Passwd string
|
Passwd string
|
||||||
BindAddr string
|
BindAddr string
|
||||||
ListenPort int64
|
ListenPort int64
|
||||||
|
|
||||||
Status int64
|
Status int64
|
||||||
Listener *conn.Listener // accept new connection from remote users
|
Listener *conn.Listener // accept new connection from remote users
|
||||||
CtlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel
|
CtlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel
|
||||||
CliConnChan chan *conn.Conn // get client conns from control goroutine
|
CliConnChan chan *conn.Conn // get client conns from control goroutine
|
||||||
UserConnList *list.List // store user conns
|
UserConnList *list.List // store user conns
|
||||||
Mutex sync.Mutex
|
Mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProxyServer) Init() {
|
func (p *ProxyServer) Init() {
|
||||||
@ -55,7 +55,7 @@ func (p *ProxyServer) Start() (err error) {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
// block
|
// block
|
||||||
c := p.Listener.GetConn()
|
c := p.Listener.GetConn()
|
||||||
log.Debug("ProxyName [%s], get one new user conn [%s]", p.Name, c.GetRemoteAddr())
|
log.Debug("ProxyName [%s], get one new user conn [%s]", p.Name, c.GetRemoteAddr())
|
||||||
|
|
||||||
// put to list
|
// put to list
|
||||||
@ -93,7 +93,7 @@ func (p *ProxyServer) Start() (err error) {
|
|||||||
|
|
||||||
// msg will transfer to another without modifying
|
// msg will transfer to another without modifying
|
||||||
log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", cliConn.GetLocalAddr(), cliConn.GetRemoteAddr(),
|
log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", cliConn.GetLocalAddr(), cliConn.GetRemoteAddr(),
|
||||||
userConn.GetLocalAddr(), userConn.GetRemoteAddr())
|
userConn.GetLocalAddr(), userConn.GetRemoteAddr())
|
||||||
go conn.Join(cliConn, userConn)
|
go conn.Join(cliConn, userConn)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -112,5 +112,5 @@ func (p *ProxyServer) Close() {
|
|||||||
|
|
||||||
func (p *ProxyServer) WaitUserConn() (res int64) {
|
func (p *ProxyServer) WaitUserConn() (res int64) {
|
||||||
res = <-p.CtlMsgChan
|
res = <-p.CtlMsgChan
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package conn
|
package conn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"sync"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/utils/log"
|
"github.com/fatedier/frp/pkg/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Listener struct {
|
type Listener struct {
|
||||||
Addr net.Addr
|
Addr net.Addr
|
||||||
Conns chan *Conn
|
Conns chan *Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait util get one
|
// wait util get one
|
||||||
@ -22,8 +22,8 @@ func (l *Listener) GetConn() (conn *Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
TcpConn *net.TCPConn
|
TcpConn *net.TCPConn
|
||||||
Reader *bufio.Reader
|
Reader *bufio.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) ConnectServer(host string, port int64) (err error) {
|
func (c *Conn) ConnectServer(host string, port int64) (err error) {
|
||||||
@ -70,8 +70,8 @@ func Listen(bindAddr string, bindPort int64) (l *Listener, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
l = &Listener{
|
l = &Listener{
|
||||||
Addr: listener.Addr(),
|
Addr: listener.Addr(),
|
||||||
Conns: make(chan *Conn),
|
Conns: make(chan *Conn),
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -83,7 +83,7 @@ func Listen(bindAddr string, bindPort int64) (l *Listener, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := &Conn{
|
c := &Conn{
|
||||||
TcpConn: conn,
|
TcpConn: conn,
|
||||||
}
|
}
|
||||||
c.Reader = bufio.NewReader(c.TcpConn)
|
c.Reader = bufio.NewReader(c.TcpConn)
|
||||||
l.Conns <- c
|
l.Conns <- c
|
||||||
|
@ -22,7 +22,7 @@ func SetLogFile(logWay string, logFile string) {
|
|||||||
if logWay == "console" {
|
if logWay == "console" {
|
||||||
Log.SetLogger("console", "")
|
Log.SetLogger("console", "")
|
||||||
} else {
|
} else {
|
||||||
Log.SetLogger("file", `{"filename": "` + logFile + `"}`)
|
Log.SetLogger("file", `{"filename": "`+logFile+`"}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user