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 {