mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-23 02:18:13 -05:00
15c36a9580
refactor limiter fix getLink bug add connection limit move limit config to ControllerConfig del dynamic speed limit (next version will be re add) del online ip sync (next version will be re add)
29 lines
549 B
Go
29 lines
549 B
Go
package rate
|
|
|
|
import (
|
|
"github.com/juju/ratelimit"
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/buf"
|
|
)
|
|
|
|
type Writer struct {
|
|
writer buf.Writer
|
|
limiter *ratelimit.Bucket
|
|
}
|
|
|
|
func NewRateLimitWriter(writer buf.Writer, limiter *ratelimit.Bucket) buf.Writer {
|
|
return &Writer{
|
|
writer: writer,
|
|
limiter: limiter,
|
|
}
|
|
}
|
|
|
|
func (w *Writer) Close() error {
|
|
return common.Close(w.writer)
|
|
}
|
|
|
|
func (w *Writer) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|
w.limiter.Wait(int64(mb.Len()))
|
|
return w.writer.WriteMultiBuffer(mb)
|
|
}
|