add observePeriod option for observer
This commit is contained in:
@ -14,9 +14,9 @@ import (
|
||||
"github.com/go-gost/gosocks4"
|
||||
ctxvalue "github.com/go-gost/x/ctx"
|
||||
netpkg "github.com/go-gost/x/internal/net"
|
||||
stats_util "github.com/go-gost/x/internal/util/stats"
|
||||
"github.com/go-gost/x/limiter/traffic/wrapper"
|
||||
"github.com/go-gost/x/registry"
|
||||
stats_util "github.com/go-gost/x/internal/util/stats"
|
||||
"github.com/go-gost/x/stats"
|
||||
stats_wrapper "github.com/go-gost/x/stats/wrapper"
|
||||
)
|
||||
@ -218,7 +218,11 @@ func (h *socks4Handler) observeStats(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
d := h.md.observePeriod
|
||||
if d < time.Millisecond {
|
||||
d = 5 * time.Second
|
||||
}
|
||||
ticker := time.NewTicker(d)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
|
@ -8,17 +8,14 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
readTimeout time.Duration
|
||||
hash string
|
||||
readTimeout time.Duration
|
||||
hash string
|
||||
observePeriod time.Duration
|
||||
}
|
||||
|
||||
func (h *socks4Handler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
readTimeout = "readTimeout"
|
||||
hash = "hash"
|
||||
)
|
||||
|
||||
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
|
||||
h.md.hash = mdutil.GetString(md, hash)
|
||||
h.md.readTimeout = mdutil.GetDuration(md, "readTimeout")
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user