mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 09:58:14 -05:00
BUG修复前不对UDP链接进行限速
This commit is contained in:
parent
9e8f87740e
commit
07d49293d8
@ -4,9 +4,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/juju/ratelimit"
|
"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 {
|
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)
|
return c.Conn.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
type PacketConnCounter struct {
|
type PacketConnCounter struct {
|
||||||
network.PacketConn
|
network.PacketConn
|
||||||
limiter *ratelimit.Bucket
|
limiter *ratelimit.Bucket
|
||||||
@ -47,10 +45,11 @@ func (p *PacketConnCounter) ReadPacket(buff *buf.Buffer) (destination M.Socksadd
|
|||||||
pLen := buff.Len()
|
pLen := buff.Len()
|
||||||
destination, err = p.PacketConn.ReadPacket(buff)
|
destination, err = p.PacketConn.ReadPacket(buff)
|
||||||
p.limiter.Wait(int64(buff.Len() - pLen))
|
p.limiter.Wait(int64(buff.Len() - pLen))
|
||||||
return
|
return destination, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PacketConnCounter) WritePacket(buff *buf.Buffer, destination M.Socksaddr) (err error) {
|
func (p *PacketConnCounter) WritePacket(buff *buf.Buffer, destination M.Socksaddr) (err error) {
|
||||||
p.limiter.Wait(int64(buff.Len()))
|
p.limiter.Wait(int64(buff.Len()))
|
||||||
return p.PacketConn.WritePacket(buff, destination)
|
return p.PacketConn.WritePacket(buff, destination)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
@ -167,7 +167,7 @@ func (h *HookServer) RoutedPacketConnection(_ context.Context, conn N.PacketConn
|
|||||||
log.Error("[", m.Inbound, "] ", "Limited ", m.User, " by ip or conn")
|
log.Error("[", m.Inbound, "] ", "Limited ", m.User, " by ip or conn")
|
||||||
return conn, t
|
return conn, t
|
||||||
} else if b != nil {
|
} else if b != nil {
|
||||||
conn = rate.NewPacketConnCounter(conn, b)
|
//conn = rate.NewPacketConnCounter(conn, b)
|
||||||
}
|
}
|
||||||
if h.EnableConnClear {
|
if h.EnableConnClear {
|
||||||
var key int
|
var key int
|
||||||
|
@ -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
|
limit := int64(determineSpeedLimit(nodeLimit, userLimit)) * 1000000 / 8 // If you need the Speed limit
|
||||||
if limit > 0 {
|
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 {
|
if v, ok := l.SpeedLimiter.LoadOrStore(taguuid, Bucket); ok {
|
||||||
return v.(*ratelimit.Bucket), false
|
return v.(*ratelimit.Bucket), false
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user