mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
rename interfaces
This commit is contained in:
parent
3214a5078c
commit
f90ec9fff0
@ -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() {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
@ -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.")
|
||||||
}
|
}
|
||||||
|
2
v2ray.go
2
v2ray.go
@ -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{
|
||||||
|
Loading…
Reference in New Issue
Block a user