-
Notifications
You must be signed in to change notification settings - Fork 55
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
Adding UDP support to Socks5 dialer #257
Conversation
@fortuna I'd appreciate it if you could review this PR. |
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.
Almost there.
transport/socks5/packet_dialer.go
Outdated
|
||
pkt = pkt[addrLen:] // Skip the address | ||
port := binary.BigEndian.Uint16(pkt[:2]) | ||
fmt.Printf("Received packet from %d:%d\n", addr, port) |
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.
We need to remove all these prints.
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.
@fortuna sure! I removed most of logging prints but will do a clean up at the end.
Co-authored-by: Vinicius Fortuna <[email protected]>
Co-authored-by: Vinicius Fortuna <[email protected]>
Co-authored-by: Vinicius Fortuna <[email protected]>
Co-authored-by: Vinicius Fortuna <[email protected]>
|
||
go func() { | ||
err := proxySrv.Serve(listener) | ||
defer listener.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.
Move this to where the listener is created. Otherwise the server is never shutdown.
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.
This still needs to be moved.
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.
@fortuna There's a small detail here. I can move defer listener.Close()
to right after where we start listening but when the test finishes and listener closes the server goroutine throws a closed connection error. Unfortunately the server does not accept a context parameter to cancel it; Once solution is to consider an exception for server's net.ErrClosed
error and basically ignore it. Not the cleanest approach though. Do you have any thoughts on this?
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
defer listener.Close()
proxyServerAddress := listener.Addr().String()
go func() {
err := proxySrv.Serve(listener)
if !errors.Is(err, net.ErrClosed) && err != nil {
require.NoError(t, err) // Assert no error if it's not the expected close error
}
}()
transport/socks5/socks5.go
Outdated
addrLen := int(addrType[0]) | ||
fqdn := make([]byte, addrLen) |
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.
This is not needed if you keep the type of addrLen as byte.
Why are you converting to int?
Co-authored-by: Vinicius Fortuna <[email protected]>
@fortuna thanks again for the feedback. I applied the latest rounds of comments. |
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.
Looks good. Just one minor thing. Your test is leaking a goroutine
|
||
go func() { | ||
err := proxySrv.Serve(listener) | ||
defer listener.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.
This still needs to be moved.
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.
Thanks for all the changes! This is great work!
@fortuna I resolved the merge conflict in
Not sure what I am doing wrong... |
This PR add packet dialing (UDP) support to Socks5 dialer. The test runs a local UDP echo (ping-pong) server and socks5 server and routes the UDP packet through the local proxy server to the echo server and back. This was tested with several remote servers including soax service.