Skip to content

Commit

Permalink
replace TypedMessage with anypb.Any
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang committed Sep 4, 2021
1 parent add3753 commit ba2dd59
Show file tree
Hide file tree
Showing 65 changed files with 720 additions and 858 deletions.
3 changes: 2 additions & 1 deletion app/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package commander

import (
"context"
"github.com/v2fly/v2ray-core/v4/common/serial"
"net"
"sync"

Expand Down Expand Up @@ -35,7 +36,7 @@ func NewCommander(ctx context.Context, config *Config) (*Commander, error) {
}))

for _, rawConfig := range config.Service {
config, err := rawConfig.GetInstance()
config, err := serial.GetInstanceOf(rawConfig)
if err != nil {
return nil, err
}
Expand Down
41 changes: 20 additions & 21 deletions app/commander/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/commander/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ message Config {
string tag = 1;
// Services that supported by this server. All services must implement Service
// interface.
repeated v2ray.core.common.serial.TypedMessage service = 2;
repeated google.protobuf.Any service = 2;
}

// ReflectionConfig is the placeholder config for ReflectionService.
Expand Down
17 changes: 9 additions & 8 deletions app/dns/dns_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dns_test

import (
"google.golang.org/protobuf/types/known/anypb"
"testing"
"time"

Expand Down Expand Up @@ -122,7 +123,7 @@ func TestUDPServerSubnet(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServers: []*net.Endpoint{
{
Expand Down Expand Up @@ -177,7 +178,7 @@ func TestUDPServer(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServers: []*net.Endpoint{
{
Expand Down Expand Up @@ -278,7 +279,7 @@ func TestPrioritizedDomain(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServers: []*net.Endpoint{
{
Expand Down Expand Up @@ -360,7 +361,7 @@ func TestUDPServerIPv6(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServers: []*net.Endpoint{
{
Expand Down Expand Up @@ -416,7 +417,7 @@ func TestStaticHostDomain(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServers: []*net.Endpoint{
{
Expand Down Expand Up @@ -481,7 +482,7 @@ func TestIPMatch(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServer: []*NameServer{
// private dns, not match
Expand Down Expand Up @@ -591,7 +592,7 @@ func TestLocalDomain(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServers: []*net.Endpoint{
{
Expand Down Expand Up @@ -787,7 +788,7 @@ func TestMultiMatchPrioritizedDomain(t *testing.T) {
time.Sleep(time.Second)

config := &core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&Config{
NameServers: []*net.Endpoint{
{
Expand Down
3 changes: 2 additions & 1 deletion app/log/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command_test

import (
"context"
"google.golang.org/protobuf/types/known/anypb"
"testing"

core "github.com/v2fly/v2ray-core/v4"
Expand All @@ -17,7 +18,7 @@ import (

func TestLoggerRestart(t *testing.T) {
v, err := core.New(&core.Config{
App: []*serial.TypedMessage{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{}),
serial.ToTypedMessage(&dispatcher.Config{}),
serial.ToTypedMessage(&proxyman.InboundConfig{}),
Expand Down
5 changes: 3 additions & 2 deletions app/proxyman/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"context"
"github.com/v2fly/v2ray-core/v4/common/serial"

grpc "google.golang.org/grpc"

Expand Down Expand Up @@ -81,7 +82,7 @@ func (s *handlerServer) RemoveInbound(ctx context.Context, request *RemoveInboun
}

func (s *handlerServer) AlterInbound(ctx context.Context, request *AlterInboundRequest) (*AlterInboundResponse, error) {
rawOperation, err := request.Operation.GetInstance()
rawOperation, err := serial.GetInstanceOf(request.Operation)
if err != nil {
return nil, newError("unknown operation").Base(err)
}
Expand Down Expand Up @@ -110,7 +111,7 @@ func (s *handlerServer) RemoveOutbound(ctx context.Context, request *RemoveOutbo
}

func (s *handlerServer) AlterOutbound(ctx context.Context, request *AlterOutboundRequest) (*AlterOutboundResponse, error) {
rawOperation, err := request.Operation.GetInstance()
rawOperation, err := serial.GetInstanceOf(request.Operation)
if err != nil {
return nil, newError("unknown operation").Base(err)
}
Expand Down
Loading

0 comments on commit ba2dd59

Please sign in to comment.