修改缓存

Signed-off-by: dmy@lab <dmy@lab.com>
This commit is contained in:
dmy@lab 2015-11-05 15:22:22 +08:00
parent 980983578b
commit a9adc5de64
1 changed files with 1 additions and 25 deletions

View File

@ -59,30 +59,15 @@ func (this *Tunnel) run() { //单向的从src发送到dest
}
}()
cache := make([]byte, 1024*32) //128kB
cache := make([]byte, 1024*4) //4kB
//构建Carrier
// revCarrier := &tscipher.Carrier{
// src,
// tscipher.NewCipher("XOR"),
// cache,
// this.id,
// }
revCarrier := tscipher.NewCarrier(src, tscipher.NewCipher("XOR"), cache, this.id)
// sendCarrier := &tscipher.Carrier{
// dest,
// tscipher.NewCipher("XOR"),
// cache, //TODO:危险cache的容量容易被不小心修改
// this.id,
// }
sendCarrier := tscipher.NewCarrier(dest, tscipher.NewCipher("XOR"), cache, this.id)
for {
// log.Info("a loop Tunnel id %s", id)
var nByte int
// log.Debug("Encrypt Direction %s ID %s", cipherDirection, id)
var err error
if cipherDirection != "receive" {
revCarrier.Cipher = nil
// log.Debug("Read not crypted. Tunnel: %s", id)
nByte, err = tscipher.RowReceiveData(revCarrier)
} else {
nByte, err = tscipher.ReceiveData(revCarrier)
@ -93,21 +78,12 @@ func (this *Tunnel) run() { //单向的从src发送到dest
log.Info("Reived %d bytes from %s. Tunnel: id %s", nByte, src.RemoteAddr().String(), id)
if cipherDirection != "send" {
sendCarrier.Cipher = nil
// log.Debug("Write not crypted. Tunnel: %s", id)
}
// for {
n, err := tscipher.SendData(sendCarrier, nByte)
if err != nil {
log.Panic("Write panic. ID: %s, Err: %s, Remote Add: %s", id, err, dest.RemoteAddr().String())
}
log.Info("Write %d bytes from %s to %s. Tunnel: %s . 18 bytes", n, dest.LocalAddr(), dest.RemoteAddr().String(), id, string(sendCarrier.Cache[:18]))
// if n == 0 {
// log.Info("Retry Write id %s", id)
// continue
// }
// break
// }
}
}