mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
pool: added a function to init bufPools
This commit is contained in:
parent
0b0611a0dc
commit
b74880ae7a
@ -4,29 +4,21 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var bufSizes = [...]int{
|
var bufSizes = []int{
|
||||||
1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9,
|
1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9,
|
||||||
1 << 10, 2 << 10, 4 << 10, 8 << 10, 16 << 10, 32 << 10, 64 << 10,
|
1 << 10, 2 << 10, 4 << 10, 8 << 10, 16 << 10, 32 << 10, 64 << 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
var bufPools = [...]sync.Pool{
|
var bufPools = initPools(bufSizes)
|
||||||
{New: func() interface{} { return make([]byte, 1<<0) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 1<<1) }},
|
func initPools(sizes []int) []sync.Pool {
|
||||||
{New: func() interface{} { return make([]byte, 1<<2) }},
|
pools := make([]sync.Pool, len(sizes))
|
||||||
{New: func() interface{} { return make([]byte, 1<<3) }},
|
for k := range pools {
|
||||||
{New: func() interface{} { return make([]byte, 1<<4) }},
|
pools[k].New = func() interface{} {
|
||||||
{New: func() interface{} { return make([]byte, 1<<5) }},
|
return make([]byte, sizes[k])
|
||||||
{New: func() interface{} { return make([]byte, 1<<6) }},
|
}
|
||||||
{New: func() interface{} { return make([]byte, 1<<7) }},
|
}
|
||||||
{New: func() interface{} { return make([]byte, 1<<8) }},
|
return pools
|
||||||
{New: func() interface{} { return make([]byte, 1<<9) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 1<<10) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 2<<10) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 4<<10) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 8<<10) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 16<<10) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 32<<10) }},
|
|
||||||
{New: func() interface{} { return make([]byte, 64<<10) }},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuffer(size int) []byte {
|
func GetBuffer(size int) []byte {
|
||||||
|
2
conf.go
2
conf.go
@ -43,7 +43,7 @@ func confInit() {
|
|||||||
flag.StringVar(&conf.StrategyConfig.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
|
flag.StringVar(&conf.StrategyConfig.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
|
||||||
flag.IntVar(&conf.StrategyConfig.CheckInterval, "checkinterval", 30, "proxy check interval(seconds)")
|
flag.IntVar(&conf.StrategyConfig.CheckInterval, "checkinterval", 30, "proxy check interval(seconds)")
|
||||||
flag.IntVar(&conf.StrategyConfig.CheckTimeout, "checktimeout", 10, "proxy check timeout(seconds)")
|
flag.IntVar(&conf.StrategyConfig.CheckTimeout, "checktimeout", 10, "proxy check timeout(seconds)")
|
||||||
flag.BoolVar(&conf.StrategyConfig.CheckFailedOnly, "checkfailedonly", false, "check failed fowarder only")
|
flag.BoolVar(&conf.StrategyConfig.CheckDisabledOnly, "checkdisabledonly", false, "check disabled fowarders only")
|
||||||
flag.IntVar(&conf.StrategyConfig.MaxFailures, "maxfailures", 3, "max failures to change forwarder status to disabled")
|
flag.IntVar(&conf.StrategyConfig.MaxFailures, "maxfailures", 3, "max failures to change forwarder status to disabled")
|
||||||
flag.StringVar(&conf.StrategyConfig.IntFace, "interface", "", "source ip or source interface")
|
flag.StringVar(&conf.StrategyConfig.IntFace, "interface", "", "source ip or source interface")
|
||||||
|
|
||||||
|
@ -158,9 +158,12 @@ checkwebsite=www.apple.com
|
|||||||
# check interval(seconds)
|
# check interval(seconds)
|
||||||
checkinterval=30
|
checkinterval=30
|
||||||
|
|
||||||
# check timeout(seconds)
|
# timeout to set a forwarder to be disabled(seconds)
|
||||||
checktimeout=10
|
checktimeout=10
|
||||||
|
|
||||||
|
# check disabled fowarders only
|
||||||
|
checkdisabledonly=false
|
||||||
|
|
||||||
# DNS FORWARDING SERVER
|
# DNS FORWARDING SERVER
|
||||||
# ----------------
|
# ----------------
|
||||||
# we can specify different upstream dns server in rule file for different destinations
|
# we can specify different upstream dns server in rule file for different destinations
|
||||||
|
@ -118,7 +118,8 @@ func parseFirstLine(line string) (r1, r2, r3 string, ok bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateClientKey() string {
|
func generateClientKey() string {
|
||||||
p := make([]byte, 16)
|
p := pool.GetBuffer(16)
|
||||||
|
defer pool.PutBuffer(p)
|
||||||
rand.Read(p)
|
rand.Read(p)
|
||||||
return base64.StdEncoding.EncodeToString(p)
|
return base64.StdEncoding.EncodeToString(p)
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ import (
|
|||||||
|
|
||||||
// Config is strategy config struct.
|
// Config is strategy config struct.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Strategy string
|
Strategy string
|
||||||
CheckWebSite string
|
CheckWebSite string
|
||||||
CheckInterval int
|
CheckInterval int
|
||||||
CheckTimeout int
|
CheckTimeout int
|
||||||
CheckFailedOnly bool
|
CheckDisabledOnly bool
|
||||||
MaxFailures int
|
MaxFailures int
|
||||||
IntFace string
|
IntFace string
|
||||||
}
|
}
|
||||||
|
|
||||||
// forwarder slice orderd by priority
|
// forwarder slice orderd by priority
|
||||||
@ -204,7 +204,7 @@ func (p *Proxy) check(f *Forwarder) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Enabled() && p.config.CheckFailedOnly {
|
if f.Enabled() && p.config.CheckDisabledOnly {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user