2020-11-25 14:01:53 +03:00
|
|
|
package dispatcher
|
|
|
|
|
2020-12-04 04:36:16 +03:00
|
|
|
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
2020-11-25 14:01:53 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/common"
|
|
|
|
"github.com/xtls/xray-core/common/buf"
|
|
|
|
"github.com/xtls/xray-core/common/log"
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/common/protocol"
|
|
|
|
"github.com/xtls/xray-core/common/session"
|
|
|
|
"github.com/xtls/xray-core/core"
|
2021-12-15 03:28:47 +03:00
|
|
|
"github.com/xtls/xray-core/features/dns"
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/features/outbound"
|
|
|
|
"github.com/xtls/xray-core/features/policy"
|
|
|
|
"github.com/xtls/xray-core/features/routing"
|
|
|
|
routing_session "github.com/xtls/xray-core/features/routing/session"
|
|
|
|
"github.com/xtls/xray-core/features/stats"
|
|
|
|
"github.com/xtls/xray-core/transport"
|
|
|
|
"github.com/xtls/xray-core/transport/pipe"
|
2020-11-25 14:01:53 +03:00
|
|
|
)
|
|
|
|
|
2021-10-19 19:57:14 +03:00
|
|
|
var errSniffingTimeout = newError("timeout on sniffing")
|
2020-11-25 14:01:53 +03:00
|
|
|
|
|
|
|
type cachedReader struct {
|
|
|
|
sync.Mutex
|
|
|
|
reader *pipe.Reader
|
|
|
|
cache buf.MultiBuffer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *cachedReader) Cache(b *buf.Buffer) {
|
|
|
|
mb, _ := r.reader.ReadMultiBufferTimeout(time.Millisecond * 100)
|
|
|
|
r.Lock()
|
|
|
|
if !mb.IsEmpty() {
|
|
|
|
r.cache, _ = buf.MergeMulti(r.cache, mb)
|
|
|
|
}
|
|
|
|
b.Clear()
|
|
|
|
rawBytes := b.Extend(buf.Size)
|
|
|
|
n := r.cache.Copy(rawBytes)
|
|
|
|
b.Resize(0, int32(n))
|
|
|
|
r.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *cachedReader) readInternal() buf.MultiBuffer {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
if r.cache != nil && !r.cache.IsEmpty() {
|
|
|
|
mb := r.cache
|
|
|
|
r.cache = nil
|
|
|
|
return mb
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *cachedReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|
|
|
mb := r.readInternal()
|
|
|
|
if mb != nil {
|
|
|
|
return mb, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.reader.ReadMultiBuffer()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *cachedReader) ReadMultiBufferTimeout(timeout time.Duration) (buf.MultiBuffer, error) {
|
|
|
|
mb := r.readInternal()
|
|
|
|
if mb != nil {
|
|
|
|
return mb, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.reader.ReadMultiBufferTimeout(timeout)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *cachedReader) Interrupt() {
|
|
|
|
r.Lock()
|
|
|
|
if r.cache != nil {
|
|
|
|
r.cache = buf.ReleaseMulti(r.cache)
|
|
|
|
}
|
|
|
|
r.Unlock()
|
|
|
|
r.reader.Interrupt()
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultDispatcher is a default implementation of Dispatcher.
|
|
|
|
type DefaultDispatcher struct {
|
|
|
|
ohm outbound.Manager
|
|
|
|
router routing.Router
|
|
|
|
policy policy.Manager
|
|
|
|
stats stats.Manager
|
2021-09-28 09:41:31 +03:00
|
|
|
hosts dns.HostsLookup
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
|
|
|
d := new(DefaultDispatcher)
|
2021-09-28 09:41:31 +03:00
|
|
|
if err := core.RequireFeatures(ctx, func(om outbound.Manager, router routing.Router, pm policy.Manager, sm stats.Manager, dc dns.Client) error {
|
|
|
|
return d.Init(config.(*Config), om, router, pm, sm, dc)
|
2020-11-25 14:01:53 +03:00
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return d, nil
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes DefaultDispatcher.
|
2021-09-28 09:41:31 +03:00
|
|
|
func (d *DefaultDispatcher) Init(config *Config, om outbound.Manager, router routing.Router, pm policy.Manager, sm stats.Manager, dc dns.Client) error {
|
2020-11-25 14:01:53 +03:00
|
|
|
d.ohm = om
|
|
|
|
d.router = router
|
|
|
|
d.policy = pm
|
|
|
|
d.stats = sm
|
2021-09-28 09:41:31 +03:00
|
|
|
if hosts, ok := dc.(dns.HostsLookup); ok {
|
|
|
|
d.hosts = hosts
|
|
|
|
}
|
2020-11-25 14:01:53 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type implements common.HasType.
|
|
|
|
func (*DefaultDispatcher) Type() interface{} {
|
|
|
|
return routing.DispatcherType()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start implements common.Runnable.
|
|
|
|
func (*DefaultDispatcher) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close implements common.Closable.
|
|
|
|
func (*DefaultDispatcher) Close() error { return nil }
|
|
|
|
|
|
|
|
func (d *DefaultDispatcher) getLink(ctx context.Context) (*transport.Link, *transport.Link) {
|
|
|
|
opt := pipe.OptionsFromContext(ctx)
|
|
|
|
uplinkReader, uplinkWriter := pipe.New(opt...)
|
|
|
|
downlinkReader, downlinkWriter := pipe.New(opt...)
|
|
|
|
|
|
|
|
inboundLink := &transport.Link{
|
|
|
|
Reader: downlinkReader,
|
|
|
|
Writer: uplinkWriter,
|
|
|
|
}
|
|
|
|
|
|
|
|
outboundLink := &transport.Link{
|
|
|
|
Reader: uplinkReader,
|
|
|
|
Writer: downlinkWriter,
|
|
|
|
}
|
|
|
|
|
|
|
|
sessionInbound := session.InboundFromContext(ctx)
|
|
|
|
var user *protocol.MemoryUser
|
|
|
|
if sessionInbound != nil {
|
|
|
|
user = sessionInbound.User
|
|
|
|
}
|
|
|
|
|
|
|
|
if user != nil && len(user.Email) > 0 {
|
|
|
|
p := d.policy.ForLevel(user.Level)
|
|
|
|
if p.Stats.UserUplink {
|
|
|
|
name := "user>>>" + user.Email + ">>>traffic>>>uplink"
|
|
|
|
if c, _ := stats.GetOrRegisterCounter(d.stats, name); c != nil {
|
|
|
|
inboundLink.Writer = &SizeStatWriter{
|
|
|
|
Counter: c,
|
|
|
|
Writer: inboundLink.Writer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if p.Stats.UserDownlink {
|
|
|
|
name := "user>>>" + user.Email + ">>>traffic>>>downlink"
|
|
|
|
if c, _ := stats.GetOrRegisterCounter(d.stats, name); c != nil {
|
|
|
|
outboundLink.Writer = &SizeStatWriter{
|
|
|
|
Counter: c,
|
|
|
|
Writer: outboundLink.Writer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return inboundLink, outboundLink
|
|
|
|
}
|
|
|
|
|
2021-03-07 07:39:50 +03:00
|
|
|
func shouldOverride(ctx context.Context, result SniffResult, request session.SniffingRequest, destination net.Destination) bool {
|
2021-01-21 23:50:09 +03:00
|
|
|
domain := result.Domain()
|
|
|
|
for _, d := range request.ExcludeForDomain {
|
2021-04-18 08:21:17 +03:00
|
|
|
if strings.ToLower(domain) == d {
|
2021-01-21 23:50:09 +03:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2021-03-07 07:39:50 +03:00
|
|
|
var fakeDNSEngine dns.FakeDNSEngine
|
|
|
|
core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
|
|
|
|
fakeDNSEngine = fdns
|
|
|
|
})
|
|
|
|
protocolString := result.Protocol()
|
|
|
|
if resComp, ok := result.(SnifferResultComposite); ok {
|
|
|
|
protocolString = resComp.ProtocolForDomainResult()
|
|
|
|
}
|
2021-01-21 23:50:09 +03:00
|
|
|
for _, p := range request.OverrideDestinationForProtocol {
|
2021-03-07 07:39:50 +03:00
|
|
|
if strings.HasPrefix(protocolString, p) {
|
|
|
|
return true
|
|
|
|
}
|
2021-10-20 08:15:49 +03:00
|
|
|
if fkr0, ok := fakeDNSEngine.(dns.FakeDNSEngineRev0); ok && protocolString != "bittorrent" && p == "fakedns" &&
|
|
|
|
destination.Address.Family().IsIP() && fkr0.IsIPInIPPool(destination.Address) {
|
2021-04-09 00:20:30 +03:00
|
|
|
newError("Using sniffer ", protocolString, " since the fake DNS missed").WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
return true
|
2021-10-20 08:15:49 +03:00
|
|
|
}
|
|
|
|
if resultSubset, ok := result.(SnifferIsProtoSubsetOf); ok {
|
|
|
|
if resultSubset.IsProtoSubsetOf(p) {
|
|
|
|
return true
|
|
|
|
}
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
}
|
2021-01-21 23:50:09 +03:00
|
|
|
|
2020-11-25 14:01:53 +03:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch implements routing.Dispatcher.
|
|
|
|
func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destination) (*transport.Link, error) {
|
|
|
|
if !destination.IsValid() {
|
|
|
|
panic("Dispatcher: Invalid destination.")
|
|
|
|
}
|
|
|
|
ob := &session.Outbound{
|
|
|
|
Target: destination,
|
|
|
|
}
|
|
|
|
ctx = session.ContextWithOutbound(ctx, ob)
|
|
|
|
|
|
|
|
inbound, outbound := d.getLink(ctx)
|
|
|
|
content := session.ContentFromContext(ctx)
|
|
|
|
if content == nil {
|
|
|
|
content = new(session.Content)
|
|
|
|
ctx = session.ContextWithContent(ctx, content)
|
|
|
|
}
|
|
|
|
sniffingRequest := content.SniffingRequest
|
2021-03-07 07:39:50 +03:00
|
|
|
switch {
|
|
|
|
case !sniffingRequest.Enabled:
|
|
|
|
go d.routedDispatch(ctx, outbound, destination)
|
|
|
|
case destination.Network != net.Network_TCP:
|
|
|
|
// Only metadata sniff will be used for non tcp connection
|
|
|
|
result, err := sniffer(ctx, nil, true)
|
|
|
|
if err == nil {
|
|
|
|
content.Protocol = result.Protocol()
|
|
|
|
if shouldOverride(ctx, result, sniffingRequest, destination) {
|
|
|
|
domain := result.Domain()
|
|
|
|
newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
destination.Address = net.ParseAddress(domain)
|
2021-09-16 10:05:48 +03:00
|
|
|
if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" {
|
|
|
|
ob.RouteTarget = destination
|
|
|
|
} else {
|
|
|
|
ob.Target = destination
|
|
|
|
}
|
2021-03-07 07:39:50 +03:00
|
|
|
}
|
|
|
|
}
|
2020-11-25 14:01:53 +03:00
|
|
|
go d.routedDispatch(ctx, outbound, destination)
|
2021-03-07 07:39:50 +03:00
|
|
|
default:
|
2020-11-25 14:01:53 +03:00
|
|
|
go func() {
|
|
|
|
cReader := &cachedReader{
|
|
|
|
reader: outbound.Reader.(*pipe.Reader),
|
|
|
|
}
|
|
|
|
outbound.Reader = cReader
|
2021-03-07 07:39:50 +03:00
|
|
|
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly)
|
2020-11-25 14:01:53 +03:00
|
|
|
if err == nil {
|
|
|
|
content.Protocol = result.Protocol()
|
|
|
|
}
|
2021-03-07 07:39:50 +03:00
|
|
|
if err == nil && shouldOverride(ctx, result, sniffingRequest, destination) {
|
2020-11-25 14:01:53 +03:00
|
|
|
domain := result.Domain()
|
|
|
|
newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
destination.Address = net.ParseAddress(domain)
|
2021-09-16 10:05:48 +03:00
|
|
|
if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" {
|
|
|
|
ob.RouteTarget = destination
|
|
|
|
} else {
|
|
|
|
ob.Target = destination
|
|
|
|
}
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
d.routedDispatch(ctx, outbound, destination)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
return inbound, nil
|
|
|
|
}
|
|
|
|
|
2021-09-28 04:42:57 +03:00
|
|
|
// DispatchLink implements routing.Dispatcher.
|
|
|
|
func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.Destination, outbound *transport.Link) error {
|
|
|
|
if !destination.IsValid() {
|
|
|
|
return newError("Dispatcher: Invalid destination.")
|
|
|
|
}
|
|
|
|
ob := &session.Outbound{
|
|
|
|
Target: destination,
|
|
|
|
}
|
|
|
|
ctx = session.ContextWithOutbound(ctx, ob)
|
|
|
|
content := session.ContentFromContext(ctx)
|
|
|
|
if content == nil {
|
|
|
|
content = new(session.Content)
|
|
|
|
ctx = session.ContextWithContent(ctx, content)
|
|
|
|
}
|
|
|
|
sniffingRequest := content.SniffingRequest
|
|
|
|
switch {
|
|
|
|
case !sniffingRequest.Enabled:
|
|
|
|
go d.routedDispatch(ctx, outbound, destination)
|
|
|
|
case destination.Network != net.Network_TCP:
|
|
|
|
// Only metadata sniff will be used for non tcp connection
|
|
|
|
result, err := sniffer(ctx, nil, true)
|
|
|
|
if err == nil {
|
|
|
|
content.Protocol = result.Protocol()
|
2021-09-28 09:41:31 +03:00
|
|
|
if shouldOverride(ctx, result, sniffingRequest, destination) {
|
2021-09-28 04:42:57 +03:00
|
|
|
domain := result.Domain()
|
|
|
|
newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
destination.Address = net.ParseAddress(domain)
|
|
|
|
if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" {
|
|
|
|
ob.RouteTarget = destination
|
|
|
|
} else {
|
|
|
|
ob.Target = destination
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go d.routedDispatch(ctx, outbound, destination)
|
|
|
|
default:
|
|
|
|
go func() {
|
|
|
|
cReader := &cachedReader{
|
|
|
|
reader: outbound.Reader.(*pipe.Reader),
|
|
|
|
}
|
|
|
|
outbound.Reader = cReader
|
|
|
|
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly)
|
|
|
|
if err == nil {
|
|
|
|
content.Protocol = result.Protocol()
|
|
|
|
}
|
2021-09-28 09:41:31 +03:00
|
|
|
if err == nil && shouldOverride(ctx, result, sniffingRequest, destination) {
|
2021-09-28 04:42:57 +03:00
|
|
|
domain := result.Domain()
|
|
|
|
newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
destination.Address = net.ParseAddress(domain)
|
|
|
|
if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" {
|
|
|
|
ob.RouteTarget = destination
|
|
|
|
} else {
|
|
|
|
ob.Target = destination
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d.routedDispatch(ctx, outbound, destination)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-07 07:39:50 +03:00
|
|
|
func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool) (SniffResult, error) {
|
2020-11-25 14:01:53 +03:00
|
|
|
payload := buf.New()
|
|
|
|
defer payload.Release()
|
|
|
|
|
2021-03-07 07:39:50 +03:00
|
|
|
sniffer := NewSniffer(ctx)
|
|
|
|
|
|
|
|
metaresult, metadataErr := sniffer.SniffMetadata(ctx)
|
|
|
|
|
|
|
|
if metadataOnly {
|
|
|
|
return metaresult, metadataErr
|
|
|
|
}
|
2020-11-25 14:01:53 +03:00
|
|
|
|
2021-03-07 07:39:50 +03:00
|
|
|
contentResult, contentErr := func() (SniffResult, error) {
|
|
|
|
totalAttempt := 0
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil, ctx.Err()
|
|
|
|
default:
|
|
|
|
totalAttempt++
|
|
|
|
if totalAttempt > 2 {
|
|
|
|
return nil, errSniffingTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
cReader.Cache(payload)
|
|
|
|
if !payload.IsEmpty() {
|
|
|
|
result, err := sniffer.Sniff(ctx, payload.Bytes())
|
|
|
|
if err != common.ErrNoClue {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if payload.IsFull() {
|
|
|
|
return nil, errUnknownContent
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-07 07:39:50 +03:00
|
|
|
}()
|
|
|
|
if contentErr != nil && metadataErr == nil {
|
|
|
|
return metaresult, nil
|
|
|
|
}
|
|
|
|
if contentErr == nil && metadataErr == nil {
|
|
|
|
return CompositeResult(metaresult, contentResult), nil
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
2021-03-07 07:39:50 +03:00
|
|
|
return contentResult, contentErr
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.Link, destination net.Destination) {
|
2021-09-28 09:41:31 +03:00
|
|
|
ob := session.OutboundFromContext(ctx)
|
|
|
|
if d.hosts != nil && destination.Address.Family().IsDomain() {
|
|
|
|
proxied := d.hosts.LookupHosts(ob.Target.String())
|
|
|
|
if proxied != nil {
|
|
|
|
ro := ob.RouteTarget == destination
|
|
|
|
destination.Address = *proxied
|
|
|
|
if ro {
|
|
|
|
ob.RouteTarget = destination
|
|
|
|
} else {
|
|
|
|
ob.Target = destination
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:01:53 +03:00
|
|
|
var handler outbound.Handler
|
|
|
|
|
2022-04-16 01:23:49 +03:00
|
|
|
routingLink := routing_session.AsRoutingContext(ctx)
|
|
|
|
inTag := routingLink.GetInboundTag()
|
|
|
|
isPickRoute := 0
|
2021-04-09 00:20:30 +03:00
|
|
|
if forcedOutboundTag := session.GetForcedOutboundTagFromContext(ctx); forcedOutboundTag != "" {
|
|
|
|
ctx = session.SetForcedOutboundTagToContext(ctx, "")
|
|
|
|
if h := d.ohm.GetHandler(forcedOutboundTag); h != nil {
|
2022-04-16 01:23:49 +03:00
|
|
|
isPickRoute = 1
|
2021-04-09 00:20:30 +03:00
|
|
|
newError("taking platform initialized detour [", forcedOutboundTag, "] for [", destination, "]").WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
handler = h
|
|
|
|
} else {
|
|
|
|
newError("non existing tag for platform initialized detour: ", forcedOutboundTag).AtError().WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
common.Close(link.Writer)
|
|
|
|
common.Interrupt(link.Reader)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else if d.router != nil {
|
2022-04-16 01:23:49 +03:00
|
|
|
if route, err := d.router.PickRoute(routingLink); err == nil {
|
|
|
|
outTag := route.GetOutboundTag()
|
|
|
|
if h := d.ohm.GetHandler(outTag); h != nil {
|
|
|
|
isPickRoute = 2
|
|
|
|
newError("taking detour [", outTag, "] for [", destination, "]").WriteToLog(session.ExportIDToError(ctx))
|
2020-11-25 14:01:53 +03:00
|
|
|
handler = h
|
|
|
|
} else {
|
2022-04-16 01:23:49 +03:00
|
|
|
newError("non existing outTag: ", outTag).AtWarning().WriteToLog(session.ExportIDToError(ctx))
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newError("default route for ", destination).WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if handler == nil {
|
|
|
|
handler = d.ohm.GetDefaultHandler()
|
|
|
|
}
|
|
|
|
|
|
|
|
if handler == nil {
|
|
|
|
newError("default outbound handler not exist").WriteToLog(session.ExportIDToError(ctx))
|
|
|
|
common.Close(link.Writer)
|
|
|
|
common.Interrupt(link.Reader)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if accessMessage := log.AccessMessageFromContext(ctx); accessMessage != nil {
|
|
|
|
if tag := handler.Tag(); tag != "" {
|
2022-04-16 01:23:49 +03:00
|
|
|
if inTag == "" {
|
|
|
|
accessMessage.Detour = tag
|
|
|
|
} else if isPickRoute == 1 {
|
|
|
|
accessMessage.Detour = inTag + " ==> " + tag
|
|
|
|
} else if isPickRoute == 2 {
|
|
|
|
accessMessage.Detour = inTag + " -> " + tag
|
|
|
|
} else {
|
|
|
|
accessMessage.Detour = inTag + " >> " + tag
|
|
|
|
}
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
log.Record(accessMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.Dispatch(ctx, link)
|
|
|
|
}
|