mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
Fix: CounterConnection with ReadV/WriteV (#720)
Co-authored-by: JimhHan <50871214+JimhHan@users.noreply.github.com>
This commit is contained in:
parent
f2cb13a8ec
commit
24b637cd5e
53 changed files with 247 additions and 128 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"io"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
|
@ -46,7 +48,7 @@ func fetchInput(_ context.Context, input io.Reader, reader PacketReader, conn *C
|
|||
}
|
||||
|
||||
// DialKCP dials a new KCP connections to the specific destination.
|
||||
func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) {
|
||||
func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
|
||||
dest.Network = net.Network_UDP
|
||||
newError("dialing mKCP to ", dest).WriteToLog()
|
||||
|
||||
|
@ -84,7 +86,7 @@ func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet
|
|||
|
||||
go fetchInput(ctx, rawConn, reader, session)
|
||||
|
||||
var iConn internet.Connection = session
|
||||
var iConn stat.Connection = session
|
||||
|
||||
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
||||
iConn = tls.Client(iConn, config.GetTLSConfig(tls.WithDestination(dest)))
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
|
@ -21,8 +23,8 @@ func TestDialAndListen(t *testing.T) {
|
|||
listerner, err := NewListener(context.Background(), net.LocalHostIP, net.Port(0), &internet.MemoryStreamConfig{
|
||||
ProtocolName: "mkcp",
|
||||
ProtocolSettings: &Config{},
|
||||
}, func(conn internet.Connection) {
|
||||
go func(c internet.Connection) {
|
||||
}, func(conn stat.Connection) {
|
||||
go func(c stat.Connection) {
|
||||
payload := make([]byte, 4096)
|
||||
for {
|
||||
nBytes, err := c.Read(payload)
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
gotls "crypto/tls"
|
||||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
|
||||
goxtls "github.com/xtls/go"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
|
@ -134,7 +136,7 @@ func (l *Listener) OnReceive(payload *buf.Buffer, src net.Destination) {
|
|||
Security: l.security,
|
||||
Writer: writer,
|
||||
}, writer, l.config)
|
||||
var netConn internet.Connection = conn
|
||||
var netConn stat.Connection = conn
|
||||
if l.tlsConfig != nil {
|
||||
netConn = tls.Server(conn, l.tlsConfig)
|
||||
} else if l.xtlsConfig != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue