添加了专门的常量文件

This commit is contained in:
dmy@lab 2015-11-13 15:44:17 +08:00
parent a9adc5de64
commit 0490b11224
4 changed files with 17 additions and 9 deletions

8
constant.go Normal file
View File

@ -0,0 +1,8 @@
package main
type Direction int
const (
RECEIVE Direction = 0
SEND Direction = 1
)

View File

@ -1 +1 @@
.\TransX -destip 127.0.0.1 -destport 1084 -listenport 1082 -encrypt server -log applog/server.log
.\TransX -destip 191.101.11.132 -destport 8321 -listenport 1082 -encrypt server -log applog/server.log

8
tcp.go
View File

@ -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()
}
}()

View File

@ -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)