diff --git a/CHANGELOG b/CHANGELOG index 44ea97c..2210f15 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,9 +2,11 @@ proxy更新日志 v6.6 1.优化了limitconn的关闭逻辑,释放更多资源. -2.http(s)\socks代理增加了--close-intelligent,关闭智能判断, -默认情况下,如果访问的目标不在direct里面,proxy会智能判断是否使用上级访问目标, -现在可以使用参数--close-intelligent关闭这个特性,使不在direct里面的目标都走上级. +2.http(s)\socks代理增加了--intelligent,智能模式设置,可以是intelligent|direct|parent三者之一, +默认是:intelligent.每个值的含义如下. +--intelligent=direct,不在blocked里面的目标都直连. +--intelligent=parent,不在direct里面的目标都走上级. +--intelligent=intelligent,blocked和direct里面都没有的目标,智能判断是否使用上级访问目标. v6.5 1.修复了合并企业版遗留的一些bug. diff --git a/README_ZH.md b/README_ZH.md index 3a4fa02..f38ebb5 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -99,7 +99,8 @@ Proxy是golang实现的高性能http,https,websocket,tcp,udp,socks5,ss代理服 - [1.15 限速](#115-限速) - [1.16 指定出口IP](#116-指定出口ip) - [1.17 证书参数使用base64数据](#117-证书参数使用base64数据) - - [1.18 查看帮助](#118-查看帮助) + - [1.18 智能模式](#118-智能模式) + - [1.19 查看帮助](#119-查看帮助) - [2. TCP代理(端口映射)](#2tcp代理) - [2.1 普通一级TCP代理](#21普通一级tcp代理) - [2.2 普通二级TCP代理](#22普通二级tcp代理) @@ -144,7 +145,8 @@ Proxy是golang实现的高性能http,https,websocket,tcp,udp,socks5,ss代理服 - [5.14 指定出口IP](#514-指定出口ip) - [5.15 级联认证](#515-级联认证) - [5.16 证书参数使用base64数据](#516-证书参数使用base64数据) - - [5.17 查看帮助](#517查看帮助) + - [5.17 智能模式](#517-智能模式) + - [5.18 查看帮助](#518-查看帮助) - [6. 代理协议转换](#6代理协议转换) - [6.1 功能介绍](#61-功能介绍) - [6.2 HTTP(S)转HTTP(S)+SOCKS5+SS](#62-https转httpssocks5ss) @@ -376,11 +378,6 @@ target:用户访问的URL,比如:http://demo.com:80/1.html或https://www.baidu.c #### **1.6.HTTP代理流量强制走上级HTTP代理** 默认情况下,proxy会智能判断一个网站域名是否无法访问,如果无法访问才走上级HTTP代理.通过--always可以使全部HTTP代理流量强制走上级HTTP代理. `./proxy http --always -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key` - -默认情况下,如果访问的目标不在direct里面,proxy会智能判断是否使用上级访问目标. -现在可以使用参数--close-intelligent关闭这个特性,使不在direct里面的目标都走上级. - -`./proxy http --close-intelligent -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key` #### **1.7.HTTP(S)通过SSH中转** ![1.7](/docs/images/http-ssh-1.png) @@ -556,7 +553,15 @@ HTTP(S)代理支持上级负载均衡,多个上级重复-P参数即可. 如果是base64://开头,那么就认为后面的数据是base64编码的,会解码后使用. -#### **1.18 查看帮助** +#### **1.18 智能模式** +智能模式设置,可以是intelligent|direct|parent三者之一. +默认是:intelligent. +每个值的含义如下: +`--intelligent=direct`,不在blocked里面的目标都直连. +`--intelligent=parent`,不在direct里面的目标都走上级. +`--intelligent=intelligent`,blocked和direct里面都没有的目标,智能判断是否使用上级访问目标. + +#### **1.19 查看帮助** `./proxy help http` ### **2.TCP代理** @@ -1035,7 +1040,15 @@ SOCKS5支持级联认证,-A可以设置上级认证信息. 如果是base64://开头,那么就认为后面的数据是base64编码的,会解码后使用. -#### **5.17.查看帮助** +#### **5.17 智能模式** +智能模式设置,可以是intelligent|direct|parent三者之一. +默认是:intelligent. +每个值的含义如下: +`--intelligent=direct`,不在blocked里面的目标都直连. +`--intelligent=parent`,不在direct里面的目标都走上级. +`--intelligent=intelligent`,blocked和direct里面都没有的目标,智能判断是否使用上级访问目标. + +#### **5.18.查看帮助** `./proxy help socks` ### **6.代理协议转换** diff --git a/config.go b/config.go index cfbe9af..620160c 100755 --- a/config.go +++ b/config.go @@ -117,7 +117,7 @@ func initConfig() (err error) { httpArgs.ParentKey = http.Flag("parent-key", "the password for auto encrypt/decrypt parent connection data").Short('Z').Default("").String() httpArgs.LocalCompress = http.Flag("local-compress", "auto compress/decompress data on local connection").Short('m').Default("false").Bool() httpArgs.ParentCompress = http.Flag("parent-compress", "auto compress/decompress data on parent connection").Short('M').Default("false").Bool() - httpArgs.CloseIntelligent = http.Flag("close-intelligent", "close intelligent HTTP, SOCKS5 proxy").Default("false").Bool() + httpArgs.Intelligent = http.Flag("intelligent", "settting intelligent HTTP, SOCKS5 proxy mode, can be ").Default("intelligent").Enmu("intelligent","direct","parent").String() httpArgs.LoadBalanceMethod = http.Flag("lb-method", "load balance method when use multiple parent,can be ").Default("roundrobin").Enum("roundrobin", "weight", "leastconn", "leasttime", "hash") httpArgs.LoadBalanceTimeout = http.Flag("lb-timeout", "tcp milliseconds timeout of connecting to parent").Default("500").Int() httpArgs.LoadBalanceRetryTime = http.Flag("lb-retrytime", "sleep time milliseconds after checking").Default("1000").Int() @@ -254,7 +254,7 @@ func initConfig() (err error) { socksArgs.ParentKey = socks.Flag("parent-key", "the password for auto encrypt/decrypt parent connection data").Short('Z').Default("").String() socksArgs.LocalCompress = socks.Flag("local-compress", "auto compress/decompress data on local connection").Short('m').Default("false").Bool() socksArgs.ParentCompress = socks.Flag("parent-compress", "auto compress/decompress data on parent connection").Short('M').Default("false").Bool() - socksArgs.CloseIntelligent = socks.Flag("close-intelligent", "Close intelligent HTTP, SOCKS5 proxy").Default("false").Bool() + socksArgs.Intelligent = socks.Flag("intelligent", "settting intelligent HTTP, SOCKS5 proxy mode, can be ").Default("intelligent").Enmu("intelligent","direct","parent").String() socksArgs.LoadBalanceMethod = socks.Flag("lb-method", "load balance method when use multiple parent,can be ").Default("roundrobin").Enum("roundrobin", "weight", "leastconn", "leasttime", "hash") socksArgs.LoadBalanceTimeout = socks.Flag("lb-timeout", "tcp milliseconds timeout of connecting to parent").Default("500").Int() socksArgs.LoadBalanceRetryTime = socks.Flag("lb-retrytime", "sleep time milliseconds after checking").Default("1000").Int() diff --git a/sdk/android-ios/sdk.go b/sdk/android-ios/sdk.go index ca25073..8334221 100644 --- a/sdk/android-ios/sdk.go +++ b/sdk/android-ios/sdk.go @@ -134,7 +134,7 @@ func StartWithLog(serviceID, serviceArgsStr string, loggerCallback LogCallback) httpArgs.ParentKey = http.Flag("parent-key", "the password for auto encrypt/decrypt parent connection data").Short('Z').Default("").String() httpArgs.LocalCompress = http.Flag("local-compress", "auto compress/decompress data on local connection").Short('m').Default("false").Bool() httpArgs.ParentCompress = http.Flag("parent-compress", "auto compress/decompress data on parent connection").Short('M').Default("false").Bool() - httpArgs.CloseIntelligent = http.Flag("close-intelligent", "Close intelligent HTTP, SOCKS5 proxy").Default("false").Bool() + httpArgs.Intelligent = http.Flag("intelligent", "settting intelligent HTTP, SOCKS5 proxy mode, can be ").Default("intelligent").Enmu("intelligent", "direct", "parent").String() httpArgs.LoadBalanceMethod = http.Flag("lb-method", "load balance method when use multiple parent,can be ").Default("roundrobin").Enum("roundrobin", "weight", "leastconn", "leasttime", "hash") httpArgs.LoadBalanceTimeout = http.Flag("lb-timeout", "tcp milliseconds timeout of connecting to parent").Default("500").Int() httpArgs.LoadBalanceRetryTime = http.Flag("lb-retrytime", "sleep time milliseconds after checking").Default("1000").Int() @@ -271,7 +271,7 @@ func StartWithLog(serviceID, serviceArgsStr string, loggerCallback LogCallback) socksArgs.ParentKey = socks.Flag("parent-key", "the password for auto encrypt/decrypt parent connection data").Short('Z').Default("").String() socksArgs.LocalCompress = socks.Flag("local-compress", "auto compress/decompress data on local connection").Short('m').Default("false").Bool() socksArgs.ParentCompress = socks.Flag("parent-compress", "auto compress/decompress data on parent connection").Short('M').Default("false").Bool() - socksArgs.CloseIntelligent = socks.Flag("close-intelligent", "Close intelligent HTTP, SOCKS5 proxy").Default("false").Bool() + socksArgs.Intelligent = socks.Flag("intelligent", "settting intelligent HTTP, SOCKS5 proxy mode, can be ").Default("intelligent").Enmu("intelligent", "direct", "parent").String() socksArgs.LoadBalanceMethod = socks.Flag("lb-method", "load balance method when use multiple parent,can be ").Default("roundrobin").Enum("roundrobin", "weight", "leastconn", "leasttime", "hash") socksArgs.LoadBalanceTimeout = socks.Flag("lb-timeout", "tcp milliseconds timeout of connecting to parent").Default("500").Int() socksArgs.LoadBalanceRetryTime = socks.Flag("lb-retrytime", "sleep time milliseconds after checking").Default("1000").Int() diff --git a/services/http/http.go b/services/http/http.go index 37c62c5..b0bd580 100644 --- a/services/http/http.go +++ b/services/http/http.go @@ -66,7 +66,7 @@ type HTTPArgs struct { ParentKey *string LocalCompress *bool ParentCompress *bool - CloseIntelligent *bool + Intelligent *string LoadBalanceMethod *string LoadBalanceTimeout *int LoadBalanceRetryTime *int @@ -186,7 +186,7 @@ func (s *HTTP) InitService() (err error) { s.InitBasicAuth() //init lb if len(*s.cfg.Parent) > 0 { - s.checker = utils.NewChecker(*s.cfg.HTTPTimeout, int64(*s.cfg.Interval), *s.cfg.Blocked, *s.cfg.Direct, s.log, *s.cfg.CloseIntelligent) + s.checker = utils.NewChecker(*s.cfg.HTTPTimeout, int64(*s.cfg.Interval), *s.cfg.Blocked, *s.cfg.Direct, s.log, *s.cfg.Intelligent) s.InitLB() } if *s.cfg.DNSAddress != "" { diff --git a/services/socks/socks.go b/services/socks/socks.go index d5bb09f..142942a 100644 --- a/services/socks/socks.go +++ b/services/socks/socks.go @@ -64,7 +64,7 @@ type SocksArgs struct { ParentKey *string LocalCompress *bool ParentCompress *bool - CloseIntelligent *bool + Intelligent *string LoadBalanceMethod *string LoadBalanceTimeout *int LoadBalanceRetryTime *int @@ -181,7 +181,7 @@ func (s *Socks) InitService() (err error) { (*s).domainResolver = dnsx.NewDomainResolver(*s.cfg.DNSAddress, *s.cfg.DNSTTL, s.log) } if len(*s.cfg.Parent) > 0 { - s.checker = utils.NewChecker(*s.cfg.Timeout, int64(*s.cfg.Interval), *s.cfg.Blocked, *s.cfg.Direct, s.log, *s.cfg.CloseIntelligent) + s.checker = utils.NewChecker(*s.cfg.Timeout, int64(*s.cfg.Interval), *s.cfg.Blocked, *s.cfg.Direct, s.log, *s.cfg.Intelligent) s.InitLB() } if *s.cfg.ParentType == "ssh" { diff --git a/utils/structs.go b/utils/structs.go index c3d84f6..39f1045 100644 --- a/utils/structs.go +++ b/utils/structs.go @@ -24,14 +24,14 @@ import ( ) type Checker struct { - data mapx.ConcurrentMap - blockedMap mapx.ConcurrentMap - directMap mapx.ConcurrentMap - interval int64 - timeout int - isStop bool - closeIntelligent bool - log *logger.Logger + data mapx.ConcurrentMap + blockedMap mapx.ConcurrentMap + directMap mapx.ConcurrentMap + interval int64 + timeout int + isStop bool + intelligent string + log *logger.Logger } type CheckerItem struct { Domain string @@ -44,14 +44,14 @@ type CheckerItem struct { //NewChecker args: //timeout : tcp timeout milliseconds ,connect to host //interval: recheck domain interval seconds -func NewChecker(timeout int, interval int64, blockedFile, directFile string, log *logger.Logger, closeIntelligent bool) Checker { +func NewChecker(timeout int, interval int64, blockedFile, directFile string, log *logger.Logger, intelligent string) Checker { ch := Checker{ - data: mapx.NewConcurrentMap(), - interval: interval, - timeout: timeout, - isStop: false, - closeIntelligent: closeIntelligent, - log: log, + data: mapx.NewConcurrentMap(), + interval: interval, + timeout: timeout, + isStop: false, + intelligent: intelligent, + log: log, } ch.blockedMap = ch.loadMap(blockedFile) ch.directMap = ch.loadMap(directFile) @@ -166,7 +166,12 @@ func (c *Checker) IsBlocked(domain string) (blocked, isInMap bool, failN, succes //log.Printf("%s not in map, blocked true", address) return true, false, 0, 0 } - if !c.closeIntelligent { + switch c.intelligent { + case "direct": + return false, true, 0, 0 + case "parent": + return true, true, 0, 0 + case "intelligent": item := _item.(CheckerItem) return (item.FailCount >= item.SuccessCount) && (time.Now().Unix()-item.Lasttime < 1800), true, item.FailCount, item.SuccessCount }