integration test case for policy

This commit is contained in:
Darien Raymond
2018-02-20 13:53:07 +01:00
parent b3fd320be7
commit c25a76a0cf
4 changed files with 210 additions and 29 deletions

View File

@@ -13,40 +13,17 @@ type TimeoutPolicy struct {
Handshake time.Duration
// Timeout for connection being idle, i.e., there is no egress or ingress traffic in this connection.
ConnectionIdle time.Duration
// Timeout for an uplink only connection, i.e., the downlink of the connection has ben closed.
// Timeout for an uplink only connection, i.e., the downlink of the connection has been closed.
UplinkOnly time.Duration
// Timeout for an downlink only connection, i.e., the uplink of the connection has ben closed.
// Timeout for an downlink only connection, i.e., the uplink of the connection has been closed.
DownlinkOnly time.Duration
}
// OverrideWith overrides the current TimeoutPolicy with another one. All timeouts with zero value will be overridden with the new value.
func (p TimeoutPolicy) OverrideWith(another TimeoutPolicy) TimeoutPolicy {
if p.Handshake == 0 {
p.Handshake = another.Handshake
}
if p.ConnectionIdle == 0 {
p.ConnectionIdle = another.ConnectionIdle
}
if p.UplinkOnly == 0 {
p.UplinkOnly = another.UplinkOnly
}
if p.DownlinkOnly == 0 {
p.DownlinkOnly = another.DownlinkOnly
}
return p
}
// 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
}
// OverrideWith overrides the current Policy with another one. All values with default value will be overridden.
func (p Policy) OverrideWith(another Policy) Policy {
p.Timeouts = p.Timeouts.OverrideWith(another.Timeouts)
return p
}
// PolicyManager is a feature that provides Policy for the given user by its id or level.
type PolicyManager interface {
Feature