添加了专门的常量文件
This commit is contained in:
parent
a9adc5de64
commit
0490b11224
|
|
@ -0,0 +1,8 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
type Direction int
|
||||||
|
|
||||||
|
const (
|
||||||
|
RECEIVE Direction = 0
|
||||||
|
SEND Direction = 1
|
||||||
|
)
|
||||||
|
|
@ -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
8
tcp.go
|
|
@ -56,12 +56,12 @@ func (this *TransTCP) Start(listenPort, destIP, destPort string, clientOrServer
|
||||||
log.Info("Dial %s", destConn.RemoteAddr().String())
|
log.Info("Dial %s", destConn.RemoteAddr().String())
|
||||||
//tunnel model : [ -->>server ---- client -->> ](this is a tunnel)
|
//tunnel model : [ -->>server ---- client -->> ](this is a tunnel)
|
||||||
if clientOrServer == "client" {
|
if clientOrServer == "client" {
|
||||||
go NewTunnel(listenerConn, destConn, "send").run()
|
go NewTunnel(listenerConn, destConn, SEND).run()
|
||||||
go NewTunnel(destConn, listenerConn, "receive").run()
|
go NewTunnel(destConn, listenerConn, RECEIVE).run()
|
||||||
}
|
}
|
||||||
if clientOrServer == "server" {
|
if clientOrServer == "server" {
|
||||||
go NewTunnel(listenerConn, destConn, "receive").run()
|
go NewTunnel(listenerConn, destConn, RECEIVE).run()
|
||||||
go NewTunnel(destConn, listenerConn, "send").run()
|
go NewTunnel(destConn, listenerConn, SEND).run()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,10 @@ type Tunnel struct {
|
||||||
id string
|
id string
|
||||||
src net.Conn
|
src net.Conn
|
||||||
dest 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{
|
return &Tunnel{
|
||||||
id: tunnelID(),
|
id: tunnelID(),
|
||||||
src: src,
|
src: src,
|
||||||
|
|
@ -66,7 +66,7 @@ func (this *Tunnel) run() { //单向的,从src发送到dest
|
||||||
for {
|
for {
|
||||||
var nByte int
|
var nByte int
|
||||||
var err error
|
var err error
|
||||||
if cipherDirection != "receive" {
|
if cipherDirection != RECEIVE {
|
||||||
revCarrier.Cipher = nil
|
revCarrier.Cipher = nil
|
||||||
nByte, err = tscipher.RowReceiveData(revCarrier)
|
nByte, err = tscipher.RowReceiveData(revCarrier)
|
||||||
} else {
|
} 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.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)
|
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
|
||||||
}
|
}
|
||||||
n, err := tscipher.SendData(sendCarrier, nByte)
|
n, err := tscipher.SendData(sendCarrier, nByte)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue