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

@ -5,6 +5,8 @@ import (
"io"
"sync"
"github.com/xtls/xray-core/transport/internet/stat"
"golang.org/x/net/dns/dnsmessage"
"github.com/xtls/xray-core/common"
@ -104,7 +106,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
newError("handling DNS traffic to ", dest).WriteToLog(session.ExportIDToError(ctx))
conn := &outboundConn{
dialer: func() (internet.Connection, error) {
dialer: func() (stat.Connection, error) {
return d.Dial(ctx, dest)
},
connReady: make(chan struct{}, 1),
@ -266,7 +268,7 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
type outboundConn struct {
access sync.Mutex
dialer func() (internet.Connection, error)
dialer func() (stat.Connection, error)
conn net.Conn
connReady chan struct{}

View file

@ -7,6 +7,8 @@ import (
"sync/atomic"
"time"
"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/log"
@ -18,7 +20,6 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet"
)
func init() {
@ -76,7 +77,7 @@ type hasHandshakeAddress interface {
}
// Process implements proxy.Inbound.
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WriteToLog(session.ExportIDToError(ctx))
dest := net.Destination{
Network: network,

View file

@ -6,6 +6,8 @@ import (
"context"
"time"
"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"
@ -121,7 +123,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
input := link.Reader
output := link.Writer
var conn internet.Connection
var conn stat.Connection
err := retry.ExponentialBackoff(5, 100).On(func() error {
dialDest := destination
if h.config.useIP() && dialDest.Address.Family().IsDomain() {
@ -194,7 +196,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader {
iConn := conn
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}
@ -238,7 +240,7 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
func NewPacketWriter(conn net.Conn, h *Handler, ctx context.Context, UDPOverride net.Destination) buf.Writer {
iConn := conn
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}

View file

@ -9,6 +9,8 @@ import (
"net/url"
"sync"
"github.com/xtls/xray-core/transport/internet/stat"
"golang.org/x/net/http2"
"github.com/xtls/xray-core/common"
@ -77,7 +79,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
}
var user *protocol.MemoryUser
var conn internet.Connection
var conn stat.Connection
mbuf, _ := link.Reader.ReadMultiBuffer()
len := mbuf.Len()
@ -101,7 +103,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
return err
}
}
conn = internet.Connection(netConn)
conn = stat.Connection(netConn)
}
return err
}); err != nil {
@ -231,7 +233,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
}
iConn := rawConn
if statConn, ok := iConn.(*internet.StatCouterConnection); ok {
if statConn, ok := iConn.(*stat.CounterConnection); ok {
iConn = statConn.Connection
}

View file

@ -9,6 +9,8 @@ import (
"strings"
"time"
"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/errors"
@ -22,7 +24,6 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet"
)
// Server is an HTTP proxy server.
@ -82,7 +83,7 @@ type readerOnly struct {
io.Reader
}
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
inbound := session.InboundFromContext(ctx)
if inbound != nil {
inbound.User = &protocol.MemoryUser{
@ -157,7 +158,7 @@ Start:
return err
}
func (s *Server) handleConnect(ctx context.Context, _ *http.Request, reader *bufio.Reader, conn internet.Connection, dest net.Destination, dispatcher routing.Dispatcher, inbound *session.Inbound) error {
func (s *Server) handleConnect(ctx context.Context, _ *http.Request, reader *bufio.Reader, conn stat.Connection, dest net.Destination, dispatcher routing.Dispatcher, inbound *session.Inbound) error {
_, err := conn.Write([]byte("HTTP/1.1 200 Connection established\r\n\r\n"))
if err != nil {
return newError("failed to write back OK response").Base(err)

View file

@ -5,6 +5,8 @@ import (
"context"
"time"
"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/crypto"
@ -16,7 +18,6 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet"
)
var (
@ -76,7 +77,7 @@ func isValidConnectionType(c [4]byte) bool {
return false
}
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
sPolicy := s.policy.ForLevel(s.user.Level)
if err := conn.SetDeadline(time.Now().Add(sPolicy.Timeouts.Handshake)); err != nil {

View file

@ -8,6 +8,8 @@ package proxy
import (
"context"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/features/routing"
@ -21,7 +23,7 @@ type Inbound interface {
Network() []net.Network
// Process processes a connection of given network. If necessary, the Inbound can dispatch the connection to an Outbound.
Process(context.Context, net.Network, internet.Connection, routing.Dispatcher) error
Process(context.Context, net.Network, stat.Connection, routing.Dispatcher) error
}
// An Outbound process outbound connections.

View file

@ -3,6 +3,8 @@ package shadowsocks
import (
"context"
"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/net"
@ -55,7 +57,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
network := destination.Network
var server *protocol.ServerSpec
var conn internet.Connection
var conn stat.Connection
err := retry.ExponentialBackoff(5, 100).On(func() error {
server = c.serverPicker.PickServer()

View file

@ -173,7 +173,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
if account.Cipher.IVSize() > 0 {
iv = make([]byte, account.Cipher.IVSize())
common.Must2(rand.Read(iv))
if err := buf.WriteAllBytes(writer, iv); err != nil {
if err := buf.WriteAllBytes(writer, iv, nil); err != nil {
return nil, newError("failed to write IV")
}
}
@ -218,7 +218,7 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (buf.Wr
if account.Cipher.IVSize() > 0 {
iv = make([]byte, account.Cipher.IVSize())
common.Must2(rand.Read(iv))
if err := buf.WriteAllBytes(writer, iv); err != nil {
if err := buf.WriteAllBytes(writer, iv, nil); err != nil {
return nil, newError("failed to write IV.").Base(err)
}
}

View file

@ -4,6 +4,8 @@ import (
"context"
"time"
"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/log"
@ -16,7 +18,6 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/udp"
)
@ -70,7 +71,7 @@ func (s *Server) Network() []net.Network {
return list
}
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
switch network {
case net.Network_TCP:
return s.handleConnection(ctx, conn, dispatcher)
@ -81,7 +82,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
}
}
func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dispatcher routing.Dispatcher) error {
udpServer := udp.NewDispatcher(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) {
request := protocol.RequestHeaderFromContext(ctx)
if request == nil {
@ -185,7 +186,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
return nil
}
func (s *Server) handleConnection(ctx context.Context, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dispatcher routing.Dispatcher) error {
sessionPolicy := s.policyManager.ForLevel(0)
if err := conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)); err != nil {
return newError("unable to set read deadline").Base(err).AtWarning()

View file

@ -4,6 +4,8 @@ import (
"context"
"time"
"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/net"
@ -59,7 +61,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
// Outbound server's destination.
var dest net.Destination
// Connection to the outbound server.
var conn internet.Connection
var conn stat.Connection
if err := retry.ExponentialBackoff(5, 100).On(func() error {
server = c.serverPicker.PickServer()

View file

@ -293,7 +293,7 @@ func hasAuthMethod(expectedAuth byte, authCandidates []byte) bool {
}
func writeSocks5AuthenticationResponse(writer io.Writer, version byte, auth byte) error {
return buf.WriteAllBytes(writer, []byte{version, auth})
return buf.WriteAllBytes(writer, []byte{version, auth}, nil)
}
func writeSocks5Response(writer io.Writer, errCode byte, address net.Address, port net.Port) error {
@ -305,7 +305,7 @@ func writeSocks5Response(writer io.Writer, errCode byte, address net.Address, po
return err
}
return buf.WriteAllBytes(writer, buffer.Bytes())
return buf.WriteAllBytes(writer, buffer.Bytes(), nil)
}
func writeSocks4Response(writer io.Writer, errCode byte, address net.Address, port net.Port) error {
@ -317,7 +317,7 @@ func writeSocks4Response(writer io.Writer, errCode byte, address net.Address, po
portBytes := buffer.Extend(2)
binary.BigEndian.PutUint16(portBytes, port.Value())
common.Must2(buffer.Write(address.IP()))
return buf.WriteAllBytes(writer, buffer.Bytes())
return buf.WriteAllBytes(writer, buffer.Bytes(), nil)
}
func DecodeUDPPacket(packet *buf.Buffer) (*protocol.RequestHeader, error) {
@ -422,7 +422,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
defer b.Release()
common.Must2(b.Write([]byte{socks5Version, 0x01, authByte}))
if err := buf.WriteAllBytes(writer, b.Bytes()); err != nil {
if err := buf.WriteAllBytes(writer, b.Bytes(), nil); err != nil {
return nil, err
}
@ -446,7 +446,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
common.Must2(b.WriteString(account.Username))
common.Must(b.WriteByte(byte(len(account.Password))))
common.Must2(b.WriteString(account.Password))
if err := buf.WriteAllBytes(writer, b.Bytes()); err != nil {
if err := buf.WriteAllBytes(writer, b.Bytes(), nil); err != nil {
return nil, err
}
@ -474,7 +474,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
}
}
if err := buf.WriteAllBytes(writer, b.Bytes()); err != nil {
if err := buf.WriteAllBytes(writer, b.Bytes(), nil); err != nil {
return nil, err
}

View file

@ -5,6 +5,8 @@ import (
"io"
"time"
"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/log"
@ -18,7 +20,6 @@ import (
"github.com/xtls/xray-core/features"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/udp"
)
@ -62,7 +63,7 @@ func (s *Server) Network() []net.Network {
}
// Process implements proxy.Inbound.
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
if inbound := session.InboundFromContext(ctx); inbound != nil {
inbound.User = &protocol.MemoryUser{
Level: s.config.UserLevel,
@ -79,7 +80,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
}
}
func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) processTCP(ctx context.Context, conn stat.Connection, dispatcher routing.Dispatcher) error {
plcy := s.policy()
if err := conn.SetReadDeadline(time.Now().Add(plcy.Timeouts.Handshake)); err != nil {
newError("failed to set deadline").Base(err).WriteToLog(session.ExportIDToError(ctx))
@ -191,7 +192,7 @@ func (s *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
return nil
}
func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dispatcher routing.Dispatcher) error {
udpServer := udp.NewDispatcher(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) {
payload := packet.Payload
newError("writing back UDP response with ", payload.Len(), " bytes").AtDebug().WriteToLog(session.ExportIDToError(ctx))

View file

@ -5,6 +5,8 @@ import (
"syscall"
"time"
"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/errors"
@ -61,7 +63,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
network := destination.Network
var server *protocol.ServerSpec
var conn internet.Connection
var conn stat.Connection
err := retry.ExponentialBackoff(5, 100).On(func() error {
server = c.serverPicker.PickServer()
@ -81,7 +83,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
defer conn.Close()
iConn := conn
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}

View file

@ -8,6 +8,8 @@ import (
"runtime"
"syscall"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
@ -15,7 +17,6 @@ import (
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/common/signal"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/xtls"
)
@ -298,7 +299,7 @@ func ReadV(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, c
if sctx != nil {
if inbound := session.InboundFromContext(sctx); inbound != nil && inbound.Conn != nil {
iConn := inbound.Conn
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}
@ -325,7 +326,7 @@ func ReadV(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, c
//panic("XTLS Splice: nil inbound or nil inbound.Conn")
}
}
reader = buf.NewReadVReader(conn.Connection, rawConn)
reader = buf.NewReadVReader(conn.Connection, rawConn, nil)
ct = counter
if conn.SHOW {
fmt.Println(conn.MARK, "ReadV")

View file

@ -9,6 +9,8 @@ import (
"syscall"
"time"
"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/errors"
@ -25,7 +27,6 @@ import (
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/udp"
"github.com/xtls/xray-core/transport/internet/xtls"
)
@ -141,11 +142,11 @@ func (s *Server) Network() []net.Network {
}
// Process implements proxy.Inbound.Process().
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error {
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
sid := session.ExportIDToError(ctx)
iConn := conn
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}
@ -343,7 +344,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade
func (s *Server) handleConnection(ctx context.Context, sessionPolicy policy.Session,
destination net.Destination,
clientReader buf.Reader,
clientWriter buf.Writer, dispatcher routing.Dispatcher, iConn internet.Connection, rawConn syscall.RawConn, statConn *internet.StatCouterConnection) error {
clientWriter buf.Writer, dispatcher routing.Dispatcher, iConn stat.Connection, rawConn syscall.RawConn, statConn *stat.CounterConnection) error {
ctx, cancel := context.WithCancel(ctx)
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
ctx = policy.ContextWithBufferPolicy(ctx, sessionPolicy.Buffer)
@ -391,7 +392,7 @@ func (s *Server) handleConnection(ctx context.Context, sessionPolicy policy.Sess
return nil
}
func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err error, sessionPolicy policy.Session, connection internet.Connection, iConn internet.Connection, napfb map[string]map[string]map[string]*Fallback, first *buf.Buffer, firstLen int64, reader buf.Reader) error {
func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err error, sessionPolicy policy.Session, connection stat.Connection, iConn stat.Connection, napfb map[string]map[string]map[string]*Fallback, first *buf.Buffer, firstLen int64, reader buf.Reader) error {
if err := connection.SetReadDeadline(time.Time{}); err != nil {
newError("unable to set back read deadline").Base(err).AtWarning().WriteToLog(sid)
}

View file

@ -9,6 +9,8 @@ import (
"runtime"
"syscall"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
@ -17,7 +19,6 @@ import (
"github.com/xtls/xray-core/common/signal"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/proxy/vless"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/xtls"
)
@ -185,7 +186,7 @@ func ReadV(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, c
if sctx != nil {
if inbound := session.InboundFromContext(sctx); inbound != nil && inbound.Conn != nil {
iConn := inbound.Conn
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}
@ -212,7 +213,7 @@ func ReadV(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, c
//panic("XTLS Splice: nil inbound or nil inbound.Conn")
}
}
reader = buf.NewReadVReader(conn.Connection, rawConn)
reader = buf.NewReadVReader(conn.Connection, rawConn, nil)
ct = counter
if conn.SHOW {
fmt.Println(conn.MARK, "ReadV")

View file

@ -10,6 +10,8 @@ import (
"syscall"
"time"
"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/errors"
@ -29,7 +31,6 @@ import (
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/proxy/vless"
"github.com/xtls/xray-core/proxy/vless/encoding"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/tls"
"github.com/xtls/xray-core/transport/internet/xtls"
)
@ -172,11 +173,11 @@ func (*Handler) Network() []net.Network {
}
// Process implements proxy.Inbound.Process().
func (h *Handler) Process(ctx context.Context, network net.Network, connection internet.Connection, dispatcher routing.Dispatcher) error {
func (h *Handler) Process(ctx context.Context, network net.Network, connection stat.Connection, dispatcher routing.Dispatcher) error {
sid := session.ExportIDToError(ctx)
iConn := connection
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}

View file

@ -7,6 +7,8 @@ import (
"syscall"
"time"
"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/net"
@ -77,7 +79,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
// Process implements proxy.Outbound.Process().
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
var rec *protocol.ServerSpec
var conn internet.Connection
var conn stat.Connection
if err := retry.ExponentialBackoff(5, 200).On(func() error {
rec = h.serverPicker.PickServer()
@ -93,7 +95,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
defer conn.Close()
iConn := conn
statConn, ok := iConn.(*internet.StatCouterConnection)
statConn, ok := iConn.(*stat.CounterConnection)
if ok {
iConn = statConn.Connection
}

View file

@ -9,6 +9,8 @@ import (
"sync"
"time"
"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/errors"
@ -26,7 +28,6 @@ import (
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/proxy/vmess"
"github.com/xtls/xray-core/proxy/vmess/encoding"
"github.com/xtls/xray-core/transport/internet"
)
var (
@ -220,14 +221,14 @@ func isInsecureEncryption(s protocol.SecurityType) bool {
}
// Process implements proxy.Inbound.Process().
func (h *Handler) Process(ctx context.Context, network net.Network, connection internet.Connection, dispatcher routing.Dispatcher) error {
func (h *Handler) Process(ctx context.Context, network net.Network, connection stat.Connection, dispatcher routing.Dispatcher) error {
sessionPolicy := h.policyManager.ForLevel(0)
if err := connection.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)); err != nil {
return newError("unable to set read deadline").Base(err).AtWarning()
}
iConn := connection
if statConn, ok := iConn.(*internet.StatCouterConnection); ok {
if statConn, ok := iConn.(*stat.CounterConnection); ok {
iConn = statConn.Connection
}
_, isDrain := iConn.(*net.TCPConn)

View file

@ -6,6 +6,8 @@ import (
"context"
"time"
"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/net"
@ -57,7 +59,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
// Process implements proxy.Outbound.Process().
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
var rec *protocol.ServerSpec
var conn internet.Connection
var conn stat.Connection
err := retry.ExponentialBackoff(5, 200).On(func() error {
rec = h.serverPicker.PickServer()