add traffic limiter for relay bind

This commit is contained in:
ginuerzh
2025-02-18 17:37:13 +08:00
parent 2495b13053
commit d610e2dc01
4 changed files with 82 additions and 60 deletions
+5 -14
View File
@@ -4,7 +4,6 @@ import (
"crypto"
"crypto/tls"
"crypto/x509"
"math"
"time"
"github.com/go-gost/core/bypass"
@@ -15,12 +14,11 @@ import (
)
type metadata struct {
readTimeout time.Duration
enableBind bool
udpBufferSize int
noDelay bool
hash string
muxCfg *mux.Config
readTimeout time.Duration
enableBind bool
noDelay bool
hash string
muxCfg *mux.Config
observerPeriod time.Duration
observerResetTraffic bool
@@ -47,13 +45,6 @@ func (h *relayHandler) parseMetadata(md mdata.Metadata) (err error) {
h.md.enableBind = mdutil.GetBool(md, "bind")
h.md.noDelay = mdutil.GetBool(md, "nodelay")
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.muxCfg = &mux.Config{