From 67a00e7902450eb37d88a5d7755a40b84ad8b99d Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Sat, 21 Nov 2015 16:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86XOR=E5=8A=A0=E5=AF=86=E7=94=A8C?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benckmark.go | 6 +++--- main.go | 4 ++-- protocol/tunnel.go | 12 ++++++++++-- tscipher/xor.go | 40 +++++++++++++++++++++++++++++++--------- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/benckmark.go b/benckmark.go index 761272f..f656f6e 100644 --- a/benckmark.go +++ b/benckmark.go @@ -58,17 +58,17 @@ func randMillionSecond() time.Duration { func attack() { c := make(chan int) - for i := 0; i < 10; i++ { + for i := 0; i < 20; i++ { time.Sleep(time.Millisecond * randMillionSecond()) go doHttp(c) } - for i := 0; i < 10; i++ { + for i := 0; i < 20; i++ { <-c } log.Println("Finish") } -func main1() { +func main() { cfg := profile.Config{ MemProfile: true, ProfilePath: "./profile", // store profiles in current directory diff --git a/main.go b/main.go index fa0b3fe..2341109 100644 --- a/main.go +++ b/main.go @@ -25,11 +25,11 @@ func tunnel() { } -func main() { +func main1() { // defer profile.Start(profile.CPUProfile).Stop() flag.Parse() fmt.Println("Hello World!") - log.LogTo(cli.LogTo, "ERROR") + log.LogTo(cli.LogTo, "INFO") if cli.ProfilePort != 0 { go func() { http.ListenAndServe("0.0.0.0:"+strconv.Itoa(cli.ProfilePort), nil) diff --git a/protocol/tunnel.go b/protocol/tunnel.go index 8a6d129..9996757 100644 --- a/protocol/tunnel.go +++ b/protocol/tunnel.go @@ -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) } } diff --git a/tscipher/xor.go b/tscipher/xor.go index 6191cf5..e6bc134 100644 --- a/tscipher/xor.go +++ b/tscipher/xor.go @@ -1,6 +1,24 @@ package tscipher -import () +/* +#cgo CFLAGS: -O3 +#include +char* decrypt(char* inBuff,char* buff,int buffLen,char* key,int keyLen){ + for(int i=0;i