add observePeriod option for observer
This commit is contained in:
@ -452,7 +452,11 @@ func (h *httpHandler) 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 {
|
||||
|
@ -3,6 +3,7 @@ package http
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/core/metadata/util"
|
||||
@ -18,20 +19,11 @@ type metadata struct {
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
observePeriod time.Duration
|
||||
}
|
||||
|
||||
func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
|
||||
const (
|
||||
header = "header"
|
||||
probeResistKey = "probeResistance"
|
||||
probeResistKeyX = "probe_resist"
|
||||
knock = "knock"
|
||||
enableUDP = "udp"
|
||||
hash = "hash"
|
||||
authBasicRealm = "authBasicRealm"
|
||||
)
|
||||
|
||||
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
|
||||
if m := mdutil.GetStringMapString(md, "http.header", "header"); len(m) > 0 {
|
||||
hd := http.Header{}
|
||||
for k, v := range m {
|
||||
hd.Add(k, v)
|
||||
@ -39,22 +31,20 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
|
||||
h.md.header = hd
|
||||
}
|
||||
|
||||
pr := mdutil.GetString(md, probeResistKey)
|
||||
if pr == "" {
|
||||
pr = mdutil.GetString(md, probeResistKeyX)
|
||||
}
|
||||
if pr != "" {
|
||||
if pr := mdutil.GetString(md, "probeResist", "probe_resist"); pr != "" {
|
||||
if ss := strings.SplitN(pr, ":", 2); len(ss) == 2 {
|
||||
h.md.probeResistance = &probeResistance{
|
||||
Type: ss[0],
|
||||
Value: ss[1],
|
||||
Knock: mdutil.GetString(md, knock),
|
||||
Knock: mdutil.GetString(md, "knock"),
|
||||
}
|
||||
}
|
||||
}
|
||||
h.md.enableUDP = mdutil.GetBool(md, enableUDP)
|
||||
h.md.hash = mdutil.GetString(md, hash)
|
||||
h.md.authBasicRealm = mdutil.GetString(md, authBasicRealm)
|
||||
h.md.enableUDP = mdutil.GetBool(md, "udp")
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
h.md.authBasicRealm = mdutil.GetString(md, "authBasicRealm")
|
||||
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -419,7 +419,11 @@ func (h *http2Handler) 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 {
|
||||
|
@ -3,6 +3,7 @@ package http2
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/core/metadata/util"
|
||||
@ -17,19 +18,11 @@ type metadata struct {
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
observePeriod time.Duration
|
||||
}
|
||||
|
||||
func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
|
||||
const (
|
||||
header = "header"
|
||||
probeResistKey = "probeResistance"
|
||||
probeResistKeyX = "probe_resist"
|
||||
knock = "knock"
|
||||
hash = "hash"
|
||||
authBasicRealm = "authBasicRealm"
|
||||
)
|
||||
|
||||
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
|
||||
if m := mdutil.GetStringMapString(md, "http.header", "header"); len(m) > 0 {
|
||||
hd := http.Header{}
|
||||
for k, v := range m {
|
||||
hd.Add(k, v)
|
||||
@ -37,21 +30,19 @@ func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
|
||||
h.md.header = hd
|
||||
}
|
||||
|
||||
pr := mdutil.GetString(md, probeResistKey)
|
||||
if pr == "" {
|
||||
pr = mdutil.GetString(md, probeResistKeyX)
|
||||
}
|
||||
if pr != "" {
|
||||
if pr := mdutil.GetString(md, "probeResist", "probe_resist"); pr != "" {
|
||||
if ss := strings.SplitN(pr, ":", 2); len(ss) == 2 {
|
||||
h.md.probeResistance = &probeResistance{
|
||||
Type: ss[0],
|
||||
Value: ss[1],
|
||||
Knock: mdutil.GetString(md, knock),
|
||||
Knock: mdutil.GetString(md, "knock"),
|
||||
}
|
||||
}
|
||||
}
|
||||
h.md.hash = mdutil.GetString(md, hash)
|
||||
h.md.authBasicRealm = mdutil.GetString(md, authBasicRealm)
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
h.md.authBasicRealm = mdutil.GetString(md, "authBasicRealm")
|
||||
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -204,7 +204,11 @@ func (h *relayHandler) 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 {
|
||||
|
@ -16,28 +16,21 @@ type metadata struct {
|
||||
noDelay bool
|
||||
hash string
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
}
|
||||
|
||||
func (h *relayHandler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
readTimeout = "readTimeout"
|
||||
enableBind = "bind"
|
||||
udpBufferSize = "udpBufferSize"
|
||||
noDelay = "nodelay"
|
||||
hash = "hash"
|
||||
)
|
||||
h.md.readTimeout = mdutil.GetDuration(md, "readTimeout")
|
||||
h.md.enableBind = mdutil.GetBool(md, "bind")
|
||||
h.md.noDelay = mdutil.GetBool(md, "nodelay")
|
||||
|
||||
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
|
||||
h.md.enableBind = mdutil.GetBool(md, enableBind)
|
||||
h.md.noDelay = mdutil.GetBool(md, noDelay)
|
||||
|
||||
if bs := mdutil.GetInt(md, udpBufferSize); bs > 0 {
|
||||
if bs := mdutil.GetInt(md, "udpBufferSize"); bs > 0 {
|
||||
h.md.udpBufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
|
||||
} else {
|
||||
h.md.udpBufferSize = 4096
|
||||
}
|
||||
|
||||
h.md.hash = mdutil.GetString(md, hash)
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
|
||||
h.md.muxCfg = &mux.Config{
|
||||
Version: mdutil.GetInt(md, "mux.version"),
|
||||
@ -49,5 +42,7 @@ func (h *relayHandler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
MaxStreamBuffer: mdutil.GetInt(md, "mux.maxStreamBuffer"),
|
||||
}
|
||||
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -160,7 +160,11 @@ func (h *socks5Handler) 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 {
|
||||
|
@ -18,32 +18,23 @@ type metadata struct {
|
||||
compatibilityMode bool
|
||||
hash string
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
}
|
||||
|
||||
func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
readTimeout = "readTimeout"
|
||||
noTLS = "notls"
|
||||
enableBind = "bind"
|
||||
enableUDP = "udp"
|
||||
udpBufferSize = "udpBufferSize"
|
||||
compatibilityMode = "comp"
|
||||
hash = "hash"
|
||||
)
|
||||
h.md.readTimeout = mdutil.GetDuration(md, "readTimeout")
|
||||
h.md.noTLS = mdutil.GetBool(md, "notls")
|
||||
h.md.enableBind = mdutil.GetBool(md, "bind")
|
||||
h.md.enableUDP = mdutil.GetBool(md, "udp")
|
||||
|
||||
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
|
||||
h.md.noTLS = mdutil.GetBool(md, noTLS)
|
||||
h.md.enableBind = mdutil.GetBool(md, enableBind)
|
||||
h.md.enableUDP = mdutil.GetBool(md, enableUDP)
|
||||
|
||||
if bs := mdutil.GetInt(md, udpBufferSize); bs > 0 {
|
||||
if bs := mdutil.GetInt(md, "udpBufferSize"); bs > 0 {
|
||||
h.md.udpBufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
|
||||
} else {
|
||||
h.md.udpBufferSize = 4096
|
||||
}
|
||||
|
||||
h.md.compatibilityMode = mdutil.GetBool(md, compatibilityMode)
|
||||
h.md.hash = mdutil.GetString(md, hash)
|
||||
h.md.compatibilityMode = mdutil.GetBool(md, "comp")
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
|
||||
h.md.muxCfg = &mux.Config{
|
||||
Version: mdutil.GetInt(md, "mux.version"),
|
||||
@ -55,5 +46,7 @@ func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
MaxStreamBuffer: mdutil.GetInt(md, "mux.maxStreamBuffer"),
|
||||
}
|
||||
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user