parent
980983578b
commit
a9adc5de64
26
tunnel.go
26
tunnel.go
|
|
@ -59,30 +59,15 @@ func (this *Tunnel) run() { //单向的,从src发送到dest
|
||||||
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
cache := make([]byte, 1024*32) //128kB
|
cache := make([]byte, 1024*4) //4kB
|
||||||
//构建Carrier
|
//构建Carrier
|
||||||
// revCarrier := &tscipher.Carrier{
|
|
||||||
// src,
|
|
||||||
// tscipher.NewCipher("XOR"),
|
|
||||||
// cache,
|
|
||||||
// this.id,
|
|
||||||
// }
|
|
||||||
revCarrier := tscipher.NewCarrier(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)
|
sendCarrier := tscipher.NewCarrier(dest, tscipher.NewCipher("XOR"), cache, this.id)
|
||||||
for {
|
for {
|
||||||
// log.Info("a loop Tunnel id %s", id)
|
|
||||||
var nByte int
|
var nByte int
|
||||||
// log.Debug("Encrypt Direction %s ID %s", cipherDirection, id)
|
|
||||||
var err error
|
var err error
|
||||||
if cipherDirection != "receive" {
|
if cipherDirection != "receive" {
|
||||||
revCarrier.Cipher = nil
|
revCarrier.Cipher = nil
|
||||||
// log.Debug("Read not crypted. Tunnel: %s", id)
|
|
||||||
nByte, err = tscipher.RowReceiveData(revCarrier)
|
nByte, err = tscipher.RowReceiveData(revCarrier)
|
||||||
} else {
|
} else {
|
||||||
nByte, err = tscipher.ReceiveData(revCarrier)
|
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)
|
log.Info("Reived %d bytes from %s. Tunnel: id %s", nByte, src.RemoteAddr().String(), id)
|
||||||
if cipherDirection != "send" {
|
if cipherDirection != "send" {
|
||||||
sendCarrier.Cipher = nil
|
sendCarrier.Cipher = nil
|
||||||
// log.Debug("Write not crypted. Tunnel: %s", id)
|
|
||||||
}
|
}
|
||||||
// for {
|
|
||||||
n, err := tscipher.SendData(sendCarrier, nByte)
|
n, err := tscipher.SendData(sendCarrier, nByte)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic("Write panic. ID: %s, Err: %s, Remote Add: %s", id, err, dest.RemoteAddr().String())
|
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]))
|
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
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue