forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy.go
74 lines (56 loc) · 1.11 KB
/
policy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package core
import (
"sync"
"time"
"v2ray.com/core/common"
"v2ray.com/core/features/policy"
)
type syncPolicyManager struct {
sync.RWMutex
policy.Manager
}
func (*syncPolicyManager) Type() interface{} {
return policy.ManagerType()
}
func (m *syncPolicyManager) ForLevel(level uint32) policy.Session {
m.RLock()
defer m.RUnlock()
if m.Manager == nil {
p := policy.SessionDefault()
if level == 1 {
p.Timeouts.ConnectionIdle = time.Second * 600
}
return p
}
return m.Manager.ForLevel(level)
}
func (m *syncPolicyManager) ForSystem() policy.System {
m.RLock()
defer m.RUnlock()
if m.Manager == nil {
return policy.System{}
}
return m.Manager.ForSystem()
}
func (m *syncPolicyManager) Start() error {
m.RLock()
defer m.RUnlock()
if m.Manager == nil {
return nil
}
return m.Manager.Start()
}
func (m *syncPolicyManager) Close() error {
m.RLock()
defer m.RUnlock()
return common.Close(m.Manager)
}
func (m *syncPolicyManager) Set(manager policy.Manager) {
if manager == nil {
return
}
m.Lock()
defer m.Unlock()
common.Close(m.Manager) // nolint: errcheck
m.Manager = manager
}