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:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user