-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat(network): add DNS fallback (truncated) PacketProxy #26
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose a change to lwip2transport.Device
that would make it easier to provide custom handlers. See comments.
This PR introduces a network stack neutral `network.PacketProxy` that can be used to **relay** (e.g. a UDP proxy server) or **process** (e.g. a local DNS server) UDP packets. It is more efficient than the `transport.PacketListener` when you try to implement a local UDP server that can process UDP requests and get the responses without going to the internet (see #26 ).
network/dnstruncate/packet_proxy.go
Outdated
if !h.closed.CompareAndSwap(false, true) { | ||
return network.ErrClosed | ||
} | ||
h.respWriter.Close() // TODO(junyi): potential inf loop (rw.Close -> req.Close -> rw.Close ...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you figure out the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no problem for this (because I've checked closed
), but I will create another one with both the fix and a reproducing test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see the TODO there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a reproducing test in #30 , will fix the potential issue in that pr.
network/dnstruncate/packet_proxy.go
Outdated
if !h.closed.CompareAndSwap(false, true) { | ||
return network.ErrClosed | ||
} | ||
h.respWriter.Close() // TODO(junyi): potential inf loop (rw.Close -> req.Close -> rw.Close ...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see the TODO there
Co-authored-by: Vinicius Fortuna <[email protected]>
Co-authored-by: Vinicius Fortuna <[email protected]>
I added
dnstruncated.NewPacketProxy()
to the SDK. This type can be used when the remote Shadowsocks server doesn't support UDP traffic at all. By using thisPacketProxy
, we will always set theTC
(truncated) bit in the DNS responses for all UDP DNS requests. So a well-implemented DNS client (e.g. the browser, thedig
command) should retry the same DNS request over TCP.Related PR: #24 , #27