Skip to content
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

SOCKS5 support for peer connections #160

Open
gen2brain opened this issue Jun 3, 2017 · 11 comments
Open

SOCKS5 support for peer connections #160

gen2brain opened this issue Jun 3, 2017 · 11 comments

Comments

@gen2brain
Copy link

Hi, I am still browsing through this package, I don't see a way to configure proxy. Can I do something with golang.org/x/net/proxy , I am interested in socks5 proxy.

Thanks

@anacrolix
Copy link
Owner

I don't currently have plans to implement socks support. I'll take any PRs, cheers.

@deranjer
Copy link

deranjer commented Jan 3, 2018

I looked into this a little bit since this is a feature I would like as well, where the code would need to be changed is here in client.go:

func (cl *Client) dialTCP(ctx context.Context, addr string) (c net.Conn, err error) {
	d := net.Dialer{
	// LocalAddr: cl.tcpListener.Addr(),
	}
	c, err = d.DialContext(ctx, "tcp", addr)
	countDialResult(err)
	if err == nil {
		c.(*net.TCPConn).SetLinger(0)
	}
	c = pproffd.WrapNetConn(c)
	return
}

Essentially we would replace the net.dialer with a proxy.dialer and pull the proxy from the config as a URL.

Unfortunately the proxy package does not currently support DialContext, I didn't look around to see if other proxy packages did support it. However, adding Context with proxy support is listed as expected in Go 1.11 in July 2018. Until this it is beyond my ability to investigate.

@anacrolix
Copy link
Owner

Thanks for looking into this. It looks like when this lands it'll be as simple as allowing a custom Dialer to be set for various Dials in the code base. If anyone needs this sooner, please recommend or refer us to an existing proxy implementation (that doesn't suck) that provides DialContext.

@anacrolix
Copy link
Owner

Could we create a Dialer that implicitly performs the DialContext underneath, and use that as the forward argument to golang.org/x/net/proxy.FromURL?

@anacrolix
Copy link
Owner

Here's an example of that kind of thing: https://github.com/anacrolix/missinggo/blob/master/reader_context.go

@anacrolix
Copy link
Owner

Take a look at #256

@anacrolix
Copy link
Owner

Proxy support has been added by @elgatito , see the ProxyURL field in the Config struct.

@anacrolix
Copy link
Owner

@gen2brain or anyone else following this thread: Are there any good socks5 client packages that support SOCKS5, and possibly UDP ASSOCIATE?

@anacrolix anacrolix self-assigned this Sep 1, 2021
@anacrolix
Copy link
Owner

@elgatito I know you don't use this repo actively anymore, but do you know what would be required to support incoming connections over SOCKS? Would that be TCP BIND and UDP ASSOCIATE? The PR that you made allowed outgoing SOCKS connections? Do you know if it worked for UDP? Cheers

@anacrolix anacrolix reopened this Sep 1, 2021
@anacrolix anacrolix changed the title Proxy support Proxy support for peer connections Sep 1, 2021
@anacrolix
Copy link
Owner

I've opened anacrolix/go-libutp#17, as I suspect go-libutp will require some extra configuration to support SOCKS.

@anacrolix
Copy link
Owner

Unfortunately the proxy package does not currently support DialContext, I didn't look around to see if other proxy packages did support it. However, adding Context with proxy support is listed as expected in Go 1.11 in July 2018.

@deranjer https://pkg.go.dev/golang.org/x/net/proxy#ContextDialer now exists. My limited understanding of SOCKS suggestions this is only the outgoing part. We still need special support to receive incoming connections.

@anacrolix anacrolix removed their assignment Sep 20, 2021
@anacrolix anacrolix removed the blocked label Oct 27, 2021
@anacrolix anacrolix changed the title Proxy support for peer connections SOCKS5 support for peer connections Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants