refactor(deps): replace github.com/golang/protobuf with google.golang.org/protobuf

This commit is contained in:
hax0r31337 2023-08-10 04:43:34 +00:00 committed by yuhan6665
parent e584b71b60
commit f67167bb3b
37 changed files with 63 additions and 46 deletions

View File

@ -9,7 +9,6 @@ import (
"sync"
"time"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common"
v2net "github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/session"
@ -19,6 +18,7 @@ import (
"github.com/xtls/xray-core/features/extension"
"github.com/xtls/xray-core/features/outbound"
"github.com/xtls/xray-core/transport/internet/tagged"
"google.golang.org/protobuf/proto"
)
type Observer struct {

View File

@ -4,7 +4,6 @@ import (
"context"
"time"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/mux"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/session"
@ -12,6 +11,7 @@ import (
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/pipe"
"google.golang.org/protobuf/proto"
)
// Bridge is a component in reverse proxy, that relays connections from Portal to local address.

View File

@ -5,7 +5,6 @@ import (
"sync"
"time"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/mux"
@ -15,6 +14,7 @@ import (
"github.com/xtls/xray-core/features/outbound"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/pipe"
"google.golang.org/protobuf/proto"
)
type Portal struct {

View File

@ -5,12 +5,12 @@ import (
"path/filepath"
"testing"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/router"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/platform"
"github.com/xtls/xray-core/common/platform/filesystem"
"google.golang.org/protobuf/proto"
)
func init() {

View File

@ -6,7 +6,6 @@ import (
"strconv"
"testing"
"github.com/golang/protobuf/proto"
. "github.com/xtls/xray-core/app/router"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
@ -18,6 +17,7 @@ import (
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/features/routing"
routing_session "github.com/xtls/xray-core/features/routing/session"
"google.golang.org/protobuf/proto"
)
func init() {

View File

@ -1,10 +1,9 @@
package serial
import (
"errors"
"reflect"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
// ToTypedMessage converts a proto Message into TypedMessage.
@ -21,16 +20,17 @@ func ToTypedMessage(message proto.Message) *TypedMessage {
// GetMessageType returns the name of this proto Message.
func GetMessageType(message proto.Message) string {
return proto.MessageName(message)
return string(message.ProtoReflect().Descriptor().FullName())
}
// GetInstance creates a new instance of the message with messageType.
func GetInstance(messageType string) (interface{}, error) {
mType := proto.MessageType(messageType)
if mType == nil || mType.Elem() == nil {
return nil, errors.New("Serial: Unknown type: " + messageType)
messageTypeDescriptor := protoreflect.FullName(messageType)
mType, err := protoregistry.GlobalTypes.FindMessageByName(messageTypeDescriptor)
if err != nil {
return nil, err
}
return reflect.New(mType.Elem()).Interface(), nil
return mType.New().Interface(), nil
}
// GetInstance converts current TypedMessage into a proto Message.

View File

@ -4,11 +4,11 @@ import (
"io"
"strings"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/cmdarg"
"github.com/xtls/xray-core/main/confloader"
"google.golang.org/protobuf/proto"
)
// ConfigFormat is a configurable format of Xray config file.

View File

@ -7,7 +7,6 @@ import (
"testing"
"time"
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/app/proxyman"
@ -18,6 +17,7 @@ import (
"github.com/xtls/xray-core/proxy/freedom"
"github.com/xtls/xray-core/testing/servers/tcp"
"github.com/xtls/xray-core/testing/servers/udp"
"google.golang.org/protobuf/proto"
)
func xor(b []byte) []byte {

View File

@ -3,7 +3,6 @@ package core_test
import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/app/proxyman"
"github.com/xtls/xray-core/common"
@ -19,6 +18,7 @@ import (
"github.com/xtls/xray-core/proxy/vmess"
"github.com/xtls/xray-core/proxy/vmess/outbound"
"github.com/xtls/xray-core/testing/servers/tcp"
"google.golang.org/protobuf/proto"
)
func TestXrayDependency(t *testing.T) {

View File

@ -3,8 +3,8 @@ package extension
import (
"context"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/features"
"google.golang.org/protobuf/proto"
)
type Observatory interface {

2
go.mod
View File

@ -5,7 +5,6 @@ go 1.20
require (
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.5.9
github.com/gorilla/websocket v1.5.0
github.com/miekg/dns v1.1.55
@ -38,6 +37,7 @@ require (
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/gaukas/godicttls v0.0.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect
github.com/klauspost/compress v1.16.6 // indirect

View File

@ -3,9 +3,9 @@ package conf
import (
"encoding/json"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/proxy/blackhole"
"google.golang.org/protobuf/proto"
)
type NoneResponse struct{}

View File

@ -1,6 +1,6 @@
package conf
import "github.com/golang/protobuf/proto"
import "google.golang.org/protobuf/proto"
type Buildable interface {
Build() (proto.Message, error)

View File

@ -1,9 +1,9 @@
package conf
import (
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/proxy/dns"
"google.golang.org/protobuf/proto"
)
type DNSOutboundConfig struct {

View File

@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/dns"
"github.com/xtls/xray-core/app/router"
"github.com/xtls/xray-core/common"
@ -14,6 +13,7 @@ import (
"github.com/xtls/xray-core/common/platform"
"github.com/xtls/xray-core/common/platform/filesystem"
. "github.com/xtls/xray-core/infra/conf"
"google.golang.org/protobuf/proto"
)
func init() {

View File

@ -1,8 +1,8 @@
package conf
import (
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/proxy/dokodemo"
"google.golang.org/protobuf/proto"
)
type DokodemoConfig struct {

View File

@ -5,10 +5,10 @@ import (
"strconv"
"strings"
"github.com/golang/protobuf/proto"
v2net "github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/proxy/freedom"
"google.golang.org/protobuf/proto"
)
type FreedomConfig struct {

View File

@ -4,9 +4,9 @@ import (
"encoding/json"
"testing"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common"
. "github.com/xtls/xray-core/infra/conf"
"google.golang.org/protobuf/proto"
)
func loadJSON(creator func() Buildable) func(string) (proto.Message, error) {

View File

@ -1,8 +1,8 @@
package conf
import (
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/transport/internet/grpc"
"google.golang.org/protobuf/proto"
)
type GRPCConfig struct {

View File

@ -3,10 +3,10 @@ package conf
import (
"encoding/json"
"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/http"
"google.golang.org/protobuf/proto"
)
type HTTPAccount struct {

View File

@ -1,8 +1,8 @@
package conf
import (
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/proxy/loopback"
"google.golang.org/protobuf/proto"
)
type LoopbackConfig struct {

View File

@ -1,9 +1,9 @@
package conf
import (
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/observatory"
"github.com/xtls/xray-core/infra/conf/cfgcommon/duration"
"google.golang.org/protobuf/proto"
)
type ObservatoryConfig struct {

View File

@ -1,8 +1,8 @@
package conf
import (
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/reverse"
"google.golang.org/protobuf/proto"
)
type BridgeConfig struct {

View File

@ -6,10 +6,10 @@ import (
"strconv"
"strings"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/router"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/platform/filesystem"
"google.golang.org/protobuf/proto"
)
type RouterRulesConfig struct {
@ -245,6 +245,23 @@ func loadSite(file, code string) ([]*router.Domain, error) {
return SiteCache[index].Domain, nil
}
func DecodeVarint(buf []byte) (x uint64, n int) {
for shift := uint(0); shift < 64; shift += 7 {
if n >= len(buf) {
return 0, 0
}
b := uint64(buf[n])
n++
x |= (b & 0x7F) << shift
if (b & 0x80) == 0 {
return x, n
}
}
// The number is too large to represent in a 64-bit value.
return 0, 0
}
func find(data, code []byte) []byte {
codeL := len(code)
if codeL == 0 {
@ -255,7 +272,7 @@ func find(data, code []byte) []byte {
if dataL < 2 {
return nil
}
x, y := proto.DecodeVarint(data[1:])
x, y := DecodeVarint(data[1:])
if x == 0 && y == 0 {
return nil
}

View File

@ -7,13 +7,13 @@ import (
"testing"
_ "unsafe"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/router"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/platform"
"github.com/xtls/xray-core/common/platform/filesystem"
. "github.com/xtls/xray-core/infra/conf"
"google.golang.org/protobuf/proto"
)
func init() {

View File

@ -3,13 +3,13 @@ package conf
import (
"strings"
"github.com/golang/protobuf/proto"
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
C "github.com/sagernet/sing/common"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/proxy/shadowsocks"
"github.com/xtls/xray-core/proxy/shadowsocks_2022"
"google.golang.org/protobuf/proto"
)
func cipherFromString(c string) shadowsocks.CipherType {

View File

@ -4,10 +4,10 @@ import (
"encoding/json"
"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/socks"
"google.golang.org/protobuf/proto"
)
type SocksAccount struct {

View File

@ -3,7 +3,6 @@ package conf
import (
"sort"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/transport/internet/headers/dns"
"github.com/xtls/xray-core/transport/internet/headers/http"
"github.com/xtls/xray-core/transport/internet/headers/noop"
@ -12,6 +11,7 @@ import (
"github.com/xtls/xray-core/transport/internet/headers/utp"
"github.com/xtls/xray-core/transport/internet/headers/wechat"
"github.com/xtls/xray-core/transport/internet/headers/wireguard"
"google.golang.org/protobuf/proto"
)
type NoOpAuthenticator struct{}

View File

@ -11,7 +11,6 @@ import (
"strings"
"syscall"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/platform/filesystem"
"github.com/xtls/xray-core/common/protocol"
@ -26,6 +25,7 @@ import (
"github.com/xtls/xray-core/transport/internet/tcp"
"github.com/xtls/xray-core/transport/internet/tls"
"github.com/xtls/xray-core/transport/internet/websocket"
"google.golang.org/protobuf/proto"
)
var (

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"testing"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/serial"
. "github.com/xtls/xray-core/infra/conf"
@ -18,6 +17,7 @@ import (
"github.com/xtls/xray-core/transport/internet/quic"
"github.com/xtls/xray-core/transport/internet/tcp"
"github.com/xtls/xray-core/transport/internet/websocket"
"google.golang.org/protobuf/proto"
)
func TestSocketConfig(t *testing.T) {

View File

@ -6,11 +6,11 @@ import (
"strconv"
"syscall"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/proxy/trojan"
"google.golang.org/protobuf/proto"
)
// TrojanServerTarget is configuration of a single trojan server

View File

@ -6,7 +6,6 @@ import (
"strconv"
"syscall"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/serial"
@ -14,6 +13,7 @@ import (
"github.com/xtls/xray-core/proxy/vless"
"github.com/xtls/xray-core/proxy/vless/inbound"
"github.com/xtls/xray-core/proxy/vless/outbound"
"google.golang.org/protobuf/proto"
)
type VLessInboundFallback struct {

View File

@ -4,13 +4,13 @@ import (
"encoding/json"
"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/common/uuid"
"github.com/xtls/xray-core/proxy/vmess"
"github.com/xtls/xray-core/proxy/vmess/inbound"
"github.com/xtls/xray-core/proxy/vmess/outbound"
"google.golang.org/protobuf/proto"
)
type VMessAccount struct {

View File

@ -4,8 +4,8 @@ import (
"encoding/base64"
"encoding/hex"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/proxy/wireguard"
"google.golang.org/protobuf/proto"
)
type WireGuardPeerConfig struct {

View File

@ -5,7 +5,6 @@ import (
"reflect"
"testing"
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/app/log"
@ -27,6 +26,7 @@ import (
"github.com/xtls/xray-core/transport/internet/http"
"github.com/xtls/xray-core/transport/internet/tls"
"github.com/xtls/xray-core/transport/internet/websocket"
"google.golang.org/protobuf/proto"
)
func TestXrayConfig(t *testing.T) {

View File

@ -3,10 +3,10 @@ package encoding
import (
"io"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/proxy/vless"
"google.golang.org/protobuf/proto"
)
func EncodeHeaderAddons(buffer *buf.Buffer, addons *Addons) error {

View File

@ -14,7 +14,6 @@ import (
"testing"
"time"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/app/proxyman"
"github.com/xtls/xray-core/common"
@ -25,6 +24,7 @@ import (
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/common/units"
core "github.com/xtls/xray-core/core"
"google.golang.org/protobuf/proto"
)
func xor(b []byte) []byte {