@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/xtls/xray-core/common"
1313 "github.com/xtls/xray-core/common/buf"
14+ "github.com/xtls/xray-core/common/errors"
1415 "github.com/xtls/xray-core/common/log"
1516 "github.com/xtls/xray-core/common/net"
1617 "github.com/xtls/xray-core/common/protocol"
@@ -169,7 +170,7 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network, sn
169170 // Speed Limit and Device Limit
170171 bucket , ok , reject := d .Limiter .GetUserBucket (sessionInbound .Tag , user .Email , sessionInbound .Source .Address .IP ().String ())
171172 if reject {
172- newError ( "Devices reach the limit: " , user .Email ). AtWarning (). WriteToLog ( )
173+ errors . LogWarning ( ctx , "Devices reach the limit: " , user .Email )
173174 common .Close (outboundLink .Writer )
174175 common .Close (inboundLink .Writer )
175176 common .Interrupt (outboundLink .Reader )
@@ -217,12 +218,12 @@ func (d *DefaultDispatcher) shouldOverride(ctx context.Context, result SniffResu
217218 protocolString = resComp .ProtocolForDomainResult ()
218219 }
219220 for _ , p := range request .OverrideDestinationForProtocol {
220- if strings .HasPrefix (protocolString , p ) {
221+ if strings .HasPrefix (protocolString , p ) || strings . HasPrefix ( p , protocolString ) {
221222 return true
222223 }
223224 if fkr0 , ok := d .fdns .(dns.FakeDNSEngineRev0 ); ok && protocolString != "bittorrent" && p == "fakedns" &&
224225 destination .Address .Family ().IsIP () && fkr0 .IsIPInIPPool (destination .Address ) {
225- newError ( "Using sniffer " , protocolString , " since the fake DNS missed" ). WriteToLog ( session . ExportIDToError ( ctx ) )
226+ errors . LogInfo ( ctx , "Using sniffer " , protocolString , " since the fake DNS missed" )
226227 return true
227228 }
228229 if resultSubset , ok := result .(SnifferIsProtoSubsetOf ); ok {
@@ -273,7 +274,7 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
273274 }
274275 if err == nil && d .shouldOverride (ctx , result , sniffingRequest , destination ) {
275276 domain := result .Domain ()
276- newError ( "sniffed domain: " , domain ). WriteToLog ( session . ExportIDToError ( ctx ) )
277+ errors . LogInfo ( ctx , "sniffed domain: " , domain )
277278 destination .Address = net .ParseAddress (domain )
278279 if sniffingRequest .RouteOnly && result .Protocol () != "fakedns" {
279280 ob .RouteTarget = destination
@@ -320,7 +321,7 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
320321 }
321322 if err == nil && d .shouldOverride (ctx , result , sniffingRequest , destination ) {
322323 domain := result .Domain ()
323- newError ( "sniffed domain: " , domain ). WriteToLog ( session . ExportIDToError ( ctx ) )
324+ errors . LogInfo ( ctx , "sniffed domain: " , domain )
324325 destination .Address = net .ParseAddress (domain )
325326 if sniffingRequest .RouteOnly && result .Protocol () != "fakedns" {
326327 ob .RouteTarget = destination
@@ -404,7 +405,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
404405 // Whether the inbound connection contains a user
405406 if sessionInbound .User != nil {
406407 if d .RuleManager .Detect (sessionInbound .Tag , destination .String (), sessionInbound .User .Email ) {
407- newError ( fmt .Sprintf ("User %s access %s reject by rule" , sessionInbound .User .Email , destination .String ())). AtError (). WriteToLog ( )
408+ errors . LogError ( ctx , fmt .Sprintf ("User %s access %s reject by rule" , sessionInbound .User .Email , destination .String ()))
408409 newError ("destination is reject by rule" )
409410 common .Close (link .Writer )
410411 common .Interrupt (link .Reader )
@@ -419,10 +420,10 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
419420 ctx = session .SetForcedOutboundTagToContext (ctx , "" )
420421 if h := d .ohm .GetHandler (forcedOutboundTag ); h != nil {
421422 isPickRoute = 1
422- newError ( "taking platform initialized detour [" , forcedOutboundTag , "] for [" , destination , "]" ). WriteToLog ( session . ExportIDToError ( ctx ) )
423+ errors . LogInfo ( ctx , "taking platform initialized detour [" , forcedOutboundTag , "] for [" , destination , "]" )
423424 handler = h
424425 } else {
425- newError ( "non existing tag for platform initialized detour: " , forcedOutboundTag ). AtError (). WriteToLog ( session . ExportIDToError ( ctx ) )
426+ errors . LogError ( ctx , "non existing tag for platform initialized detour: " , forcedOutboundTag )
426427 common .Close (link .Writer )
427428 common .Interrupt (link .Reader )
428429 return
@@ -432,13 +433,13 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
432433 outTag := route .GetOutboundTag ()
433434 if h := d .ohm .GetHandler (outTag ); h != nil {
434435 isPickRoute = 2
435- newError ( "taking detour [" , outTag , "] for [" , destination , "]" ). WriteToLog ( session . ExportIDToError ( ctx ) )
436+ errors . LogInfo ( ctx , "taking detour [" , outTag , "] for [" , destination , "]" )
436437 handler = h
437438 } else {
438- newError ( "non existing outTag: " , outTag ). AtWarning (). WriteToLog ( session . ExportIDToError ( ctx ) )
439+ errors . LogWarning ( ctx , "non existing outTag: " , outTag )
439440 }
440441 } else {
441- newError ( "default route for " , destination ). WriteToLog ( session . ExportIDToError ( ctx ) )
442+ errors . LogInfo ( ctx , "default route for " , destination )
442443 }
443444 }
444445
@@ -452,7 +453,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
452453 }
453454
454455 if handler == nil {
455- newError ( "default outbound handler not exist" ). WriteToLog ( session . ExportIDToError ( ctx ) )
456+ errors . LogInfo ( ctx , "default outbound handler not exist" )
456457 common .Close (link .Writer )
457458 common .Interrupt (link .Reader )
458459 return
0 commit comments