Merge pull request #19 from InazumaV/dev_new

Dev new
This commit is contained in:
Yuzuki
2023-09-25 16:24:07 +08:00
committed by GitHub

View File

@@ -164,12 +164,12 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (*
if user != nil && len(user.Email) > 0 { if user != nil && len(user.Email) > 0 {
limit, err = limiter.GetLimiter(sessionInbound.Tag) limit, err = limiter.GetLimiter(sessionInbound.Tag)
if err != nil { 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(outboundLink.Writer)
common.Close(inboundLink.Writer) common.Close(inboundLink.Writer)
common.Interrupt(outboundLink.Reader) common.Interrupt(outboundLink.Reader)
common.Interrupt(inboundLink.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 // Speed Limit and Device Limit
w, reject := limit.CheckLimit(user.Email, w, reject := limit.CheckLimit(user.Email,
@@ -414,25 +414,22 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
} }
sessionInbound := session.InboundFromContext(ctx) sessionInbound := session.InboundFromContext(ctx)
if sessionInbound.User != nil {
if l != nil { if l != nil {
// del connect count // del connect count
if sessionInbound.User != nil {
if destination.Network == net.Network_TCP { if destination.Network == net.Network_TCP {
defer func() { defer func() {
l.ConnLimiter.DelConnCount(sessionInbound.User.Email, sessionInbound.Source.Address.IP().String()) l.ConnLimiter.DelConnCount(sessionInbound.User.Email, sessionInbound.Source.Address.IP().String())
}() }()
} }
}
} else { } else {
var err error var err error
l, err = limiter.GetLimiter(sessionInbound.Tag) l, err = limiter.GetLimiter(sessionInbound.Tag)
if err != nil { if err != nil {
newError("get limiter error: ", err).AtError().WriteToLog(session.ExportIDToError(ctx)) newError("get limiter ", sessionInbound.Tag, " error: ", err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
common.Close(link.Writer)
common.Interrupt(link.Reader)
return
} }
} }
if l != nil {
var destStr string var destStr string
if destination.Address.Family().IsDomain() { if destination.Address.Family().IsDomain() {
destStr = destination.Address.Domain() destStr = destination.Address.Domain()
@@ -459,6 +456,8 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
return return
} }
} }
}
}
var handler outbound.Handler var handler outbound.Handler