1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-26 01:15:38 +00:00

remove duplicated targeted dispatch

This commit is contained in:
Shelikhoo 2021-06-19 11:27:23 +01:00
parent 44040ca684
commit e38839aaf9
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -208,15 +208,11 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
ctx = session.ContextWithContent(ctx, content)
}
handler := session.HandlerFromContext(ctx)
sniffingRequest := content.SniffingRequest
switch {
case !sniffingRequest.Enabled:
if handler != nil {
go d.targetedDispatch(ctx, outbound, handler.Tag)
} else {
go d.routedDispatch(ctx, outbound, destination)
}
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)
@ -246,11 +242,7 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
destination.Address = net.ParseAddress(domain)
ob.Target = destination
}
if handler != nil {
d.targetedDispatch(ctx, outbound, handler.Tag)
} else {
d.routedDispatch(ctx, outbound, destination)
}
d.routedDispatch(ctx, outbound, destination)
}()
}
return inbound, nil
@ -301,26 +293,6 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool) (Sni
}
return contentResult, contentErr
}
// TODO Pending removal for tagged connection
func (d *DefaultDispatcher) targetedDispatch(ctx context.Context, link *transport.Link, tag string) {
handler := d.ohm.GetHandler(tag)
if handler == nil {
newError("outbound handler [", tag, "] not exist").AtError().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 != "" {
accessMessage.Detour = tag
}
log.Record(accessMessage)
}
handler.Dispatch(ctx, link)
}
func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.Link, destination net.Destination) {
var handler outbound.Handler