address_sorter.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #ifndef NET_DNS_ADDRESS_SORTER_H_
  5. #define NET_DNS_ADDRESS_SORTER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "net/base/ip_endpoint.h"
  10. #include "net/base/net_export.h"
  11. namespace net {
  12. class AddressList;
  13. // Sorts AddressList according to RFC3484, by likelihood of successful
  14. // connection. Depending on the platform, the sort could be performed
  15. // asynchronously by the OS, or synchronously by local implementation.
  16. // AddressSorter does not necessarily preserve port numbers on the sorted list.
  17. class NET_EXPORT AddressSorter {
  18. public:
  19. using CallbackType =
  20. base::OnceCallback<void(bool success, std::vector<IPEndPoint> sorted)>;
  21. AddressSorter(const AddressSorter&) = delete;
  22. AddressSorter& operator=(const AddressSorter&) = delete;
  23. virtual ~AddressSorter() = default;
  24. // Sorts `endpoints`, which must include at least one IPv6 address.
  25. // Calls `callback` upon completion. Could complete synchronously. Could
  26. // complete after this AddressSorter is destroyed.
  27. virtual void Sort(const std::vector<IPEndPoint>& endpoints,
  28. CallbackType callback) const = 0;
  29. // Creates platform-dependent AddressSorter.
  30. static std::unique_ptr<AddressSorter> CreateAddressSorter();
  31. protected:
  32. AddressSorter() = default;
  33. };
  34. } // namespace net
  35. #endif // NET_DNS_ADDRESS_SORTER_H_