adjust init sequence

pull/861/head
Darien Raymond 2018-01-31 13:23:23 +01:00
parent 0273b36027
commit cf832a4272
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 11 additions and 8 deletions

View File

@ -82,13 +82,6 @@ type Handler struct {
// New creates a new VMess inbound handler. // New creates a new VMess inbound handler.
func New(ctx context.Context, config *Config) (*Handler, error) { 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) v := core.FromContext(ctx)
if v == nil { if v == nil {
return nil, newError("V is not in context.") return nil, newError("V is not in context.")
@ -97,12 +90,18 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
handler := &Handler{ handler := &Handler{
policyManager: v.PolicyManager(), policyManager: v.PolicyManager(),
inboundHandlerManager: v.InboundHandlerManager(), inboundHandlerManager: v.InboundHandlerManager(),
clients: allowedClients, clients: vmess.NewTimedUserValidator(ctx, protocol.DefaultIDHash),
detours: config.Detour, detours: config.Detour,
usersByEmail: newUserByEmail(config.User, config.GetDefaultValue()), usersByEmail: newUserByEmail(config.User, config.GetDefaultValue()),
sessionHistory: encoding.NewSessionHistory(ctx), 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 return handler, nil
} }
@ -121,6 +120,10 @@ func (h *Handler) GetUser(email string) *protocol.User {
return 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 { func transferRequest(timer signal.ActivityUpdater, session *encoding.ServerSession, request *protocol.RequestHeader, input io.Reader, output ray.OutputStream) error {
defer output.Close() defer output.Close()