1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 06:16:09 -04:00

rename interfaces

This commit is contained in:
Darien Raymond 2017-11-27 22:18:39 +01:00
parent 3214a5078c
commit f90ec9fff0
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
11 changed files with 21 additions and 18 deletions

View File

@ -52,7 +52,7 @@ func (m *Instance) Close() {
} }
func (m *Instance) Interface() interface{} { func (m *Instance) Interface() interface{} {
return (*policy.Interface)(nil) return (*policy.Manager)(nil)
} }
func init() { func init() {

View File

@ -4,14 +4,17 @@ import (
"v2ray.com/core/app" "v2ray.com/core/app"
) )
type Interface interface { // Manager is an utility to manage policy per user level.
type Manager interface {
// GetPolicy returns the Policy for the given user level.
GetPolicy(level uint32) Policy GetPolicy(level uint32) Policy
} }
func PolicyFromSpace(space app.Space) Interface { // FromSpace returns the policy.Manager in a space.
app := space.GetApplication((*Interface)(nil)) func FromSpace(space app.Space) Manager {
app := space.GetApplication((*Manager)(nil))
if app == nil { if app == nil {
return nil return nil
} }
return app.(Interface) return app.(Manager)
} }

View File

@ -39,7 +39,7 @@ func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
port: net.Port(config.Port), port: net.Port(config.Port),
} }
space.OnInitialize(func() error { space.OnInitialize(func() error {
pm := policy.PolicyFromSpace(space) pm := policy.FromSpace(space)
if pm == nil { if pm == nil {
return newError("Policy not found in space.") return newError("Policy not found in space.")
} }

View File

@ -47,7 +47,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
return newError("DNS server is not found in the space") return newError("DNS server is not found in the space")
} }
} }
pm := policy.PolicyFromSpace(space) pm := policy.FromSpace(space)
if pm == nil { if pm == nil {
return newError("Policy not found in space.") return newError("Policy not found in space.")
} }

View File

@ -38,7 +38,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
config: config, config: config,
} }
space.OnInitialize(func() error { space.OnInitialize(func() error {
pm := policy.PolicyFromSpace(space) pm := policy.FromSpace(space)
if pm == nil { if pm == nil {
return newError("Policy not found in space.") return newError("Policy not found in space.")
} }

View File

@ -20,7 +20,7 @@ import (
// Client is a inbound handler for Shadowsocks protocol // Client is a inbound handler for Shadowsocks protocol
type Client struct { type Client struct {
serverPicker protocol.ServerPicker serverPicker protocol.ServerPicker
policyManager policy.Interface policyManager policy.Manager
} }
// NewClient create a new Shadowsocks client. // NewClient create a new Shadowsocks client.
@ -40,7 +40,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
return nil, newError("Space not found.") return nil, newError("Space not found.")
} }
space.OnInitialize(func() error { space.OnInitialize(func() error {
pm := policy.PolicyFromSpace(space) pm := policy.FromSpace(space)
if pm == nil { if pm == nil {
return newError("Policy not found in space.") return newError("Policy not found in space.")
} }

View File

@ -22,7 +22,7 @@ type Server struct {
config *ServerConfig config *ServerConfig
user *protocol.User user *protocol.User
account *ShadowsocksAccount account *ShadowsocksAccount
policyManager policy.Interface policyManager policy.Manager
} }
// NewServer create a new Shadowsocks server. // NewServer create a new Shadowsocks server.
@ -48,7 +48,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
} }
space.OnInitialize(func() error { space.OnInitialize(func() error {
pm := policy.PolicyFromSpace(space) pm := policy.FromSpace(space)
if pm == nil { if pm == nil {
return newError("Policy not found in space.") return newError("Policy not found in space.")
} }

View File

@ -35,7 +35,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
config: config, config: config,
} }
space.OnInitialize(func() error { space.OnInitialize(func() error {
pm := policy.PolicyFromSpace(space) pm := policy.FromSpace(space)
if pm == nil { if pm == nil {
return newError("Policy not found in space.") return newError("Policy not found in space.")
} }

View File

@ -79,7 +79,7 @@ type Handler struct {
usersByEmail *userByEmail usersByEmail *userByEmail
detours *DetourConfig detours *DetourConfig
sessionHistory *encoding.SessionHistory sessionHistory *encoding.SessionHistory
policyManager policy.Interface policyManager policy.Manager
} }
// New creates a new VMess inbound handler. // New creates a new VMess inbound handler.
@ -108,7 +108,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
if handler.inboundHandlerManager == nil { if handler.inboundHandlerManager == nil {
return newError("InboundHandlerManager is not found is space.") return newError("InboundHandlerManager is not found is space.")
} }
handler.policyManager = policy.PolicyFromSpace(space) handler.policyManager = policy.FromSpace(space)
if handler.policyManager == nil { if handler.policyManager == nil {
return newError("Policy is not found in space.") return newError("Policy is not found in space.")
} }

View File

@ -26,7 +26,7 @@ import (
type Handler struct { type Handler struct {
serverList *protocol.ServerList serverList *protocol.ServerList
serverPicker protocol.ServerPicker serverPicker protocol.ServerPicker
policyManager policy.Interface policyManager policy.Manager
} }
func New(ctx context.Context, config *Config) (*Handler, error) { func New(ctx context.Context, config *Config) (*Handler, error) {
@ -45,7 +45,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
} }
space.OnInitialize(func() error { space.OnInitialize(func() error {
pm := policy.PolicyFromSpace(space) pm := policy.FromSpace(space)
if pm == nil { if pm == nil {
return newError("Policy is not found in space.") return newError("Policy is not found in space.")
} }

View File

@ -118,7 +118,7 @@ func newSimpleServer(config *Config) (*simpleServer, error) {
common.Must(space.AddApplication(d)) common.Must(space.AddApplication(d))
} }
if p := policy.PolicyFromSpace(space); p == nil { if p := policy.FromSpace(space); p == nil {
p, err := app.CreateAppFromConfig(ctx, &policy.Config{ p, err := app.CreateAppFromConfig(ctx, &policy.Config{
Level: map[uint32]*policy.Policy{ Level: map[uint32]*policy.Policy{
1: &policy.Policy{ 1: &policy.Policy{