Skip to content

Removing code that was not being executed and should not be executed. #4721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025

Conversation

patterniha
Copy link
Contributor

@patterniha patterniha commented May 12, 2025

during reading dispatcher codes, I encountered a strange code:

if hosts, ok := d.dns.(dns.HostsLookup); ok && destination.Address.Family().IsDomain() {
proxied := hosts.LookupHosts(ob.Target.String())
if proxied != nil {
ro := ob.RouteTarget == destination
destination.Address = *proxied
if ro {
ob.RouteTarget = destination
} else {
ob.Target = destination
}
}
}

First, fortunately this code was not executed at all, because ob.Target.String() has prefix("tcp:"/"udp:") and hosts.LookupHosts(ob.Target.String()) always returned nil and as a result proxied was always nil and the code was not executed at all !!!

Second, this code should not be executed at all, because the logic of this code is completely wrong, and we should not use built-in-dns-hosts to replace the ob.Target and change the destination, because suppose we are in client-side and we want to use built-in-dns‍ only in client-side, and destination is used in server-side, so we should not change the destination and ob.Target by using built-in-dns-hosts, also if we have multiple-ip for a domain this code only replaces one IP.

///

fortunately, this code was not executed at all, and removing it is just to clean up the code.

@Fangliding
Copy link
Member

Fangliding commented May 12, 2025

2722486#diff-c3820ebfbe4f1eb7e9d13008e995e0fa8912cad9f058c9f7767aed1df10533d8

tcp:/udp: 前缀似乎确实是没有意料到

ro的判断有点奇怪 去掉的话似乎可以成为一种在客户端强制将域名解析成IP发送的方法?("tcp:ip.sb:80": "127.0.0.1" 这样的写法其实是可以被正常识别的 而且写成域名会被后续的dns解析器继续解析成IP)

@yuhan6665
Copy link
Member

I'm for removing deadcode.. It seems we can remove d.dns as well

@patterniha
Copy link
Contributor Author

patterniha commented May 12, 2025

@Fangliding

first, this code can only use hosts to replace the domain to IP, and does not use dns-servers, So it's not very practical.

second, if we want to replace the domain with IP, we can use dialerProxy.

third, you didn't mention "tcp:example.com:80": "127.0.0.1" for hosts in documentation.

anyway, even adding "tcp:example.com:80": "127.0.0.1" to documentation doesn't help much because we still can't use dns-servers, so it is better to use dialerProxy instead.

@Fangliding
Copy link
Member

just mention

@Fangliding
Copy link
Member

I'm for removing deadcode.. It seems we can remove d.dns as well

这个DNS client可能会被用于(吵了不知道多少遍的)域名解析为IP发送

或者我们可能可以提供一个 net.LookXrayDNS() 之类的函数供其他部分使用(eg: freedom) 虽然这会打破原本的 core features 封装(不过大概本来就已经乱成一团糟了)

@yuhan6665
Copy link
Member

等真的需要再加回来。。如果都同意这段代码没用那就先删了 删了总归是减小复杂度

@Fangliding
Copy link
Member

行 那我删了

@yuhan6665
Copy link
Member

Thanks both!

@yuhan6665 yuhan6665 merged commit 882975c into XTLS:main May 15, 2025
39 checks passed
@patterniha patterniha deleted the fix-bug5 branch May 17, 2025 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants