From 94817e0f824b44a10e22a6193bf67e3f06b56abf Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 25 Sep 2023 15:56:27 +0800 Subject: [PATCH] fix routedDispatch --- core/xray/app/dispatcher/default.go | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/core/xray/app/dispatcher/default.go b/core/xray/app/dispatcher/default.go index cb823df..18173bc 100644 --- a/core/xray/app/dispatcher/default.go +++ b/core/xray/app/dispatcher/default.go @@ -164,12 +164,12 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (* if user != nil && len(user.Email) > 0 { limit, err = limiter.GetLimiter(sessionInbound.Tag) if err != nil { - newError("Get limit info error: ", err).AtError().WriteToLog() + newError("get limiter ", sessionInbound.Tag, " error: ", err).AtError().WriteToLog() common.Close(outboundLink.Writer) common.Close(inboundLink.Writer) common.Interrupt(outboundLink.Reader) common.Interrupt(inboundLink.Reader) - return nil, nil, nil, newError("Get limit info error: ", err) + return nil, nil, nil, newError("get limiter ", sessionInbound.Tag, " error: ", err) } // Speed Limit and Device Limit w, reject := limit.CheckLimit(user.Email, @@ -427,10 +427,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. var err error l, err = limiter.GetLimiter(sessionInbound.Tag) if err != nil { - newError("get limiter error: ", err).AtError().WriteToLog(session.ExportIDToError(ctx)) - common.Close(link.Writer) - common.Interrupt(link.Reader) - return + newError("get limiter ", sessionInbound.Tag, " error: ", err).AtWarning().WriteToLog(session.ExportIDToError(ctx)) } } var destStr string @@ -439,25 +436,27 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. } else { destStr = destination.Address.IP().String() } - if l.CheckDomainRule(destStr) { - newError(fmt.Sprintf( - "User %s access domain %s reject by rule", - sessionInbound.User.Email, - destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) - common.Close(link.Writer) - common.Interrupt(link.Reader) - return - } - if len(protocol) != 0 { - if l.CheckProtocolRule(protocol) { + if l != nil { + if l.CheckDomainRule(destStr) { newError(fmt.Sprintf( - "User %s access protocol %s reject by rule", + "User %s access domain %s reject by rule", sessionInbound.User.Email, - protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) common.Close(link.Writer) common.Interrupt(link.Reader) return } + if len(protocol) != 0 { + if l.CheckProtocolRule(protocol) { + newError(fmt.Sprintf( + "User %s access protocol %s reject by rule", + sessionInbound.User.Email, + protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + common.Close(link.Writer) + common.Interrupt(link.Reader) + return + } + } } var handler outbound.Handler