From 7b707275dfed073d874bc924904cb63ad520065a Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Mon, 13 Feb 2017 13:16:37 +0100 Subject: [PATCH] naming refactoring --- proxy/vmess/inbound/inbound.go | 20 +++++++++++--------- proxy/vmess/outbound/command.go | 4 ++-- proxy/vmess/outbound/outbound.go | 12 ++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 222dd41d4..90c2b74d5 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -71,8 +71,8 @@ func (v *userByEmail) Get(email string) (*protocol.User, bool) { return user, found } -// Inbound connection handler that handles messages in VMess format. -type VMessInboundHandler struct { +// Handler is an inbound connection handler that handles messages in VMess protocol. +type Handler struct { inboundHandlerManager proxyman.InboundHandlerManager clients protocol.UserValidator usersByEmail *userByEmail @@ -80,7 +80,7 @@ type VMessInboundHandler struct { sessionHistory *encoding.SessionHistory } -func New(ctx context.Context, config *Config) (*VMessInboundHandler, error) { +func New(ctx context.Context, config *Config) (*Handler, error) { space := app.SpaceFromContext(ctx) if space == nil { return nil, errors.New("VMess|Inbound: No space in context.") @@ -91,7 +91,7 @@ func New(ctx context.Context, config *Config) (*VMessInboundHandler, error) { allowedClients.Add(user) } - handler := &VMessInboundHandler{ + handler := &Handler{ clients: allowedClients, detours: config.Detour, usersByEmail: NewUserByEmail(config.User, config.GetDefaultValue()), @@ -109,13 +109,14 @@ func New(ctx context.Context, config *Config) (*VMessInboundHandler, error) { return handler, nil } -func (*VMessInboundHandler) Network() net.NetworkList { +// Network implements proxy.Inbound.Network(). +func (*Handler) Network() net.NetworkList { return net.NetworkList{ Network: []net.Network{net.Network_TCP}, } } -func (v *VMessInboundHandler) GetUser(email string) *protocol.User { +func (v *Handler) GetUser(email string) *protocol.User { user, existing := v.usersByEmail.Get(email) if !existing { v.clients.Add(user) @@ -168,7 +169,8 @@ func transferResponse(timer *signal.ActivityTimer, session *encoding.ServerSessi return nil } -func (v *VMessInboundHandler) Process(ctx context.Context, network net.Network, connection internet.Connection, dispatcher dispatcher.Interface) error { +// Process implements proxy.Inbound.Process(). +func (v *Handler) Process(ctx context.Context, network net.Network, connection internet.Connection, dispatcher dispatcher.Interface) error { connection.SetReadDeadline(time.Now().Add(time.Second * 8)) reader := bufio.NewReader(connection) @@ -238,7 +240,7 @@ func (v *VMessInboundHandler) Process(ctx context.Context, network net.Network, return nil } -func (v *VMessInboundHandler) generateCommand(ctx context.Context, request *protocol.RequestHeader) protocol.ResponseCommand { +func (v *Handler) generateCommand(ctx context.Context, request *protocol.RequestHeader) protocol.ResponseCommand { if v.detours != nil { tag := v.detours.To if v.inboundHandlerManager != nil { @@ -248,7 +250,7 @@ func (v *VMessInboundHandler) generateCommand(ctx context.Context, request *prot return nil } proxyHandler, port, availableMin := handler.GetRandomInboundProxy() - inboundHandler, ok := proxyHandler.(*VMessInboundHandler) + inboundHandler, ok := proxyHandler.(*Handler) if ok && inboundHandler != nil { if availableMin > 255 { availableMin = 255 diff --git a/proxy/vmess/outbound/command.go b/proxy/vmess/outbound/command.go index 0c7f2742b..918980604 100644 --- a/proxy/vmess/outbound/command.go +++ b/proxy/vmess/outbound/command.go @@ -9,7 +9,7 @@ import ( "v2ray.com/core/proxy/vmess" ) -func (v *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) { +func (v *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) { account := &vmess.Account{ Id: cmd.ID.String(), AlterId: uint32(cmd.AlterIds), @@ -28,7 +28,7 @@ func (v *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAc v.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user)) } -func (v *VMessOutboundHandler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) { +func (v *Handler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) { switch typedCommand := cmd.(type) { case *protocol.CommandSwitchAccount: if typedCommand.Host == nil { diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index c0def0b7c..188aec726 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -22,13 +22,13 @@ import ( "v2ray.com/core/transport/ray" ) -// VMessOutboundHandler is an outbound connection handler for VMess protocol. -type VMessOutboundHandler struct { +// Handler is an outbound connection handler for VMess protocol. +type Handler struct { serverList *protocol.ServerList serverPicker protocol.ServerPicker } -func New(ctx context.Context, config *Config) (*VMessOutboundHandler, error) { +func New(ctx context.Context, config *Config) (*Handler, error) { space := app.SpaceFromContext(ctx) if space == nil { return nil, errors.New("VMess|Outbound: No space in context.") @@ -38,7 +38,7 @@ func New(ctx context.Context, config *Config) (*VMessOutboundHandler, error) { for _, rec := range config.Receiver { serverList.AddServer(protocol.NewServerSpecFromPB(*rec)) } - handler := &VMessOutboundHandler{ + handler := &Handler{ serverList: serverList, serverPicker: protocol.NewRoundRobinServerPicker(serverList), } @@ -46,8 +46,8 @@ func New(ctx context.Context, config *Config) (*VMessOutboundHandler, error) { return handler, nil } -// Dispatch implements OutboundHandler.Dispatch(). -func (v *VMessOutboundHandler) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error { +// Process implements proxy.Outbound.Process(). +func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error { var rec *protocol.ServerSpec var conn internet.Connection