From 95e9816223faa154a8f86c43b565a1e203b61937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=90=B2=93=F0=90=B3=9B=F0=90=B3=AA=F0=90=B3=82?= =?UTF-8?q?=F0=90=B3=90=20=F0=90=B2=80=F0=90=B3=A2=F0=90=B3=A6=F0=90=B3=AB?= =?UTF-8?q?=F0=90=B3=A2=20=F0=90=B2=A5=F0=90=B3=94=F0=90=B3=9B=F0=90=B3=AA?= =?UTF-8?q?=F0=90=B3=8C=F0=90=B3=91=F0=90=B3=96=F0=90=B3=87?= <26771058+KobeArthurScofield@users.noreply.github.com> Date: Tue, 9 Jun 2026 18:55:42 +0800 Subject: [PATCH] Chore: Limit sing* dependencies to shadowsocks_2022 only (#6286) https://github.com/XTLS/Xray-core/pull/6286#issuecomment-4658968225 --- app/proxyman/outbound/handler.go | 6 ---- app/proxyman/outbound/uot.go | 35 ------------------ infra/conf/shadowsocks.go | 46 ++++++++++-------------- proxy/shadowsocks_2022/config.pb.go | 37 +++++-------------- proxy/shadowsocks_2022/config.proto | 2 -- proxy/shadowsocks_2022/outbound.go | 29 ++++----------- transport/internet/finalmask/udp_test.go | 21 ----------- 7 files changed, 34 insertions(+), 142 deletions(-) delete mode 100644 app/proxyman/outbound/uot.go diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index 7284a848..578b2ca1 100644 --- a/app/proxyman/outbound/handler.go +++ b/app/proxyman/outbound/handler.go @@ -6,7 +6,6 @@ import ( goerrors "errors" "io" "math/big" - "os" "github.com/xtls/xray-core/common/dice" @@ -306,11 +305,6 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (stat.Connecti ob := outbounds[len(outbounds)-1] h.SetOutboundGateway(ctx, ob) } - - } - - if conn, err := h.getUoTConnection(ctx, dest); err != os.ErrInvalid { - return conn, err } conn, err := internet.Dial(ctx, dest, h.streamSettings) diff --git a/app/proxyman/outbound/uot.go b/app/proxyman/outbound/uot.go deleted file mode 100644 index 659f65a1..00000000 --- a/app/proxyman/outbound/uot.go +++ /dev/null @@ -1,35 +0,0 @@ -package outbound - -import ( - "context" - "os" - - "github.com/sagernet/sing/common/uot" - "github.com/xtls/xray-core/common/errors" - "github.com/xtls/xray-core/common/net" - "github.com/xtls/xray-core/transport/internet" - "github.com/xtls/xray-core/transport/internet/stat" -) - -func (h *Handler) getUoTConnection(ctx context.Context, dest net.Destination) (stat.Connection, error) { - if dest.Address == nil { - return nil, errors.New("nil destination address") - } - if !dest.Address.Family().IsDomain() { - return nil, os.ErrInvalid - } - var uotVersion int - if dest.Address.Domain() == uot.MagicAddress { - uotVersion = uot.Version - } else if dest.Address.Domain() == uot.LegacyMagicAddress { - uotVersion = uot.LegacyVersion - } else { - return nil, os.ErrInvalid - } - packetConn, err := internet.ListenSystemPacket(ctx, &net.UDPAddr{IP: net.AnyIP.IP(), Port: 0}, h.streamSettings.SocketSettings) - if err != nil { - return nil, errors.New("unable to listen socket").Base(err) - } - conn := uot.NewServerConn(packetConn, uotVersion) - return h.getStatCouterConnection(conn), nil -} diff --git a/infra/conf/shadowsocks.go b/infra/conf/shadowsocks.go index 30a7fd65..2cfc0953 100644 --- a/infra/conf/shadowsocks.go +++ b/infra/conf/shadowsocks.go @@ -179,26 +179,22 @@ func buildShadowsocks2022(v *ShadowsocksServerConfig) (proto.Message, error) { } type ShadowsocksServerTarget struct { - Address *Address `json:"address"` - Port uint16 `json:"port"` - Level byte `json:"level"` - Email string `json:"email"` - Cipher string `json:"method"` - Password string `json:"password"` - UoT bool `json:"uot"` - UoTVersion int `json:"uotVersion"` + Address *Address `json:"address"` + Port uint16 `json:"port"` + Level byte `json:"level"` + Email string `json:"email"` + Cipher string `json:"method"` + Password string `json:"password"` } type ShadowsocksClientConfig struct { - Address *Address `json:"address"` - Port uint16 `json:"port"` - Level byte `json:"level"` - Email string `json:"email"` - Cipher string `json:"method"` - Password string `json:"password"` - UoT bool `json:"uot"` - UoTVersion int `json:"uotVersion"` - Servers []*ShadowsocksServerTarget `json:"servers"` + Address *Address `json:"address"` + Port uint16 `json:"port"` + Level byte `json:"level"` + Email string `json:"email"` + Cipher string `json:"method"` + Password string `json:"password"` + Servers []*ShadowsocksServerTarget `json:"servers"` } func (v *ShadowsocksClientConfig) Build() (proto.Message, error) { @@ -207,14 +203,12 @@ func (v *ShadowsocksClientConfig) Build() (proto.Message, error) { if v.Address != nil { v.Servers = []*ShadowsocksServerTarget{ { - Address: v.Address, - Port: v.Port, - Level: v.Level, - Email: v.Email, - Cipher: v.Cipher, - Password: v.Password, - UoT: v.UoT, - UoTVersion: v.UoTVersion, + Address: v.Address, + Port: v.Port, + Level: v.Level, + Email: v.Email, + Cipher: v.Cipher, + Password: v.Password, }, } } @@ -240,8 +234,6 @@ func (v *ShadowsocksClientConfig) Build() (proto.Message, error) { config.Port = uint32(server.Port) config.Method = server.Cipher config.Key = server.Password - config.UdpOverTcp = server.UoT - config.UdpOverTcpVersion = uint32(server.UoTVersion) return config, nil } } diff --git a/proxy/shadowsocks_2022/config.pb.go b/proxy/shadowsocks_2022/config.pb.go index df2ee7cb..7213bd2d 100644 --- a/proxy/shadowsocks_2022/config.pb.go +++ b/proxy/shadowsocks_2022/config.pb.go @@ -356,15 +356,13 @@ func (x *Account) GetKey() string { } type ClientConfig struct { - state protoimpl.MessageState `protogen:"open.v1"` - Address *net.IPOrDomain `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - Port uint32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` - Method string `protobuf:"bytes,3,opt,name=method,proto3" json:"method,omitempty"` - Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` - UdpOverTcp bool `protobuf:"varint,5,opt,name=udp_over_tcp,json=udpOverTcp,proto3" json:"udp_over_tcp,omitempty"` - UdpOverTcpVersion uint32 `protobuf:"varint,6,opt,name=udp_over_tcp_version,json=udpOverTcpVersion,proto3" json:"udp_over_tcp_version,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Address *net.IPOrDomain `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Port uint32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` + Method string `protobuf:"bytes,3,opt,name=method,proto3" json:"method,omitempty"` + Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *ClientConfig) Reset() { @@ -425,20 +423,6 @@ func (x *ClientConfig) GetKey() string { return "" } -func (x *ClientConfig) GetUdpOverTcp() bool { - if x != nil { - return x.UdpOverTcp - } - return false -} - -func (x *ClientConfig) GetUdpOverTcpVersion() uint32 { - if x != nil { - return x.UdpOverTcpVersion - } - return 0 -} - var File_proxy_shadowsocks_2022_config_proto protoreflect.FileDescriptor const file_proxy_shadowsocks_2022_config_proto_rawDesc = "" + @@ -467,15 +451,12 @@ const file_proxy_shadowsocks_2022_config_proto_rawDesc = "" + "\fdestinations\x18\x03 \x03(\v2-.xray.proxy.shadowsocks_2022.RelayDestinationR\fdestinations\x122\n" + "\anetwork\x18\x04 \x03(\x0e2\x18.xray.common.net.NetworkR\anetwork\"\x1b\n" + "\aAccount\x12\x10\n" + - "\x03key\x18\x01 \x01(\tR\x03key\"\xd6\x01\n" + + "\x03key\x18\x01 \x01(\tR\x03key\"\x83\x01\n" + "\fClientConfig\x125\n" + "\aaddress\x18\x01 \x01(\v2\x1b.xray.common.net.IPOrDomainR\aaddress\x12\x12\n" + "\x04port\x18\x02 \x01(\rR\x04port\x12\x16\n" + "\x06method\x18\x03 \x01(\tR\x06method\x12\x10\n" + - "\x03key\x18\x04 \x01(\tR\x03key\x12 \n" + - "\fudp_over_tcp\x18\x05 \x01(\bR\n" + - "udpOverTcp\x12/\n" + - "\x14udp_over_tcp_version\x18\x06 \x01(\rR\x11udpOverTcpVersionBr\n" + + "\x03key\x18\x04 \x01(\tR\x03keyBr\n" + "\x1fcom.xray.proxy.shadowsocks_2022P\x01Z0github.com/xtls/xray-core/proxy/shadowsocks_2022\xaa\x02\x1aXray.Proxy.Shadowsocks2022b\x06proto3" var ( diff --git a/proxy/shadowsocks_2022/config.proto b/proxy/shadowsocks_2022/config.proto index 14006648..c73943d4 100644 --- a/proxy/shadowsocks_2022/config.proto +++ b/proxy/shadowsocks_2022/config.proto @@ -49,6 +49,4 @@ message ClientConfig { uint32 port = 2; string method = 3; string key = 4; - bool udp_over_tcp = 5; - uint32 udp_over_tcp_version = 6; } diff --git a/proxy/shadowsocks_2022/outbound.go b/proxy/shadowsocks_2022/outbound.go index bd3e4c4e..f1195950 100644 --- a/proxy/shadowsocks_2022/outbound.go +++ b/proxy/shadowsocks_2022/outbound.go @@ -10,7 +10,6 @@ import ( B "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/bufio" N "github.com/sagernet/sing/common/network" - "github.com/sagernet/sing/common/uot" "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/errors" @@ -29,10 +28,9 @@ func init() { } type Outbound struct { - ctx context.Context - server net.Destination - method shadowsocks.Method - uotClient *uot.Client + ctx context.Context + server net.Destination + method shadowsocks.Method } func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) { @@ -56,9 +54,6 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) { } else { return nil, errors.New("unknown method ", config.Method) } - if config.UdpOverTcp { - o.uotClient = &uot.Client{Version: uint8(config.UdpOverTcpVersion)} - } return o, nil } @@ -82,11 +77,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int errors.LogInfo(ctx, "tunneling request to ", destination, " via ", o.server.NetAddr()) serverDestination := o.server - if o.uotClient != nil { - serverDestination.Network = net.Network_TCP - } else { - serverDestination.Network = network - } + serverDestination.Network = network connection, err := dialer.Dial(ctx, serverDestination) if err != nil { return errors.New("failed to connect to server").Base(err) @@ -149,15 +140,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int } } - if o.uotClient != nil { - uConn, err := o.uotClient.DialEarlyConn(o.method.DialEarlyConn(connection, uot.RequestDestination(o.uotClient.Version)), false, singbridge.ToSocksaddr(destination)) - if err != nil { - return err - } - return singbridge.ReturnError(bufio.CopyPacketConn(ctx, packetConn, uConn)) - } else { - serverConn := o.method.DialPacketConn(connection) - return singbridge.ReturnError(bufio.CopyPacketConn(ctx, packetConn, serverConn)) - } + serverConn := o.method.DialPacketConn(connection) + return singbridge.ReturnError(bufio.CopyPacketConn(ctx, packetConn, serverConn)) } } diff --git a/transport/internet/finalmask/udp_test.go b/transport/internet/finalmask/udp_test.go index 8a507d2e..95233e02 100644 --- a/transport/internet/finalmask/udp_test.go +++ b/transport/internet/finalmask/udp_test.go @@ -2,7 +2,6 @@ package finalmask_test import ( "bytes" - "context" "encoding/binary" "io" "net" @@ -10,8 +9,6 @@ import ( "testing" "time" - singM "github.com/sagernet/sing/common/metadata" - singN "github.com/sagernet/sing/common/network" "github.com/xtls/xray-core/proxy" "github.com/xtls/xray-core/transport/internet/finalmask" "github.com/xtls/xray-core/transport/internet/finalmask/header/custom" @@ -134,24 +131,6 @@ func (c *scriptedPacketConn) SetWriteDeadline(t time.Time) error { return nil } -type captureUDPHandler struct { - gotMetadata chan singM.Metadata -} - -func (h *captureUDPHandler) NewConnection(_ context.Context, _ net.Conn, _ singM.Metadata) error { - return nil -} - -func (h *captureUDPHandler) NewPacketConnection(_ context.Context, _ singN.PacketConn, metadata singM.Metadata) error { - select { - case h.gotMetadata <- metadata: - default: - } - return nil -} - -func (h *captureUDPHandler) NewError(_ context.Context, _ error) {} - func newStandaloneEchoUDPConfig() *custom.UDPStandaloneConfig { return &custom.UDPStandaloneConfig{ Client: []*custom.UDPItem{