-
Notifications
You must be signed in to change notification settings - Fork 5.5k
upstream: Implement Happy Eyeballs address sorting #18906
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
Changes from 6 commits
7c4538c
e03104a
ef769a6
3f3a4ac
0a3f5da
eb86577
0561593
9c84f2b
8fd62a2
545928d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ HappyEyeballsConnectionImpl::HappyEyeballsConnectionImpl( | |
| Address::InstanceConstSharedPtr source_address, TransportSocketFactory& socket_factory, | ||
| TransportSocketOptionsConstSharedPtr transport_socket_options, | ||
| const ConnectionSocket::OptionsSharedPtr options) | ||
| : id_(ConnectionImpl::next_global_id_++), dispatcher_(dispatcher), address_list_(address_list), | ||
| : id_(ConnectionImpl::next_global_id_++), dispatcher_(dispatcher), | ||
| address_list_(sortAddresses(address_list)), | ||
| connection_construction_state_( | ||
| {source_address, socket_factory, transport_socket_options, options}), | ||
| next_attempt_timer_(dispatcher_.createTimer([this]() -> void { tryAnotherConnection(); })) { | ||
|
|
@@ -379,6 +380,27 @@ void HappyEyeballsConnectionImpl::dumpState(std::ostream& os, int indent_level) | |
| } | ||
| } | ||
|
|
||
| std::vector<Address::InstanceConstSharedPtr> | ||
| HappyEyeballsConnectionImpl::sortAddresses(const std::vector<Address::InstanceConstSharedPtr>& in) { | ||
| std::vector<Address::InstanceConstSharedPtr> address_list = in; | ||
| for (auto current = address_list.begin(); current != address_list.end(); ++current) { | ||
| // Find the first address with a different address family than the current address. | ||
| auto it = std::find_if(current, address_list.end(), [&](const auto& val) { | ||
| return (val->type() != Address::Type::Ip || (*current)->type() != Address::Type::Ip || | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kinda curious, does the spec say what to do with non IP addresses? Should we just remove those if we see any?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The specs refer specifically to IP addresses. I don't think they even consider non-IP addresses. The other address types are |
||
| (*current)->ip()->version() != val->ip()->version()); | ||
| }); | ||
| // If there are no more addresses with different families the sorting is finished. | ||
| if (it == address_list.end()) { | ||
| break; | ||
| } | ||
| // Bubble the address up to the current position. | ||
| auto start = std::make_reverse_iterator(it + 1); | ||
| auto end = std::make_reverse_iterator(current + 1); | ||
| std::rotate(start, start + 1, end); | ||
| } | ||
| return address_list; | ||
|
alyssawilk marked this conversation as resolved.
|
||
| } | ||
|
|
||
| ClientConnectionPtr HappyEyeballsConnectionImpl::createNextConnection() { | ||
| ASSERT(next_address_ < address_list_.size()); | ||
| auto connection = dispatcher_.createClientConnection( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,13 @@ class HappyEyeballsConnectionImpl : public ClientConnection, | |
| void hashKey(std::vector<uint8_t>& hash_key) const override; | ||
| void dumpState(std::ostream& os, int indent_level) const override; | ||
|
|
||
| // Returns a new vector containing the contents of |address_list| sorted | ||
| // with address families interleaved, as per Section 4 of RFC 8305, Happy | ||
| // Eyeballs v2. It is assumed that the list must already sorted as per | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "list must already BE sorted...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. PTAL? |
||
| // Section 6 of RFC6724, which happens in ares_getaddrinfo(). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the Apple implementation also do this? If not, then we would be breaking this requirement for iOS
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it does, according to what I read online.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe comment as such.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment about Apple DNS. Good idea. As for detecting that this sorting might be missing, I'm not sure how we would do that short of implementing the sorting rules and checking that addr[i] < addr[i+1] but that's non-trivial. I'm open to suggestions though! |
||
| static std::vector<Address::InstanceConstSharedPtr> | ||
| sortAddresses(const std::vector<Address::InstanceConstSharedPtr>& address_list); | ||
|
|
||
| private: | ||
| // ConnectionCallbacks which will be set on an ClientConnection which | ||
| // sends connection events back to the HappyEyeballsConnectionImpl. | ||
|
|
@@ -196,7 +203,7 @@ class HappyEyeballsConnectionImpl : public ClientConnection, | |
| Event::Dispatcher& dispatcher_; | ||
|
|
||
| // List of addresses to attempt to connect to. | ||
| const std::vector<Address::InstanceConstSharedPtr>& address_list_; | ||
| const std::vector<Address::InstanceConstSharedPtr> address_list_; | ||
| // Index of the next address to use. | ||
| size_t next_address_ = 0; | ||
|
|
||
|
|
||
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.
food for thought: do we care about making this behavior configurable? i.e., opt-out via config?
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.
Hm. I'm inclined to say "no", or at least "not unless someone asks for it". Happy Eyeballs itself is already configurable and I can't really imagine why this would be something we'd want to disable if Happy Eyeballs were in use. That being said, if someone ask for it then we could definitely make it configurable. WDYT?
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.
fair. sg!