From f34c092a06e7110209792952c476d614fa0006ae Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Mon, 22 Jun 2020 22:49:25 -0400 Subject: [PATCH 1/3] Rename fields in StatCouterConnection The fields will be used by Outbounds as well in the next commit --- app/proxyman/inbound/worker.go | 6 +++--- transport/internet/connection.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index 81d26234..b10a5867 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -91,9 +91,9 @@ func (w *tcpWorker) callback(conn internet.Connection) { ctx = session.ContextWithContent(ctx, content) if w.uplinkCounter != nil || w.downlinkCounter != nil { conn = &internet.StatCouterConnection{ - Connection: conn, - Uplink: w.uplinkCounter, - Downlink: w.downlinkCounter, + Connection: conn, + ReadCounter: w.uplinkCounter, + WriteCounter: w.downlinkCounter, } } if err := w.proxy.Process(ctx, net.Network_TCP, conn, w.dispatcher); err != nil { diff --git a/transport/internet/connection.go b/transport/internet/connection.go index 0c627042..b55b0606 100644 --- a/transport/internet/connection.go +++ b/transport/internet/connection.go @@ -12,14 +12,14 @@ type Connection interface { type StatCouterConnection struct { Connection - Uplink stats.Counter - Downlink stats.Counter + ReadCounter stats.Counter + WriteCounter stats.Counter } func (c *StatCouterConnection) Read(b []byte) (int, error) { nBytes, err := c.Connection.Read(b) - if c.Uplink != nil { - c.Uplink.Add(int64(nBytes)) + if c.ReadCounter != nil { + c.ReadCounter.Add(int64(nBytes)) } return nBytes, err @@ -27,8 +27,8 @@ func (c *StatCouterConnection) Read(b []byte) (int, error) { func (c *StatCouterConnection) Write(b []byte) (int, error) { nBytes, err := c.Connection.Write(b) - if c.Downlink != nil { - c.Downlink.Add(int64(nBytes)) + if c.WriteCounter != nil { + c.WriteCounter.Add(int64(nBytes)) } return nBytes, err } From 886598542c6ff038cfa28dc6dfe3901a4af14da6 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Mon, 22 Jun 2020 23:55:00 -0400 Subject: [PATCH 2/3] Add stats counter for outbounds --- app/policy/config.go | 6 +- app/policy/config.pb.go | 282 +++++++++++++++++-------------- app/policy/config.proto | 2 + app/proxyman/outbound/handler.go | 48 +++++- features/policy/policy.go | 4 + infra/conf/policy.go | 12 +- release/config/config.json | 4 +- 7 files changed, 221 insertions(+), 137 deletions(-) diff --git a/app/policy/config.go b/app/policy/config.go index ffe81138..4856e94d 100644 --- a/app/policy/config.go +++ b/app/policy/config.go @@ -84,8 +84,10 @@ func (p *Policy) ToCorePolicy() policy.Session { func (p *SystemPolicy) ToCorePolicy() policy.System { return policy.System{ Stats: policy.SystemStats{ - InboundUplink: p.Stats.InboundUplink, - InboundDownlink: p.Stats.InboundDownlink, + InboundUplink: p.Stats.InboundUplink, + InboundDownlink: p.Stats.InboundDownlink, + OutboundUplink: p.Stats.OutboundUplink, + OutboundDownlink: p.Stats.OutboundDownlink, }, } } diff --git a/app/policy/config.pb.go b/app/policy/config.pb.go index 70a26f44..3a2ea555 100644 --- a/app/policy/config.pb.go +++ b/app/policy/config.pb.go @@ -1,3 +1,9 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.24.0 +// protoc (unknown) +// source: config.proto + package policy import ( @@ -30,7 +36,7 @@ type Second struct { func (x *Second) Reset() { *x = Second{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[0] + mi := &file_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -43,7 +49,7 @@ func (x *Second) String() string { func (*Second) ProtoMessage() {} func (x *Second) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[0] + mi := &file_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -56,7 +62,7 @@ func (x *Second) ProtoReflect() protoreflect.Message { // Deprecated: Use Second.ProtoReflect.Descriptor instead. func (*Second) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{0} + return file_config_proto_rawDescGZIP(), []int{0} } func (x *Second) GetValue() uint32 { @@ -79,7 +85,7 @@ type Policy struct { func (x *Policy) Reset() { *x = Policy{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[1] + mi := &file_config_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -92,7 +98,7 @@ func (x *Policy) String() string { func (*Policy) ProtoMessage() {} func (x *Policy) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[1] + mi := &file_config_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -105,7 +111,7 @@ func (x *Policy) ProtoReflect() protoreflect.Message { // Deprecated: Use Policy.ProtoReflect.Descriptor instead. func (*Policy) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{1} + return file_config_proto_rawDescGZIP(), []int{1} } func (x *Policy) GetTimeout() *Policy_Timeout { @@ -140,7 +146,7 @@ type SystemPolicy struct { func (x *SystemPolicy) Reset() { *x = SystemPolicy{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[2] + mi := &file_config_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -153,7 +159,7 @@ func (x *SystemPolicy) String() string { func (*SystemPolicy) ProtoMessage() {} func (x *SystemPolicy) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[2] + mi := &file_config_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -166,7 +172,7 @@ func (x *SystemPolicy) ProtoReflect() protoreflect.Message { // Deprecated: Use SystemPolicy.ProtoReflect.Descriptor instead. func (*SystemPolicy) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{2} + return file_config_proto_rawDescGZIP(), []int{2} } func (x *SystemPolicy) GetStats() *SystemPolicy_Stats { @@ -188,7 +194,7 @@ type Config struct { func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[3] + mi := &file_config_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -201,7 +207,7 @@ func (x *Config) String() string { func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[3] + mi := &file_config_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -214,7 +220,7 @@ func (x *Config) ProtoReflect() protoreflect.Message { // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{3} + return file_config_proto_rawDescGZIP(), []int{3} } func (x *Config) GetLevel() map[uint32]*Policy { @@ -246,7 +252,7 @@ type Policy_Timeout struct { func (x *Policy_Timeout) Reset() { *x = Policy_Timeout{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[4] + mi := &file_config_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -259,7 +265,7 @@ func (x *Policy_Timeout) String() string { func (*Policy_Timeout) ProtoMessage() {} func (x *Policy_Timeout) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[4] + mi := &file_config_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -272,7 +278,7 @@ func (x *Policy_Timeout) ProtoReflect() protoreflect.Message { // Deprecated: Use Policy_Timeout.ProtoReflect.Descriptor instead. func (*Policy_Timeout) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{1, 0} + return file_config_proto_rawDescGZIP(), []int{1, 0} } func (x *Policy_Timeout) GetHandshake() *Second { @@ -315,7 +321,7 @@ type Policy_Stats struct { func (x *Policy_Stats) Reset() { *x = Policy_Stats{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[5] + mi := &file_config_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -328,7 +334,7 @@ func (x *Policy_Stats) String() string { func (*Policy_Stats) ProtoMessage() {} func (x *Policy_Stats) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[5] + mi := &file_config_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -341,7 +347,7 @@ func (x *Policy_Stats) ProtoReflect() protoreflect.Message { // Deprecated: Use Policy_Stats.ProtoReflect.Descriptor instead. func (*Policy_Stats) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{1, 1} + return file_config_proto_rawDescGZIP(), []int{1, 1} } func (x *Policy_Stats) GetUserUplink() bool { @@ -370,7 +376,7 @@ type Policy_Buffer struct { func (x *Policy_Buffer) Reset() { *x = Policy_Buffer{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[6] + mi := &file_config_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -383,7 +389,7 @@ func (x *Policy_Buffer) String() string { func (*Policy_Buffer) ProtoMessage() {} func (x *Policy_Buffer) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[6] + mi := &file_config_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -396,7 +402,7 @@ func (x *Policy_Buffer) ProtoReflect() protoreflect.Message { // Deprecated: Use Policy_Buffer.ProtoReflect.Descriptor instead. func (*Policy_Buffer) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{1, 2} + return file_config_proto_rawDescGZIP(), []int{1, 2} } func (x *Policy_Buffer) GetConnection() int32 { @@ -411,14 +417,16 @@ type SystemPolicy_Stats struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - InboundUplink bool `protobuf:"varint,1,opt,name=inbound_uplink,json=inboundUplink,proto3" json:"inbound_uplink,omitempty"` - InboundDownlink bool `protobuf:"varint,2,opt,name=inbound_downlink,json=inboundDownlink,proto3" json:"inbound_downlink,omitempty"` + InboundUplink bool `protobuf:"varint,1,opt,name=inbound_uplink,json=inboundUplink,proto3" json:"inbound_uplink,omitempty"` + InboundDownlink bool `protobuf:"varint,2,opt,name=inbound_downlink,json=inboundDownlink,proto3" json:"inbound_downlink,omitempty"` + OutboundUplink bool `protobuf:"varint,3,opt,name=outbound_uplink,json=outboundUplink,proto3" json:"outbound_uplink,omitempty"` + OutboundDownlink bool `protobuf:"varint,4,opt,name=outbound_downlink,json=outboundDownlink,proto3" json:"outbound_downlink,omitempty"` } func (x *SystemPolicy_Stats) Reset() { *x = SystemPolicy_Stats{} if protoimpl.UnsafeEnabled { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[7] + mi := &file_config_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -431,7 +439,7 @@ func (x *SystemPolicy_Stats) String() string { func (*SystemPolicy_Stats) ProtoMessage() {} func (x *SystemPolicy_Stats) ProtoReflect() protoreflect.Message { - mi := &file_v2ray_com_core_app_policy_config_proto_msgTypes[7] + mi := &file_config_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -444,7 +452,7 @@ func (x *SystemPolicy_Stats) ProtoReflect() protoreflect.Message { // Deprecated: Use SystemPolicy_Stats.ProtoReflect.Descriptor instead. func (*SystemPolicy_Stats) Descriptor() ([]byte, []int) { - return file_v2ray_com_core_app_policy_config_proto_rawDescGZIP(), []int{2, 0} + return file_config_proto_rawDescGZIP(), []int{2, 0} } func (x *SystemPolicy_Stats) GetInboundUplink() bool { @@ -461,98 +469,116 @@ func (x *SystemPolicy_Stats) GetInboundDownlink() bool { return false } -var File_v2ray_com_core_app_policy_config_proto protoreflect.FileDescriptor - -var file_v2ray_com_core_app_policy_config_proto_rawDesc = []byte{ - 0x0a, 0x26, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, - 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x15, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, - 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, - 0x1e, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, - 0xd0, 0x04, 0x0a, 0x06, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x3f, 0x0a, 0x07, 0x74, 0x69, - 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x76, 0x32, - 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, - 0x69, 0x63, 0x79, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x6f, - 0x75, 0x74, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x39, 0x0a, 0x05, 0x73, - 0x74, 0x61, 0x74, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x76, 0x32, 0x72, - 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, - 0x63, 0x79, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x73, 0x52, - 0x05, 0x73, 0x74, 0x61, 0x74, 0x73, 0x12, 0x3c, 0x0a, 0x06, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x50, - 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x52, 0x06, 0x62, 0x75, - 0x66, 0x66, 0x65, 0x72, 0x1a, 0x92, 0x02, 0x0a, 0x07, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, - 0x12, 0x3b, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, - 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x65, 0x63, 0x6f, - 0x6e, 0x64, 0x52, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x12, 0x46, 0x0a, - 0x0f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x6c, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, - 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x52, 0x0e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x49, 0x64, 0x6c, 0x65, 0x12, 0x3e, 0x0a, 0x0b, 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x5f, - 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, - 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, - 0x63, 0x79, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x52, 0x0a, 0x75, 0x70, 0x6c, 0x69, 0x6e, - 0x6b, 0x4f, 0x6e, 0x6c, 0x79, 0x12, 0x42, 0x0a, 0x0d, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, - 0x6b, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, +func (x *SystemPolicy_Stats) GetOutboundUplink() bool { + if x != nil { + return x.OutboundUplink + } + return false +} + +func (x *SystemPolicy_Stats) GetOutboundDownlink() bool { + if x != nil { + return x.OutboundDownlink + } + return false +} + +var File_config_proto protoreflect.FileDescriptor + +var file_config_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x15, + 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, + 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x1e, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xd0, 0x04, 0x0a, 0x06, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, + 0x12, 0x3f, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x25, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, + 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, + 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, + 0x74, 0x12, 0x39, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x23, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, + 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, + 0x53, 0x74, 0x61, 0x74, 0x73, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x73, 0x12, 0x3c, 0x0a, 0x06, + 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, - 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x52, 0x0c, 0x64, 0x6f, 0x77, - 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x4f, 0x6e, 0x6c, 0x79, 0x1a, 0x4d, 0x0a, 0x05, 0x53, 0x74, 0x61, - 0x74, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x75, 0x70, 0x6c, 0x69, 0x6e, - 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x55, 0x70, 0x6c, - 0x69, 0x6e, 0x6b, 0x12, 0x23, 0x0a, 0x0d, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x64, 0x6f, 0x77, 0x6e, - 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x75, 0x73, 0x65, 0x72, - 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x1a, 0x28, 0x0a, 0x06, 0x42, 0x75, 0x66, 0x66, - 0x65, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x22, 0xaa, 0x01, 0x0a, 0x0c, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x50, 0x6f, 0x6c, - 0x69, 0x63, 0x79, 0x12, 0x3f, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x79, 0x73, 0x74, 0x65, - 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x73, 0x52, 0x05, 0x73, - 0x74, 0x61, 0x74, 0x73, 0x1a, 0x59, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, 0x25, 0x0a, - 0x0e, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x55, 0x70, - 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x29, 0x0a, 0x10, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, - 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, - 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x22, - 0xde, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x3e, 0x0a, 0x05, 0x6c, 0x65, - 0x76, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x76, 0x32, 0x72, 0x61, + 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x42, 0x75, 0x66, 0x66, + 0x65, 0x72, 0x52, 0x06, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x1a, 0x92, 0x02, 0x0a, 0x07, 0x54, + 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3b, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, + 0x61, 0x6b, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, - 0x79, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x45, 0x6e, - 0x74, 0x72, 0x79, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x3b, 0x0a, 0x06, 0x73, 0x79, - 0x73, 0x74, 0x65, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x76, 0x32, 0x72, - 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, - 0x63, 0x79, 0x2e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, - 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x1a, 0x57, 0x0a, 0x0a, 0x4c, 0x65, 0x76, 0x65, 0x6c, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x50, - 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x42, 0x3d, 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, - 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x50, 0x01, 0x5a, - 0x06, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0xaa, 0x02, 0x15, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, - 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x79, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x52, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, + 0x61, 0x6b, 0x65, 0x12, 0x46, 0x0a, 0x0f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x5f, 0x69, 0x64, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, + 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, + 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x52, 0x0e, 0x63, 0x6f, 0x6e, + 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x6c, 0x65, 0x12, 0x3e, 0x0a, 0x0b, 0x75, + 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, + 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x52, + 0x0a, 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x4f, 0x6e, 0x6c, 0x79, 0x12, 0x42, 0x0a, 0x0d, 0x64, + 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, + 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, + 0x64, 0x52, 0x0c, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x4f, 0x6e, 0x6c, 0x79, 0x1a, + 0x4d, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x75, 0x73, 0x65, 0x72, + 0x5f, 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x75, + 0x73, 0x65, 0x72, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x23, 0x0a, 0x0d, 0x75, 0x73, 0x65, + 0x72, 0x5f, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x0c, 0x75, 0x73, 0x65, 0x72, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x1a, 0x28, + 0x0a, 0x06, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x6e, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x63, 0x6f, + 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x81, 0x02, 0x0a, 0x0c, 0x53, 0x79, 0x73, + 0x74, 0x65, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x3f, 0x0a, 0x05, 0x73, 0x74, 0x61, + 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, + 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, + 0x2e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x53, 0x74, + 0x61, 0x74, 0x73, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x73, 0x1a, 0xaf, 0x01, 0x0a, 0x05, 0x53, + 0x74, 0x61, 0x74, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, + 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x69, 0x6e, + 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x29, 0x0a, 0x10, 0x69, + 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x44, 0x6f, + 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x27, 0x0a, 0x0f, 0x6f, 0x75, 0x74, 0x62, 0x6f, 0x75, + 0x6e, 0x64, 0x5f, 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x0e, 0x6f, 0x75, 0x74, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x12, + 0x2b, 0x0a, 0x11, 0x6f, 0x75, 0x74, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, 0x64, 0x6f, 0x77, 0x6e, + 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x10, 0x6f, 0x75, 0x74, 0x62, + 0x6f, 0x75, 0x6e, 0x64, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x22, 0xde, 0x01, 0x0a, + 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x3e, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x3b, 0x0a, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, + 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, + 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, + 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x06, 0x73, 0x79, + 0x73, 0x74, 0x65, 0x6d, 0x1a, 0x57, 0x0a, 0x0a, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, + 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x50, 0x6f, 0x6c, 0x69, + 0x63, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x3d, 0x0a, + 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, + 0x61, 0x70, 0x70, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x50, 0x01, 0x5a, 0x06, 0x70, 0x6f, + 0x6c, 0x69, 0x63, 0x79, 0xaa, 0x02, 0x15, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, + 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( - file_v2ray_com_core_app_policy_config_proto_rawDescOnce sync.Once - file_v2ray_com_core_app_policy_config_proto_rawDescData = file_v2ray_com_core_app_policy_config_proto_rawDesc + file_config_proto_rawDescOnce sync.Once + file_config_proto_rawDescData = file_config_proto_rawDesc ) -func file_v2ray_com_core_app_policy_config_proto_rawDescGZIP() []byte { - file_v2ray_com_core_app_policy_config_proto_rawDescOnce.Do(func() { - file_v2ray_com_core_app_policy_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_v2ray_com_core_app_policy_config_proto_rawDescData) +func file_config_proto_rawDescGZIP() []byte { + file_config_proto_rawDescOnce.Do(func() { + file_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_config_proto_rawDescData) }) - return file_v2ray_com_core_app_policy_config_proto_rawDescData + return file_config_proto_rawDescData } -var file_v2ray_com_core_app_policy_config_proto_msgTypes = make([]protoimpl.MessageInfo, 9) -var file_v2ray_com_core_app_policy_config_proto_goTypes = []interface{}{ +var file_config_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_config_proto_goTypes = []interface{}{ (*Second)(nil), // 0: v2ray.core.app.policy.Second (*Policy)(nil), // 1: v2ray.core.app.policy.Policy (*SystemPolicy)(nil), // 2: v2ray.core.app.policy.SystemPolicy @@ -563,7 +589,7 @@ var file_v2ray_com_core_app_policy_config_proto_goTypes = []interface{}{ (*SystemPolicy_Stats)(nil), // 7: v2ray.core.app.policy.SystemPolicy.Stats nil, // 8: v2ray.core.app.policy.Config.LevelEntry } -var file_v2ray_com_core_app_policy_config_proto_depIdxs = []int32{ +var file_config_proto_depIdxs = []int32{ 4, // 0: v2ray.core.app.policy.Policy.timeout:type_name -> v2ray.core.app.policy.Policy.Timeout 5, // 1: v2ray.core.app.policy.Policy.stats:type_name -> v2ray.core.app.policy.Policy.Stats 6, // 2: v2ray.core.app.policy.Policy.buffer:type_name -> v2ray.core.app.policy.Policy.Buffer @@ -582,13 +608,13 @@ var file_v2ray_com_core_app_policy_config_proto_depIdxs = []int32{ 0, // [0:11] is the sub-list for field type_name } -func init() { file_v2ray_com_core_app_policy_config_proto_init() } -func file_v2ray_com_core_app_policy_config_proto_init() { - if File_v2ray_com_core_app_policy_config_proto != nil { +func init() { file_config_proto_init() } +func file_config_proto_init() { + if File_config_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_v2ray_com_core_app_policy_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Second); i { case 0: return &v.state @@ -600,7 +626,7 @@ func file_v2ray_com_core_app_policy_config_proto_init() { return nil } } - file_v2ray_com_core_app_policy_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Policy); i { case 0: return &v.state @@ -612,7 +638,7 @@ func file_v2ray_com_core_app_policy_config_proto_init() { return nil } } - file_v2ray_com_core_app_policy_config_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SystemPolicy); i { case 0: return &v.state @@ -624,7 +650,7 @@ func file_v2ray_com_core_app_policy_config_proto_init() { return nil } } - file_v2ray_com_core_app_policy_config_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state @@ -636,7 +662,7 @@ func file_v2ray_com_core_app_policy_config_proto_init() { return nil } } - file_v2ray_com_core_app_policy_config_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Policy_Timeout); i { case 0: return &v.state @@ -648,7 +674,7 @@ func file_v2ray_com_core_app_policy_config_proto_init() { return nil } } - file_v2ray_com_core_app_policy_config_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Policy_Stats); i { case 0: return &v.state @@ -660,7 +686,7 @@ func file_v2ray_com_core_app_policy_config_proto_init() { return nil } } - file_v2ray_com_core_app_policy_config_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Policy_Buffer); i { case 0: return &v.state @@ -672,7 +698,7 @@ func file_v2ray_com_core_app_policy_config_proto_init() { return nil } } - file_v2ray_com_core_app_policy_config_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SystemPolicy_Stats); i { case 0: return &v.state @@ -689,18 +715,18 @@ func file_v2ray_com_core_app_policy_config_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_v2ray_com_core_app_policy_config_proto_rawDesc, + RawDescriptor: file_config_proto_rawDesc, NumEnums: 0, NumMessages: 9, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_v2ray_com_core_app_policy_config_proto_goTypes, - DependencyIndexes: file_v2ray_com_core_app_policy_config_proto_depIdxs, - MessageInfos: file_v2ray_com_core_app_policy_config_proto_msgTypes, + GoTypes: file_config_proto_goTypes, + DependencyIndexes: file_config_proto_depIdxs, + MessageInfos: file_config_proto_msgTypes, }.Build() - File_v2ray_com_core_app_policy_config_proto = out.File - file_v2ray_com_core_app_policy_config_proto_rawDesc = nil - file_v2ray_com_core_app_policy_config_proto_goTypes = nil - file_v2ray_com_core_app_policy_config_proto_depIdxs = nil + File_config_proto = out.File + file_config_proto_rawDesc = nil + file_config_proto_goTypes = nil + file_config_proto_depIdxs = nil } diff --git a/app/policy/config.proto b/app/policy/config.proto index 70530cbc..30cd2be5 100644 --- a/app/policy/config.proto +++ b/app/policy/config.proto @@ -38,6 +38,8 @@ message SystemPolicy { message Stats { bool inbound_uplink = 1; bool inbound_downlink = 2; + bool outbound_uplink = 3; + bool outbound_downlink = 4; } Stats stats = 1; diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index 34ad6cc7..3ffe9ae2 100644 --- a/app/proxyman/outbound/handler.go +++ b/app/proxyman/outbound/handler.go @@ -10,6 +10,8 @@ import ( "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/features/outbound" + "v2ray.com/core/features/policy" + "v2ray.com/core/features/stats" "v2ray.com/core/proxy" "v2ray.com/core/transport" "v2ray.com/core/transport/internet" @@ -17,6 +19,31 @@ import ( "v2ray.com/core/transport/pipe" ) +func getStatCounter(v *core.Instance, tag string) (stats.Counter, stats.Counter) { + var uplinkCounter stats.Counter + var downlinkCounter stats.Counter + + policy := v.GetFeature(policy.ManagerType()).(policy.Manager) + if len(tag) > 0 && policy.ForSystem().Stats.OutboundUplink { + statsManager := v.GetFeature(stats.ManagerType()).(stats.Manager) + name := "outbound>>>" + tag + ">>>traffic>>>uplink" + c, _ := stats.GetOrRegisterCounter(statsManager, name) + if c != nil { + uplinkCounter = c + } + } + if len(tag) > 0 && policy.ForSystem().Stats.OutboundDownlink { + statsManager := v.GetFeature(stats.ManagerType()).(stats.Manager) + name := "outbound>>>" + tag + ">>>traffic>>>downlink" + c, _ := stats.GetOrRegisterCounter(statsManager, name) + if c != nil { + downlinkCounter = c + } + } + + return uplinkCounter, downlinkCounter +} + // Handler is an implements of outbound.Handler. type Handler struct { tag string @@ -25,14 +52,19 @@ type Handler struct { proxy proxy.Outbound outboundManager outbound.Manager mux *mux.ClientManager + uplinkCounter stats.Counter + downlinkCounter stats.Counter } // NewHandler create a new Handler based on the given configuration. func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbound.Handler, error) { v := core.MustFromContext(ctx) + uplinkCounter, downlinkCounter := getStatCounter(v, config.Tag) h := &Handler{ tag: config.Tag, outboundManager: v.GetFeature(outbound.ManagerType()).(outbound.Manager), + uplinkCounter: uplinkCounter, + downlinkCounter: downlinkCounter, } if config.SenderSettings != nil { @@ -148,7 +180,7 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Conn conn = tls.Client(conn, tlsConfig) } - return conn, nil + return h.getStatCouterConnection(conn), nil } newError("failed to get outbound handler with tag: ", tag).AtWarning().WriteToLog(session.ExportIDToError(ctx)) @@ -164,7 +196,19 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Conn } } - return internet.Dial(ctx, dest, h.streamSettings) + conn, err := internet.Dial(ctx, dest, h.streamSettings) + return h.getStatCouterConnection(conn), err +} + +func (h *Handler) getStatCouterConnection(conn internet.Connection) (internet.Connection) { + if h.uplinkCounter != nil || h.downlinkCounter != nil { + return &internet.StatCouterConnection{ + Connection: conn, + ReadCounter: h.downlinkCounter, + WriteCounter: h.uplinkCounter, + } + } + return conn } // GetOutbound implements proxy.GetOutbound. diff --git a/features/policy/policy.go b/features/policy/policy.go index 984b32f4..b00ffeb7 100644 --- a/features/policy/policy.go +++ b/features/policy/policy.go @@ -41,6 +41,10 @@ type SystemStats struct { InboundUplink bool // Whether or not to enable stat counter for downlink traffic in inbound handlers. InboundDownlink bool + // Whether or not to enable stat counter for uplink traffic in outbound handlers. + OutboundUplink bool + // Whether or not to enable stat counter for downlink traffic in outbound handlers. + OutboundDownlink bool } // System contains policy settings at system level. diff --git a/infra/conf/policy.go b/infra/conf/policy.go index 46e2a2ce..73a8a3fc 100644 --- a/infra/conf/policy.go +++ b/infra/conf/policy.go @@ -51,15 +51,19 @@ func (t *Policy) Build() (*policy.Policy, error) { } type SystemPolicy struct { - StatsInboundUplink bool `json:"statsInboundUplink"` - StatsInboundDownlink bool `json:"statsInboundDownlink"` + StatsInboundUplink bool `json:"statsInboundUplink"` + StatsInboundDownlink bool `json:"statsInboundDownlink"` + StatsOutboundUplink bool `json:"statsOutboundUplink"` + StatsOutboundDownlink bool `json:"statsOutboundDownlink"` } func (p *SystemPolicy) Build() (*policy.SystemPolicy, error) { return &policy.SystemPolicy{ Stats: &policy.SystemPolicy_Stats{ - InboundUplink: p.StatsInboundUplink, - InboundDownlink: p.StatsInboundDownlink, + InboundUplink: p.StatsInboundUplink, + InboundDownlink: p.StatsInboundDownlink, + OutboundUplink: p.StatsOutboundUplink, + OutboundDownlink: p.StatsOutboundDownlink, }, }, nil } diff --git a/release/config/config.json b/release/config/config.json index e79155d5..72172772 100644 --- a/release/config/config.json +++ b/release/config/config.json @@ -119,7 +119,9 @@ }, "system": { "statsInboundUplink": false, - "statsInboundDownlink": false + "statsInboundDownlink": false, + "statsOutboundUplink": false, + "statsOutboundDownlink": false } }, From cef1836f5a0638242be288508e810117bc71f322 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 27 Jun 2020 00:28:53 -0400 Subject: [PATCH 3/3] Add unit test for outbound handler --- app/proxyman/outbound/handler_test.go | 67 +++++++++++++++++++++++++++ context.go | 5 +- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/app/proxyman/outbound/handler_test.go b/app/proxyman/outbound/handler_test.go index 25906f17..c0518378 100644 --- a/app/proxyman/outbound/handler_test.go +++ b/app/proxyman/outbound/handler_test.go @@ -1,13 +1,80 @@ package outbound_test import ( + "context" "testing" + "v2ray.com/core" + "v2ray.com/core/app/policy" . "v2ray.com/core/app/proxyman/outbound" + "v2ray.com/core/app/stats" + "v2ray.com/core/common/net" + "v2ray.com/core/common/serial" "v2ray.com/core/features/outbound" + "v2ray.com/core/proxy/freedom" + "v2ray.com/core/transport/internet" ) func TestInterfaces(t *testing.T) { _ = (outbound.Handler)(new(Handler)) _ = (outbound.Manager)(new(Manager)) } + +const v2rayKey core.V2rayKey = 1 + +func TestOutboundWithoutStatCounter(t *testing.T) { + config := &core.Config{ + App: []*serial.TypedMessage{ + serial.ToTypedMessage(&stats.Config{}), + serial.ToTypedMessage(&policy.Config{ + System: &policy.SystemPolicy{ + Stats: &policy.SystemPolicy_Stats{ + InboundUplink: true, + }, + }, + }), + }, + } + + v, _ := core.New(config) + v.AddFeature((outbound.Manager)(new(Manager))) + ctx := context.WithValue(context.Background(), v2rayKey, v) + h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{ + Tag: "tag", + ProxySettings: serial.ToTypedMessage(&freedom.Config{}), + }) + conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146)) + _, ok := conn.(*internet.StatCouterConnection) + if ok { + t.Errorf("Expected conn to not be StatCouterConnection") + } +} + +func TestOutboundWithStatCounter(t *testing.T) { + config := &core.Config{ + App: []*serial.TypedMessage{ + serial.ToTypedMessage(&stats.Config{}), + serial.ToTypedMessage(&policy.Config{ + System: &policy.SystemPolicy{ + Stats: &policy.SystemPolicy_Stats{ + OutboundUplink: true, + OutboundDownlink: true, + }, + }, + }), + }, + } + + v, _ := core.New(config) + v.AddFeature((outbound.Manager)(new(Manager))) + ctx := context.WithValue(context.Background(), v2rayKey, v) + h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{ + Tag: "tag", + ProxySettings: serial.ToTypedMessage(&freedom.Config{}), + }) + conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146)) + _, ok := conn.(*internet.StatCouterConnection) + if !ok { + t.Errorf("Expected conn to be StatCouterConnection") + } +} diff --git a/context.go b/context.go index 5dd7aee7..84cd2396 100644 --- a/context.go +++ b/context.go @@ -6,9 +6,10 @@ import ( "context" ) -type key int +// V2rayKey is the key type of Instance in Context, exported for test. +type V2rayKey int -const v2rayKey key = 1 +const v2rayKey V2rayKey = 1 // FromContext returns an Instance from the given context, or nil if the context doesn't contain one. func FromContext(ctx context.Context) *Instance {