1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-28 21:15:46 -05:00

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

@@ -9,17 +9,19 @@ import (
// Instance is an instance of Policy manager.
type Instance struct {
levels map[uint32]core.Policy
levels map[uint32]*Policy
}
// New creates new Policy manager instance.
func New(ctx context.Context, config *Config) (*Instance, error) {
m := &Instance{
levels: make(map[uint32]core.Policy),
levels: make(map[uint32]*Policy),
}
if len(config.Level) > 0 {
for lv, p := range config.Level {
m.levels[lv] = p.ToCorePolicy().OverrideWith(core.DefaultPolicy())
pp := defaultPolicy()
pp.overrideWith(p)
m.levels[lv] = pp
}
}
@@ -36,7 +38,7 @@ func New(ctx context.Context, config *Config) (*Instance, error) {
// ForLevel implements core.PolicyManager.
func (m *Instance) ForLevel(level uint32) core.Policy {
if p, ok := m.levels[level]; ok {
return p
return p.ToCorePolicy()
}
return core.DefaultPolicy()
}