[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef NET_DNS_ADDRESS_SORTER_H_ | ||||
6 | #define NET_DNS_ADDRESS_SORTER_H_ | ||||
7 | |||||
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 8 | #include <memory> |
Eric Orth | 48b1b7c | 2022-01-21 00:21:16 | [diff] [blame] | 9 | #include <vector> |
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 10 | |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 11 | #include "base/callback.h" |
Eric Orth | 48b1b7c | 2022-01-21 00:21:16 | [diff] [blame] | 12 | #include "net/base/ip_endpoint.h" |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 13 | #include "net/base/net_export.h" |
14 | |||||
15 | namespace net { | ||||
16 | |||||
Christian Dullweber | 1b2df591 | 2021-11-03 11:37:35 | [diff] [blame] | 17 | class AddressList; |
18 | |||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 19 | // Sorts AddressList according to RFC3484, by likelihood of successful |
20 | // connection. Depending on the platform, the sort could be performed | ||||
21 | // asynchronously by the OS, or synchronously by local implementation. | ||||
22 | // AddressSorter does not necessarily preserve port numbers on the sorted list. | ||||
23 | class NET_EXPORT AddressSorter { | ||||
24 | public: | ||||
Christian Dullweber | 1b2df591 | 2021-11-03 11:37:35 | [diff] [blame] | 25 | using CallbackType = |
Eric Orth | 48b1b7c | 2022-01-21 00:21:16 | [diff] [blame] | 26 | base::OnceCallback<void(bool success, std::vector<IPEndPoint> sorted)>; |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 27 | |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 28 | AddressSorter(const AddressSorter&) = delete; |
29 | AddressSorter& operator=(const AddressSorter&) = delete; | ||||
30 | |||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 31 | virtual ~AddressSorter() {} |
32 | |||||
Eric Orth | 48b1b7c | 2022-01-21 00:21:16 | [diff] [blame] | 33 | // Sorts `endpoints`, which must include at least one IPv6 address. |
34 | // Calls `callback` upon completion. Could complete synchronously. Could | ||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 35 | // complete after this AddressSorter is destroyed. |
Eric Orth | 48b1b7c | 2022-01-21 00:21:16 | [diff] [blame] | 36 | virtual void Sort(const std::vector<IPEndPoint>& endpoints, |
37 | CallbackType callback) const = 0; | ||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 38 | |
39 | // Creates platform-dependent AddressSorter. | ||||
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 40 | static std::unique_ptr<AddressSorter> CreateAddressSorter(); |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 41 | |
42 | protected: | ||||
43 | AddressSorter() {} | ||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 44 | }; |
45 | |||||
46 | } // namespace net | ||||
47 | |||||
48 | #endif // NET_DNS_ADDRESS_SORTER_H_ |