1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-29 18:45:23 +00:00

naming refactoring

This commit is contained in:
Darien Raymond 2017-02-13 13:16:37 +01:00
parent 4f27a07c29
commit 7b707275df
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 19 additions and 17 deletions

View File

@ -71,8 +71,8 @@ func (v *userByEmail) Get(email string) (*protocol.User, bool) {
return user, found return user, found
} }
// Inbound connection handler that handles messages in VMess format. // Handler is an inbound connection handler that handles messages in VMess protocol.
type VMessInboundHandler struct { type Handler struct {
inboundHandlerManager proxyman.InboundHandlerManager inboundHandlerManager proxyman.InboundHandlerManager
clients protocol.UserValidator clients protocol.UserValidator
usersByEmail *userByEmail usersByEmail *userByEmail
@ -80,7 +80,7 @@ type VMessInboundHandler struct {
sessionHistory *encoding.SessionHistory 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) space := app.SpaceFromContext(ctx)
if space == nil { if space == nil {
return nil, errors.New("VMess|Inbound: No space in context.") 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) allowedClients.Add(user)
} }
handler := &VMessInboundHandler{ handler := &Handler{
clients: allowedClients, clients: allowedClients,
detours: config.Detour, detours: config.Detour,
usersByEmail: NewUserByEmail(config.User, config.GetDefaultValue()), usersByEmail: NewUserByEmail(config.User, config.GetDefaultValue()),
@ -109,13 +109,14 @@ func New(ctx context.Context, config *Config) (*VMessInboundHandler, error) {
return handler, nil return handler, nil
} }
func (*VMessInboundHandler) Network() net.NetworkList { // Network implements proxy.Inbound.Network().
func (*Handler) Network() net.NetworkList {
return net.NetworkList{ return net.NetworkList{
Network: []net.Network{net.Network_TCP}, 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) user, existing := v.usersByEmail.Get(email)
if !existing { if !existing {
v.clients.Add(user) v.clients.Add(user)
@ -168,7 +169,8 @@ func transferResponse(timer *signal.ActivityTimer, session *encoding.ServerSessi
return nil 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)) connection.SetReadDeadline(time.Now().Add(time.Second * 8))
reader := bufio.NewReader(connection) reader := bufio.NewReader(connection)
@ -238,7 +240,7 @@ func (v *VMessInboundHandler) Process(ctx context.Context, network net.Network,
return nil 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 { if v.detours != nil {
tag := v.detours.To tag := v.detours.To
if v.inboundHandlerManager != nil { if v.inboundHandlerManager != nil {
@ -248,7 +250,7 @@ func (v *VMessInboundHandler) generateCommand(ctx context.Context, request *prot
return nil return nil
} }
proxyHandler, port, availableMin := handler.GetRandomInboundProxy() proxyHandler, port, availableMin := handler.GetRandomInboundProxy()
inboundHandler, ok := proxyHandler.(*VMessInboundHandler) inboundHandler, ok := proxyHandler.(*Handler)
if ok && inboundHandler != nil { if ok && inboundHandler != nil {
if availableMin > 255 { if availableMin > 255 {
availableMin = 255 availableMin = 255

View File

@ -9,7 +9,7 @@ import (
"v2ray.com/core/proxy/vmess" "v2ray.com/core/proxy/vmess"
) )
func (v *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) { func (v *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
account := &vmess.Account{ account := &vmess.Account{
Id: cmd.ID.String(), Id: cmd.ID.String(),
AlterId: uint32(cmd.AlterIds), 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)) 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) { switch typedCommand := cmd.(type) {
case *protocol.CommandSwitchAccount: case *protocol.CommandSwitchAccount:
if typedCommand.Host == nil { if typedCommand.Host == nil {

View File

@ -22,13 +22,13 @@ import (
"v2ray.com/core/transport/ray" "v2ray.com/core/transport/ray"
) )
// VMessOutboundHandler is an outbound connection handler for VMess protocol. // Handler is an outbound connection handler for VMess protocol.
type VMessOutboundHandler struct { type Handler struct {
serverList *protocol.ServerList serverList *protocol.ServerList
serverPicker protocol.ServerPicker 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) space := app.SpaceFromContext(ctx)
if space == nil { if space == nil {
return nil, errors.New("VMess|Outbound: No space in context.") 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 { for _, rec := range config.Receiver {
serverList.AddServer(protocol.NewServerSpecFromPB(*rec)) serverList.AddServer(protocol.NewServerSpecFromPB(*rec))
} }
handler := &VMessOutboundHandler{ handler := &Handler{
serverList: serverList, serverList: serverList,
serverPicker: protocol.NewRoundRobinServerPicker(serverList), serverPicker: protocol.NewRoundRobinServerPicker(serverList),
} }
@ -46,8 +46,8 @@ func New(ctx context.Context, config *Config) (*VMessOutboundHandler, error) {
return handler, nil return handler, nil
} }
// Dispatch implements OutboundHandler.Dispatch(). // Process implements proxy.Outbound.Process().
func (v *VMessOutboundHandler) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error { func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error {
var rec *protocol.ServerSpec var rec *protocol.ServerSpec
var conn internet.Connection var conn internet.Connection