Skip to content

Commit

Permalink
优化错误消息
Browse files Browse the repository at this point in the history
  • Loading branch information
侯锐 committed Jan 21, 2019
1 parent 3a071c6 commit 8ca3e07
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions core/network/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package network
import (
"encoding/binary"
"errors"
"fmt"
"github.com/sirupsen/logrus"
"net"
)
Expand Down Expand Up @@ -37,6 +38,12 @@ func (c Connection) Read(length uint32) ([]byte, error) {

var buf = make([]byte, length)
var bufSize, err = c.conn.Read(buf)
// 连接被远程主机主动关闭
if bufSize == 0 {
e := fmt.Sprintf("conn closed by remote, %s -> %s", c.LocalAddress(), c.RemoteAddress())
logrus.Debug(e)
return nil, errors.New(e)
}
if err != nil {
c.Close()
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions local/socks/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func HandlerSocks5Data(localConn network.Connection, remoteConn network.Connecti
// 浏览器 -> local
buf, err := localConn.Read(1024)
if err != nil {
//log.Println(localConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug(localConn.RemoteAddress() + " -> " + err.Error())
remoteConn.Close()
break
}
Expand All @@ -188,7 +188,7 @@ func HandlerSocks5Data(localConn network.Connection, remoteConn network.Connecti
// local -> server
err = remoteConn.WriteWithLength(buf)
if err != nil {
//log.Println(remoteConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug(remoteConn.RemoteAddress() + " -> " + err.Error())
localConn.Close()
break
}
Expand All @@ -200,7 +200,7 @@ func HandlerSocks5Data(localConn network.Connection, remoteConn network.Connecti
// server -> local
buf, err := remoteConn.ReadWithLength()
if err != nil {
//log.Println(remoteConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug(remoteConn.RemoteAddress() + " -> " + err.Error())
localConn.Close()
break
}
Expand All @@ -211,7 +211,7 @@ func HandlerSocks5Data(localConn network.Connection, remoteConn network.Connecti
// local -> 浏览器
err = localConn.Write(buf)
if err != nil {
//log.Println(localConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug(localConn.RemoteAddress() + " -> " + err.Error())
remoteConn.Close()
break
}
Expand Down
8 changes: 4 additions & 4 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ func handlerClient(localConn network.Connection) {
// local -> server
buf, err := localConn.ReadWithLength()
if err != nil {
logrus.Info("local -> server " + localConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug("local -> server " + localConn.RemoteAddress() + " -> " + err.Error())
remoteConn.Close()
break
}
buf = codec.Decrypt(buf)
// server -> remote
err = remoteConn.Write(buf)
if err != nil {
logrus.Info("server -> remote " + remoteConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug("server -> remote " + remoteConn.RemoteAddress() + " -> " + err.Error())
localConn.Close()
break
}
Expand All @@ -125,15 +125,15 @@ func handlerClient(localConn network.Connection) {
// remote -> server
buf, err := remoteConn.Read(1024)
if err != nil {
logrus.Info("remote -> server " + remoteConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug("remote -> server " + remoteConn.RemoteAddress() + " -> " + err.Error())
localConn.Close()
break
}
buf = codec.Encrypt(buf)
// server -> local
err = localConn.WriteWithLength(buf)
if err != nil {
logrus.Info("server -> local " + localConn.RemoteAddress() + " -> " + err.Error())
logrus.Debug("server -> local " + localConn.RemoteAddress() + " -> " + err.Error())
remoteConn.Close()
break
}
Expand Down

0 comments on commit 8ca3e07

Please sign in to comment.