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"
|
||||
|
||||
"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)
|
||||
}
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user