add limiterRefreshInterval option for limiter
This commit is contained in:
@@ -75,7 +75,7 @@ func (h *socks5Handler) Init(md md.Metadata) (err error) {
|
||||
}
|
||||
|
||||
if limiter := h.options.Limiter; limiter != nil {
|
||||
h.limiter = limiter_util.NewCachedTrafficLimiter(limiter, 30*time.Second, 60*time.Second)
|
||||
h.limiter = limiter_util.NewCachedTrafficLimiter(limiter, h.md.limiterRefreshInterval, 60*time.Second)
|
||||
}
|
||||
|
||||
for _, ro := range h.options.Recorders {
|
||||
@@ -216,11 +216,7 @@ func (h *socks5Handler) observeStats(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
d := h.md.observePeriod
|
||||
if d < time.Millisecond {
|
||||
d = 5 * time.Second
|
||||
}
|
||||
ticker := time.NewTicker(d)
|
||||
ticker := time.NewTicker(h.md.observePeriod)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
|
||||
@@ -15,15 +15,16 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
readTimeout time.Duration
|
||||
noTLS bool
|
||||
enableBind bool
|
||||
enableUDP bool
|
||||
udpBufferSize int
|
||||
compatibilityMode bool
|
||||
hash string
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
readTimeout time.Duration
|
||||
noTLS bool
|
||||
enableBind bool
|
||||
enableUDP bool
|
||||
udpBufferSize int
|
||||
compatibilityMode bool
|
||||
hash string
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
|
||||
sniffing bool
|
||||
sniffingTimeout time.Duration
|
||||
@@ -65,7 +66,21 @@ func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
MaxStreamBuffer: mdutil.GetInt(md, "mux.maxStreamBuffer"),
|
||||
}
|
||||
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod", "observer.observePeriod")
|
||||
if h.md.observePeriod == 0 {
|
||||
h.md.observePeriod = 5 * time.Second
|
||||
}
|
||||
if h.md.observePeriod < time.Second {
|
||||
h.md.observePeriod = time.Second
|
||||
}
|
||||
|
||||
h.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if h.md.limiterRefreshInterval == 0 {
|
||||
h.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if h.md.limiterRefreshInterval < time.Second {
|
||||
h.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
h.md.sniffing = mdutil.GetBool(md, "sniffing")
|
||||
h.md.sniffingTimeout = mdutil.GetDuration(md, "sniffing.timeout")
|
||||
|
||||
Reference in New Issue
Block a user