Merge branch 'fix_some_bugs' of https://github.com/Hurricanezwf/frp into Hurricanezwf-fix_some_bugs

Conflicts:
	cmd/frpc/config.go
	cmd/frpc/control.go
	cmd/frpc/main.go
	cmd/frps/config.go
	cmd/frps/control.go
	cmd/frps/main.go
	pkg/models/server.go
This commit is contained in:
fatedier
2016-02-18 11:42:31 +08:00
11 changed files with 185 additions and 68 deletions

View File

@@ -63,6 +63,7 @@ func (p *ProxyClient) StartTunnel(serverAddr string, serverPort int64) (err erro
return
}
// l means local, r means remote
log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", localConn.GetLocalAddr(), localConn.GetRemoteAddr(),
remoteConn.GetLocalAddr(), remoteConn.GetRemoteAddr())
go conn.Join(localConn, remoteConn)

View File

@@ -19,17 +19,19 @@ type ProxyServer struct {
BindAddr string
ListenPort int64
Status int64
Listener *conn.Listener // accept new connection from remote users
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
UserConnList *list.List // store user conns
Mutex sync.Mutex
Status int64
Listener *conn.Listener // accept new connection from remote users
CtlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel
StopBlockChan chan int64 // put any number to the channel, if you want to stop wait user conn
CliConnChan chan *conn.Conn // get client conns from control goroutine
UserConnList *list.List // store user conns
Mutex sync.Mutex
}
func (p *ProxyServer) Init() {
p.Status = Idle
p.CtlMsgChan = make(chan int64)
p.StopBlockChan = make(chan int64)
p.CliConnChan = make(chan *conn.Conn)
p.UserConnList = list.New()
}
@@ -87,11 +89,13 @@ func (p *ProxyServer) Start() (err error) {
p.UserConnList.Remove(element)
} else {
cliConn.Close()
p.Unlock()
continue
}
p.Unlock()
// msg will transfer to another without modifying
// l means local, r means remote
log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", cliConn.GetLocalAddr(), cliConn.GetRemoteAddr(),
userConn.GetLocalAddr(), userConn.GetRemoteAddr())
go conn.Join(cliConn, userConn)
@@ -110,7 +114,15 @@ func (p *ProxyServer) Close() {
p.Unlock()
}
func (p *ProxyServer) WaitUserConn() (res int64) {
res = <-p.CtlMsgChan
return
func (p *ProxyServer) WaitUserConn() (res int64, isStop bool) {
select {
case res = <-p.CtlMsgChan:
return res, false
case <-p.StopBlockChan:
return 0, true
}
}
func (p *ProxyServer) StopWaitUserConn() {
p.StopBlockChan <- 1
}

View File

@@ -59,7 +59,9 @@ func (c *Conn) Write(content string) (err error) {
}
func (c *Conn) Close() {
c.TcpConn.Close()
if c.TcpConn != nil {
c.TcpConn.Close()
}
}
func Listen(bindAddr string, bindPort int64) (l *Listener, err error) {

View File

@@ -6,7 +6,7 @@ import (
"testing"
)
func Test_Encrypto(t *testing.T) {
func TestEncrypto(t *testing.T) {
pp := new(Pcrypto)
pp.Init([]byte("Hana"))
res, err := pp.Encrypto([]byte("Just One Test!"))
@@ -17,7 +17,7 @@ func Test_Encrypto(t *testing.T) {
fmt.Printf("[%x]\n", res)
}
func Test_Decrypto(t *testing.T) {
func TestDecrypto(t *testing.T) {
pp := new(Pcrypto)
pp.Init([]byte("Hana"))
res, err := pp.Encrypto([]byte("Just One Test!"))
@@ -33,13 +33,13 @@ func Test_Decrypto(t *testing.T) {
fmt.Printf("[%s]\n", string(res))
}
func Test_PKCS7Padding(t *testing.T) {
func TestPKCS7Padding(t *testing.T) {
ltt := []byte("Test_PKCS7Padding")
ltt = PKCS7Padding(ltt, aes.BlockSize)
fmt.Printf("[%x]\n", (ltt))
}
func Test_PKCS7UnPadding(t *testing.T) {
func TestPKCS7UnPadding(t *testing.T) {
ltt := []byte("Test_PKCS7Padding")
ltt = PKCS7Padding(ltt, aes.BlockSize)
ltt = PKCS7UnPadding(ltt)