add limiterRefreshInterval option for limiter
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package direct
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type conn struct{}
|
||||
|
||||
func (c *conn) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *conn) Read(b []byte) (n int, err error) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func (c *conn) Write(b []byte) (n int, err error) {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
func (c *conn) LocalAddr() net.Addr {
|
||||
return &net.TCPAddr{}
|
||||
}
|
||||
|
||||
func (c *conn) RemoteAddr() net.Addr {
|
||||
return &net.TCPAddr{}
|
||||
}
|
||||
|
||||
func (c *conn) SetDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *conn) SetReadDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *conn) SetWriteDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package forward
|
||||
package direct
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -16,6 +16,7 @@ func init() {
|
||||
}
|
||||
|
||||
type directConnector struct {
|
||||
md metadata
|
||||
options connector.Options
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ func NewConnector(opts ...connector.Option) connector.Connector {
|
||||
}
|
||||
|
||||
func (c *directConnector) Init(md md.Metadata) (err error) {
|
||||
return nil
|
||||
return c.parseMetadata(md)
|
||||
}
|
||||
|
||||
func (c *directConnector) Connect(ctx context.Context, _ net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||
@@ -40,6 +41,10 @@ func (c *directConnector) Connect(ctx context.Context, _ net.Conn, network, addr
|
||||
opt(&cOpts)
|
||||
}
|
||||
|
||||
if c.md.action == "reject" {
|
||||
return &conn{}, nil
|
||||
}
|
||||
|
||||
conn, err := cOpts.Dialer.Dial(ctx, network, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package direct
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
action string
|
||||
}
|
||||
|
||||
func (c *directConnector) parseMetadata(md mdata.Metadata) (err error) {
|
||||
c.md.action = strings.ToLower(mdutil.GetString(md, "action"))
|
||||
return
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (h *httpHandler) Init(md md.Metadata) 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 {
|
||||
@@ -949,11 +949,7 @@ func (h *httpHandler) 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 {
|
||||
|
||||
+26
-11
@@ -20,16 +20,17 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
readTimeout time.Duration
|
||||
keepalive bool
|
||||
compression bool
|
||||
probeResistance *probeResistance
|
||||
enableUDP bool
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
observePeriod time.Duration
|
||||
proxyAgent string
|
||||
readTimeout time.Duration
|
||||
keepalive bool
|
||||
compression bool
|
||||
probeResistance *probeResistance
|
||||
enableUDP bool
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
proxyAgent string
|
||||
observePeriod time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
|
||||
sniffing bool
|
||||
sniffingTimeout time.Duration
|
||||
@@ -72,7 +73,21 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
h.md.authBasicRealm = mdutil.GetString(md, "authBasicRealm")
|
||||
|
||||
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.proxyAgent = mdutil.GetString(md, "http.proxyAgent", "proxyAgent")
|
||||
if h.md.proxyAgent == "" {
|
||||
|
||||
@@ -77,7 +77,7 @@ func (h *http2Handler) Init(md md.Metadata) 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 {
|
||||
@@ -487,11 +487,7 @@ func (h *http2Handler) 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 {
|
||||
|
||||
@@ -14,11 +14,12 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
probeResistance *probeResistance
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
observePeriod time.Duration
|
||||
probeResistance *probeResistance
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
observePeriod time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
|
||||
@@ -42,7 +43,21 @@ func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
h.md.authBasicRealm = mdutil.GetString(md, "authBasicRealm")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (h *relayHandler) 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 {
|
||||
@@ -253,11 +253,7 @@ func (h *relayHandler) 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,13 +15,14 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
readTimeout time.Duration
|
||||
enableBind bool
|
||||
udpBufferSize int
|
||||
noDelay bool
|
||||
hash string
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
readTimeout time.Duration
|
||||
enableBind bool
|
||||
udpBufferSize int
|
||||
noDelay bool
|
||||
hash string
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
|
||||
sniffing bool
|
||||
sniffingTimeout time.Duration
|
||||
@@ -61,7 +62,21 @@ func (h *relayHandler) 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")
|
||||
|
||||
@@ -75,7 +75,7 @@ func (h *socks4Handler) 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 {
|
||||
@@ -338,11 +338,7 @@ func (h *socks4Handler) 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 {
|
||||
|
||||
@@ -13,9 +13,10 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
readTimeout time.Duration
|
||||
hash string
|
||||
observePeriod time.Duration
|
||||
readTimeout time.Duration
|
||||
hash string
|
||||
observePeriod time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
|
||||
sniffing bool
|
||||
sniffingTimeout time.Duration
|
||||
@@ -35,7 +36,22 @@ func (h *socks4Handler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -120,7 +120,7 @@ func (h *tunnelHandler) 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)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -320,11 +320,7 @@ func (h *tunnelHandler) 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 {
|
||||
|
||||
@@ -31,12 +31,13 @@ type metadata struct {
|
||||
sniffingWebsocket bool
|
||||
sniffingWebsocketSampleRate float64
|
||||
|
||||
directTunnel bool
|
||||
tunnelTTL time.Duration
|
||||
ingress ingress.Ingress
|
||||
sd sd.SD
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
directTunnel bool
|
||||
tunnelTTL time.Duration
|
||||
ingress ingress.Ingress
|
||||
sd sd.SD
|
||||
muxCfg *mux.Config
|
||||
observePeriod time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (h *tunnelHandler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -104,7 +105,21 @@ func (h *tunnelHandler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
h.md.muxCfg.MaxStreamBuffer = 1048576
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,22 +9,22 @@ import (
|
||||
)
|
||||
|
||||
type cachedTrafficLimiter struct {
|
||||
inLimits *Cache
|
||||
outLimits *Cache
|
||||
limiter traffic.TrafficLimiter
|
||||
ttl time.Duration
|
||||
inLimits *Cache
|
||||
outLimits *Cache
|
||||
limiter traffic.TrafficLimiter
|
||||
refreshInterval time.Duration
|
||||
}
|
||||
|
||||
func NewCachedTrafficLimiter(limiter traffic.TrafficLimiter, ttl time.Duration, cleanupInterval time.Duration) traffic.TrafficLimiter {
|
||||
func NewCachedTrafficLimiter(limiter traffic.TrafficLimiter, refreshInterval time.Duration, cleanupInterval time.Duration) traffic.TrafficLimiter {
|
||||
if limiter == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
lim := &cachedTrafficLimiter{
|
||||
inLimits: NewCache(cleanupInterval),
|
||||
outLimits: NewCache(cleanupInterval),
|
||||
limiter: limiter,
|
||||
ttl: ttl,
|
||||
inLimits: NewCache(cleanupInterval),
|
||||
outLimits: NewCache(cleanupInterval),
|
||||
limiter: limiter,
|
||||
refreshInterval: refreshInterval,
|
||||
}
|
||||
return lim
|
||||
}
|
||||
@@ -45,11 +45,11 @@ func (p *cachedTrafficLimiter) In(ctx context.Context, key string, opts ...limit
|
||||
limNew = lim
|
||||
}
|
||||
if item == nil || !p.equal(lim, limNew) {
|
||||
p.inLimits.Set(key, NewItem(limNew, p.ttl))
|
||||
p.inLimits.Set(key, NewItem(limNew, p.refreshInterval))
|
||||
return limNew
|
||||
}
|
||||
|
||||
p.inLimits.Set(key, NewItem(lim, p.ttl))
|
||||
p.inLimits.Set(key, NewItem(lim, p.refreshInterval))
|
||||
|
||||
return lim
|
||||
}
|
||||
@@ -70,11 +70,11 @@ func (p *cachedTrafficLimiter) Out(ctx context.Context, key string, opts ...limi
|
||||
limNew = lim
|
||||
}
|
||||
if item == nil || !p.equal(lim, limNew) {
|
||||
p.outLimits.Set(key, NewItem(limNew, p.ttl))
|
||||
p.outLimits.Set(key, NewItem(limNew, p.refreshInterval))
|
||||
return limNew
|
||||
}
|
||||
|
||||
p.outLimits.Set(key, NewItem(lim, p.ttl))
|
||||
p.outLimits.Set(key, NewItem(lim, p.refreshInterval))
|
||||
|
||||
return lim
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (l *dnsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
|
||||
l.server = &dnsServer{
|
||||
@@ -124,7 +124,7 @@ func (l *dnsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
|
||||
l.server = &dnsServer{
|
||||
@@ -166,7 +166,7 @@ func (l *dnsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
|
||||
l.server = &dohServer{
|
||||
@@ -205,7 +205,7 @@ func (l *dnsListener) Init(md md.Metadata) (err error) {
|
||||
|
||||
pc = limiter_wrapper.WrapPacketConn(
|
||||
pc,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
@@ -251,7 +251,7 @@ func (l *dnsListener) Accept() (conn net.Conn, err error) {
|
||||
conn = admission.WrapConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -12,12 +12,13 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
mode string
|
||||
readBufferSize int
|
||||
readTimeout time.Duration
|
||||
writeTimeout time.Duration
|
||||
backlog int
|
||||
mptcp bool
|
||||
mode string
|
||||
readBufferSize int
|
||||
readTimeout time.Duration
|
||||
writeTimeout time.Duration
|
||||
backlog int
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *dnsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -40,5 +41,13 @@ func (l *dnsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func (l *dtlsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -104,7 +104,7 @@ func (l *dtlsListener) Accept() (conn net.Conn, err error) {
|
||||
conn = xdtls.Conn(c, l.md.bufferSize)
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -12,9 +12,10 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
mtu int
|
||||
bufferSize int
|
||||
flightInterval time.Duration
|
||||
mtu int
|
||||
bufferSize int
|
||||
flightInterval time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *dtlsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -26,5 +27,13 @@ func (l *dtlsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
|
||||
l.md.flightInterval = mdutil.GetDuration(md, "dtls.flightInterval", "flightInterval")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func (l *ftcpListener) Init(md md.Metadata) (err error) {
|
||||
conn = admission.WrapPacketConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapPacketConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
@@ -88,7 +88,7 @@ func (l *ftcpListener) Accept() (conn net.Conn, err error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -15,7 +15,8 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
ttl time.Duration
|
||||
ttl time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
|
||||
readBufferSize int
|
||||
readQueueSize int
|
||||
@@ -49,5 +50,13 @@ func (l *ftcpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.backlog = defaultBacklog
|
||||
}
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (l *grpcListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -124,7 +124,7 @@ func (l *grpcListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -22,6 +22,7 @@ type metadata struct {
|
||||
keepalivePermitWithoutStream bool
|
||||
keepaliveMaxConnectionIdle time.Duration
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *grpcListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -53,5 +54,13 @@ func (l *grpcListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
}
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func (l *h2Listener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -130,7 +130,7 @@ func (l *h2Listener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package h2
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
@@ -10,9 +12,10 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
path string
|
||||
backlog int
|
||||
mptcp bool
|
||||
path string
|
||||
backlog int
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *h2Listener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -29,5 +32,13 @@ func (l *h2Listener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.path = mdutil.GetString(md, path)
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (l *http2Listener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -111,7 +111,7 @@ func (l *http2Listener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package http2
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
@@ -10,8 +12,9 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
backlog int
|
||||
mptcp bool
|
||||
backlog int
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *http2Listener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -25,5 +28,13 @@ func (l *http2Listener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (l *http3Listener) Accept() (conn net.Conn, err error) {
|
||||
conn = admission.WrapConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -26,6 +26,8 @@ type metadata struct {
|
||||
maxIdleTimeout time.Duration
|
||||
handshakeTimeout time.Duration
|
||||
maxStreams int
|
||||
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *http3Listener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -67,5 +69,13 @@ func (l *http3Listener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
|
||||
l.md.maxStreams = mdutil.GetInt(md, maxStreams)
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (l *wtListener) Init(md md.Metadata) (err error) {
|
||||
pc = admission.WrapPacketConn(l.options.Admission, pc)
|
||||
pc = limiter_wrapper.WrapPacketConn(
|
||||
pc,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
@@ -130,7 +130,7 @@ func (l *wtListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -21,6 +21,8 @@ type metadata struct {
|
||||
maxIdleTimeout time.Duration
|
||||
handshakeTimeout time.Duration
|
||||
maxStreams int
|
||||
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *wtListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -54,5 +56,13 @@ func (l *wtListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
|
||||
l.md.maxStreams = mdutil.GetInt(md, maxStreams)
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (l *icmpListener) Init(md md.Metadata) (err error) {
|
||||
conn = admission.WrapPacketConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapPacketConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
@@ -123,7 +123,7 @@ func (l *icmpListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -16,7 +16,8 @@ type metadata struct {
|
||||
handshakeTimeout time.Duration
|
||||
maxIdleTimeout time.Duration
|
||||
|
||||
backlog int
|
||||
backlog int
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *icmpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -34,5 +35,13 @@ func (l *icmpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.handshakeTimeout = mdutil.GetDuration(md, "handshakeTimeout")
|
||||
l.md.maxIdleTimeout = mdutil.GetDuration(md, "maxIdleTimeout")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (l *kcpListener) Init(md md.Metadata) (err error) {
|
||||
conn = admission.WrapUDPConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapUDPConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
@@ -124,7 +124,7 @@ func (l *kcpListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -2,10 +2,11 @@ package kcp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
kcp_util "github.com/go-gost/x/internal/util/kcp"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -13,8 +14,9 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
config *kcp_util.Config
|
||||
backlog int
|
||||
config *kcp_util.Config
|
||||
backlog int
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *kcpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -64,5 +66,13 @@ func (l *kcpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.backlog = defaultBacklog
|
||||
}
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (l *mtcpListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.ln = ln
|
||||
@@ -101,7 +101,7 @@ func (l *mtcpListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package mtcp
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
md "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/go-gost/x/internal/util/mux"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -11,9 +13,10 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
mptcp bool
|
||||
muxCfg *mux.Config
|
||||
backlog int
|
||||
mptcp bool
|
||||
muxCfg *mux.Config
|
||||
backlog int
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *mtcpListener) parseMetadata(md md.Metadata) (err error) {
|
||||
@@ -36,5 +39,14 @@ func (l *mtcpListener) parseMetadata(md md.Metadata) (err error) {
|
||||
if l.md.backlog <= 0 {
|
||||
l.md.backlog = defaultBacklog
|
||||
}
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (l *mtlsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.Listener = tls.NewListener(ln, l.options.TLSConfig)
|
||||
@@ -92,7 +92,7 @@ func (l *mtlsListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package mtls
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/go-gost/x/internal/util/mux"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -11,9 +13,10 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
muxCfg *mux.Config
|
||||
backlog int
|
||||
mptcp bool
|
||||
muxCfg *mux.Config
|
||||
backlog int
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *mtlsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -33,5 +36,13 @@ func (l *mtlsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (l *mwsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -142,7 +142,7 @@ func (l *mwsListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/go-gost/x/internal/util/mux"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -27,7 +27,8 @@ type metadata struct {
|
||||
|
||||
muxCfg *mux.Config
|
||||
|
||||
mptcp bool
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *mwsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -67,5 +68,13 @@ func (l *mwsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (l *obfsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -84,7 +84,7 @@ func (l *obfsListener) Accept() (net.Conn, error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -2,14 +2,16 @@ package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
header http.Header
|
||||
mptcp bool
|
||||
header http.Header
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *obfsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -26,5 +28,14 @@ func (l *obfsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (l *obfsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -84,7 +84,7 @@ func (l *obfsListener) Accept() (net.Conn, error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
package tls
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
md "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
mptcp bool
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *obfsListener) parseMetadata(md md.Metadata) (err error) {
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func (l *phtListener) Accept() (conn net.Conn, err error) {
|
||||
conn = admission.WrapConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -2,6 +2,7 @@ package pht
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
@@ -15,11 +16,12 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
authorizePath string
|
||||
pushPath string
|
||||
pullPath string
|
||||
backlog int
|
||||
mptcp bool
|
||||
authorizePath string
|
||||
pushPath string
|
||||
pullPath string
|
||||
backlog int
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *phtListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -50,5 +52,14 @@ func (l *phtListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (l *quicListener) Init(md md.Metadata) (err error) {
|
||||
conn = admission.WrapPacketConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapPacketConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
@@ -119,7 +119,7 @@ func (l *quicListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -18,8 +18,9 @@ type metadata struct {
|
||||
maxIdleTimeout time.Duration
|
||||
maxStreams int
|
||||
|
||||
cipherKey []byte
|
||||
backlog int
|
||||
cipherKey []byte
|
||||
backlog int
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -53,5 +54,13 @@ func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
|
||||
l.md.maxStreams = mdutil.GetInt(md, maxStreams)
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (l *redirectListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.ln = ln
|
||||
@@ -88,7 +88,7 @@ func (l *redirectListener) Accept() (conn net.Conn, err error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
tproxy bool
|
||||
mptcp bool
|
||||
tproxy bool
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *redirectListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.tproxy = mdutil.GetBool(md, "tproxy")
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (l *redirectListener) Accept() (conn net.Conn, err error) {
|
||||
conn = admission.WrapConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -13,8 +13,9 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
ttl time.Duration
|
||||
readBufferSize int
|
||||
ttl time.Duration
|
||||
readBufferSize int
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *redirectListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -33,5 +34,13 @@ func (l *redirectListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.readBufferSize = defaultReadBufferSize
|
||||
}
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ type rtcpListener struct {
|
||||
ln net.Listener
|
||||
logger logger.Logger
|
||||
closed chan struct{}
|
||||
md metadata
|
||||
options listener.Options
|
||||
mu sync.Mutex
|
||||
}
|
||||
@@ -87,7 +88,7 @@ func (l *rtcpListener) Accept() (conn net.Conn, err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.setListener(ln)
|
||||
@@ -109,7 +110,7 @@ func (l *rtcpListener) Accept() (conn net.Conn, err error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
package rtcp
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct{}
|
||||
type metadata struct {
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *rtcpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func (l *rudpListener) Accept() (conn net.Conn, err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -116,7 +116,7 @@ func (l *rudpListener) Accept() (conn net.Conn, err error) {
|
||||
uc = admission.WrapUDPConn(l.options.Admission, uc)
|
||||
conn = limiter_wrapper.WrapUDPConn(
|
||||
uc,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -15,10 +15,11 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
ttl time.Duration
|
||||
readBufferSize int
|
||||
readQueueSize int
|
||||
backlog int
|
||||
ttl time.Duration
|
||||
readBufferSize int
|
||||
readQueueSize int
|
||||
backlog int
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *rudpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -48,5 +49,13 @@ func (l *rudpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.backlog = defaultBacklog
|
||||
}
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func (l *serialListener) listenLoop() {
|
||||
conn = stats.WrapConn(conn, l.options.Stats)
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -8,10 +8,20 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
timeout time.Duration
|
||||
timeout time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *serialListener) parseMetadata(md md.Metadata) (err error) {
|
||||
l.md.timeout = mdutil.GetDuration(md, "timeout", "serial.timeout", "listener.serial.timeout")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (l *sshListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.Listener = ln
|
||||
@@ -104,7 +104,7 @@ func (l *sshListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -2,10 +2,11 @@ package ssh
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
ssh_util "github.com/go-gost/x/internal/util/ssh"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -15,10 +16,11 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
signer ssh.Signer
|
||||
authorizedKeys map[string]bool
|
||||
backlog int
|
||||
mptcp bool
|
||||
signer ssh.Signer
|
||||
authorizedKeys map[string]bool
|
||||
backlog int
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *sshListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -71,5 +73,14 @@ func (l *sshListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (l *sshdListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.Listener = ln
|
||||
@@ -112,7 +112,7 @@ func (l *sshdListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -3,10 +3,11 @@ package ssh
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
ssh_util "github.com/go-gost/x/internal/util/ssh"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/zalando/go-keyring"
|
||||
"golang.org/x/crypto/ssh"
|
||||
@@ -17,10 +18,11 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
signer ssh.Signer
|
||||
authorizedKeys map[string]bool
|
||||
backlog int
|
||||
mptcp bool
|
||||
signer ssh.Signer
|
||||
authorizedKeys map[string]bool
|
||||
backlog int
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *sshdListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -81,5 +83,14 @@ func (l *sshdListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func (l *tapListener) listenLoop() {
|
||||
c = stats.WrapConn(c, l.options.Stats)
|
||||
c = limiter_wrapper.WrapConn(
|
||||
c,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
c.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -3,10 +3,11 @@ package tap
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
tap_util "github.com/go-gost/x/internal/util/tap"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -14,7 +15,8 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
config *tap_util.Config
|
||||
config *tap_util.Config
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *tapListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -71,5 +73,13 @@ func (l *tapListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
|
||||
l.md.config = config
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func (l *tcpListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.ln = ln
|
||||
@@ -87,7 +87,7 @@ func (l *tcpListener) Accept() (conn net.Conn, err error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
md "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
mptcp bool
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *tcpListener) parseMetadata(md md.Metadata) (err error) {
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (l *tlsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -86,7 +86,7 @@ func (l *tlsListener) Accept() (conn net.Conn, err error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
package tls
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
mptcp bool
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *tlsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func (l *tunListener) listenLoop() {
|
||||
c = stats.WrapConn(c, l.options.Stats)
|
||||
c = limiter_wrapper.WrapConn(
|
||||
c,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
c.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -3,12 +3,13 @@ package tun
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/core/logger"
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/go-gost/core/router"
|
||||
tun_util "github.com/go-gost/x/internal/util/tun"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
"github.com/go-gost/x/registry"
|
||||
xrouter "github.com/go-gost/x/router"
|
||||
)
|
||||
@@ -19,8 +20,9 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
config *tun_util.Config
|
||||
readBufferSize int
|
||||
config *tun_util.Config
|
||||
readBufferSize int
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -111,5 +113,13 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
|
||||
l.md.config = config
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func (l *udpListener) Init(md md.Metadata) (err error) {
|
||||
conn = admission.WrapPacketConn(l.options.Admission, conn)
|
||||
conn = limiter_wrapper.WrapPacketConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
"",
|
||||
limiter.ScopeOption(limiter.ScopeService),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -15,11 +15,12 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
readBufferSize int
|
||||
readQueueSize int
|
||||
backlog int
|
||||
keepalive bool
|
||||
ttl time.Duration
|
||||
readBufferSize int
|
||||
readQueueSize int
|
||||
backlog int
|
||||
keepalive bool
|
||||
ttl time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *udpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -51,5 +52,13 @@ func (l *udpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
l.md.keepalive = mdutil.GetBool(md, keepalive)
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func (l *unixListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
l.ln = ln
|
||||
@@ -71,7 +71,7 @@ func (l *unixListener) Accept() (conn net.Conn, err error) {
|
||||
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
package unix
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
md "github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/x/metadata/util"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *unixListener) parseMetadata(md md.Metadata) (err error) {
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func (l *wsListener) Init(md md.Metadata) (err error) {
|
||||
ln = limiter_wrapper.WrapListener(
|
||||
l.options.Service,
|
||||
ln,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
)
|
||||
ln = climiter.WrapListener(l.options.ConnLimiter, ln)
|
||||
|
||||
@@ -138,7 +138,7 @@ func (l *wsListener) Accept() (conn net.Conn, err error) {
|
||||
case conn = <-l.cqueue:
|
||||
conn = limiter_wrapper.WrapConn(
|
||||
conn,
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, 30*time.Second, 60*time.Second),
|
||||
limiter_util.NewCachedTrafficLimiter(l.options.TrafficLimiter, l.md.limiterRefreshInterval, 60*time.Second),
|
||||
conn.RemoteAddr().String(),
|
||||
limiter.ScopeOption(limiter.ScopeConn),
|
||||
limiter.ServiceOption(l.options.Service),
|
||||
|
||||
+11
-1
@@ -24,7 +24,8 @@ type metadata struct {
|
||||
enableCompression bool
|
||||
header http.Header
|
||||
|
||||
mptcp bool
|
||||
mptcp bool
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (l *wsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -53,5 +54,14 @@ func (l *wsListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
}
|
||||
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
|
||||
l.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if l.md.limiterRefreshInterval == 0 {
|
||||
l.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if l.md.limiterRefreshInterval < time.Second {
|
||||
l.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user