1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

fix buffer policy settings

This commit is contained in:
Darien Raymond 2018-05-25 13:12:00 +02:00
parent b24e808a8a
commit 65bd8509d7
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 62 additions and 74 deletions

View File

@ -25,8 +25,7 @@ func defaultPolicy() *Policy {
DownlinkOnly: &Second{Value: uint32(p.Timeouts.DownlinkOnly / time.Second)},
},
Buffer: &Policy_Buffer{
Enabled: p.Buffer.Enabled,
Size: p.Buffer.Size,
Connection: p.Buffer.PerConnection,
},
}
}
@ -71,8 +70,7 @@ func (p *Policy) ToCorePolicy() core.Policy {
cp.Stats.UserDownlink = p.Stats.UserDownlink
}
if p.Buffer != nil {
cp.Buffer.Enabled = p.Buffer.Enabled
cp.Buffer.Size = p.Buffer.Size
cp.Buffer.PerConnection = p.Buffer.Connection
}
return cp
}

View File

@ -26,7 +26,7 @@ func (m *Second) Reset() { *m = Second{} }
func (m *Second) String() string { return proto.CompactTextString(m) }
func (*Second) ProtoMessage() {}
func (*Second) Descriptor() ([]byte, []int) {
return fileDescriptor_config_505638f2092d854e, []int{0}
return fileDescriptor_config_700aba7c9186c0c0, []int{0}
}
func (m *Second) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Second.Unmarshal(m, b)
@ -66,7 +66,7 @@ func (m *Policy) Reset() { *m = Policy{} }
func (m *Policy) String() string { return proto.CompactTextString(m) }
func (*Policy) ProtoMessage() {}
func (*Policy) Descriptor() ([]byte, []int) {
return fileDescriptor_config_505638f2092d854e, []int{1}
return fileDescriptor_config_700aba7c9186c0c0, []int{1}
}
func (m *Policy) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Policy.Unmarshal(m, b)
@ -122,7 +122,7 @@ func (m *Policy_Timeout) Reset() { *m = Policy_Timeout{} }
func (m *Policy_Timeout) String() string { return proto.CompactTextString(m) }
func (*Policy_Timeout) ProtoMessage() {}
func (*Policy_Timeout) Descriptor() ([]byte, []int) {
return fileDescriptor_config_505638f2092d854e, []int{1, 0}
return fileDescriptor_config_700aba7c9186c0c0, []int{1, 0}
}
func (m *Policy_Timeout) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Policy_Timeout.Unmarshal(m, b)
@ -182,7 +182,7 @@ 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 fileDescriptor_config_505638f2092d854e, []int{1, 1}
return fileDescriptor_config_700aba7c9186c0c0, []int{1, 1}
}
func (m *Policy_Stats) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Policy_Stats.Unmarshal(m, b)
@ -217,8 +217,8 @@ func (m *Policy_Stats) GetUserDownlink() bool {
}
type Policy_Buffer struct {
Enabled bool `protobuf:"varint,1,opt,name=enabled" json:"enabled,omitempty"`
Size uint32 `protobuf:"varint,2,opt,name=size" json:"size,omitempty"`
// Buffer size per connection, in bytes. -1 for unlimited buffer.
Connection int32 `protobuf:"varint,1,opt,name=connection" json:"connection,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -228,7 +228,7 @@ func (m *Policy_Buffer) Reset() { *m = Policy_Buffer{} }
func (m *Policy_Buffer) String() string { return proto.CompactTextString(m) }
func (*Policy_Buffer) ProtoMessage() {}
func (*Policy_Buffer) Descriptor() ([]byte, []int) {
return fileDescriptor_config_505638f2092d854e, []int{1, 2}
return fileDescriptor_config_700aba7c9186c0c0, []int{1, 2}
}
func (m *Policy_Buffer) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Policy_Buffer.Unmarshal(m, b)
@ -248,16 +248,9 @@ func (m *Policy_Buffer) XXX_DiscardUnknown() {
var xxx_messageInfo_Policy_Buffer proto.InternalMessageInfo
func (m *Policy_Buffer) GetEnabled() bool {
func (m *Policy_Buffer) GetConnection() int32 {
if m != nil {
return m.Enabled
}
return false
}
func (m *Policy_Buffer) GetSize() uint32 {
if m != nil {
return m.Size
return m.Connection
}
return 0
}
@ -273,7 +266,7 @@ func (m *SystemPolicy) Reset() { *m = SystemPolicy{} }
func (m *SystemPolicy) String() string { return proto.CompactTextString(m) }
func (*SystemPolicy) ProtoMessage() {}
func (*SystemPolicy) Descriptor() ([]byte, []int) {
return fileDescriptor_config_505638f2092d854e, []int{2}
return fileDescriptor_config_700aba7c9186c0c0, []int{2}
}
func (m *SystemPolicy) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_SystemPolicy.Unmarshal(m, b)
@ -312,7 +305,7 @@ func (m *SystemPolicy_Stats) Reset() { *m = SystemPolicy_Stats{} }
func (m *SystemPolicy_Stats) String() string { return proto.CompactTextString(m) }
func (*SystemPolicy_Stats) ProtoMessage() {}
func (*SystemPolicy_Stats) Descriptor() ([]byte, []int) {
return fileDescriptor_config_505638f2092d854e, []int{2, 0}
return fileDescriptor_config_700aba7c9186c0c0, []int{2, 0}
}
func (m *SystemPolicy_Stats) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_SystemPolicy_Stats.Unmarshal(m, b)
@ -358,7 +351,7 @@ func (m *Config) Reset() { *m = Config{} }
func (m *Config) String() string { return proto.CompactTextString(m) }
func (*Config) ProtoMessage() {}
func (*Config) Descriptor() ([]byte, []int) {
return fileDescriptor_config_505638f2092d854e, []int{3}
return fileDescriptor_config_700aba7c9186c0c0, []int{3}
}
func (m *Config) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Config.Unmarshal(m, b)
@ -405,42 +398,42 @@ func init() {
}
func init() {
proto.RegisterFile("v2ray.com/core/app/policy/config.proto", fileDescriptor_config_505638f2092d854e)
proto.RegisterFile("v2ray.com/core/app/policy/config.proto", fileDescriptor_config_700aba7c9186c0c0)
}
var fileDescriptor_config_505638f2092d854e = []byte{
// 523 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 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d, 0xb5, 0x59, 0xf1, 0xbe, 0x99, 0x60, 0x87, 0xb0, 0x1d, 0xf3,
0x89, 0x28, 0x78, 0x74, 0x3d, 0x9b, 0xa3, 0xab, 0x3a, 0xde, 0x11, 0xec, 0x1a, 0xec, 0x9f, 0x84,
0x3b, 0xba, 0x6e, 0x42, 0x76, 0x2f, 0x2d, 0xb0, 0x5f, 0xc9, 0xad, 0x22, 0xa7, 0xd0, 0x64, 0xb8,
0x40, 0xe6, 0x5a, 0xfb, 0xf5, 0x5e, 0x7b, 0xd0, 0x5b, 0xf1, 0x4c, 0x45, 0xfb, 0xef, 0x2b, 0xf4,
0x0d, 0xcf, 0xd3, 0x92, 0x2a, 0x19, 0x39, 0x01, 0x3b, 0x93, 0x11, 0x36, 0x6c, 0xc3, 0xd5, 0x9c,
0x54, 0x4b, 0xbc, 0xaf, 0x00, 0x4b, 0x47, 0xb2, 0x0b, 0xf5, 0x19, 0x96, 0x7a, 0x6f, 0xab, 0x23,
0x39, 0x36, 0xbb, 0xbc, 0x7e, 0x3a, 0xb5, 0xab, 0x62, 0x9f, 0xd6, 0x1e, 0x5b, 0xc3, 0xe7, 0x70,
0x27, 0x14, 0xf3, 0x9b, 0xf1, 0x33, 0xeb, 0xbb, 0xad, 0x4e, 0x17, 0xb5, 0xbd, 0x2f, 0x03, 0x1a,
0x54, 0xe9, 0x52, 0xf4, 0x5f, 0x26, 0x89, 0x76, 0x9a, 0xd8, 0xf2, 0x5f, 0x73, 0xfc, 0x27, 0x00,
0x00, 0xff, 0xff, 0x2c, 0x2e, 0xe6, 0xcf, 0x95, 0x04, 0x00, 0x00,
var fileDescriptor_config_700aba7c9186c0c0 = []byte{
// 513 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xdb, 0x6a, 0x13, 0x41,
0x1c, 0xc6, 0xd9, 0xa4, 0xbb, 0xad, 0xff, 0x24, 0x6d, 0x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0xe3, 0x80, 0xf7, 0x4a, 0xbd,
0x23, 0x74, 0x01, 0x2e, 0xa3, 0x73, 0xca, 0xda, 0xce, 0x51, 0xbd, 0xdb, 0xe8, 0x77, 0x57, 0x5c,
0x53, 0xd3, 0xf8, 0x7d, 0x89, 0xbe, 0xe1, 0x59, 0x52, 0x10, 0x6d, 0x43, 0xe7, 0xe0, 0xa5, 0xaa,
0xc2, 0x86, 0xfd, 0x5f, 0xec, 0x49, 0x8c, 0xc5, 0xff, 0x0a, 0x50, 0x25, 0xa2, 0x7d, 0xa8, 0x4f,
0x69, 0x61, 0x5e, 0x6a, 0x79, 0x44, 0x67, 0xf6, 0xf5, 0xae, 0xdf, 0x47, 0x93, 0xaa, 0xd9, 0xa7,
0xb5, 0xc7, 0xce, 0xe0, 0x39, 0xdc, 0x0b, 0xc5, 0x6c, 0x39, 0x7e, 0xe9, 0x7c, 0xf7, 0xf4, 0xe9,
0xba, 0x76, 0xf0, 0xa5, 0x4f, 0x82, 0xb2, 0x5d, 0x42, 0xf1, 0x4b, 0x29, 0x4d, 0xd2, 0xd8, 0x53,
0x5f, 0x97, 0xb3, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe9, 0xde, 0xee, 0x20, 0x87, 0x04, 0x00,
0x00,
}

View File

@ -25,8 +25,8 @@ message Policy {
}
message Buffer {
bool enabled = 1;
uint32 size = 2;
// Buffer size per connection, in bytes. -1 for unlimited buffer.
int32 connection = 1;
}
Timeout timeout = 1;

View File

@ -31,10 +31,8 @@ type StatsPolicy struct {
// BufferPolicy contains settings for internal buffer.
type BufferPolicy struct {
// Whether or not to enable internal buffer.
Enabled bool
// Size of internal buffer, in bytes.
Size uint32
// Size of buffer per connection, in bytes. -1 for unlimited buffer.
PerConnection int32
}
type SystemStatsPolicy struct {
@ -67,7 +65,7 @@ type PolicyManager interface {
ForSystem() SystemPolicy
}
var defaultBufferSize uint32 = 10 * 1024 * 1024
var defaultBufferSize int32 = 10 * 1024 * 1024
func init() {
const key = "v2ray.ray.buffer.size"
@ -76,16 +74,15 @@ func init() {
AltName: platform.NormalizeEnvName(key),
}.GetValueAsInt(10)
if size == 0 {
defaultBufferSize = 2147483647
defaultBufferSize = -1
} else {
defaultBufferSize = uint32(size) * 1024 * 1024
defaultBufferSize = int32(size) * 1024 * 1024
}
}
func defaultBufferPolicy() BufferPolicy {
return BufferPolicy{
Enabled: true,
Size: defaultBufferSize,
PerConnection: defaultBufferSize,
}
}

View File

@ -194,7 +194,7 @@ func TestZeroBuffer(t *testing.T) {
DownlinkOnly: &policy.Second{Value: 0},
},
Buffer: &policy.Policy_Buffer{
Enabled: false,
Connection: 0,
},
},
},

View File

@ -25,8 +25,8 @@ func OptionsFromContext(ctx context.Context) []Option {
var opt []Option
bp := core.BufferPolicyFromContext(ctx)
if bp.Enabled {
opt = append(opt, WithSizeLimit(int32(bp.Size)))
if bp.PerConnection >= 0 {
opt = append(opt, WithSizeLimit(bp.PerConnection))
} else {
opt = append(opt, WithoutSizeLimit())
}
@ -37,7 +37,7 @@ func OptionsFromContext(ctx context.Context) []Option {
// New creates a new Reader and Writer that connects to each other.
func New(opts ...Option) (*Reader, *Writer) {
p := &pipe{
limit: 0,
limit: -1,
readSignal: signal.NewNotifier(),
writeSignal: signal.NewNotifier(),
}