Przeglądaj źródła

register commander

Shelikhoo 4 lat temu
rodzic
commit
8ed83b6d0a
3 zmienionych plików z 123 dodań i 18 usunięć
  1. 19 0
      app/commander/commander.go
  2. 94 18
      app/commander/config.pb.go
  3. 10 0
      app/commander/config.proto

+ 19 - 0
app/commander/commander.go

@@ -5,6 +5,7 @@ package commander
 import (
 	"context"
 	"github.com/v2fly/v2ray-core/v4/common/serial"
+	"github.com/v2fly/v2ray-core/v4/infra/conf/v5cfg"
 	"net"
 	"sync"
 
@@ -107,3 +108,21 @@ func init() {
 		return NewCommander(ctx, cfg.(*Config))
 	}))
 }
+
+func init() {
+	common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
+		simplifiedConfig := cfg.(*SimplifiedConfig)
+		fullConfig := &Config{
+			Tag:     simplifiedConfig.Tag,
+			Service: nil,
+		}
+		for _, v := range simplifiedConfig.Name {
+			pack, err := v5cfg.LoadHeterogeneousConfigFromRawJson(ctx, "grpcservice", v, []byte("{}"))
+			if err != nil {
+				return nil, err
+			}
+			fullConfig.Service = append(fullConfig.Service, serial.ToTypedMessage(pack))
+		}
+		return common.CreateObject(ctx, fullConfig)
+	}))
+}

+ 94 - 18
app/commander/config.pb.go

@@ -7,6 +7,7 @@
 package commander
 
 import (
+	_ "github.com/v2fly/v2ray-core/v4/common/protoext"
 	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	anypb "google.golang.org/protobuf/types/known/anypb"
@@ -119,6 +120,61 @@ func (*ReflectionConfig) Descriptor() ([]byte, []int) {
 	return file_app_commander_config_proto_rawDescGZIP(), []int{1}
 }
 
+type SimplifiedConfig struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Tag  string   `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"`
+	Name []string `protobuf:"bytes,2,rep,name=name,proto3" json:"name,omitempty"`
+}
+
+func (x *SimplifiedConfig) Reset() {
+	*x = SimplifiedConfig{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_app_commander_config_proto_msgTypes[2]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *SimplifiedConfig) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*SimplifiedConfig) ProtoMessage() {}
+
+func (x *SimplifiedConfig) ProtoReflect() protoreflect.Message {
+	mi := &file_app_commander_config_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use SimplifiedConfig.ProtoReflect.Descriptor instead.
+func (*SimplifiedConfig) Descriptor() ([]byte, []int) {
+	return file_app_commander_config_proto_rawDescGZIP(), []int{2}
+}
+
+func (x *SimplifiedConfig) GetTag() string {
+	if x != nil {
+		return x.Tag
+	}
+	return ""
+}
+
+func (x *SimplifiedConfig) GetName() []string {
+	if x != nil {
+		return x.Name
+	}
+	return nil
+}
+
 var File_app_commander_config_proto protoreflect.FileDescriptor
 
 var file_app_commander_config_proto_rawDesc = []byte{
@@ -127,20 +183,27 @@ var file_app_commander_config_proto_rawDesc = []byte{
 	0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x63, 0x6f, 0x6d,
 	0x6d, 0x61, 0x6e, 0x64, 0x65, 0x72, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70,
 	0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74,
-	0x6f, 0x22, 0x4a, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x74,
-	0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x2e, 0x0a,
-	0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14,
-	0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
-	0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0x12, 0x0a,
-	0x10, 0x52, 0x65, 0x66, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69,
-	0x67, 0x42, 0x69, 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63,
-	0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x65,
-	0x72, 0x50, 0x01, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
-	0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65,
-	0x2f, 0x76, 0x34, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x65,
-	0x72, 0xaa, 0x02, 0x18, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41,
-	0x70, 0x70, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72,
-	0x6f, 0x74, 0x6f, 0x33,
+	0x6f, 0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65,
+	0x78, 0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x22, 0x4a, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x10, 0x0a,
+	0x03, 0x74, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12,
+	0x2e, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b,
+	0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
+	0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22,
+	0x12, 0x0a, 0x10, 0x52, 0x65, 0x66, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e,
+	0x66, 0x69, 0x67, 0x22, 0x56, 0x0a, 0x10, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x69, 0x66, 0x69, 0x65,
+	0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x01,
+	0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d,
+	0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x1c, 0x82,
+	0xb5, 0x18, 0x09, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x82, 0xb5, 0x18, 0x0b,
+	0x12, 0x09, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x65, 0x72, 0x42, 0x69, 0x0a, 0x1c, 0x63,
+	0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70,
+	0x70, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x01, 0x5a, 0x2c, 0x67,
+	0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f,
+	0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x61, 0x70,
+	0x70, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x65, 0x72, 0xaa, 0x02, 0x18, 0x56, 0x32,
+	0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x43, 0x6f, 0x6d,
+	0x6d, 0x61, 0x6e, 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -155,14 +218,15 @@ func file_app_commander_config_proto_rawDescGZIP() []byte {
 	return file_app_commander_config_proto_rawDescData
 }
 
-var file_app_commander_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_app_commander_config_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
 var file_app_commander_config_proto_goTypes = []interface{}{
 	(*Config)(nil),           // 0: v2ray.core.app.commander.Config
 	(*ReflectionConfig)(nil), // 1: v2ray.core.app.commander.ReflectionConfig
-	(*anypb.Any)(nil),        // 2: google.protobuf.Any
+	(*SimplifiedConfig)(nil), // 2: v2ray.core.app.commander.SimplifiedConfig
+	(*anypb.Any)(nil),        // 3: google.protobuf.Any
 }
 var file_app_commander_config_proto_depIdxs = []int32{
-	2, // 0: v2ray.core.app.commander.Config.service:type_name -> google.protobuf.Any
+	3, // 0: v2ray.core.app.commander.Config.service:type_name -> google.protobuf.Any
 	1, // [1:1] is the sub-list for method output_type
 	1, // [1:1] is the sub-list for method input_type
 	1, // [1:1] is the sub-list for extension type_name
@@ -200,6 +264,18 @@ func file_app_commander_config_proto_init() {
 				return nil
 			}
 		}
+		file_app_commander_config_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*SimplifiedConfig); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
 	}
 	type x struct{}
 	out := protoimpl.TypeBuilder{
@@ -207,7 +283,7 @@ func file_app_commander_config_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_app_commander_config_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   2,
+			NumMessages:   3,
 			NumExtensions: 0,
 			NumServices:   0,
 		},

+ 10 - 0
app/commander/config.proto

@@ -7,6 +7,7 @@ option java_package = "com.v2ray.core.app.commander";
 option java_multiple_files = true;
 
 import "google/protobuf/any.proto";
+import "common/protoext/extensions.proto";
 
 // Config is the settings for Commander.
 message Config {
@@ -19,3 +20,12 @@ message Config {
 
 // ReflectionConfig is the placeholder config for ReflectionService.
 message ReflectionConfig {}
+
+
+message SimplifiedConfig {
+  option (v2ray.core.common.protoext.message_opt).type = "service";
+  option (v2ray.core.common.protoext.message_opt).short_name = "commander";
+
+  string tag = 1;
+  repeated string name = 2;
+}