2017-11-27 16:09:30 -05:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2018-01-10 06:22:37 -05:00
|
|
|
|
|
|
|
"v2ray.com/core"
|
2017-11-27 16:09:30 -05:00
|
|
|
)
|
|
|
|
|
2017-12-14 09:02:36 -05:00
|
|
|
// Duration converts Second to time.Duration.
|
2017-11-27 16:09:30 -05:00
|
|
|
func (s *Second) Duration() time.Duration {
|
2018-01-10 06:22:37 -05:00
|
|
|
if s == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2017-11-27 16:09:30 -05:00
|
|
|
return time.Second * time.Duration(s.Value)
|
|
|
|
}
|
|
|
|
|
2017-12-14 09:02:36 -05:00
|
|
|
// OverrideWith overrides current Policy with another one.
|
2017-11-27 16:09:30 -05:00
|
|
|
func (p *Policy) OverrideWith(another *Policy) {
|
2017-11-27 17:25:43 -05:00
|
|
|
if another.Timeout != nil {
|
|
|
|
if another.Timeout.Handshake != nil {
|
|
|
|
p.Timeout.Handshake = another.Timeout.Handshake
|
|
|
|
}
|
|
|
|
if another.Timeout.ConnectionIdle != nil {
|
|
|
|
p.Timeout.ConnectionIdle = another.Timeout.ConnectionIdle
|
|
|
|
}
|
|
|
|
if another.Timeout.UplinkOnly != nil {
|
|
|
|
p.Timeout.UplinkOnly = another.Timeout.UplinkOnly
|
|
|
|
}
|
|
|
|
if another.Timeout.DownlinkOnly != nil {
|
|
|
|
p.Timeout.DownlinkOnly = another.Timeout.DownlinkOnly
|
|
|
|
}
|
|
|
|
}
|
2017-11-27 16:09:30 -05:00
|
|
|
}
|
2018-01-10 06:22:37 -05:00
|
|
|
|
|
|
|
func (p *Policy) ToCorePolicy() core.Policy {
|
|
|
|
var cp core.Policy
|
|
|
|
if p.Timeout != nil {
|
|
|
|
cp.Timeouts.ConnectionIdle = p.Timeout.ConnectionIdle.Duration()
|
|
|
|
cp.Timeouts.Handshake = p.Timeout.Handshake.Duration()
|
|
|
|
cp.Timeouts.DownlinkOnly = p.Timeout.DownlinkOnly.Duration()
|
|
|
|
cp.Timeouts.UplinkOnly = p.Timeout.UplinkOnly.Duration()
|
|
|
|
}
|
|
|
|
return cp
|
|
|
|
}
|