mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-12 11:29:36 +03:00
Fix: CounterConnection with ReadV/WriteV (#720)
Co-authored-by: JimhHan <50871214+JimhHan@users.noreply.github.com>
This commit is contained in:
@ -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() {
|
||||
|
@ -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()
|
||||
}()
|
||||
|
Reference in New Issue
Block a user