mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +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
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue