From debd2e3ba85b38762f765496cd3b45cd97e4f3db Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Thu, 15 Sep 2022 22:16:29 -0400 Subject: [PATCH] Remove compatibility code The minimum support go version is already 1.18 --- app/proxyman/outbound/uot.go | 2 - app/proxyman/outbound/uot_stub.go | 15 -- common/protocol/quic/qtls_go116.go | 19 --- common/protocol/quic/qtls_go117.go | 19 --- common/protocol/quic/qtls_go118.go | 3 - infra/conf/shadowsocks.go | 2 - infra/conf/shadowsocks_legacy.go | 154 --------------------- proxy/shadowsocks_2022/inbound.go | 2 - proxy/shadowsocks_2022/inbound_multi.go | 2 - proxy/shadowsocks_2022/outbound.go | 2 - proxy/shadowsocks_2022/shadowsocks_2022.go | 2 - 11 files changed, 222 deletions(-) delete mode 100644 app/proxyman/outbound/uot_stub.go delete mode 100644 common/protocol/quic/qtls_go116.go delete mode 100644 common/protocol/quic/qtls_go117.go delete mode 100644 infra/conf/shadowsocks_legacy.go diff --git a/app/proxyman/outbound/uot.go b/app/proxyman/outbound/uot.go index b1a851d9..a4af220c 100644 --- a/app/proxyman/outbound/uot.go +++ b/app/proxyman/outbound/uot.go @@ -1,5 +1,3 @@ -//go:build go1.18 - package outbound import ( diff --git a/app/proxyman/outbound/uot_stub.go b/app/proxyman/outbound/uot_stub.go deleted file mode 100644 index 05f421cf..00000000 --- a/app/proxyman/outbound/uot_stub.go +++ /dev/null @@ -1,15 +0,0 @@ -//go:build !go1.18 - -package outbound - -import ( - "context" - "os" - - "github.com/xtls/xray-core/common/net" - "github.com/xtls/xray-core/transport/internet/stat" -) - -func (h *Handler) getUoTConnection(ctx context.Context, dest net.Destination) (stat.Connection, error) { - return nil, os.ErrInvalid -} diff --git a/common/protocol/quic/qtls_go116.go b/common/protocol/quic/qtls_go116.go deleted file mode 100644 index da849ea3..00000000 --- a/common/protocol/quic/qtls_go116.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build go1.16 && !go1.17 -// +build go1.16,!go1.17 - -package quic - -import ( - "crypto/cipher" - - "github.com/marten-seemann/qtls-go1-16" -) - -type ( - // A CipherSuiteTLS13 is a cipher suite for TLS 1.3 - CipherSuiteTLS13 = qtls.CipherSuiteTLS13 -) - -func AEADAESGCMTLS13(key, fixedNonce []byte) cipher.AEAD { - return qtls.AEADAESGCMTLS13(key, fixedNonce) -} diff --git a/common/protocol/quic/qtls_go117.go b/common/protocol/quic/qtls_go117.go deleted file mode 100644 index 08e8d483..00000000 --- a/common/protocol/quic/qtls_go117.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build go1.17 && !go1.18 -// +build go1.17,!go1.18 - -package quic - -import ( - "crypto/cipher" - - "github.com/marten-seemann/qtls-go1-17" -) - -type ( - // A CipherSuiteTLS13 is a cipher suite for TLS 1.3 - CipherSuiteTLS13 = qtls.CipherSuiteTLS13 -) - -func AEADAESGCMTLS13(key, fixedNonce []byte) cipher.AEAD { - return qtls.AEADAESGCMTLS13(key, fixedNonce) -} diff --git a/common/protocol/quic/qtls_go118.go b/common/protocol/quic/qtls_go118.go index 0bcacff2..ce5169b5 100644 --- a/common/protocol/quic/qtls_go118.go +++ b/common/protocol/quic/qtls_go118.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package quic import ( diff --git a/infra/conf/shadowsocks.go b/infra/conf/shadowsocks.go index 853010c3..d35aa3ab 100644 --- a/infra/conf/shadowsocks.go +++ b/infra/conf/shadowsocks.go @@ -1,5 +1,3 @@ -//go:build go1.18 - package conf import ( diff --git a/infra/conf/shadowsocks_legacy.go b/infra/conf/shadowsocks_legacy.go deleted file mode 100644 index c3f0e67a..00000000 --- a/infra/conf/shadowsocks_legacy.go +++ /dev/null @@ -1,154 +0,0 @@ -//go:build !go1.18 - -package conf - -import ( - "strings" - - "github.com/golang/protobuf/proto" - "github.com/xtls/xray-core/common/protocol" - "github.com/xtls/xray-core/common/serial" - "github.com/xtls/xray-core/proxy/shadowsocks" -) - -func cipherFromString(c string) shadowsocks.CipherType { - switch strings.ToLower(c) { - case "aes-128-gcm", "aead_aes_128_gcm": - return shadowsocks.CipherType_AES_128_GCM - case "aes-256-gcm", "aead_aes_256_gcm": - return shadowsocks.CipherType_AES_256_GCM - case "chacha20-poly1305", "aead_chacha20_poly1305", "chacha20-ietf-poly1305": - return shadowsocks.CipherType_CHACHA20_POLY1305 - case "xchacha20-poly1305", "aead_xchacha20_poly1305", "xchacha20-ietf-poly1305": - return shadowsocks.CipherType_XCHACHA20_POLY1305 - case "none", "plain": - return shadowsocks.CipherType_NONE - default: - return shadowsocks.CipherType_UNKNOWN - } -} - -type ShadowsocksUserConfig struct { - Cipher string `json:"method"` - Password string `json:"password"` - Level byte `json:"level"` - Email string `json:"email"` -} - -type ShadowsocksServerConfig struct { - Cipher string `json:"method"` - Password string `json:"password"` - Level byte `json:"level"` - Email string `json:"email"` - Users []*ShadowsocksUserConfig `json:"clients"` - NetworkList *NetworkList `json:"network"` - IVCheck bool `json:"ivCheck"` -} - -func (v *ShadowsocksServerConfig) Build() (proto.Message, error) { - config := new(shadowsocks.ServerConfig) - config.Network = v.NetworkList.Build() - - if v.Users != nil { - for _, user := range v.Users { - account := &shadowsocks.Account{ - Password: user.Password, - CipherType: cipherFromString(user.Cipher), - IvCheck: v.IVCheck, - } - if account.Password == "" { - return nil, newError("Shadowsocks password is not specified.") - } - if account.CipherType < shadowsocks.CipherType_AES_128_GCM || - account.CipherType > shadowsocks.CipherType_XCHACHA20_POLY1305 { - return nil, newError("unsupported cipher method: ", user.Cipher) - } - config.Users = append(config.Users, &protocol.User{ - Email: user.Email, - Level: uint32(user.Level), - Account: serial.ToTypedMessage(account), - }) - } - } else { - account := &shadowsocks.Account{ - Password: v.Password, - CipherType: cipherFromString(v.Cipher), - IvCheck: v.IVCheck, - } - if account.Password == "" { - return nil, newError("Shadowsocks password is not specified.") - } - if account.CipherType == shadowsocks.CipherType_UNKNOWN { - return nil, newError("unknown cipher method: ", v.Cipher) - } - config.Users = append(config.Users, &protocol.User{ - Email: v.Email, - Level: uint32(v.Level), - Account: serial.ToTypedMessage(account), - }) - } - - return config, nil -} - -type ShadowsocksServerTarget struct { - Address *Address `json:"address"` - Port uint16 `json:"port"` - Cipher string `json:"method"` - Password string `json:"password"` - Email string `json:"email"` - Level byte `json:"level"` - IVCheck bool `json:"ivCheck"` - UoT bool `json:"uot"` -} - -type ShadowsocksClientConfig struct { - Servers []*ShadowsocksServerTarget `json:"servers"` -} - -func (v *ShadowsocksClientConfig) Build() (proto.Message, error) { - if len(v.Servers) == 0 { - return nil, newError("0 Shadowsocks server configured.") - } - - config := new(shadowsocks.ClientConfig) - serverSpecs := make([]*protocol.ServerEndpoint, len(v.Servers)) - for idx, server := range v.Servers { - if server.Address == nil { - return nil, newError("Shadowsocks server address is not set.") - } - if server.Port == 0 { - return nil, newError("Invalid Shadowsocks port.") - } - if server.Password == "" { - return nil, newError("Shadowsocks password is not specified.") - } - account := &shadowsocks.Account{ - Password: server.Password, - } - account.CipherType = cipherFromString(server.Cipher) - if account.CipherType == shadowsocks.CipherType_UNKNOWN { - return nil, newError("unknown cipher method: ", server.Cipher) - } - - account.IvCheck = server.IVCheck - - ss := &protocol.ServerEndpoint{ - Address: server.Address.Build(), - Port: uint32(server.Port), - User: []*protocol.User{ - { - Level: uint32(server.Level), - Email: server.Email, - Account: serial.ToTypedMessage(account), - }, - }, - } - - serverSpecs[idx] = ss - } - - config.Server = serverSpecs - - return config, nil -} diff --git a/proxy/shadowsocks_2022/inbound.go b/proxy/shadowsocks_2022/inbound.go index ce1a5aa8..55bdda9f 100644 --- a/proxy/shadowsocks_2022/inbound.go +++ b/proxy/shadowsocks_2022/inbound.go @@ -1,5 +1,3 @@ -//go:build go1.18 - package shadowsocks_2022 import ( diff --git a/proxy/shadowsocks_2022/inbound_multi.go b/proxy/shadowsocks_2022/inbound_multi.go index 10f0efc2..cbc27e41 100644 --- a/proxy/shadowsocks_2022/inbound_multi.go +++ b/proxy/shadowsocks_2022/inbound_multi.go @@ -1,5 +1,3 @@ -//go:build go1.18 - package shadowsocks_2022 import ( diff --git a/proxy/shadowsocks_2022/outbound.go b/proxy/shadowsocks_2022/outbound.go index d2813b4e..cc23f737 100644 --- a/proxy/shadowsocks_2022/outbound.go +++ b/proxy/shadowsocks_2022/outbound.go @@ -1,5 +1,3 @@ -//go:build go1.18 - package shadowsocks_2022 import ( diff --git a/proxy/shadowsocks_2022/shadowsocks_2022.go b/proxy/shadowsocks_2022/shadowsocks_2022.go index 3d095e8f..945c4499 100644 --- a/proxy/shadowsocks_2022/shadowsocks_2022.go +++ b/proxy/shadowsocks_2022/shadowsocks_2022.go @@ -1,5 +1,3 @@ -//go:build go1.18 - package shadowsocks_2022 import (