From 0490b11224df5a843bfe374eab26c46660f67315 Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Fri, 13 Nov 2015 15:44:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=93=E9=97=A8?= =?UTF-8?q?=E7=9A=84=E5=B8=B8=E9=87=8F=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constant.go | 8 ++++++++ server.bat | 2 +- tcp.go | 8 ++++---- tunnel.go | 8 ++++---- 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 constant.go diff --git a/constant.go b/constant.go new file mode 100644 index 0000000..ef96390 --- /dev/null +++ b/constant.go @@ -0,0 +1,8 @@ +package main + +type Direction int + +const ( + RECEIVE Direction = 0 + SEND Direction = 1 +) diff --git a/server.bat b/server.bat index 70ce34d..96aaec8 100644 --- a/server.bat +++ b/server.bat @@ -1 +1 @@ -.\TransX -destip 127.0.0.1 -destport 1084 -listenport 1082 -encrypt server -log applog/server.log \ No newline at end of file +.\TransX -destip 191.101.11.132 -destport 8321 -listenport 1082 -encrypt server -log applog/server.log \ No newline at end of file diff --git a/tcp.go b/tcp.go index 2c12f56..b572a27 100644 --- a/tcp.go +++ b/tcp.go @@ -56,12 +56,12 @@ func (this *TransTCP) Start(listenPort, destIP, destPort string, clientOrServer log.Info("Dial %s", destConn.RemoteAddr().String()) //tunnel model : [ -->>server ---- client -->> ](this is a tunnel) if clientOrServer == "client" { - go NewTunnel(listenerConn, destConn, "send").run() - go NewTunnel(destConn, listenerConn, "receive").run() + go NewTunnel(listenerConn, destConn, SEND).run() + go NewTunnel(destConn, listenerConn, RECEIVE).run() } if clientOrServer == "server" { - go NewTunnel(listenerConn, destConn, "receive").run() - go NewTunnel(destConn, listenerConn, "send").run() + go NewTunnel(listenerConn, destConn, RECEIVE).run() + go NewTunnel(destConn, listenerConn, SEND).run() } }() diff --git a/tunnel.go b/tunnel.go index cdfaacf..40eedc0 100644 --- a/tunnel.go +++ b/tunnel.go @@ -22,10 +22,10 @@ type Tunnel struct { id string src net.Conn dest net.Conn - cipherDirection string + cipherDirection Direction } -func NewTunnel(src, dest net.Conn, cipherDirection string) *Tunnel { +func NewTunnel(src, dest net.Conn, cipherDirection Direction) *Tunnel { return &Tunnel{ id: tunnelID(), src: src, @@ -66,7 +66,7 @@ func (this *Tunnel) run() { //单向的,从src发送到dest for { var nByte int var err error - if cipherDirection != "receive" { + if cipherDirection != RECEIVE { revCarrier.Cipher = nil nByte, err = tscipher.RowReceiveData(revCarrier) } else { @@ -76,7 +76,7 @@ func (this *Tunnel) run() { //单向的,从src发送到dest log.Panic("Read panic. Tunnel id: %s. Remote Add: %s Local: %s. Err:%s", id, src.RemoteAddr().String(), src.LocalAddr().String(), err.Error()) } log.Info("Reived %d bytes from %s. Tunnel: id %s", nByte, src.RemoteAddr().String(), id) - if cipherDirection != "send" { + if cipherDirection != SEND { sendCarrier.Cipher = nil } n, err := tscipher.SendData(sendCarrier, nByte)