From cf832a42729d6c153674d88ef2d6873da638af02 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 31 Jan 2018 13:23:23 +0100 Subject: [PATCH] adjust init sequence --- proxy/vmess/inbound/inbound.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 5553f14e..9949383a 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -82,13 +82,6 @@ type Handler struct { // New creates a new VMess inbound handler. func New(ctx context.Context, config *Config) (*Handler, error) { - allowedClients := vmess.NewTimedUserValidator(ctx, protocol.DefaultIDHash) - for _, user := range config.User { - if err := allowedClients.Add(user); err != nil { - return nil, newError("failed to initiate user").Base(err) - } - } - v := core.FromContext(ctx) if v == nil { return nil, newError("V is not in context.") @@ -97,12 +90,18 @@ func New(ctx context.Context, config *Config) (*Handler, error) { handler := &Handler{ policyManager: v.PolicyManager(), inboundHandlerManager: v.InboundHandlerManager(), - clients: allowedClients, + clients: vmess.NewTimedUserValidator(ctx, protocol.DefaultIDHash), detours: config.Detour, usersByEmail: newUserByEmail(config.User, config.GetDefaultValue()), sessionHistory: encoding.NewSessionHistory(ctx), } + for _, user := range config.User { + if err := handler.AddUser(ctx, user); err != nil { + return nil, newError("failed to initiate user").Base(err) + } + } + return handler, nil } @@ -121,6 +120,10 @@ func (h *Handler) GetUser(email string) *protocol.User { return user } +func (h *Handler) AddUser(ctx context.Context, user *protocol.User) error { + return h.clients.Add(user) +} + func transferRequest(timer signal.ActivityUpdater, session *encoding.ServerSession, request *protocol.RequestHeader, input io.Reader, output ray.OutputStream) error { defer output.Close()