1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-26 01:15:38 +00:00

support stats in policy

This commit is contained in:
Darien Raymond 2018-03-30 23:39:54 +02:00
parent f7dd7e6279
commit 695a4f8493
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 72 additions and 23 deletions

View File

@ -46,6 +46,10 @@ func (p *Policy) overrideWith(another *Policy) {
if another.Timeout != nil {
p.Timeout.overrideWith(another.Timeout)
}
if another.Stats != nil && p.Stats == nil {
p.Stats = new(Policy_Stats)
*p.Stats = *another.Stats
}
}
func (p *Policy) ToCorePolicy() core.Policy {
@ -56,5 +60,8 @@ func (p *Policy) ToCorePolicy() core.Policy {
cp.Timeouts.DownlinkOnly = p.Timeout.DownlinkOnly.Duration()
cp.Timeouts.UplinkOnly = p.Timeout.UplinkOnly.Duration()
}
if p.Stats != nil {
cp.Stats.EnablePerUser = p.Stats.EnablePerUser
}
return cp
}

View File

@ -33,6 +33,7 @@ func (m *Second) GetValue() uint32 {
type Policy struct {
Timeout *Policy_Timeout `protobuf:"bytes,1,opt,name=timeout" json:"timeout,omitempty"`
Stats *Policy_Stats `protobuf:"bytes,2,opt,name=stats" json:"stats,omitempty"`
}
func (m *Policy) Reset() { *m = Policy{} }
@ -47,6 +48,13 @@ func (m *Policy) GetTimeout() *Policy_Timeout {
return nil
}
func (m *Policy) GetStats() *Policy_Stats {
if m != nil {
return m.Stats
}
return nil
}
// Timeout is a message for timeout settings in various stages, in seconds.
type Policy_Timeout struct {
Handshake *Second `protobuf:"bytes,1,opt,name=handshake" json:"handshake,omitempty"`
@ -88,6 +96,22 @@ func (m *Policy_Timeout) GetDownlinkOnly() *Second {
return nil
}
type Policy_Stats struct {
EnablePerUser bool `protobuf:"varint,1,opt,name=enable_per_user,json=enablePerUser" json:"enable_per_user,omitempty"`
}
func (m *Policy_Stats) Reset() { *m = Policy_Stats{} }
func (m *Policy_Stats) String() string { return proto.CompactTextString(m) }
func (*Policy_Stats) ProtoMessage() {}
func (*Policy_Stats) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1, 1} }
func (m *Policy_Stats) GetEnablePerUser() bool {
if m != nil {
return m.EnablePerUser
}
return false
}
type Config struct {
Level map[uint32]*Policy `protobuf:"bytes,1,rep,name=level" json:"level,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}
@ -108,33 +132,38 @@ func init() {
proto.RegisterType((*Second)(nil), "v2ray.core.app.policy.Second")
proto.RegisterType((*Policy)(nil), "v2ray.core.app.policy.Policy")
proto.RegisterType((*Policy_Timeout)(nil), "v2ray.core.app.policy.Policy.Timeout")
proto.RegisterType((*Policy_Stats)(nil), "v2ray.core.app.policy.Policy.Stats")
proto.RegisterType((*Config)(nil), "v2ray.core.app.policy.Config")
}
func init() { proto.RegisterFile("v2ray.com/core/app/policy/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 349 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4a, 0xeb, 0x40,
0x14, 0x86, 0x49, 0x7a, 0x9b, 0x72, 0x4f, 0x6f, 0xaf, 0x32, 0x58, 0x88, 0x05, 0xa5, 0x14, 0x94,
0xae, 0x26, 0x90, 0x6e, 0x44, 0xb1, 0x62, 0x45, 0x41, 0x10, 0x2c, 0x51, 0x14, 0xdc, 0x94, 0x71,
0x32, 0xda, 0xd0, 0xe9, 0x9c, 0x21, 0xa6, 0x95, 0xbc, 0x86, 0x6f, 0xe0, 0xd6, 0x87, 0xf2, 0x59,
0x24, 0x99, 0x84, 0x6c, 0x5a, 0xe9, 0x6e, 0x72, 0xf8, 0xfe, 0x8f, 0x43, 0xfe, 0x03, 0x87, 0x4b,
0x3f, 0x66, 0x29, 0xe5, 0x38, 0xf7, 0x38, 0xc6, 0xc2, 0x63, 0x5a, 0x7b, 0x1a, 0x65, 0xc4, 0x53,
0x8f, 0xa3,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1, 0x36, 0x13, 0x69, 0xd1,
0x66, 0xf6, 0x24, 0x83, 0xb2, 0xe1, 0xdf, 0x7f, 0x96, 0xa9, 0xaf, 0x38, 0x80, 0x63, 0xfb, 0xc8,
0x1a, 0x9d, 0xc2, 0x2e, 0xc7, 0xf9, 0x6a, 0x7c, 0x6c, 0x3d, 0x39, 0xe6, 0xf5, 0x65, 0xb7, 0x1f,
0xfc, 0x80, 0x65, 0x0b, 0xc6, 0x82, 0x9e, 0x6b, 0x5d, 0x98, 0x9e, 0x9d, 0xfc, 0x02, 0x07, 0x3f,
0x01, 0x00, 0x00, 0xff, 0xff, 0xcf, 0x25, 0x25, 0xc2, 0xab, 0x02, 0x00, 0x00,
// 403 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xdd, 0x8a, 0xd3, 0x40,
0x14, 0xc7, 0x49, 0x62, 0xb2, 0x7a, 0x6a, 0x5d, 0x19, 0x5c, 0x88, 0x05, 0x65, 0xa9, 0xb8, 0xf4,
0x6a, 0x02, 0xd9, 0x1b, 0x3f, 0x70, 0xc5, 0x15, 0x05, 0x41, 0xb0, 0xa4, 0x7e, 0x80, 0x37, 0x61,
0x3a, 0x39, 0xda, 0xd0, 0xe9, 0xcc, 0x30, 0x49, 0x2a, 0x79, 0x0d, 0xdf, 0xc0, 0x5b, 0x1f, 0xc5,
0xa7, 0x92, 0x64, 0x12, 0x72, 0xd3, 0x76, 0x7b, 0x37, 0x19, 0x7e, 0xff, 0x5f, 0x4e, 0x4e, 0xfe,
0x70, 0xb1, 0x8d, 0x0d, 0xab, 0x29, 0x57, 0x9b, 0x88, 0x2b, 0x83, 0x11, 0xd3, 0x3a, 0xd2, 0x4a,
0xe4, 0xbc, 0x8e, 0xb8, 0x92, 0x3f, 0xf2, 0x9f, 0x54, 0x1b, 0x55, 0x2a, 0x72, 0xd6, 0x73, 0x06,
0x29, 0xd3, 0x9a,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, 0x6d, 0x4b, 0x41,
0xae, 0xc0, 0x17, 0xb8, 0x45, 0x11, 0x3a, 0xe7, 0xde, 0x6c, 0x14, 0xcf, 0xf6, 0xbc, 0xd7, 0xd2,
0xf4, 0x63, 0x83, 0xbe, 0x93, 0xa5, 0xa9, 0x13, 0x1b, 0x9b, 0x7c, 0x03, 0x18, 0x2e, 0xc9, 0x7d,
0xf0, 0xd6, 0x58, 0x77, 0xcd, 0x69, 0x8e, 0xe4, 0xb2, 0x6f, 0xd3, 0xe1, 0xed, 0xda, 0x7f, 0xdd,
0x95, 0xed, 0x85, 0xfb, 0xcc, 0xb9, 0x7e, 0x05, 0x0f, 0xb9, 0xda, 0xec, 0xc6, 0xe7, 0xce, 0xf7,
0xc0, 0x9e, 0xfe, 0xba, 0x67, 0x5f, 0xe3, 0x84, 0x35, 0x03, 0x1a, 0xa4, 0x6f, 0xb4, 0xee, 0x4c,
0xcb, 0xa0, 0x6d, 0xfb, 0xe5, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0xad, 0x5f, 0x54, 0x17,
0x03, 0x00, 0x00,
}

View File

@ -19,7 +19,12 @@ message Policy {
Second downlink_only = 4;
}
message Stats {
bool enable_per_user = 1;
}
Timeout timeout = 1;
Stats stats = 2;
}
message Config {

View File

@ -19,9 +19,14 @@ type TimeoutPolicy struct {
DownlinkOnly time.Duration
}
type StatsPolicy struct {
EnablePerUser bool
}
// Policy is session based settings for controlling V2Ray requests. It contains various settings (or limits) that may differ for different users in the context.
type Policy struct {
Timeouts TimeoutPolicy // Timeout settings
Stats StatsPolicy
}
// PolicyManager is a feature that provides Policy for the given user by its id or level.
@ -41,6 +46,9 @@ func DefaultPolicy() Policy {
UplinkOnly: time.Second * 5,
DownlinkOnly: time.Second * 30,
},
Stats: StatsPolicy{
EnablePerUser: false,
},
}
}