2015-10-08 20:40:36 +08:00
|
|
|
// main.go
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2015-10-17 23:14:43 +08:00
|
|
|
"flag"
|
2015-10-08 20:40:36 +08:00
|
|
|
"fmt"
|
2015-10-17 23:14:43 +08:00
|
|
|
"github.com/TransX/cli"
|
2015-10-16 23:21:38 +08:00
|
|
|
"github.com/TransX/log"
|
2015-11-18 23:16:57 +08:00
|
|
|
"github.com/TransX/protocol"
|
2015-11-20 17:31:32 +08:00
|
|
|
// "github.com/davecheney/profile"
|
|
|
|
|
"net/http"
|
|
|
|
|
_ "net/http/pprof"
|
2015-10-17 23:14:43 +08:00
|
|
|
"strconv"
|
2015-10-08 20:40:36 +08:00
|
|
|
)
|
|
|
|
|
|
2015-10-17 23:14:43 +08:00
|
|
|
func tunnel() {
|
2015-11-18 23:16:57 +08:00
|
|
|
trans := protocol.NewTransTCP()
|
2015-10-18 17:44:56 +08:00
|
|
|
log.Info("%s side is encrypted.", cli.EncryptSide)
|
2015-10-17 23:14:43 +08:00
|
|
|
if cli.DestPort != 0 {
|
2015-10-21 12:04:07 +08:00
|
|
|
log.Info("Listening on 0.0.0.0:%d. Forward %s:%d", cli.ListenPort, cli.DestIP, cli.DestPort)
|
2015-10-18 17:44:56 +08:00
|
|
|
trans.Start(strconv.Itoa(cli.ListenPort), cli.DestIP, strconv.Itoa(cli.DestPort), cli.EncryptSide)
|
2015-10-17 23:14:43 +08:00
|
|
|
} else {
|
2015-10-18 17:44:56 +08:00
|
|
|
trans.Start("1200", "192.168.0.120", "8118", "client")
|
2015-10-17 23:14:43 +08:00
|
|
|
}
|
|
|
|
|
|
2015-10-10 18:28:19 +08:00
|
|
|
}
|
|
|
|
|
|
2016-01-31 12:32:41 +08:00
|
|
|
func main() {
|
2015-11-20 17:31:32 +08:00
|
|
|
// defer profile.Start(profile.CPUProfile).Stop()
|
2015-10-17 23:14:43 +08:00
|
|
|
flag.Parse()
|
2015-10-24 16:07:23 +08:00
|
|
|
fmt.Println("Hello World!")
|
2015-11-21 16:54:04 +08:00
|
|
|
log.LogTo(cli.LogTo, "INFO")
|
2015-11-20 17:31:32 +08:00
|
|
|
if cli.ProfilePort != 0 {
|
|
|
|
|
go func() {
|
|
|
|
|
http.ListenAndServe("0.0.0.0:"+strconv.Itoa(cli.ProfilePort), nil)
|
|
|
|
|
}()
|
|
|
|
|
}
|
2015-10-17 23:14:43 +08:00
|
|
|
tunnel()
|
2015-10-08 20:40:36 +08:00
|
|
|
}
|