From f90ec9fff05019eaa4e88647679858c3ebea3872 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Mon, 27 Nov 2017 22:18:39 +0100 Subject: [PATCH] rename interfaces --- app/policy/manager/manager.go | 2 +- app/policy/policy.go | 11 +++++++---- proxy/dokodemo/dokodemo.go | 2 +- proxy/freedom/freedom.go | 2 +- proxy/http/server.go | 2 +- proxy/shadowsocks/client.go | 4 ++-- proxy/shadowsocks/server.go | 4 ++-- proxy/socks/server.go | 2 +- proxy/vmess/inbound/inbound.go | 4 ++-- proxy/vmess/outbound/outbound.go | 4 ++-- v2ray.go | 2 +- 11 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/policy/manager/manager.go b/app/policy/manager/manager.go index 73ec14f8e..8f53be705 100644 --- a/app/policy/manager/manager.go +++ b/app/policy/manager/manager.go @@ -52,7 +52,7 @@ func (m *Instance) Close() { } func (m *Instance) Interface() interface{} { - return (*policy.Interface)(nil) + return (*policy.Manager)(nil) } func init() { diff --git a/app/policy/policy.go b/app/policy/policy.go index 1849a5ffa..f67e736e9 100644 --- a/app/policy/policy.go +++ b/app/policy/policy.go @@ -4,14 +4,17 @@ import ( "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 } -func PolicyFromSpace(space app.Space) Interface { - app := space.GetApplication((*Interface)(nil)) +// FromSpace returns the policy.Manager in a space. +func FromSpace(space app.Space) Manager { + app := space.GetApplication((*Manager)(nil)) if app == nil { return nil } - return app.(Interface) + return app.(Manager) } diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 064105690..6dc442912 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -39,7 +39,7 @@ func New(ctx context.Context, config *Config) (*DokodemoDoor, error) { port: net.Port(config.Port), } space.OnInitialize(func() error { - pm := policy.PolicyFromSpace(space) + pm := policy.FromSpace(space) if pm == nil { return newError("Policy not found in space.") } diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index d38bb618d..d44df1405 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -47,7 +47,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) { return newError("DNS server is not found in the space") } } - pm := policy.PolicyFromSpace(space) + pm := policy.FromSpace(space) if pm == nil { return newError("Policy not found in space.") } diff --git a/proxy/http/server.go b/proxy/http/server.go index e7e0b65ea..1dcc9423a 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -38,7 +38,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) { config: config, } space.OnInitialize(func() error { - pm := policy.PolicyFromSpace(space) + pm := policy.FromSpace(space) if pm == nil { return newError("Policy not found in space.") } diff --git a/proxy/shadowsocks/client.go b/proxy/shadowsocks/client.go index 473ecf626..6f67c91a7 100644 --- a/proxy/shadowsocks/client.go +++ b/proxy/shadowsocks/client.go @@ -20,7 +20,7 @@ import ( // Client is a inbound handler for Shadowsocks protocol type Client struct { serverPicker protocol.ServerPicker - policyManager policy.Interface + policyManager policy.Manager } // 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.") } space.OnInitialize(func() error { - pm := policy.PolicyFromSpace(space) + pm := policy.FromSpace(space) if pm == nil { return newError("Policy not found in space.") } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index f2d409449..b0a05ccf3 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -22,7 +22,7 @@ type Server struct { config *ServerConfig user *protocol.User account *ShadowsocksAccount - policyManager policy.Interface + policyManager policy.Manager } // NewServer create a new Shadowsocks server. @@ -48,7 +48,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) { } space.OnInitialize(func() error { - pm := policy.PolicyFromSpace(space) + pm := policy.FromSpace(space) if pm == nil { return newError("Policy not found in space.") } diff --git a/proxy/socks/server.go b/proxy/socks/server.go index de45358e3..473739618 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -35,7 +35,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) { config: config, } space.OnInitialize(func() error { - pm := policy.PolicyFromSpace(space) + pm := policy.FromSpace(space) if pm == nil { return newError("Policy not found in space.") } diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 731ba440d..4c10f959c 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -79,7 +79,7 @@ type Handler struct { usersByEmail *userByEmail detours *DetourConfig sessionHistory *encoding.SessionHistory - policyManager policy.Interface + policyManager policy.Manager } // New creates a new VMess inbound handler. @@ -108,7 +108,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) { if handler.inboundHandlerManager == nil { return newError("InboundHandlerManager is not found is space.") } - handler.policyManager = policy.PolicyFromSpace(space) + handler.policyManager = policy.FromSpace(space) if handler.policyManager == nil { return newError("Policy is not found in space.") } diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index a1a0287bb..1547cc473 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -26,7 +26,7 @@ import ( type Handler struct { serverList *protocol.ServerList serverPicker protocol.ServerPicker - policyManager policy.Interface + policyManager policy.Manager } 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 { - pm := policy.PolicyFromSpace(space) + pm := policy.FromSpace(space) if pm == nil { return newError("Policy is not found in space.") } diff --git a/v2ray.go b/v2ray.go index 1107e3b8c..687ca8edb 100644 --- a/v2ray.go +++ b/v2ray.go @@ -118,7 +118,7 @@ func newSimpleServer(config *Config) (*simpleServer, error) { 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{ Level: map[uint32]*policy.Policy{ 1: &policy.Policy{