1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/policy.go

75 lines
1.1 KiB
Go
Raw Normal View History

package core
import (
"sync"
"time"
2018-02-08 09:39:46 -05:00
"v2ray.com/core/common"
2018-10-11 16:34:31 -04:00
"v2ray.com/core/features/policy"
)
type syncPolicyManager struct {
sync.RWMutex
2018-10-11 16:34:31 -04:00
policy.Manager
}
2018-10-12 17:57:56 -04:00
func (*syncPolicyManager) Type() interface{} {
return policy.ManagerType()
}
2018-10-11 16:34:31 -04:00
func (m *syncPolicyManager) ForLevel(level uint32) policy.Session {
m.RLock()
defer m.RUnlock()
2018-10-11 16:34:31 -04:00
if m.Manager == nil {
p := policy.SessionDefault()
if level == 1 {
p.Timeouts.ConnectionIdle = time.Second * 600
}
return p
}
2018-10-11 16:34:31 -04:00
return m.Manager.ForLevel(level)
}
2018-10-11 16:34:31 -04:00
func (m *syncPolicyManager) ForSystem() policy.System {
2018-04-12 03:57:41 -04:00
m.RLock()
defer m.RUnlock()
2018-10-11 16:34:31 -04:00
if m.Manager == nil {
return policy.System{}
2018-04-12 03:57:41 -04:00
}
2018-10-11 16:34:31 -04:00
return m.Manager.ForSystem()
2018-04-12 03:57:41 -04:00
}
func (m *syncPolicyManager) Start() error {
m.RLock()
defer m.RUnlock()
2018-10-11 16:34:31 -04:00
if m.Manager == nil {
return nil
}
2018-10-11 16:34:31 -04:00
return m.Manager.Start()
}
2018-02-08 09:39:46 -05:00
func (m *syncPolicyManager) Close() error {
m.RLock()
defer m.RUnlock()
2018-10-11 16:34:31 -04:00
return common.Close(m.Manager)
}
2018-10-11 16:34:31 -04:00
func (m *syncPolicyManager) Set(manager policy.Manager) {
if manager == nil {
return
}
m.Lock()
defer m.Unlock()
2018-10-11 16:34:31 -04:00
common.Close(m.Manager) // nolint: errcheck
m.Manager = manager
}