1.添加了用于测试的文件
2.cache太小会有问题,还在研究。 Signed-off-by: dmy@lab <dmy@lab.com>
This commit is contained in:
parent
b97df11243
commit
fed05b3de3
2
main.go
2
main.go
|
|
@ -13,7 +13,7 @@ func tunnel() {
|
|||
trans := NewTransTCP()
|
||||
log.Info("%s side is encrypted.", cli.EncryptSide)
|
||||
if cli.DestPort != 0 {
|
||||
log.Info("Listening on 127.0.0.1:%d. Forward %s:%d", cli.ListenPort, cli.DestIP, cli.DestPort)
|
||||
log.Info("Listening on 0.0.0.0:%d. Forward %s:%d", cli.ListenPort, cli.DestIP, cli.DestPort)
|
||||
trans.Start(strconv.Itoa(cli.ListenPort), cli.DestIP, strconv.Itoa(cli.DestPort), cli.EncryptSide)
|
||||
} else {
|
||||
trans.Start("1200", "192.168.0.120", "8118", "client")
|
||||
|
|
|
|||
36
main_test.go
36
main_test.go
|
|
@ -1,13 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"github.com/TransX/log"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func server(t *testing.T) {
|
||||
file, _ := os.Open("test/cipher.txt")
|
||||
reader := bufio.NewReader(file)
|
||||
listener, err := net.Listen("tcp4", "127.0.0.1:1244")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -18,8 +22,21 @@ func server(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bytes := make([]byte, 32)
|
||||
bytes := make([]byte, 1024*32)
|
||||
n, err := conn.Read(bytes)
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Error("client read %", err)
|
||||
break
|
||||
}
|
||||
if string(bytes[:n]) != line {
|
||||
log.Error("cipher failed %s", string(bytes[:n]))
|
||||
log.Error("%s %s", len(bytes[:n]), len([]byte(line)))
|
||||
for i := 0; i < n; i++ {
|
||||
log.Error("%d", bytes[i]-[]byte(line)[i])
|
||||
}
|
||||
|
||||
}
|
||||
log.Info("Test Server Receive %s", string(bytes[:n]))
|
||||
_, err = conn.Write([]byte("OK"))
|
||||
log.Info("Test Server write")
|
||||
|
|
@ -32,15 +49,24 @@ func server(t *testing.T) {
|
|||
}
|
||||
|
||||
func client(t *testing.T) {
|
||||
file, _ := os.Open("test/cipher.txt")
|
||||
reader := bufio.NewReader(file)
|
||||
for {
|
||||
conn, err := net.Dial("tcp4", "127.0.0.1:1200")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn.Write([]byte("Client"))
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Error("client read %", err)
|
||||
|
||||
}
|
||||
bytesLine := []byte(line)
|
||||
n, _ := conn.Write(bytesLine)
|
||||
log.Info("Test Client write %s", string(bytesLine[:n]))
|
||||
log.Info("Test Client write")
|
||||
bytes := make([]byte, 32)
|
||||
n, err := conn.Read(bytes)
|
||||
bytes := make([]byte, 1024*32)
|
||||
n, err = conn.Read(bytes)
|
||||
log.Info("Test Client read")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -54,7 +80,7 @@ func client(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTunnel(t *testing.T) {
|
||||
log.LogTo("log.txt", "DEBUG")
|
||||
log.LogTo("log.txt", "INFO")
|
||||
log.Info("Test Start testing.")
|
||||
go server(t)
|
||||
go client(t)
|
||||
|
|
|
|||
2
tcp.go
2
tcp.go
|
|
@ -62,7 +62,7 @@ func (this *TransTCP) tunnel(src, dest net.Conn, id string, encrypDirection stri
|
|||
|
||||
}
|
||||
}()
|
||||
cache := make([]byte, 1024*128) //128kB
|
||||
cache := make([]byte, 1024*32) //128kB
|
||||
for {
|
||||
//构建Carrier
|
||||
revCarrier := &tscipher.Carrier{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
About 4,000 have arrived in Slovenia, the UN refugee agency says. Most aim to travel on to Austria, Germany and other countries.
|
||||
Slovenia's army has been placed on standby to help police deal with the influx, Prime Minister Miro Cerar said.
|
||||
He said Slovenia would accept the migrants as long as Austria and Germany kept their borders open.
|
||||
Hungary said it had closed its border with Croatia at midnight on Friday because European Union leaders had failed to agree a plan to stem the flow of asylum seekers.
|
||||
Last month it also shut its frontier with Serbia, which was another transit route to Western Europe.
|
||||
|
||||
|
||||
On Saturday, hundreds of refugees were bussed across Croatia, from its border with Serbia to its border with Slovenia.
|
||||
Many had spent weeks walking through Greece, Macedonia and Serbia to reach the Croatian border.
|
||||
|
|
@ -10,9 +10,8 @@ func (this *XOR) Decrypt(data []byte) (decrypted []byte, err error) {
|
|||
decrypted = make([]byte, len(data))
|
||||
for i := 0; i < len(data); i++ {
|
||||
decrypted[i] = data[len(data)-i-1] ^ this.key[i%len(this.key)]
|
||||
// decrypted[i] = data[i] ^ this.key[i%len(this.key)]
|
||||
// decrypted[i] = data[i]
|
||||
}
|
||||
// copy(decrypted,data)
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
|
|
@ -21,9 +20,8 @@ func (this *XOR) Encrypt(data []byte) (encryped []byte, err error) {
|
|||
encryped = make([]byte, len(data))
|
||||
for i := 0; i < len(data); i++ {
|
||||
encryped[len(data)-i-1] = data[i] ^ this.key[i%len(this.key)]
|
||||
// encryped[i] = data[i] ^ this.key[i%len(this.key)]
|
||||
// encryped[i] = data[i]
|
||||
}
|
||||
// copy(encryped,data)
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue