mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-06 11:48:47 +00:00
Chore: Limit sing* dependencies to shadowsocks_2022 only (#6286)
https://github.com/XTLS/Xray-core/pull/6286#issuecomment-4658968225
This commit is contained in:
committed by
GitHub
parent
3239d21168
commit
95e9816223
@@ -6,7 +6,6 @@ import (
|
|||||||
goerrors "errors"
|
goerrors "errors"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/dice"
|
"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]
|
ob := outbounds[len(outbounds)-1]
|
||||||
h.SetOutboundGateway(ctx, ob)
|
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)
|
conn, err := internet.Dial(ctx, dest, h.streamSettings)
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
+19
-27
@@ -179,26 +179,22 @@ func buildShadowsocks2022(v *ShadowsocksServerConfig) (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ShadowsocksServerTarget struct {
|
type ShadowsocksServerTarget struct {
|
||||||
Address *Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Level byte `json:"level"`
|
Level byte `json:"level"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Cipher string `json:"method"`
|
Cipher string `json:"method"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
UoT bool `json:"uot"`
|
|
||||||
UoTVersion int `json:"uotVersion"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShadowsocksClientConfig struct {
|
type ShadowsocksClientConfig struct {
|
||||||
Address *Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Level byte `json:"level"`
|
Level byte `json:"level"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Cipher string `json:"method"`
|
Cipher string `json:"method"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
UoT bool `json:"uot"`
|
Servers []*ShadowsocksServerTarget `json:"servers"`
|
||||||
UoTVersion int `json:"uotVersion"`
|
|
||||||
Servers []*ShadowsocksServerTarget `json:"servers"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ShadowsocksClientConfig) Build() (proto.Message, error) {
|
func (v *ShadowsocksClientConfig) Build() (proto.Message, error) {
|
||||||
@@ -207,14 +203,12 @@ func (v *ShadowsocksClientConfig) Build() (proto.Message, error) {
|
|||||||
if v.Address != nil {
|
if v.Address != nil {
|
||||||
v.Servers = []*ShadowsocksServerTarget{
|
v.Servers = []*ShadowsocksServerTarget{
|
||||||
{
|
{
|
||||||
Address: v.Address,
|
Address: v.Address,
|
||||||
Port: v.Port,
|
Port: v.Port,
|
||||||
Level: v.Level,
|
Level: v.Level,
|
||||||
Email: v.Email,
|
Email: v.Email,
|
||||||
Cipher: v.Cipher,
|
Cipher: v.Cipher,
|
||||||
Password: v.Password,
|
Password: v.Password,
|
||||||
UoT: v.UoT,
|
|
||||||
UoTVersion: v.UoTVersion,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,8 +234,6 @@ func (v *ShadowsocksClientConfig) Build() (proto.Message, error) {
|
|||||||
config.Port = uint32(server.Port)
|
config.Port = uint32(server.Port)
|
||||||
config.Method = server.Cipher
|
config.Method = server.Cipher
|
||||||
config.Key = server.Password
|
config.Key = server.Password
|
||||||
config.UdpOverTcp = server.UoT
|
|
||||||
config.UdpOverTcpVersion = uint32(server.UoTVersion)
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,15 +356,13 @@ func (x *Account) GetKey() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ClientConfig struct {
|
type ClientConfig struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Address *net.IPOrDomain `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
|
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"`
|
Port uint32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"`
|
||||||
Method string `protobuf:"bytes,3,opt,name=method,proto3" json:"method,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"`
|
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"`
|
unknownFields protoimpl.UnknownFields
|
||||||
UdpOverTcpVersion uint32 `protobuf:"varint,6,opt,name=udp_over_tcp_version,json=udpOverTcpVersion,proto3" json:"udp_over_tcp_version,omitempty"`
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ClientConfig) Reset() {
|
func (x *ClientConfig) Reset() {
|
||||||
@@ -425,20 +423,6 @@ func (x *ClientConfig) GetKey() string {
|
|||||||
return ""
|
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
|
var File_proxy_shadowsocks_2022_config_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
const file_proxy_shadowsocks_2022_config_proto_rawDesc = "" +
|
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" +
|
"\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" +
|
"\anetwork\x18\x04 \x03(\x0e2\x18.xray.common.net.NetworkR\anetwork\"\x1b\n" +
|
||||||
"\aAccount\x12\x10\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" +
|
"\fClientConfig\x125\n" +
|
||||||
"\aaddress\x18\x01 \x01(\v2\x1b.xray.common.net.IPOrDomainR\aaddress\x12\x12\n" +
|
"\aaddress\x18\x01 \x01(\v2\x1b.xray.common.net.IPOrDomainR\aaddress\x12\x12\n" +
|
||||||
"\x04port\x18\x02 \x01(\rR\x04port\x12\x16\n" +
|
"\x04port\x18\x02 \x01(\rR\x04port\x12\x16\n" +
|
||||||
"\x06method\x18\x03 \x01(\tR\x06method\x12\x10\n" +
|
"\x06method\x18\x03 \x01(\tR\x06method\x12\x10\n" +
|
||||||
"\x03key\x18\x04 \x01(\tR\x03key\x12 \n" +
|
"\x03key\x18\x04 \x01(\tR\x03keyBr\n" +
|
||||||
"\fudp_over_tcp\x18\x05 \x01(\bR\n" +
|
|
||||||
"udpOverTcp\x12/\n" +
|
|
||||||
"\x14udp_over_tcp_version\x18\x06 \x01(\rR\x11udpOverTcpVersionBr\n" +
|
|
||||||
"\x1fcom.xray.proxy.shadowsocks_2022P\x01Z0github.com/xtls/xray-core/proxy/shadowsocks_2022\xaa\x02\x1aXray.Proxy.Shadowsocks2022b\x06proto3"
|
"\x1fcom.xray.proxy.shadowsocks_2022P\x01Z0github.com/xtls/xray-core/proxy/shadowsocks_2022\xaa\x02\x1aXray.Proxy.Shadowsocks2022b\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -49,6 +49,4 @@ message ClientConfig {
|
|||||||
uint32 port = 2;
|
uint32 port = 2;
|
||||||
string method = 3;
|
string method = 3;
|
||||||
string key = 4;
|
string key = 4;
|
||||||
bool udp_over_tcp = 5;
|
|
||||||
uint32 udp_over_tcp_version = 6;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
B "github.com/sagernet/sing/common/buf"
|
B "github.com/sagernet/sing/common/buf"
|
||||||
"github.com/sagernet/sing/common/bufio"
|
"github.com/sagernet/sing/common/bufio"
|
||||||
N "github.com/sagernet/sing/common/network"
|
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"
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
@@ -29,10 +28,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Outbound struct {
|
type Outbound struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
server net.Destination
|
server net.Destination
|
||||||
method shadowsocks.Method
|
method shadowsocks.Method
|
||||||
uotClient *uot.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
|
func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
|
||||||
@@ -56,9 +54,6 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
|
|||||||
} else {
|
} else {
|
||||||
return nil, errors.New("unknown method ", config.Method)
|
return nil, errors.New("unknown method ", config.Method)
|
||||||
}
|
}
|
||||||
if config.UdpOverTcp {
|
|
||||||
o.uotClient = &uot.Client{Version: uint8(config.UdpOverTcpVersion)}
|
|
||||||
}
|
|
||||||
return o, nil
|
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())
|
errors.LogInfo(ctx, "tunneling request to ", destination, " via ", o.server.NetAddr())
|
||||||
|
|
||||||
serverDestination := o.server
|
serverDestination := o.server
|
||||||
if o.uotClient != nil {
|
serverDestination.Network = network
|
||||||
serverDestination.Network = net.Network_TCP
|
|
||||||
} else {
|
|
||||||
serverDestination.Network = network
|
|
||||||
}
|
|
||||||
connection, err := dialer.Dial(ctx, serverDestination)
|
connection, err := dialer.Dial(ctx, serverDestination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("failed to connect to server").Base(err)
|
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 {
|
serverConn := o.method.DialPacketConn(connection)
|
||||||
uConn, err := o.uotClient.DialEarlyConn(o.method.DialEarlyConn(connection, uot.RequestDestination(o.uotClient.Version)), false, singbridge.ToSocksaddr(destination))
|
return singbridge.ReturnError(bufio.CopyPacketConn(ctx, packetConn, serverConn))
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package finalmask_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@@ -10,8 +9,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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/proxy"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask"
|
"github.com/xtls/xray-core/transport/internet/finalmask"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/header/custom"
|
"github.com/xtls/xray-core/transport/internet/finalmask/header/custom"
|
||||||
@@ -134,24 +131,6 @@ func (c *scriptedPacketConn) SetWriteDeadline(t time.Time) error {
|
|||||||
return nil
|
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 {
|
func newStandaloneEchoUDPConfig() *custom.UDPStandaloneConfig {
|
||||||
return &custom.UDPStandaloneConfig{
|
return &custom.UDPStandaloneConfig{
|
||||||
Client: []*custom.UDPItem{
|
Client: []*custom.UDPItem{
|
||||||
|
|||||||
Reference in New Issue
Block a user