From 07d49293d82f28f915444a71c2876b427ea223cd Mon Sep 17 00:00:00 2001 From: wyx2685 Date: Wed, 14 Aug 2024 01:35:30 +0900 Subject: [PATCH] =?UTF-8?q?BUG=E4=BF=AE=E5=A4=8D=E5=89=8D=E4=B8=8D?= =?UTF-8?q?=E5=AF=B9UDP=E9=93=BE=E6=8E=A5=E8=BF=9B=E8=A1=8C=E9=99=90?= =?UTF-8?q?=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/rate/conn.go | 7 +++---- core/sing/hook.go | 2 +- limiter/limiter.go | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/common/rate/conn.go b/common/rate/conn.go index 134a538..c94b041 100644 --- a/common/rate/conn.go +++ b/common/rate/conn.go @@ -4,9 +4,6 @@ import ( "net" "github.com/juju/ratelimit" - "github.com/sagernet/sing/common/buf" - M "github.com/sagernet/sing/common/metadata" - "github.com/sagernet/sing/common/network" ) func NewConnRateLimiter(c net.Conn, l *ratelimit.Bucket) *Conn { @@ -31,6 +28,7 @@ func (c *Conn) Write(b []byte) (n int, err error) { return c.Conn.Write(b) } +/* type PacketConnCounter struct { network.PacketConn limiter *ratelimit.Bucket @@ -47,10 +45,11 @@ func (p *PacketConnCounter) ReadPacket(buff *buf.Buffer) (destination M.Socksadd pLen := buff.Len() destination, err = p.PacketConn.ReadPacket(buff) p.limiter.Wait(int64(buff.Len() - pLen)) - return + return destination, err } func (p *PacketConnCounter) WritePacket(buff *buf.Buffer, destination M.Socksaddr) (err error) { p.limiter.Wait(int64(buff.Len())) return p.PacketConn.WritePacket(buff, destination) } +*/ diff --git a/core/sing/hook.go b/core/sing/hook.go index 307d759..4340a85 100644 --- a/core/sing/hook.go +++ b/core/sing/hook.go @@ -167,7 +167,7 @@ func (h *HookServer) RoutedPacketConnection(_ context.Context, conn N.PacketConn log.Error("[", m.Inbound, "] ", "Limited ", m.User, " by ip or conn") return conn, t } else if b != nil { - conn = rate.NewPacketConnCounter(conn, b) + //conn = rate.NewPacketConnCounter(conn, b) } if h.EnableConnClear { var key int diff --git a/limiter/limiter.go b/limiter/limiter.go index e8e3117..d421500 100644 --- a/limiter/limiter.go +++ b/limiter/limiter.go @@ -183,7 +183,7 @@ func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool, noSSUDP bool limit := int64(determineSpeedLimit(nodeLimit, userLimit)) * 1000000 / 8 // If you need the Speed limit if limit > 0 { - Bucket = ratelimit.NewBucketWithQuantum(time.Second, 5*limit, limit) // Byte/s + Bucket = ratelimit.NewBucketWithQuantum(time.Second, limit, limit) // Byte/s if v, ok := l.SpeedLimiter.LoadOrStore(taguuid, Bucket); ok { return v.(*ratelimit.Bucket), false } else {