mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-29 21:10:11 +00:00
refactor
This commit is contained in:
@@ -181,8 +181,7 @@ func (h *Handler) Tag() string {
|
|||||||
func (h *Handler) Dispatch(ctx context.Context, link *transport.Link) {
|
func (h *Handler) Dispatch(ctx context.Context, link *transport.Link) {
|
||||||
outbounds := session.OutboundsFromContext(ctx)
|
outbounds := session.OutboundsFromContext(ctx)
|
||||||
ob := outbounds[len(outbounds)-1]
|
ob := outbounds[len(outbounds)-1]
|
||||||
content := session.ContentFromContext(ctx)
|
if h.senderSettings != nil && h.senderSettings.TargetStrategy.HasStrategy() && ob.Target.Address.Family().IsDomain() && !session.SkipDNSResolveFromContext(ctx) {
|
||||||
if h.senderSettings != nil && h.senderSettings.TargetStrategy.HasStrategy() && ob.Target.Address.Family().IsDomain() && (content == nil || !content.SkipDNSResolve) {
|
|
||||||
strategy := h.senderSettings.TargetStrategy
|
strategy := h.senderSettings.TargetStrategy
|
||||||
if ob.Target.Network == net.Network_UDP && ob.OriginalTarget.Address != nil {
|
if ob.Target.Network == net.Network_UDP && ob.OriginalTarget.Address != nil {
|
||||||
strategy = strategy.GetDynamicStrategy(ob.OriginalTarget.Address.Family())
|
strategy = strategy.GetDynamicStrategy(ob.OriginalTarget.Address.Family())
|
||||||
|
|||||||
@@ -44,9 +44,8 @@ func (c routingContext) GetRuleTag() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSkipDNSResolve is a mock implementation here to match the interface,
|
// GetSkipDNSResolve implements routing.Context.
|
||||||
// SkipDNSResolve is set from dns module, no use if coming from a protobuf object?
|
// The protobuf RoutingContext has no skip flag, so API contexts use false.
|
||||||
// TODO: please confirm @Vigilans
|
|
||||||
func (c routingContext) GetSkipDNSResolve() bool {
|
func (c routingContext) GetSkipDNSResolve() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ func ContentFromContext(ctx context.Context) *Content {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SkipDNSResolveFromContext(ctx context.Context) bool {
|
||||||
|
content := ContentFromContext(ctx)
|
||||||
|
return content != nil && content.SkipDNSResolve
|
||||||
|
}
|
||||||
|
|
||||||
func ContextWithIsReverseMux(ctx context.Context, isReverseMux bool) context.Context {
|
func ContextWithIsReverseMux(ctx context.Context, isReverseMux bool) context.Context {
|
||||||
return context.WithValue(ctx, isReverseMuxKey, isReverseMux)
|
return context.WithValue(ctx, isReverseMuxKey, isReverseMux)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,6 @@ type Context interface {
|
|||||||
// GetAttributes returns extra attributes from the conneciont content.
|
// GetAttributes returns extra attributes from the conneciont content.
|
||||||
GetAttributes() map[string]string
|
GetAttributes() map[string]string
|
||||||
|
|
||||||
// GetSkipDNSResolve returns a flag switch for weather skip dns resolve during route pick.
|
// GetSkipDNSResolve reports whether built-in DNS resolution should be skipped during routing.
|
||||||
GetSkipDNSResolve() bool
|
GetSkipDNSResolve() bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -278,12 +278,6 @@ func isValidAddress(addr *net.IPOrDomain) bool {
|
|||||||
|
|
||||||
// Process implements proxy.Outbound.
|
// Process implements proxy.Outbound.
|
||||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||||
if content := session.ContentFromContext(ctx); content != nil && content.SkipDNSResolve {
|
|
||||||
// Keep DNS connections from resolving their server through the built-in DNS.
|
|
||||||
handler := *h
|
|
||||||
handler.resolveStrategy = internet.DomainStrategy_AS_IS
|
|
||||||
h = &handler
|
|
||||||
}
|
|
||||||
outbounds := session.OutboundsFromContext(ctx)
|
outbounds := session.OutboundsFromContext(ctx)
|
||||||
ob := outbounds[len(outbounds)-1]
|
ob := outbounds[len(outbounds)-1]
|
||||||
if !ob.Target.IsValid() {
|
if !ob.Target.IsValid() {
|
||||||
@@ -291,6 +285,13 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
}
|
}
|
||||||
ob.Name = "freedom"
|
ob.Name = "freedom"
|
||||||
ob.CanSpliceCopy = 1
|
ob.CanSpliceCopy = 1
|
||||||
|
|
||||||
|
if session.SkipDNSResolveFromContext(ctx) {
|
||||||
|
handler := *h
|
||||||
|
handler.resolveStrategy = internet.DomainStrategy_AS_IS
|
||||||
|
h = &handler
|
||||||
|
}
|
||||||
|
|
||||||
inbound := session.InboundFromContext(ctx)
|
inbound := session.InboundFromContext(ctx)
|
||||||
var defaultRule *FinalRule
|
var defaultRule *FinalRule
|
||||||
if !h.usesDialerProxy { // freedom is not the final outbound, final rules do not apply (and the domain is not resolved)
|
if !h.usesDialerProxy { // freedom is not the final outbound, final rules do not apply (and the domain is not resolved)
|
||||||
|
|||||||
@@ -248,10 +248,7 @@ func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig
|
|||||||
dest = *newDest
|
dest = *newDest
|
||||||
}
|
}
|
||||||
|
|
||||||
content := session.ContentFromContext(ctx)
|
if sockopt.DomainStrategy.HasStrategy() && dest.Address.Family().IsDomain() && !(outboundName == "freedom" && session.SkipDNSResolveFromContext(ctx)) {
|
||||||
// Only Freedom's target resolution is skipped; proxy server resolution still follows sockopt.
|
|
||||||
skipDNSResolve := outboundName == "freedom" && content != nil && content.SkipDNSResolve
|
|
||||||
if sockopt.DomainStrategy.HasStrategy() && dest.Address.Family().IsDomain() && !skipDNSResolve {
|
|
||||||
finalStrategy := sockopt.DomainStrategy
|
finalStrategy := sockopt.DomainStrategy
|
||||||
if outboundName == "freedom" && dest.Network == net.Network_UDP && origTargetAddr != nil && src == nil {
|
if outboundName == "freedom" && dest.Network == net.Network_UDP && origTargetAddr != nil && src == nil {
|
||||||
finalStrategy = finalStrategy.GetDynamicStrategy(origTargetAddr.Family())
|
finalStrategy = finalStrategy.GetDynamicStrategy(origTargetAddr.Family())
|
||||||
|
|||||||
Reference in New Issue
Block a user