add close intelligent HTTP, SOCKS5 proxy
为了方便用于代理上网行为管理, 有时候不需要智能判断代理是否可用而进行跳转, 所以增加一个关闭智能跳转代理的参数.
This commit is contained in:
@ -117,6 +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.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.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.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.LoadBalanceMethod = http.Flag("lb-method", "load balance method when use multiple parent,can be <roundrobin|leastconn|leasttime|hash|weight>").Default("roundrobin").Enum("roundrobin", "weight", "leastconn", "leasttime", "hash")
|
httpArgs.LoadBalanceMethod = http.Flag("lb-method", "load balance method when use multiple parent,can be <roundrobin|leastconn|leasttime|hash|weight>").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.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()
|
httpArgs.LoadBalanceRetryTime = http.Flag("lb-retrytime", "sleep time milliseconds after checking").Default("1000").Int()
|
||||||
@ -253,6 +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.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.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.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.LoadBalanceMethod = socks.Flag("lb-method", "load balance method when use multiple parent,can be <roundrobin|leastconn|leasttime|hash|weight>").Default("roundrobin").Enum("roundrobin", "weight", "leastconn", "leasttime", "hash")
|
socksArgs.LoadBalanceMethod = socks.Flag("lb-method", "load balance method when use multiple parent,can be <roundrobin|leastconn|leasttime|hash|weight>").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.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()
|
socksArgs.LoadBalanceRetryTime = socks.Flag("lb-retrytime", "sleep time milliseconds after checking").Default("1000").Int()
|
||||||
|
|||||||
@ -66,6 +66,7 @@ type HTTPArgs struct {
|
|||||||
ParentKey *string
|
ParentKey *string
|
||||||
LocalCompress *bool
|
LocalCompress *bool
|
||||||
ParentCompress *bool
|
ParentCompress *bool
|
||||||
|
CloseIntelligent *bool
|
||||||
LoadBalanceMethod *string
|
LoadBalanceMethod *string
|
||||||
LoadBalanceTimeout *int
|
LoadBalanceTimeout *int
|
||||||
LoadBalanceRetryTime *int
|
LoadBalanceRetryTime *int
|
||||||
@ -185,7 +186,8 @@ func (s *HTTP) InitService() (err error) {
|
|||||||
s.InitBasicAuth()
|
s.InitBasicAuth()
|
||||||
//init lb
|
//init lb
|
||||||
if len(*s.cfg.Parent) > 0 {
|
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.log.Printf("CloseIntelligent: %v", *s.cfg.CloseIntelligent)
|
||||||
|
s.checker = utils.NewChecker(*s.cfg.HTTPTimeout, int64(*s.cfg.Interval), *s.cfg.Blocked, *s.cfg.Direct, s.log, *s.cfg.CloseIntelligent)
|
||||||
s.InitLB()
|
s.InitLB()
|
||||||
}
|
}
|
||||||
if *s.cfg.DNSAddress != "" {
|
if *s.cfg.DNSAddress != "" {
|
||||||
|
|||||||
@ -64,6 +64,7 @@ type SocksArgs struct {
|
|||||||
ParentKey *string
|
ParentKey *string
|
||||||
LocalCompress *bool
|
LocalCompress *bool
|
||||||
ParentCompress *bool
|
ParentCompress *bool
|
||||||
|
CloseIntelligent *bool
|
||||||
LoadBalanceMethod *string
|
LoadBalanceMethod *string
|
||||||
LoadBalanceTimeout *int
|
LoadBalanceTimeout *int
|
||||||
LoadBalanceRetryTime *int
|
LoadBalanceRetryTime *int
|
||||||
@ -180,7 +181,7 @@ func (s *Socks) InitService() (err error) {
|
|||||||
(*s).domainResolver = dnsx.NewDomainResolver(*s.cfg.DNSAddress, *s.cfg.DNSTTL, s.log)
|
(*s).domainResolver = dnsx.NewDomainResolver(*s.cfg.DNSAddress, *s.cfg.DNSTTL, s.log)
|
||||||
}
|
}
|
||||||
if len(*s.cfg.Parent) > 0 {
|
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.checker = utils.NewChecker(*s.cfg.Timeout, int64(*s.cfg.Interval), *s.cfg.Blocked, *s.cfg.Direct, s.log, *s.cfg.CloseIntelligent)
|
||||||
s.InitLB()
|
s.InitLB()
|
||||||
}
|
}
|
||||||
if *s.cfg.ParentType == "ssh" {
|
if *s.cfg.ParentType == "ssh" {
|
||||||
|
|||||||
@ -30,6 +30,7 @@ type Checker struct {
|
|||||||
interval int64
|
interval int64
|
||||||
timeout int
|
timeout int
|
||||||
isStop bool
|
isStop bool
|
||||||
|
closeIntelligent bool
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
}
|
}
|
||||||
type CheckerItem struct {
|
type CheckerItem struct {
|
||||||
@ -43,12 +44,13 @@ type CheckerItem struct {
|
|||||||
//NewChecker args:
|
//NewChecker args:
|
||||||
//timeout : tcp timeout milliseconds ,connect to host
|
//timeout : tcp timeout milliseconds ,connect to host
|
||||||
//interval: recheck domain interval seconds
|
//interval: recheck domain interval seconds
|
||||||
func NewChecker(timeout int, interval int64, blockedFile, directFile string, log *logger.Logger) Checker {
|
func NewChecker(timeout int, interval int64, blockedFile, directFile string, log *logger.Logger, CloseIntelligent bool) Checker {
|
||||||
ch := Checker{
|
ch := Checker{
|
||||||
data: mapx.NewConcurrentMap(),
|
data: mapx.NewConcurrentMap(),
|
||||||
interval: interval,
|
interval: interval,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
isStop: false,
|
isStop: false,
|
||||||
|
closeIntelligent: CloseIntelligent,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
ch.blockedMap = ch.loadMap(blockedFile)
|
ch.blockedMap = ch.loadMap(blockedFile)
|
||||||
@ -164,9 +166,11 @@ func (c *Checker) IsBlocked(domain string) (blocked, isInMap bool, failN, succes
|
|||||||
//log.Printf("%s not in map, blocked true", address)
|
//log.Printf("%s not in map, blocked true", address)
|
||||||
return true, false, 0, 0
|
return true, false, 0, 0
|
||||||
}
|
}
|
||||||
|
if !c.closeIntelligent {
|
||||||
item := _item.(CheckerItem)
|
item := _item.(CheckerItem)
|
||||||
|
|
||||||
return (item.FailCount >= item.SuccessCount) && (time.Now().Unix()-item.Lasttime < 1800), true, item.FailCount, item.SuccessCount
|
return (item.FailCount >= item.SuccessCount) && (time.Now().Unix()-item.Lasttime < 1800), true, item.FailCount, item.SuccessCount
|
||||||
|
}
|
||||||
|
return true, false, 0, 0
|
||||||
}
|
}
|
||||||
func (c *Checker) domainIsInMap(address string, blockedMap bool) bool {
|
func (c *Checker) domainIsInMap(address string, blockedMap bool) bool {
|
||||||
u, err := url.Parse("http://" + address)
|
u, err := url.Parse("http://" + address)
|
||||||
|
|||||||
Reference in New Issue
Block a user