mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-16 14:59:56 +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) {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
content := session.ContentFromContext(ctx)
|
||||
if h.senderSettings != nil && h.senderSettings.TargetStrategy.HasStrategy() && ob.Target.Address.Family().IsDomain() && (content == nil || !content.SkipDNSResolve) {
|
||||
if h.senderSettings != nil && h.senderSettings.TargetStrategy.HasStrategy() && ob.Target.Address.Family().IsDomain() && !session.SkipDNSResolveFromContext(ctx) {
|
||||
strategy := h.senderSettings.TargetStrategy
|
||||
if ob.Target.Network == net.Network_UDP && ob.OriginalTarget.Address != nil {
|
||||
strategy = strategy.GetDynamicStrategy(ob.OriginalTarget.Address.Family())
|
||||
|
||||
@@ -44,9 +44,8 @@ func (c routingContext) GetRuleTag() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetSkipDNSResolve is a mock implementation here to match the interface,
|
||||
// SkipDNSResolve is set from dns module, no use if coming from a protobuf object?
|
||||
// TODO: please confirm @Vigilans
|
||||
// GetSkipDNSResolve implements routing.Context.
|
||||
// The protobuf RoutingContext has no skip flag, so API contexts use false.
|
||||
func (c routingContext) GetSkipDNSResolve() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -77,6 +77,11 @@ func ContentFromContext(ctx context.Context) *Content {
|
||||
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 {
|
||||
return context.WithValue(ctx, isReverseMuxKey, isReverseMux)
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@ type Context interface {
|
||||
// GetAttributes returns extra attributes from the conneciont content.
|
||||
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
|
||||
}
|
||||
|
||||
@@ -278,12 +278,6 @@ func isValidAddress(addr *net.IPOrDomain) bool {
|
||||
|
||||
// Process implements proxy.Outbound.
|
||||
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)
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
@@ -291,6 +285,13 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
}
|
||||
ob.Name = "freedom"
|
||||
ob.CanSpliceCopy = 1
|
||||
|
||||
if session.SkipDNSResolveFromContext(ctx) {
|
||||
handler := *h
|
||||
handler.resolveStrategy = internet.DomainStrategy_AS_IS
|
||||
h = &handler
|
||||
}
|
||||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
var defaultRule *FinalRule
|
||||
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
|
||||
}
|
||||
|
||||
content := session.ContentFromContext(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 {
|
||||
if sockopt.DomainStrategy.HasStrategy() && dest.Address.Family().IsDomain() && !(outboundName == "freedom" && session.SkipDNSResolveFromContext(ctx)) {
|
||||
finalStrategy := sockopt.DomainStrategy
|
||||
if outboundName == "freedom" && dest.Network == net.Network_UDP && origTargetAddr != nil && src == nil {
|
||||
finalStrategy = finalStrategy.GetDynamicStrategy(origTargetAddr.Family())
|
||||
|
||||
Reference in New Issue
Block a user