webrtc/api/async_dns_resolver.h
Mirko Bonadei 5a40b37105 Revert "Use the new DNS resolver API in PeerConnection"
This reverts commit acf8ccb3c9.

Reason for revert: Speculative revert for https://ci.chromium.org/ui/p/chromium/builders/try/win10_chromium_x64_rel_ng/b8851745102358680592/overview.

Original change's description:
> Use the new DNS resolver API in PeerConnection
>
> Bug: webrtc:12598
> Change-Id: I5a14058e7f28c993ed927749df7357c715ba83fb
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212961
> Reviewed-by: Niels Moller <nisse@webrtc.org>
> Commit-Queue: Harald Alvestrand <hta@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#33561}

# Not skipping CQ checks because original CL landed > 1 day ago.

TBR=hta@webrtc.org

Bug: webrtc:12598
Change-Id: Idc9853cb569849c49052f9cbd865614710fff979
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213188
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33591}
2021-03-30 08:37:01 +00:00

85 lines
3.1 KiB
C++

/*
* Copyright 2021 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef API_ASYNC_DNS_RESOLVER_H_
#define API_ASYNC_DNS_RESOLVER_H_
#include <memory>
#include "rtc_base/socket_address.h"
#include "rtc_base/system/rtc_export.h"
namespace webrtc {
// This interface defines the methods to resolve a hostname asynchronously.
// The AsyncDnsResolverInterface class encapsulates a single name query.
//
// Usage:
// std::unique_ptr<AsyncDnsResolverInterface> resolver =
// factory->Create(address-to-be-resolved, [r = resolver.get()]() {
// if (r->result.GetResolvedAddress(AF_INET, &addr) {
// // success
// } else {
// // failure
// error = r->result().GetError();
// }
// // Release resolver.
// resolver_list.erase(std::remove_if(resolver_list.begin(),
// resolver_list.end(),
// [](refptr) { refptr.get() == r; });
// });
// resolver_list.push_back(std::move(resolver));
class AsyncDnsResolverResult {
public:
virtual ~AsyncDnsResolverResult() = default;
// Returns true iff the address from |Start| was successfully resolved.
// If the address was successfully resolved, sets |addr| to a copy of the
// address from |Start| with the IP address set to the top most resolved
// address of |family| (|addr| will have both hostname and the resolved ip).
virtual bool GetResolvedAddress(int family,
rtc::SocketAddress* addr) const = 0;
// Returns error from resolver.
virtual int GetError() const = 0;
};
class RTC_EXPORT AsyncDnsResolverInterface {
public:
virtual ~AsyncDnsResolverInterface() = default;
// Start address resolution of the hostname in |addr|.
virtual void Start(const rtc::SocketAddress& addr,
std::function<void()> callback) = 0;
virtual const AsyncDnsResolverResult& result() const = 0;
};
// An abstract factory for creating AsyncDnsResolverInterfaces. This allows
// client applications to provide WebRTC with their own mechanism for
// performing DNS resolution.
class AsyncDnsResolverFactoryInterface {
public:
virtual ~AsyncDnsResolverFactoryInterface() = default;
// Creates an AsyncDnsResolver and starts resolving the name. The callback
// will be called when resolution is finished.
// The callback will be called on the thread that the caller runs on.
virtual std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAndResolve(
const rtc::SocketAddress& addr,
std::function<void()> callback) = 0;
// Creates an AsyncDnsResolver and does not start it.
// For backwards compatibility, will be deprecated and removed.
// One has to do a separate Start() call on the
// resolver to start name resolution.
virtual std::unique_ptr<webrtc::AsyncDnsResolverInterface> Create() = 0;
};
} // namespace webrtc
#endif // API_ASYNC_DNS_RESOLVER_H_