将XOR加密用C语言重写

This commit is contained in:
dmy@lab
2015-11-21 16:54:04 +08:00
parent da0e77d74c
commit 67a00e7902
4 changed files with 46 additions and 16 deletions

View File

@@ -75,17 +75,22 @@ func (this *Tunnel) Run() { //单向的从src发送到dest
}()
cache := make([]byte, 1024*4) //4kB
//构建Carrier
revCarrier := tscipher.NewCarrier(src, tscipher.NewCipher("XOR"), cache, this.id)
sendCarrier := tscipher.NewCarrier(dest, tscipher.NewCipher("XOR"), cache, this.id)
revCarrier := tscipher.NewCarrier(src, tscipher.NewCipher("XOR"), cache, id)
sendCarrier := tscipher.NewCarrier(dest, tscipher.NewCipher("XOR"), cache, id)
//timer
for {
srTimer := time.Now() //send receive timer
var nByte int
var err error
rTimer := time.Now() //receive timer
if cipherDirection != RECEIVE {
revCarrier.Cipher = nil
nByte, err = tscipher.RowReceiveData(revCarrier)
} else {
nByte, err = tscipher.ReceiveData(revCarrier)
}
log.Info("id %s time to receive %d", id, time.Since(rTimer)/1000)
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())
}
@@ -93,11 +98,14 @@ func (this *Tunnel) Run() { //单向的从src发送到dest
if cipherDirection != SEND {
sendCarrier.Cipher = nil
}
sTimer := time.Now() //send timer
n, err := tscipher.SendData(sendCarrier, nByte)
log.Info("id %s time to sned %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())
}
log.Debug("Write %d bytes from %s to %s. Tunnel: %s . 18 bytes %x", n, dest.LocalAddr(), dest.RemoteAddr().String(), id, sendCarrier.Cache[:18])
log.Info("id %s send %d /receive %d duration %d ms", n, nByte, id, time.Since(srTimer)/1000)
}
}