Skip to content

Add local_address= kwarg to open_tcp_stream - #1644

Merged
oremanj merged 2 commits into
python-trio:masterfrom
njsmith:bind-address
Jun 25, 2020
Merged

Add local_address= kwarg to open_tcp_stream#1644
oremanj merged 2 commits into
python-trio:masterfrom
njsmith:bind-address

Conversation

@njsmith

Copy link
Copy Markdown
Member

Fixesgh-275

@codecov

codecovBot commented Jun 24, 2020

Copy link
Copy Markdown

Codecov Report

Merging #1644 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@ Coverage Diff @@## master #1644 +/- ##
=======================================
Coverage 99.69% 99.69% =======================================
Files 110 110 Lines 13858 13955 +97 Branches 1062 1074 +12 =======================================
+ Hits 13816 13913 +97 
Misses 27 27 Partials 15 15 
Impacted FilesCoverage Δ
trio/_highlevel_open_tcp_stream.py97.33% <100.00%> (+0.36%)⬆️
trio/socket.py100.00% <100.00%> (ø)
trio/tests/test_highlevel_open_tcp_stream.py100.00% <100.00%> (ø)
trio/_core/_thread_cache.py100.00% <0.00%> (ø)
trio/_core/tests/test_run.py100.00% <0.00%> (ø)
trio/_core/tests/test_thread_cache.py100.00% <0.00%> (ø)
trio/_core/_run.py99.77% <0.00%> (+<0.01%)⬆️

@oremanj

Copy link
Copy Markdown
Member

Thanks for the detailed comment on bind() -- I learned something!

@oremanj
oremanj merged commit 270bf85 into python-trio:masterJun 25, 2020
@ntninja

Copy link
Copy Markdown

That was way too fast for me…! 😮

Do I see it correctly that with this API limiting a connection to socket.AF_INET/socket.AF_INET6 address families during name resolution is done by passing "0.0.0.0"/"::" respectively for the local_address=… arg?

@njsmith
njsmith deleted the bind-address branch June 25, 2020 08:39
@njsmith

Copy link
Copy Markdown
MemberAuthor

@ntninja Currently, open_tcp_stream always does full name resolution, but if you pass local_address="0.0.0.0" then it will only skip trying to connect to the AF_INET6 addresses and if you pass local_address="::" then it will skip trying to connect to the AF_INET addresses. Technically this is very slightly inefficient (getaddrinfo still has to look up both sets of addresses), but this is very minor, and in return, we get better error messages: e.g., if you accidentally try to connect to an IPv6-only host with local_address="0.0.0.0", then it will fail, but the error message will tell you that there were IPv6 addresses it considered connecting to and if you changed your local_address= you might succeed.

@ntninja

Copy link
Copy Markdown

Ok, thanks! I don't have any strong feelings on this, just wanted to know for sure!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting source interface in open_tcp_stream

3 participants

@njsmith@oremanj@ntninja