blob: 19162d86e53714e91b13c4897a69ac1572e04719 [file] [log] [blame]
[email protected]0adcb2b2012-08-15 21:30:461// 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
danakj22f90e72016-04-16 01:55:408#include <memory>
Eric Orth48b1b7c2022-01-21 00:21:169#include <vector>
danakj22f90e72016-04-16 01:55:4010
[email protected]0adcb2b2012-08-15 21:30:4611#include "base/callback.h"
Eric Orth48b1b7c2022-01-21 00:21:1612#include "net/base/ip_endpoint.h"
[email protected]0adcb2b2012-08-15 21:30:4613#include "net/base/net_export.h"
14
15namespace net {
16
Christian Dullweber1b2df5912021-11-03 11:37:3517class AddressList;
18
[email protected]0adcb2b2012-08-15 21:30:4619// 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.
23class NET_EXPORT AddressSorter {
24 public:
Christian Dullweber1b2df5912021-11-03 11:37:3525 using CallbackType =
Eric Orth48b1b7c2022-01-21 00:21:1626 base::OnceCallback<void(bool success, std::vector<IPEndPoint> sorted)>;
[email protected]0adcb2b2012-08-15 21:30:4627
Peter Boström293b1342021-09-22 17:31:4328 AddressSorter(const AddressSorter&) = delete;
29 AddressSorter& operator=(const AddressSorter&) = delete;
30
Tsuyoshi Horo07c3f0e2022-06-16 07:30:4731 virtual ~AddressSorter() = default;
[email protected]0adcb2b2012-08-15 21:30:4632
Eric Orth48b1b7c2022-01-21 00:21:1633 // Sorts `endpoints`, which must include at least one IPv6 address.
34 // Calls `callback` upon completion. Could complete synchronously. Could
[email protected]0adcb2b2012-08-15 21:30:4635 // complete after this AddressSorter is destroyed.
Eric Orth48b1b7c2022-01-21 00:21:1636 virtual void Sort(const std::vector<IPEndPoint>& endpoints,
37 CallbackType callback) const = 0;
[email protected]0adcb2b2012-08-15 21:30:4638
39 // Creates platform-dependent AddressSorter.
danakj22f90e72016-04-16 01:55:4040 static std::unique_ptr<AddressSorter> CreateAddressSorter();
[email protected]0adcb2b2012-08-15 21:30:4641
42 protected:
Tsuyoshi Horo07c3f0e2022-06-16 07:30:4743 AddressSorter() = default;
[email protected]0adcb2b2012-08-15 21:30:4644};
45
46} // namespace net
47
48#endif // NET_DNS_ADDRESS_SORTER_H_