From ca2f3679500834f467ade659e2372d664d1aba11 Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Fri, 27 Oct 2017 15:59:49 +0800 Subject: [PATCH] Signed-off-by: arraykeys@gmail.com --- CHANGELOG | 3 +++ README.md | 4 ++-- config.go | 8 +++++--- services/args.go | 15 +++++++++++---- services/http.go | 2 +- services/tcp.go | 18 ++++++++++++------ 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bcd3346..de63afb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ proxy更新日志 +v3.4 +1.tcp代理增加了kcp协议传输数据. + v3.4 1.socks5代理新增了用户名密码验证支持. 2.socks5,http(s)代理增加了kcp传输协议支持. diff --git a/README.md b/README.md index 20766ed..238a16e 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Proxy是golang实现的高性能http,https,websocket,tcp,udp,socks5代理服务 - 跨平台性,无论你是widows,linux,还是mac,甚至是树莓派,都可以很好的运行proxy. - 多协议支持,支持HTTP(S),TCP,UDP,Websocket,SOCKS5代理. - 支持内网穿透,协议支持TCP和UDP. -- HTTP(S),SOCKS5代理支持SSH中转,上级Linux服务器不需要任何服务端,本地一个proxy即可开心上网. -- HTTP(S),SOCKS5代理支持[KCP](https://github.com/xtaci/kcp-go)协议传输数据,降低延迟,提升浏览体验. +- SSH中转,HTTP(S),SOCKS5代理支持SSH中转,上级Linux服务器不需要任何服务端,本地一个proxy即可开心上网. +- 支持[KCP](https://github.com/xtaci/kcp-go)协议,HTTP(S),SOCKS5代理支持KCP协议传输数据,降低延迟,提升浏览体验. ### Why need these? - 当由于安全因素或者限制,我们不能顺畅的访问我们在其它地方的服务,我们可以通过多个相连的proxy节点建立起一个安全的隧道,顺畅的访问我们的服务. diff --git a/config.go b/config.go index 0e4516d..ebacbd4 100755 --- a/config.go +++ b/config.go @@ -66,12 +66,14 @@ func initConfig() (err error) { tcpArgs.Parent = tcp.Flag("parent", "parent address, such as: \"23.32.32.19:28008\"").Default("").Short('P').String() tcpArgs.CertFile = tcp.Flag("cert", "cert file for tls").Short('C').Default("proxy.crt").String() tcpArgs.KeyFile = tcp.Flag("key", "key file for tls").Short('K').Default("proxy.key").String() - tcpArgs.Timeout = tcp.Flag("timeout", "tcp timeout milliseconds when connect to real server or parent proxy").Short('t').Default("2000").Int() - tcpArgs.ParentType = tcp.Flag("parent-type", "parent protocol type ").Short('T').Enum("tls", "tcp", "udp") - tcpArgs.IsTLS = tcp.Flag("tls", "proxy on tls mode").Default("false").Bool() + tcpArgs.Timeout = tcp.Flag("timeout", "tcp timeout milliseconds when connect to real server or parent proxy").Short('e').Default("2000").Int() + tcpArgs.ParentType = tcp.Flag("parent-type", "parent protocol type ").Short('T').Enum("tls", "tcp", "udp", "kcp") + tcpArgs.LocalType = tcp.Flag("local-type", "local protocol type ").Default("tcp").Short('t').Enum("tls", "tcp", "kcp") tcpArgs.PoolSize = tcp.Flag("pool-size", "conn pool size , which connect to parent proxy, zero: means turn off pool").Short('L').Default("0").Int() tcpArgs.CheckParentInterval = tcp.Flag("check-parent-interval", "check if proxy is okay every interval seconds,zero: means no check").Short('I').Default("3").Int() tcpArgs.Local = tcp.Flag("local", "local ip:port to listen").Short('p').Default(":33080").String() + tcpArgs.KCPKey = tcp.Flag("kcp-key", "key for kcp encrypt/decrypt data").Short('B').Default("encrypt").String() + tcpArgs.KCPMethod = tcp.Flag("kcp-method", "kcp encrypt/decrypt method").Short('M').Default("3des").String() //########udp######### udp := app.Command("udp", "proxy on udp mode") diff --git a/services/args.go b/services/args.go index 1c21461..6a3106c 100644 --- a/services/args.go +++ b/services/args.go @@ -58,10 +58,12 @@ type TCPArgs struct { KeyBytes []byte Local *string ParentType *string - IsTLS *bool + LocalType *string Timeout *int PoolSize *int CheckParentInterval *int + KCPMethod *string + KCPKey *string } type HTTPArgs struct { @@ -133,8 +135,13 @@ type SocksArgs struct { } func (a *TCPArgs) Protocol() string { - if *a.IsTLS { - return "tls" + switch *a.LocalType { + case TYPE_TLS: + return TYPE_TLS + case TYPE_TCP: + return TYPE_TCP + case TYPE_KCP: + return TYPE_KCP } - return "tcp" + return "unknown" } diff --git a/services/http.go b/services/http.go index eea3267..4d3e0bf 100644 --- a/services/http.go +++ b/services/http.go @@ -223,7 +223,7 @@ func (s *HTTP) OutToTCP(useProxy bool, address string, inConn *net.Conn, req *ut } outAddr := outConn.RemoteAddr().String() - outLocalAddr := outConn.LocalAddr().String() + //outLocalAddr := outConn.LocalAddr().String() if req.IsHTTPS() && (!useProxy || *s.cfg.ParentType == "ssh") { //https无上级或者上级非代理,proxy需要响应connect请求,并直连目标 diff --git a/services/tcp.go b/services/tcp.go index a11b4f2..d90f1f4 100644 --- a/services/tcp.go +++ b/services/tcp.go @@ -29,9 +29,9 @@ func (s *TCP) CheckArgs() { log.Fatalf("parent required for %s %s", s.cfg.Protocol(), *s.cfg.Local) } if *s.cfg.ParentType == "" { - log.Fatalf("parent type unkown,use -T ") + log.Fatalf("parent type unkown,use -T ") } - if *s.cfg.ParentType == "tls" || *s.cfg.IsTLS { + if *s.cfg.ParentType == TYPE_TLS || *s.cfg.LocalType == TYPE_TLS { s.cfg.CertBytes, s.cfg.KeyBytes = utils.TlsBytes(*s.cfg.CertFile, *s.cfg.KeyFile) } } @@ -52,10 +52,13 @@ func (s *TCP) Start(args interface{}) (err error) { host, port, _ := net.SplitHostPort(*s.cfg.Local) p, _ := strconv.Atoi(port) sc := utils.NewServerChannel(host, p) - if !*s.cfg.IsTLS { + + if *s.cfg.LocalType == TYPE_TCP { err = sc.ListenTCP(s.callback) - } else { + } else if *s.cfg.LocalType == TYPE_TLS { err = sc.ListenTls(s.cfg.CertBytes, s.cfg.KeyBytes, s.callback) + } else if *s.cfg.LocalType == TYPE_KCP { + err = sc.ListenKCP(*s.cfg.KCPMethod, *s.cfg.KCPKey, s.callback) } if err != nil { return @@ -75,6 +78,8 @@ func (s *TCP) callback(inConn net.Conn) { }() var err error switch *s.cfg.ParentType { + case TYPE_KCP: + fallthrough case TYPE_TCP: fallthrough case TYPE_TLS: @@ -162,13 +167,14 @@ func (s *TCP) OutToUDP(inConn *net.Conn) (err error) { } func (s *TCP) InitOutConnPool() { - if *s.cfg.ParentType == TYPE_TLS || *s.cfg.ParentType == TYPE_TCP { + if *s.cfg.ParentType == TYPE_TLS || *s.cfg.ParentType == TYPE_TCP || *s.cfg.ParentType == TYPE_KCP { //dur int, isTLS bool, certBytes, keyBytes []byte, //parent string, timeout int, InitialCap int, MaxCap int s.outPool = utils.NewOutPool( *s.cfg.CheckParentInterval, *s.cfg.ParentType, - "", "", + *s.cfg.KCPMethod, + *s.cfg.KCPKey, s.cfg.CertBytes, s.cfg.KeyBytes, *s.cfg.Parent, *s.cfg.Timeout,