sorz / moproxy

A transparent TCP to SOCKSv5/HTTP proxy on Linux written in Rust.
MIT License
223 stars 35 forks source link

Support domain name resolution for proxy address from the proxy list. #22

Closed tperale closed 1 year ago

tperale commented 1 year ago

Add support for domain name resolution for proxy addresses passed in the proxy list. In some use-cases you need to pass the proxy as a domain name (for instance proxy.example.com) instead of providing the IP address.

The to_socket_addrs method returns an iterator of Option<SocketAddr> (for domain name pointing to multiple IP address). I just use the first one.

I don't know if there is any reason to not support domain name resolution by default on moproxy.

sorz commented 1 year ago

Thanks for you PR!

I don't know if there is any reason to not support domain name resolution by default on moproxy.

Just because all my upstream proxies are on localhost and I totally forget the domain name thing :)

Since you are bring this up, I think a better implementation may be keeping the domain name on ProxyServer struct, and re-resolve it (probably with cache) every time we connect to it so that it can handle IP address change gracefully.

Anyway, I will accept the PR as it since it works on your use case.