mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
test: 尝试启用xray splice拷贝
This commit is contained in:
@@ -11,7 +11,7 @@ var (
|
||||
)
|
||||
|
||||
func NewCore(c []conf.CoreConfig) (Core, error) {
|
||||
if len(c) < 0 {
|
||||
if len(c) == 0 {
|
||||
return nil, errors.New("no have vail core")
|
||||
}
|
||||
// multi core
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
|
||||
"github.com/InazumaV/V2bX/api/panel"
|
||||
"github.com/InazumaV/V2bX/conf"
|
||||
)
|
||||
@@ -50,14 +48,13 @@ func (s *Selector) Start() error {
|
||||
}
|
||||
|
||||
func (s *Selector) Close() error {
|
||||
var errs error
|
||||
var errs []error
|
||||
for i := range s.cores {
|
||||
err := s.cores[i].Close()
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
if err := s.cores[i].Close(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
return errs
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func isSupported(protocol string, protocols []string) bool {
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user