add limiterRefreshInterval option for limiter
This commit is contained in:
@@ -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