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

lib/dialer: Register dialer for socks URL scheme (fixes #4515) #4579

Closed
wants to merge 5 commits into from

Conversation

qepasa
Copy link
Contributor

@qepasa qepasa commented Dec 7, 2017

Purpose

Hello everyone. Just as described in the issue, Syncthing doesn't work with environment variable all_proxy=socks://host:port. This is my attempt at solving this issue.

Testing

I'm not sure if it's proper test for this case but I did set up proxy using ssh:
ssh -D 9898 -f -C -q -N user@my_university -p 22
export ALL_PROXY_NO_FALLBACK=1
export all_proxy=socks://127.0.0.1:9898
STTRACE=dialer bin/syncthing

building current origin/master code I got:
[monitor] 2017/12/07 21:16:27.308095 internal.go:51: DEBUG: Dialer logging disabled, as no proxy was detected
[CQLK3] 2017/12/07 21:16:27.311707 internal.go:51: DEBUG: Dialer logging disabled, as no proxy was detected

after fix:
[CQLK3] 2017/12/07 21:17:15.006258 internal.go:43: INFO: Proxy settings detected
[CQLK3] 2017/12/07 21:17:15.006282 internal.go:45: INFO: Proxy fallback disabled
...
[CQLK3] 2017/12/07 21:17:17.020198 internal.go:59: DEBUG: Dialing tcp address 186.195.228.140:22067 via proxy - success, 127.0.0.1:57400 -> 127.0.0.1:9898
[CQLK3] 2017/12/07 21:17:17.073681 internal.go:59: DEBUG: Dialing tcp address 109.230.199.119:22067 via proxy - success, 127.0.0.1:57402 -> 127.0.0.1:9898

With socks5://127.0.0.1:9898 it works, as expected, in both cases.

Documentation

I think docs should mention that "socks" scheme for all_proxy env variable works the same as socks5 in Using Proxies chapter.

@calmh
Copy link
Member

calmh commented Dec 7, 2017

Hi! You seem to have included a bunch of old commits in this PR, probably by reusing and old branch. Can you take the new commit and put that on a new branch based on current master, and push that? There's various rebase magic I could suggest, but I suspect there are better guides out there for figuring it out. Worst case you can just start a new branch from master (after pulling) and cherry-pick a9f76f3.

// This is a rip off of proxy.FromEnvironment with a custom forward dialer
func getDialer(forward proxy.Dialer) proxy.Dialer {
proxy.RegisterDialerType("socks", socksDialerFunction)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this could/should be called from an init() or similar, not every time we need a new dialer?

@qepasa
Copy link
Contributor Author

qepasa commented Dec 7, 2017

@calmh I'm sorry for inconvenience with those unnecessary commits, it's fixed now.

func getDialer(forward proxy.Dialer) proxy.Dialer {
func getDialer(forward proxy.Dialer, initCall bool) proxy.Dialer {
if initCall {
proxy.RegisterDialerType("socks", socksDialerFunction)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this to an init func

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but doesn't functions used in variable initialization get called before init()? As we get usingProxy variable by calling getDialer in variable initialization, I'd have to essentially copy that code into init() after calling RegisterDialerType. Something like that? https://pastebin.com/39qWkWuL
I may be wrong of course, I'm not a golang expert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I guess I could just move the proxyDialer and usingProxy initialization from var ( ) block to init()

@AudriusButkevicius
Copy link
Member

Apart from the triple slash in the comment, looks good to me.

@AudriusButkevicius
Copy link
Member

@st-review merge

@st-review
Copy link

👌 Merged as ece1def. Thanks, @qepasa!

@st-review st-review closed this Dec 8, 2017
st-review pushed a commit that referenced this pull request Dec 8, 2017
@st-review st-review added the pr-merged Legacy label used in the past for pull requests merged to the main tree label Jan 15, 2018
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Dec 9, 2018
@syncthing syncthing locked and limited conversation to collaborators Dec 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion pr-merged Legacy label used in the past for pull requests merged to the main tree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants