From 41ce6ccf9f0c28c9b4061c79681b5ef2d2db4fd1 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Fri, 4 Feb 2022 21:59:50 -0500 Subject: [PATCH] Make reverse proxy compatible with v2fly (#924) * Make reverse proxy compatible with v2fly * Fix gitignore * Regenerate proto files - fix v2ray name in loopback * Fix fly.org in unit tests --- .gitignore | 3 +-- app/dns/fakedns/fakedns_test.go | 12 ++++----- app/log/command/config_grpc.pb.go | 4 +++ app/observatory/command/command_grpc.pb.go | 4 +++ app/proxyman/command/command_grpc.pb.go | 4 +++ app/proxyman/config.pb.go | 2 +- app/reverse/reverse.go | 2 +- app/router/command/command_grpc.pb.go | 4 +++ app/stats/command/command_grpc.pb.go | 4 +++ proxy/loopback/config.pb.go | 26 +++++++++---------- proxy/loopback/config.proto | 2 +- .../internet/grpc/encoding/stream_grpc.pb.go | 4 +++ 12 files changed, 47 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 1c8eee3c..9242f587 100644 --- a/.gitignore +++ b/.gitignore @@ -18,8 +18,7 @@ .idea *.zip *.tar.gz -v2ray -v2ctl +xray mockgen vprotogen !infra/vprotogen/ diff --git a/app/dns/fakedns/fakedns_test.go b/app/dns/fakedns/fakedns_test.go index 139a8407..e946e238 100644 --- a/app/dns/fakedns/fakedns_test.go +++ b/app/dns/fakedns/fakedns_test.go @@ -147,31 +147,31 @@ func TestFakeDNSMulti(t *testing.T) { }) t.Run("allocateTwoAddressForTwoPool", func(t *testing.T) { - address := fakeMulti.GetFakeIPForDomain("fakednstest.v2fly.org") + address := fakeMulti.GetFakeIPForDomain("fakednstest.example.com") assert.Len(t, address, 2, "should be 2 address one for each pool") t.Run("eachOfThemShouldResolve:0", func(t *testing.T) { domain := fakeMulti.GetDomainFromFakeDNS(address[0]) - assert.Equal(t, "fakednstest.v2fly.org", domain) + assert.Equal(t, "fakednstest.example.com", domain) }) t.Run("eachOfThemShouldResolve:1", func(t *testing.T) { domain := fakeMulti.GetDomainFromFakeDNS(address[1]) - assert.Equal(t, "fakednstest.v2fly.org", domain) + assert.Equal(t, "fakednstest.example.com", domain) }) }) t.Run("understandIPTypeSelector", func(t *testing.T) { t.Run("ipv4", func(t *testing.T) { - address := fakeMulti.GetFakeIPForDomain3("fakednstestipv4.v2fly.org", true, false) + address := fakeMulti.GetFakeIPForDomain3("fakednstestipv4.example.com", true, false) assert.Len(t, address, 1, "should be 1 address") assert.True(t, address[0].Family().IsIPv4()) }) t.Run("ipv6", func(t *testing.T) { - address := fakeMulti.GetFakeIPForDomain3("fakednstestipv6.v2fly.org", false, true) + address := fakeMulti.GetFakeIPForDomain3("fakednstestipv6.example.com", false, true) assert.Len(t, address, 1, "should be 1 address") assert.True(t, address[0].Family().IsIPv6()) }) t.Run("ipv46", func(t *testing.T) { - address := fakeMulti.GetFakeIPForDomain3("fakednstestipv46.v2fly.org", true, true) + address := fakeMulti.GetFakeIPForDomain3("fakednstestipv46.example.com", true, true) assert.Len(t, address, 2, "should be 2 address") assert.True(t, address[0].Family().IsIPv4()) assert.True(t, address[1].Family().IsIPv6()) diff --git a/app/log/command/config_grpc.pb.go b/app/log/command/config_grpc.pb.go index 8c301979..7908855b 100644 --- a/app/log/command/config_grpc.pb.go +++ b/app/log/command/config_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.0 +// source: app/log/command/config.proto package command diff --git a/app/observatory/command/command_grpc.pb.go b/app/observatory/command/command_grpc.pb.go index d66a0484..0cbd9921 100644 --- a/app/observatory/command/command_grpc.pb.go +++ b/app/observatory/command/command_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.0 +// source: app/observatory/command/command.proto package command diff --git a/app/proxyman/command/command_grpc.pb.go b/app/proxyman/command/command_grpc.pb.go index c3b854c3..2b3344f7 100644 --- a/app/proxyman/command/command_grpc.pb.go +++ b/app/proxyman/command/command_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.0 +// source: app/proxyman/command/command.proto package command diff --git a/app/proxyman/config.pb.go b/app/proxyman/config.pb.go index d1722c8f..9a0be82e 100644 --- a/app/proxyman/config.pb.go +++ b/app/proxyman/config.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.1 -// protoc v3.19.1 +// protoc v3.18.0 // source: app/proxyman/config.proto package proxyman diff --git a/app/reverse/reverse.go b/app/reverse/reverse.go index ec3b6475..077a89c1 100644 --- a/app/reverse/reverse.go +++ b/app/reverse/reverse.go @@ -14,7 +14,7 @@ import ( ) const ( - internalDomain = "reverse.internal.example.com" + internalDomain = "reverse.internal.v2fly.org" // make reverse proxy compatible with v2fly ) func isDomain(dest net.Destination, domain string) bool { diff --git a/app/router/command/command_grpc.pb.go b/app/router/command/command_grpc.pb.go index 663442b8..3b830dfb 100644 --- a/app/router/command/command_grpc.pb.go +++ b/app/router/command/command_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.0 +// source: app/router/command/command.proto package command diff --git a/app/stats/command/command_grpc.pb.go b/app/stats/command/command_grpc.pb.go index 8ba3ac61..b38fadce 100644 --- a/app/stats/command/command_grpc.pb.go +++ b/app/stats/command/command_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.0 +// source: app/stats/command/command.proto package command diff --git a/proxy/loopback/config.pb.go b/proxy/loopback/config.pb.go index 319f42e7..9e5b10e8 100644 --- a/proxy/loopback/config.pb.go +++ b/proxy/loopback/config.pb.go @@ -71,18 +71,18 @@ var File_proxy_loopback_config_proto protoreflect.FileDescriptor var file_proxy_loopback_config_proto_rawDesc = []byte{ 0x0a, 0x1b, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, - 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x19, 0x76, - 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, - 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x22, 0x29, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, 0x74, 0x61, - 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, - 0x54, 0x61, 0x67, 0x42, 0x5b, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, - 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x50, 0x01, - 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, - 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x78, - 0x79, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0xaa, 0x02, 0x13, 0x58, 0x72, 0x61, - 0x79, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x78, + 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, + 0x63, 0x6b, 0x22, 0x29, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1f, 0x0a, 0x0b, + 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, 0x74, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x54, 0x61, 0x67, 0x42, 0x5b, 0x0a, + 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, + 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x50, 0x01, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, + 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, + 0x62, 0x61, 0x63, 0x6b, 0xaa, 0x02, 0x13, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x50, 0x72, 0x6f, 0x78, + 0x79, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -99,7 +99,7 @@ func file_proxy_loopback_config_proto_rawDescGZIP() []byte { var file_proxy_loopback_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_proxy_loopback_config_proto_goTypes = []interface{}{ - (*Config)(nil), // 0: v2ray.core.proxy.loopback.Config + (*Config)(nil), // 0: xray.proxy.loopback.Config } var file_proxy_loopback_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type diff --git a/proxy/loopback/config.proto b/proxy/loopback/config.proto index 64f9e119..7b8fe901 100644 --- a/proxy/loopback/config.proto +++ b/proxy/loopback/config.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package v2ray.core.proxy.loopback; +package xray.proxy.loopback; option csharp_namespace = "Xray.Proxy.Loopback"; option go_package = "github.com/xtls/xray-core/proxy/loopback"; option java_package = "com.xray.proxy.loopback"; diff --git a/transport/internet/grpc/encoding/stream_grpc.pb.go b/transport/internet/grpc/encoding/stream_grpc.pb.go index 42e440a6..fa1d1950 100644 --- a/transport/internet/grpc/encoding/stream_grpc.pb.go +++ b/transport/internet/grpc/encoding/stream_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.0 +// source: transport/internet/grpc/encoding/stream.proto package encoding