Skip to content

Use stable_sort to preserve order of IP addresses from DNS#1445

Merged
obiltschnig merged 1 commit intopocoproject:developfrom
cryptoknight:ip_stable_sort
Oct 5, 2016
Merged

Use stable_sort to preserve order of IP addresses from DNS#1445
obiltschnig merged 1 commit intopocoproject:developfrom
cryptoknight:ip_stable_sort

Conversation

@cryptoknight
Copy link
Copy Markdown
Contributor

SocketAddress uses a sort operation on IP addresses returned from DNS to ensure that IPv4 addresses are preferred over IPv6 addresses. Unfortunately, std::sort does not guarantee that the order of "equal" elements will be preserved, in which case SocketAddress can wind up with an IP other than the first one when multiple addresses are returned. Since DNS round robin-ing (https://en.wikipedia.org/wiki/Round-robin_DNS) assumes that a client will typically use the first address, it would be beneficial to have the order preserved by the sort. Switching to std::stable_sort achieves this.

@bracketttc
Copy link
Copy Markdown

Nice catch.

@obiltschnig obiltschnig merged commit d9c3c52 into pocoproject:develop Oct 5, 2016
@obiltschnig obiltschnig added the bug label Oct 5, 2016
@obiltschnig obiltschnig added this to the Release 1.7.6 milestone Oct 5, 2016
@obiltschnig obiltschnig self-assigned this Oct 5, 2016
@cryptoknight cryptoknight deleted the ip_stable_sort branch October 5, 2016 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants