Fix: CounterConnection with ReadV/WriteV (#720)

Co-authored-by: JimhHan <50871214+JimhHan@users.noreply.github.com>
This commit is contained in:
Arthur Morgan 2021-09-20 20:11:21 +08:00 committed by GitHub
parent f2cb13a8ec
commit 24b637cd5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 247 additions and 128 deletions

View file

@ -10,6 +10,8 @@ import (
"os"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/gorilla/websocket"
"github.com/xtls/xray-core/common"
@ -41,7 +43,7 @@ func init() {
}
// Dial dials a WebSocket connection to the given destination.
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) {
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
newError("creating connection to ", dest).WriteToLog(session.ExportIDToError(ctx))
var conn net.Conn
if streamSettings.ProtocolSettings.(*Config).Ed > 0 {
@ -59,7 +61,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
return nil, newError("failed to dial WebSocket").Base(err)
}
}
return internet.Connection(conn), nil
return stat.Connection(conn), nil
}
func init() {

View file

@ -6,6 +6,8 @@ import (
"testing"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol/tls/cert"
@ -20,8 +22,8 @@ func Test_listenWSAndDial(t *testing.T) {
ProtocolSettings: &Config{
Path: "ws",
},
}, func(conn internet.Connection) {
go func(c internet.Connection) {
}, func(conn stat.Connection) {
go func(c stat.Connection) {
defer c.Close()
var b [1024]byte
@ -75,8 +77,8 @@ func TestDialWithRemoteAddr(t *testing.T) {
ProtocolSettings: &Config{
Path: "ws",
},
}, func(conn internet.Connection) {
go func(c internet.Connection) {
}, func(conn stat.Connection) {
go func(c stat.Connection) {
defer c.Close()
var b [1024]byte
@ -129,7 +131,7 @@ func Test_listenWSAndDial_TLS(t *testing.T) {
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("localhost")))},
},
}
listen, err := ListenWS(context.Background(), net.LocalHostIP, 13143, streamSettings, func(conn internet.Connection) {
listen, err := ListenWS(context.Background(), net.LocalHostIP, 13143, streamSettings, func(conn stat.Connection) {
go func() {
_ = conn.Close()
}()