稍微优化一下
This commit is contained in:
parent
54cd925ab2
commit
6f8bda54e4
|
|
@ -49,6 +49,7 @@ func (this *Tunnel) run() { //单向的,从src发送到dest
|
||||||
cipherDirection := this.cipherDirection
|
cipherDirection := this.cipherDirection
|
||||||
id := this.id
|
id := this.id
|
||||||
defer func() {
|
defer func() {
|
||||||
|
log.Info("tunnel id %s ends", id)
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
if src != nil {
|
if src != nil {
|
||||||
src.Close()
|
src.Close()
|
||||||
|
|
@ -56,7 +57,6 @@ func (this *Tunnel) run() { //单向的,从src发送到dest
|
||||||
if dest != nil {
|
if dest != nil {
|
||||||
dest.Close()
|
dest.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
cache := make([]byte, 1024*4) //4kB
|
cache := make([]byte, 1024*4) //4kB
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,14 @@ func NewCarrier(conn net.Conn, cipher Cipher, cache []byte, id string) *Carrier
|
||||||
t.Cipher = cipher
|
t.Cipher = cipher
|
||||||
t.Cache = cache
|
t.Cache = cache
|
||||||
t.AttachedTunnelID = id
|
t.AttachedTunnelID = id
|
||||||
t.receiveBuff = make([]byte, 0, len(cache)*8)
|
t.receiveBuff = make([]byte, 0, len(cache))
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Carrier) GetReceiveBuff() []byte {
|
func (this *Carrier) GetReceiveBuff() []byte {
|
||||||
log.Debug("id %d receivebuff Get, len %d", this.AttachedTunnelID, len(this.receiveBuff))
|
log.Debug("id %d receivebuff Get, len %d", this.AttachedTunnelID, len(this.receiveBuff))
|
||||||
buff := this.receiveBuff
|
buff := this.receiveBuff
|
||||||
_b := make([]byte, len(buff), cap(buff))
|
_b := make([]byte, len(buff), cap(buff)) //必须这样写,没错。
|
||||||
copy(_b, buff)
|
copy(_b, buff)
|
||||||
return _b
|
return _b
|
||||||
}
|
}
|
||||||
|
|
@ -82,6 +82,8 @@ func NewCipher(cipherName string) (cipher Cipher) {
|
||||||
func WrapPackage(data []byte) []byte { //把要加密传输的数据打包成一定的格式,避免发送了100自己,只收到90字节的问题。
|
func WrapPackage(data []byte) []byte { //把要加密传输的数据打包成一定的格式,避免发送了100自己,只收到90字节的问题。
|
||||||
sizeOfData := len(data)
|
sizeOfData := len(data)
|
||||||
binSize := utils.Int2binary(sizeOfData, 10)
|
binSize := utils.Int2binary(sizeOfData, 10)
|
||||||
|
// header := make([]byte, 18)
|
||||||
|
// header = append(append(append(header, StartMark...), binSize...), EndMark...)
|
||||||
header := append(append(StartMark, binSize...), EndMark...)
|
header := append(append(StartMark, binSize...), EndMark...)
|
||||||
// log.Error("size of header %d %x", len(header), header)
|
// log.Error("size of header %d %x", len(header), header)
|
||||||
//加密
|
//加密
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue