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