mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
test: 增加MinReportTraffic最低流量上报阈值
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/InazumaV/V2bX/common/counter"
|
||||
"github.com/InazumaV/V2bX/common/rate"
|
||||
"github.com/InazumaV/V2bX/limiter"
|
||||
|
||||
@@ -98,12 +99,13 @@ func (r *cachedReader) Interrupt() {
|
||||
|
||||
// DefaultDispatcher is a default implementation of Dispatcher.
|
||||
type DefaultDispatcher struct {
|
||||
ohm outbound.Manager
|
||||
router routing.Router
|
||||
policy policy.Manager
|
||||
stats stats.Manager
|
||||
fdns dns.FakeDNSEngine
|
||||
Wm *WriterManager
|
||||
ohm outbound.Manager
|
||||
router routing.Router
|
||||
policy policy.Manager
|
||||
stats stats.Manager
|
||||
fdns dns.FakeDNSEngine
|
||||
Wm *WriterManager
|
||||
Counter sync.Map
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -204,24 +206,22 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (*
|
||||
inboundLink.Writer = rate.NewRateLimitWriter(inboundLink.Writer, w)
|
||||
outboundLink.Writer = rate.NewRateLimitWriter(outboundLink.Writer, w)
|
||||
}
|
||||
p := d.policy.ForLevel(user.Level)
|
||||
if p.Stats.UserUplink {
|
||||
name := "user>>>" + user.Email + ">>>traffic>>>uplink"
|
||||
if c, _ := stats.GetOrRegisterCounter(d.stats, name); c != nil {
|
||||
inboundLink.Writer = &SizeStatWriter{
|
||||
Counter: c,
|
||||
Writer: inboundLink.Writer,
|
||||
}
|
||||
}
|
||||
var t *counter.TrafficCounter
|
||||
if c, ok := d.Counter.Load(sessionInbound.Tag); !ok {
|
||||
t = counter.NewTrafficCounter()
|
||||
d.Counter.Store(sessionInbound.Tag, t)
|
||||
} else {
|
||||
t = c.(*counter.TrafficCounter)
|
||||
}
|
||||
if p.Stats.UserDownlink {
|
||||
name := "user>>>" + user.Email + ">>>traffic>>>downlink"
|
||||
if c, _ := stats.GetOrRegisterCounter(d.stats, name); c != nil {
|
||||
outboundLink.Writer = &SizeStatWriter{
|
||||
Counter: c,
|
||||
Writer: outboundLink.Writer,
|
||||
}
|
||||
}
|
||||
|
||||
inboundLink.Writer = &UploadTrafficWriter{
|
||||
Counter: t.GetCounter(user.Email),
|
||||
Writer: inboundLink.Writer,
|
||||
}
|
||||
|
||||
outboundLink.Writer = &DownloadTrafficWriter{
|
||||
Counter: t.GetCounter(user.Email),
|
||||
Writer: outboundLink.Writer,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,43 @@
|
||||
package dispatcher
|
||||
|
||||
import (
|
||||
"github.com/InazumaV/V2bX/common/counter"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/features/stats"
|
||||
)
|
||||
|
||||
type SizeStatWriter struct {
|
||||
Counter stats.Counter
|
||||
type UploadTrafficWriter struct {
|
||||
Counter *counter.TrafficStorage
|
||||
Writer buf.Writer
|
||||
}
|
||||
|
||||
func (w *SizeStatWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
w.Counter.Add(int64(mb.Len()))
|
||||
type DownloadTrafficWriter struct {
|
||||
Counter *counter.TrafficStorage
|
||||
Writer buf.Writer
|
||||
}
|
||||
|
||||
func (w *UploadTrafficWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
w.Counter.UpCounter.Add(int64(mb.Len()))
|
||||
return w.Writer.WriteMultiBuffer(mb)
|
||||
}
|
||||
|
||||
func (w *SizeStatWriter) Close() error {
|
||||
func (w *UploadTrafficWriter) Close() error {
|
||||
return common.Close(w.Writer)
|
||||
}
|
||||
|
||||
func (w *SizeStatWriter) Interrupt() {
|
||||
func (w *UploadTrafficWriter) Interrupt() {
|
||||
common.Interrupt(w.Writer)
|
||||
}
|
||||
|
||||
func (w *DownloadTrafficWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
w.Counter.DownCounter.Add(int64(mb.Len()))
|
||||
return w.Writer.WriteMultiBuffer(mb)
|
||||
}
|
||||
|
||||
func (w *DownloadTrafficWriter) Close() error {
|
||||
return common.Close(w.Writer)
|
||||
}
|
||||
|
||||
func (w *DownloadTrafficWriter) Interrupt() {
|
||||
common.Interrupt(w.Writer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user