test: 尝试启用xray splice拷贝

This commit is contained in:
wyx2685
2025-08-22 05:22:47 +09:00
parent 7d52a8932d
commit 6e8297c553
9 changed files with 473 additions and 454 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/InazumaV/V2bX/common/rate"
"github.com/InazumaV/V2bX/limiter"
"github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
@@ -167,7 +168,7 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (*
var user *protocol.MemoryUser
if sessionInbound != nil {
user = sessionInbound.User
sessionInbound.CanSpliceCopy = 3
//sessionInbound.CanSpliceCopy = 3
}
var limit *limiter.Limiter
@@ -214,13 +215,15 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (*
t = c.(*counter.TrafficCounter)
}
inboundLink.Writer = &UploadTrafficWriter{
Counter: t.GetCounter(user.Email),
ts := t.GetCounter(user.Email)
upcounter := &counter.XrayTrafficCounter{V: &ts.UpCounter}
downcounter := &counter.XrayTrafficCounter{V: &ts.DownCounter}
inboundLink.Writer = &dispatcher.SizeStatWriter{
Counter: upcounter,
Writer: inboundLink.Writer,
}
outboundLink.Writer = &DownloadTrafficWriter{
Counter: t.GetCounter(user.Email),
outboundLink.Writer = &dispatcher.SizeStatWriter{
Counter: downcounter,
Writer: outboundLink.Writer,
}
}

View File

@@ -1,43 +0,0 @@
package dispatcher
import (
"github.com/InazumaV/V2bX/common/counter"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
)
type UploadTrafficWriter struct {
Counter *counter.TrafficStorage
Writer buf.Writer
}
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 *UploadTrafficWriter) Close() error {
return common.Close(w.Writer)
}
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)
}

View File

@@ -1,44 +0,0 @@
package dispatcher_test
import (
"testing"
. "github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
)
type TestCounter int64
func (c *TestCounter) Value() int64 {
return int64(*c)
}
func (c *TestCounter) Add(v int64) int64 {
x := int64(*c) + v
*c = TestCounter(x)
return x
}
func (c *TestCounter) Set(v int64) int64 {
*c = TestCounter(v)
return v
}
func TestStatsWriter(t *testing.T) {
var c TestCounter
writer := &SizeStatWriter{
Counter: &c,
Writer: buf.Discard,
}
mb := buf.MergeBytes(nil, []byte("abcd"))
common.Must(writer.WriteMultiBuffer(mb))
mb = buf.MergeBytes(nil, []byte("efg"))
common.Must(writer.WriteMultiBuffer(mb))
if c.Value() != 7 {
t.Fatal("unexpected counter value. want 7, but got ", c.Value())
}
}