加了缓存

This commit is contained in:
dmy@lab
2016-01-10 13:44:02 +08:00
parent 825d0f2501
commit e8682183dd
4 changed files with 121 additions and 78 deletions

View File

@@ -5,6 +5,7 @@ import (
"crypto/md5"
"encoding/hex"
// "fmt"
"github.com/TransX/cache"
"github.com/TransX/log"
"github.com/TransX/tscipher"
"net"
@@ -63,9 +64,10 @@ func (this *Tunnel) Run() { //单向的从src发送到dest
id := this.id
// cache := make([]byte, 1024*4) //4kB
//构建Carrier
queCache := tscipher.NewQueueCache(1)
revCarrier := tscipher.NewCarrier(src, tscipher.NewCipher("XOR"), queCache, id)
sendCarrier := tscipher.NewCarrier(dest, tscipher.NewCipher("XOR"), queCache, id)
queCache := cache.NewUnblockingQueueCache(1)
msg := cache.NewBlockingQueueCache(1)
revCarrier := tscipher.NewCarrier(src, tscipher.NewCipher("XOR"), queCache, msg, id)
sendCarrier := tscipher.NewCarrier(dest, tscipher.NewCipher("XOR"), queCache, msg, id)
//timer
// for {
@@ -111,7 +113,7 @@ func (this *Tunnel) receive(revCarrier *tscipher.Carrier) {
if err != nil {
log.Panic("Read panic. Tunnel id: %s. Remote Add: %s Local: %s. Err:%s", id, src.RemoteAddr().String(), src.LocalAddr().String(), err.Error())
}
log.Debug("Reived %d bytes from %s. Tunnel: id %s", n, src.RemoteAddr().String(), id)
log.Debug("Reived %d bytes (local add %s) from %s. Tunnel: id %s", n, src.LocalAddr().String(),src.RemoteAddr().String(), id)
// nCh <- n
}
}
@@ -143,7 +145,7 @@ func (this *Tunnel) send(sendCarrier *tscipher.Carrier) {
sTimer := time.Now() //send timer
_, err := tscipher.SendData(sendCarrier)
// fmt.Println("send")
log.Info("id %s time to sned %d", id, time.Since(sTimer)/1000)
log.Info("id %s time to send %d", id, time.Since(sTimer)/1000)
if err != nil {
log.Panic("Write panic. ID: %s, Err: %s, Remote Add: %s", id, err, dest.RemoteAddr().String())
}