parent
fff90f7057
commit
da0e77d74c
|
|
@ -3,3 +3,4 @@ TransX
|
|||
server.log*
|
||||
client.log*
|
||||
applog
|
||||
profile
|
||||
17
benckmark.go
17
benckmark.go
|
|
@ -58,19 +58,26 @@ func randMillionSecond() time.Duration {
|
|||
|
||||
func attack() {
|
||||
c := make(chan int)
|
||||
for i := 0; i < 1; i++ {
|
||||
for i := 0; i < 10; i++ {
|
||||
time.Sleep(time.Millisecond * randMillionSecond())
|
||||
go doHttp(c)
|
||||
}
|
||||
for i := 0; i < 1; i++ {
|
||||
for i := 0; i < 10; i++ {
|
||||
<-c
|
||||
}
|
||||
log.Println("Finish")
|
||||
}
|
||||
|
||||
func main() {
|
||||
llog.LogTo("applog/log.txt", "INFO")
|
||||
defer profile.Start(profile.CPUProfile).Stop()
|
||||
func main1() {
|
||||
cfg := profile.Config{
|
||||
MemProfile: true,
|
||||
ProfilePath: "./profile", // store profiles in current directory
|
||||
NoShutdownHook: true, // do not hook SIGINT
|
||||
CPUProfile: true,
|
||||
BlockProfile: true,
|
||||
}
|
||||
llog.LogTo("applog/log.txt", "ERROR")
|
||||
defer profile.Start(&cfg).Stop()
|
||||
benchSeed = 0
|
||||
go transClient()
|
||||
go transServer()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ var DestPort int
|
|||
var ListenPort int
|
||||
var EncryptSide string
|
||||
var LogTo string
|
||||
var ProfilePort int
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&DestIP, "destip", "", "Destination IP")
|
||||
|
|
@ -16,4 +17,5 @@ func init() {
|
|||
flag.StringVar(&LogTo, "log", "stdout", "Log to where")
|
||||
flag.IntVar(&DestPort, "destport", 0, "Destination Port")
|
||||
flag.IntVar(&ListenPort, "listenport", 0, "Listen Port")
|
||||
flag.IntVar(&ProfilePort, "profileport", 0, "Profile Port")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
.\TransX -destip 127.0.0.1 -destport 1082 -listenport 1080 -encrypt client -log applog/client.log
|
||||
.\TransX -destip 127.0.0.1 -destport 1082 -listenport 1080 -encrypt client -log applog/client.log -profileport 6062
|
||||
15
main.go
15
main.go
|
|
@ -7,7 +7,9 @@ import (
|
|||
"github.com/TransX/cli"
|
||||
"github.com/TransX/log"
|
||||
"github.com/TransX/protocol"
|
||||
"github.com/davecheney/profile"
|
||||
// "github.com/davecheney/profile"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
@ -23,10 +25,15 @@ func tunnel() {
|
|||
|
||||
}
|
||||
|
||||
func main1() {
|
||||
defer profile.Start(profile.CPUProfile).Stop()
|
||||
func main() {
|
||||
// defer profile.Start(profile.CPUProfile).Stop()
|
||||
flag.Parse()
|
||||
fmt.Println("Hello World!")
|
||||
log.LogTo(cli.LogTo, "INFO")
|
||||
log.LogTo(cli.LogTo, "ERROR")
|
||||
if cli.ProfilePort != 0 {
|
||||
go func() {
|
||||
http.ListenAndServe("0.0.0.0:"+strconv.Itoa(cli.ProfilePort), nil)
|
||||
}()
|
||||
}
|
||||
tunnel()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ func (this *TransTCP) Start(listenPort, destIP, destPort string, clientOrServer
|
|||
}()
|
||||
|
||||
} else {
|
||||
log.Info("Failed to accept incoming connection. %s", err)
|
||||
log.Error("Failed to accept incoming connection. %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func (this *Tunnel) Run() { //单向的,从src发送到dest
|
|||
cipherDirection := this.cipherDirection
|
||||
id := this.id
|
||||
defer func() {
|
||||
log.Info("tunnel id %s ends", id)
|
||||
log.Debug("tunnel id %s ends", id)
|
||||
//注销
|
||||
this.unregChan <- this
|
||||
if r := recover(); r != nil {
|
||||
|
|
@ -89,7 +89,7 @@ func (this *Tunnel) Run() { //单向的,从src发送到dest
|
|||
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())
|
||||
}
|
||||
log.Info("Reived %d bytes from %s. Tunnel: id %s", nByte, src.RemoteAddr().String(), id)
|
||||
log.Debug("Reived %d bytes from %s. Tunnel: id %s", nByte, src.RemoteAddr().String(), id)
|
||||
if cipherDirection != SEND {
|
||||
sendCarrier.Cipher = nil
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ func (this *Tunnel) Run() { //单向的,从src发送到dest
|
|||
if err != nil {
|
||||
log.Panic("Write panic. ID: %s, Err: %s, Remote Add: %s", id, err, dest.RemoteAddr().String())
|
||||
}
|
||||
log.Info("Write %d bytes from %s to %s. Tunnel: %s . 18 bytes %x", n, dest.LocalAddr(), dest.RemoteAddr().String(), id, sendCarrier.Cache[:18])
|
||||
log.Debug("Write %d bytes from %s to %s. Tunnel: %s . 18 bytes %x", n, dest.LocalAddr(), dest.RemoteAddr().String(), id, sendCarrier.Cache[:18])
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
.\TransX -destip 127.0.0.1 -destport 1084 -listenport 1082 -encrypt server -log applog/server.log
|
||||
.\TransX -destip 127.0.0.1 -destport 1084 -listenport 1082 -encrypt server -log applog/server.log -profileport 6060
|
||||
|
|
@ -54,11 +54,11 @@ func (this *TunnelStatusManager) chanListener() {
|
|||
select {
|
||||
case r := <-this.regChan:
|
||||
this.register(r)
|
||||
log.Info("A tunnel registered")
|
||||
log.Info(this.QueryStatString())
|
||||
log.Debug("A tunnel registered")
|
||||
log.Debug(this.QueryStatString())
|
||||
case ur := <-this.unregChan:
|
||||
this.unregister(ur)
|
||||
log.Info("A tunnel unregistered")
|
||||
log.Debug("A tunnel unregistered")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ func SendData(carrier *Carrier, nByte int) (n int, err error) {
|
|||
//打包
|
||||
wraped := WrapPackage(encrypedByte[:nByte])
|
||||
n, err = carrier.Conn.Write(wraped)
|
||||
log.Info("Ready to write id %s, 18 byte %s", carrier.AttachedTunnelID, string(wraped[:18]))
|
||||
log.Debug("Ready to write id %s, 18 byte %s", carrier.AttachedTunnelID, string(wraped[:18]))
|
||||
copy(carrier.Cache, encrypedByte[:nByte]) // in case of debugging
|
||||
return
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ func ReceiveData(carrier *Carrier) (n int, err error) {
|
|||
// log.Error("ReceiveData err %s", r)
|
||||
// }
|
||||
// }()
|
||||
log.Info("id %s wrapedPackage := carrier.GetReceiveBuff()", carrier.AttachedTunnelID)
|
||||
log.Debug("id %s wrapedPackage := carrier.GetReceiveBuff()", carrier.AttachedTunnelID)
|
||||
wrapedPackage := carrier.GetReceiveBuff() //make([]byte, 0, cap(carrier.Cache))
|
||||
var packageData []byte
|
||||
var _rest []byte
|
||||
|
|
@ -191,11 +191,11 @@ func ReceiveData(carrier *Carrier) (n int, err error) {
|
|||
log.Debug("id %s length of package %d", carrier.AttachedTunnelID, len(packageData))
|
||||
if err == nil {
|
||||
//够一个完整的包
|
||||
log.Info("id %s capBuff := cap(carrier.GetReceiveBuff())", carrier.AttachedTunnelID)
|
||||
log.Debug("id %s capBuff := cap(carrier.GetReceiveBuff())", carrier.AttachedTunnelID)
|
||||
capBuff := cap(carrier.GetReceiveBuff())
|
||||
_buff := make([]byte, 0, capBuff) //释放
|
||||
_buff = append(_buff, _rest...)
|
||||
log.Info("id %s carrier.SetReceiveBuff(_buff)", carrier.AttachedTunnelID)
|
||||
log.Debug("id %s carrier.SetReceiveBuff(_buff)", carrier.AttachedTunnelID)
|
||||
carrier.SetReceiveBuff(_buff)
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue