mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Delete deprecated AsyncResolver and related classes
To be submitted after downstream usage has been removed, but no earlier than December 1, 2023. Bug: webrtc:12598 Change-Id: Id9acbac591c48c0c5883fe8f06cf6a68471b70f0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/323004 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41290}
This commit is contained in:
parent
924f716b7a
commit
24510d43dc
37 changed files with 18 additions and 958 deletions
29
api/BUILD.gn
29
api/BUILD.gn
|
@ -430,15 +430,10 @@ rtc_library("rtc_error") {
|
|||
|
||||
rtc_source_set("packet_socket_factory") {
|
||||
visibility = [ "*" ]
|
||||
sources = [
|
||||
"async_resolver_factory.h",
|
||||
"packet_socket_factory.h",
|
||||
]
|
||||
sources = [ "packet_socket_factory.h" ]
|
||||
deps = [
|
||||
":async_dns_resolver",
|
||||
":wrapping_async_dns_resolver",
|
||||
"../rtc_base:async_packet_socket",
|
||||
"../rtc_base:async_resolver_interface",
|
||||
"../rtc_base:proxy_info",
|
||||
"../rtc_base:socket_address",
|
||||
"../rtc_base/system:rtc_export",
|
||||
|
@ -456,28 +451,6 @@ rtc_source_set("async_dns_resolver") {
|
|||
absl_deps = [ "//third_party/abseil-cpp/absl/functional:any_invocable" ]
|
||||
}
|
||||
|
||||
rtc_source_set("wrapping_async_dns_resolver") {
|
||||
visibility = [
|
||||
":*",
|
||||
"../p2p:rtc_p2p",
|
||||
]
|
||||
sources = [
|
||||
"wrapping_async_dns_resolver.cc",
|
||||
"wrapping_async_dns_resolver.h",
|
||||
]
|
||||
deps = [
|
||||
":async_dns_resolver",
|
||||
":sequence_checker",
|
||||
"../rtc_base:async_resolver_interface",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:macromagic",
|
||||
"../rtc_base:socket_address",
|
||||
"../rtc_base:threading",
|
||||
"../rtc_base/third_party/sigslot",
|
||||
]
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/memory" ]
|
||||
}
|
||||
|
||||
rtc_source_set("ref_count") {
|
||||
visibility = [ "*" ]
|
||||
sources = [ "ref_count.h" ]
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 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_RESOLVER_FACTORY_H_
|
||||
#define API_ASYNC_RESOLVER_FACTORY_H_
|
||||
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// An abstract factory for creating AsyncResolverInterfaces. This allows
|
||||
// client applications to provide WebRTC with their own mechanism for
|
||||
// performing DNS resolution.
|
||||
// TODO(bugs.webrtc.org/12598): Deprecate and remove.
|
||||
class [[deprecated("Use AsyncDnsResolverFactory")]] AsyncResolverFactory {
|
||||
public:
|
||||
AsyncResolverFactory() = default;
|
||||
virtual ~AsyncResolverFactory() = default;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// The caller should call Destroy on the returned object to delete it.
|
||||
virtual rtc::AsyncResolverInterface* Create() = 0;
|
||||
#pragma clang diagnostic pop
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_ASYNC_RESOLVER_FACTORY_H_
|
|
@ -14,7 +14,6 @@
|
|||
#include <string>
|
||||
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/ref_count.h"
|
||||
#include "api/rtc_error.h"
|
||||
#include "api/rtc_event_log/rtc_event_log.h"
|
||||
|
@ -61,19 +60,8 @@ struct IceTransportInit final {
|
|||
}
|
||||
void set_async_dns_resolver_factory(
|
||||
AsyncDnsResolverFactoryInterface* async_dns_resolver_factory) {
|
||||
RTC_DCHECK(!async_resolver_factory_);
|
||||
async_dns_resolver_factory_ = async_dns_resolver_factory;
|
||||
}
|
||||
[[deprecated("Use async_dns_resolver_factory")]] AsyncResolverFactory*
|
||||
async_resolver_factory() {
|
||||
return async_resolver_factory_;
|
||||
}
|
||||
ABSL_DEPRECATED("bugs.webrtc.org/12598")
|
||||
void set_async_resolver_factory(
|
||||
AsyncResolverFactory* async_resolver_factory) {
|
||||
RTC_DCHECK(!async_dns_resolver_factory_);
|
||||
async_resolver_factory_ = async_resolver_factory;
|
||||
}
|
||||
|
||||
RtcEventLog* event_log() { return event_log_; }
|
||||
void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; }
|
||||
|
@ -115,11 +103,6 @@ struct IceTransportInit final {
|
|||
private:
|
||||
cricket::PortAllocator* port_allocator_ = nullptr;
|
||||
AsyncDnsResolverFactoryInterface* async_dns_resolver_factory_ = nullptr;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// For backwards compatibility. Only one resolver factory can be set.
|
||||
AsyncResolverFactory* async_resolver_factory_ = nullptr;
|
||||
#pragma clang diagnostic pop
|
||||
RtcEventLog* event_log_ = nullptr;
|
||||
cricket::IceControllerFactoryInterface* ice_controller_factory_ = nullptr;
|
||||
cricket::ActiveIceControllerFactoryInterface* active_ice_controller_factory_ =
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include <vector>
|
||||
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/wrapping_async_dns_resolver.h"
|
||||
#include "rtc_base/async_packet_socket.h"
|
||||
#include "rtc_base/proxy_info.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
|
@ -72,26 +71,8 @@ class RTC_EXPORT PacketSocketFactory {
|
|||
const std::string& user_agent,
|
||||
const PacketSocketTcpOptions& tcp_options) = 0;
|
||||
|
||||
// The AsyncResolverInterface is deprecated; users are encouraged
|
||||
// to switch to the AsyncDnsResolverInterface.
|
||||
// TODO(bugs.webrtc.org/12598): Remove once all downstream users
|
||||
// are converted.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[[deprecated]] virtual AsyncResolverInterface* CreateAsyncResolver() {
|
||||
// Default implementation, so that downstream users can remove this
|
||||
// immediately after changing to CreateAsyncDnsResolver
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<webrtc::AsyncDnsResolverInterface>
|
||||
CreateAsyncDnsResolver() {
|
||||
// Default implementation, to aid in transition to AsyncDnsResolverInterface
|
||||
return std::make_unique<webrtc::WrappingAsyncDnsResolver>(
|
||||
CreateAsyncResolver());
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
CreateAsyncDnsResolver() = 0;
|
||||
|
||||
private:
|
||||
PacketSocketFactory(const PacketSocketFactory&) = delete;
|
||||
|
|
|
@ -80,7 +80,6 @@
|
|||
#include "absl/types/optional.h"
|
||||
#include "api/adaptation/resource.h"
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/audio/audio_mixer.h"
|
||||
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/audio_encoder_factory.h"
|
||||
|
@ -1388,13 +1387,6 @@ struct RTC_EXPORT PeerConnectionDependencies final {
|
|||
// Factory for creating resolvers that look up hostnames in DNS
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverFactoryInterface>
|
||||
async_dns_resolver_factory;
|
||||
// Deprecated - use async_dns_resolver_factory
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[[deprecated("Use async_dns_resolver_factory")]] std::unique_ptr<
|
||||
webrtc::AsyncResolverFactory>
|
||||
async_resolver_factory;
|
||||
#pragma clang diagnostic pop
|
||||
std::unique_ptr<webrtc::IceTransportFactory> ice_transport_factory;
|
||||
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
|
||||
std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/audio/audio_mixer.h"
|
||||
#include "api/audio_options.h"
|
||||
#include "api/call/call_factory_interface.h"
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/audio/audio_mixer.h"
|
||||
#include "api/call/call_factory_interface.h"
|
||||
#include "api/fec_controller.h"
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* 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_WRAPPING_ASYNC_DNS_RESOLVER_H_
|
||||
#define API_WRAPPING_ASYNC_DNS_RESOLVER_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/sequence_checker.h"
|
||||
#include "rtc_base/async_resolver.h"
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/socket_address.h"
|
||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
||||
// This file defines a DNS resolver that wraps an old-style
|
||||
// AsyncResolver.
|
||||
// It is part of the conversion to the newer interface, and will go away
|
||||
// once conversion is finished.
|
||||
// TODO(bugs.webrtc.org/12598): Delete this API.
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class [[deprecated("Use AsyncDnsResolver directly")]] WrappingAsyncDnsResolver;
|
||||
|
||||
class [[deprecated(
|
||||
"Use AsyncDnsResolver directly")]] RTC_EXPORT WrappingAsyncDnsResolverResult
|
||||
: public AsyncDnsResolverResult {
|
||||
public:
|
||||
explicit WrappingAsyncDnsResolverResult(WrappingAsyncDnsResolver* owner)
|
||||
: owner_(owner) {}
|
||||
~WrappingAsyncDnsResolverResult() {}
|
||||
|
||||
// Note: Inline declaration not possible, since it refers to
|
||||
// WrappingAsyncDnsResolver.
|
||||
bool GetResolvedAddress(int family, rtc::SocketAddress* addr) const override;
|
||||
int GetError() const override;
|
||||
|
||||
private:
|
||||
WrappingAsyncDnsResolver* const owner_;
|
||||
};
|
||||
|
||||
class RTC_EXPORT WrappingAsyncDnsResolver : public AsyncDnsResolverInterface,
|
||||
public sigslot::has_slots<> {
|
||||
public:
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
explicit WrappingAsyncDnsResolver(rtc::AsyncResolverInterface* wrapped)
|
||||
: wrapped_(absl::WrapUnique(wrapped)), result_(this) {}
|
||||
|
||||
~WrappingAsyncDnsResolver() override {
|
||||
// Workaround to get around the fact that sigslot-using objects can't be
|
||||
// destroyed from within their callback: Alert class users early.
|
||||
// TODO(bugs.webrtc.org/12651): Delete this class once the sigslot users are
|
||||
// gone.
|
||||
RTC_CHECK(!within_resolve_result_);
|
||||
wrapped_.release()->Destroy(false);
|
||||
}
|
||||
|
||||
void Start(const rtc::SocketAddress& addr,
|
||||
absl::AnyInvocable<void()> callback) override {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
PrepareToResolve(std::move(callback));
|
||||
wrapped_->Start(addr);
|
||||
}
|
||||
|
||||
void Start(const rtc::SocketAddress& addr,
|
||||
int family,
|
||||
absl::AnyInvocable<void()> callback) override {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
PrepareToResolve(std::move(callback));
|
||||
wrapped_->Start(addr, family);
|
||||
}
|
||||
|
||||
const AsyncDnsResolverResult& result() const override {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK_EQ(State::kResolved, state_);
|
||||
return result_;
|
||||
}
|
||||
|
||||
private:
|
||||
enum class State { kNotStarted, kStarted, kResolved };
|
||||
|
||||
friend class WrappingAsyncDnsResolverResult;
|
||||
// For use by WrappingAsyncDnsResolverResult
|
||||
rtc::AsyncResolverInterface* wrapped() const {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
return wrapped_.get();
|
||||
}
|
||||
|
||||
void PrepareToResolve(absl::AnyInvocable<void()> callback) {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK_EQ(State::kNotStarted, state_);
|
||||
state_ = State::kStarted;
|
||||
callback_ = std::move(callback);
|
||||
wrapped_->SignalDone.connect(this,
|
||||
&WrappingAsyncDnsResolver::OnResolveResult);
|
||||
}
|
||||
|
||||
void OnResolveResult(rtc::AsyncResolverInterface* ref) {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK(state_ == State::kStarted);
|
||||
RTC_DCHECK_EQ(ref, wrapped_.get());
|
||||
state_ = State::kResolved;
|
||||
within_resolve_result_ = true;
|
||||
callback_();
|
||||
within_resolve_result_ = false;
|
||||
}
|
||||
|
||||
// The class variables need to be accessed on a single thread.
|
||||
SequenceChecker sequence_checker_;
|
||||
absl::AnyInvocable<void()> callback_ RTC_GUARDED_BY(sequence_checker_);
|
||||
std::unique_ptr<rtc::AsyncResolverInterface> wrapped_
|
||||
RTC_GUARDED_BY(sequence_checker_);
|
||||
State state_ RTC_GUARDED_BY(sequence_checker_) = State::kNotStarted;
|
||||
WrappingAsyncDnsResolverResult result_ RTC_GUARDED_BY(sequence_checker_);
|
||||
bool within_resolve_result_ RTC_GUARDED_BY(sequence_checker_) = false;
|
||||
#pragma clang diagnostic pop
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_WRAPPING_ASYNC_DNS_RESOLVER_H_
|
|
@ -16,6 +16,7 @@
|
|||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/net_helpers.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
|
@ -105,7 +105,6 @@ rtc_library("rtc_p2p") {
|
|||
"../api:scoped_refptr",
|
||||
"../api:sequence_checker",
|
||||
"../api:turn_customizer",
|
||||
"../api:wrapping_async_dns_resolver",
|
||||
"../api/crypto:options",
|
||||
"../api/rtc_event_log",
|
||||
"../api/task_queue",
|
||||
|
@ -117,7 +116,6 @@ rtc_library("rtc_p2p") {
|
|||
"../logging:ice_log",
|
||||
"../rtc_base:async_dns_resolver",
|
||||
"../rtc_base:async_packet_socket",
|
||||
"../rtc_base:async_resolver_interface",
|
||||
"../rtc_base:async_tcp_socket",
|
||||
"../rtc_base:async_udp_socket",
|
||||
"../rtc_base:buffer",
|
||||
|
@ -220,7 +218,6 @@ if (rtc_include_tests) {
|
|||
"base/fake_dtls_transport.h",
|
||||
"base/fake_packet_transport.h",
|
||||
"base/mock_active_ice_controller.h",
|
||||
"base/mock_async_resolver.h",
|
||||
"base/mock_dns_resolving_packet_socket_factory.h",
|
||||
"base/mock_ice_agent.h",
|
||||
"base/mock_ice_controller.h",
|
||||
|
@ -243,7 +240,6 @@ if (rtc_include_tests) {
|
|||
"../api:turn_customizer",
|
||||
"../api/crypto:options",
|
||||
"../api/transport:stun_types",
|
||||
"../rtc_base:async_resolver_interface",
|
||||
"../rtc_base:async_udp_socket",
|
||||
"../rtc_base:copy_on_write_buffer",
|
||||
"../rtc_base:gunit_helpers",
|
||||
|
@ -268,7 +264,6 @@ if (rtc_include_tests) {
|
|||
|
||||
sources = [
|
||||
"base/async_stun_tcp_socket_unittest.cc",
|
||||
"base/basic_async_resolver_factory_unittest.cc",
|
||||
"base/dtls_transport_unittest.cc",
|
||||
"base/ice_credentials_iterator_unittest.cc",
|
||||
"base/p2p_transport_channel_unittest.cc",
|
||||
|
@ -405,7 +400,6 @@ rtc_library("libstunprober") {
|
|||
"../api/transport:stun_types",
|
||||
"../api/units:time_delta",
|
||||
"../rtc_base:async_packet_socket",
|
||||
"../rtc_base:async_resolver_interface",
|
||||
"../rtc_base:byte_buffer",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:ip_address",
|
||||
|
|
|
@ -15,20 +15,11 @@
|
|||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/wrapping_async_dns_resolver.h"
|
||||
#include "rtc_base/async_dns_resolver.h"
|
||||
#include "rtc_base/async_resolver.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
rtc::AsyncResolverInterface* BasicAsyncResolverFactory::Create() {
|
||||
return new rtc::AsyncResolver();
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface>
|
||||
BasicAsyncDnsResolverFactory::Create() {
|
||||
return std::make_unique<AsyncDnsResolver>();
|
||||
|
@ -53,28 +44,4 @@ BasicAsyncDnsResolverFactory::CreateAndResolve(
|
|||
return resolver;
|
||||
}
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface>
|
||||
WrappingAsyncDnsResolverFactory::Create() {
|
||||
return std::make_unique<WrappingAsyncDnsResolver>(wrapped_factory_->Create());
|
||||
}
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface>
|
||||
WrappingAsyncDnsResolverFactory::CreateAndResolve(
|
||||
const rtc::SocketAddress& addr,
|
||||
absl::AnyInvocable<void()> callback) {
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> resolver = Create();
|
||||
resolver->Start(addr, std::move(callback));
|
||||
return resolver;
|
||||
}
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface>
|
||||
WrappingAsyncDnsResolverFactory::CreateAndResolve(
|
||||
const rtc::SocketAddress& addr,
|
||||
int family,
|
||||
absl::AnyInvocable<void()> callback) {
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> resolver = Create();
|
||||
resolver->Start(addr, family, std::move(callback));
|
||||
return resolver;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -16,21 +16,9 @@
|
|||
#include <utility>
|
||||
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
class [[deprecated(
|
||||
"Use BasicAsyncDnsResolverFactory")]] BasicAsyncResolverFactory final
|
||||
: public AsyncResolverFactory {
|
||||
public:
|
||||
rtc::AsyncResolverInterface* Create() override;
|
||||
};
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// A factory that vends AsyncDnsResolver instances.
|
||||
class BasicAsyncDnsResolverFactory final
|
||||
: public AsyncDnsResolverFactoryInterface {
|
||||
|
@ -49,40 +37,6 @@ class BasicAsyncDnsResolverFactory final
|
|||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> Create() override;
|
||||
};
|
||||
|
||||
// This class wraps a factory using the older webrtc::AsyncResolverFactory API,
|
||||
// and produces webrtc::AsyncDnsResolver objects that contain an
|
||||
// rtc::AsyncResolver object.
|
||||
class [[deprecated]] WrappingAsyncDnsResolverFactory final
|
||||
: public AsyncDnsResolverFactoryInterface {
|
||||
public:
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
explicit WrappingAsyncDnsResolverFactory(
|
||||
std::unique_ptr<AsyncResolverFactory> wrapped_factory)
|
||||
: owned_factory_(std::move(wrapped_factory)),
|
||||
wrapped_factory_(owned_factory_.get()) {}
|
||||
|
||||
explicit WrappingAsyncDnsResolverFactory(
|
||||
AsyncResolverFactory* non_owned_factory)
|
||||
: wrapped_factory_(non_owned_factory) {}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAndResolve(
|
||||
const rtc::SocketAddress& addr,
|
||||
absl::AnyInvocable<void()> callback) override;
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAndResolve(
|
||||
const rtc::SocketAddress& addr,
|
||||
int family,
|
||||
absl::AnyInvocable<void()> callback) override;
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> Create() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<AsyncResolverFactory> owned_factory_;
|
||||
AsyncResolverFactory* const wrapped_factory_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // P2P_BASE_BASIC_ASYNC_RESOLVER_FACTORY_H_
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
#include "p2p/base/basic_async_resolver_factory.h"
|
||||
|
||||
#include "api/test/mock_async_dns_resolver.h"
|
||||
#include "p2p/base/mock_async_resolver.h"
|
||||
#include "rtc_base/async_resolver.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/socket_address.h"
|
||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||
|
@ -22,95 +20,6 @@
|
|||
|
||||
namespace webrtc {
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
class BasicAsyncResolverFactoryTest : public ::testing::Test,
|
||||
public sigslot::has_slots<> {
|
||||
public:
|
||||
void TestCreate() {
|
||||
BasicAsyncResolverFactory factory;
|
||||
rtc::AsyncResolverInterface* resolver = factory.Create();
|
||||
ASSERT_TRUE(resolver);
|
||||
resolver->SignalDone.connect(
|
||||
this, &BasicAsyncResolverFactoryTest::SetAddressResolved);
|
||||
|
||||
rtc::SocketAddress address("", 0);
|
||||
resolver->Start(address);
|
||||
ASSERT_TRUE_WAIT(address_resolved_, 10000 /*ms*/);
|
||||
resolver->Destroy(false);
|
||||
}
|
||||
|
||||
void SetAddressResolved(rtc::AsyncResolverInterface* resolver) {
|
||||
address_resolved_ = true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool address_resolved_ = false;
|
||||
};
|
||||
|
||||
// This test is primarily intended to let tools check that the created resolver
|
||||
// doesn't leak.
|
||||
TEST_F(BasicAsyncResolverFactoryTest, TestCreate) {
|
||||
rtc::AutoThread main_thread;
|
||||
TestCreate();
|
||||
}
|
||||
|
||||
TEST(WrappingAsyncDnsResolverFactoryTest, TestCreateAndResolve) {
|
||||
rtc::AutoThread main_thread;
|
||||
WrappingAsyncDnsResolverFactory factory(
|
||||
std::make_unique<BasicAsyncResolverFactory>());
|
||||
|
||||
std::unique_ptr<AsyncDnsResolverInterface> resolver(factory.Create());
|
||||
ASSERT_TRUE(resolver);
|
||||
|
||||
bool address_resolved = false;
|
||||
rtc::SocketAddress address("", 0);
|
||||
resolver->Start(address, [&address_resolved]() { address_resolved = true; });
|
||||
ASSERT_TRUE_WAIT(address_resolved, 10000 /*ms*/);
|
||||
resolver.reset();
|
||||
}
|
||||
|
||||
TEST(WrappingAsyncDnsResolverFactoryTest, WrapOtherResolver) {
|
||||
rtc::AutoThread main_thread;
|
||||
BasicAsyncResolverFactory non_owned_factory;
|
||||
WrappingAsyncDnsResolverFactory factory(&non_owned_factory);
|
||||
std::unique_ptr<AsyncDnsResolverInterface> resolver(factory.Create());
|
||||
ASSERT_TRUE(resolver);
|
||||
|
||||
bool address_resolved = false;
|
||||
rtc::SocketAddress address("", 0);
|
||||
resolver->Start(address, [&address_resolved]() { address_resolved = true; });
|
||||
ASSERT_TRUE_WAIT(address_resolved, 10000 /*ms*/);
|
||||
resolver.reset();
|
||||
}
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST && defined(WEBRTC_LINUX)
|
||||
// Tests that the prohibition against deleting the resolver from the callback
|
||||
// is enforced. This is required by the use of sigslot in the wrapped resolver.
|
||||
// Checking the error message fails on a number of platforms, so run this
|
||||
// test only on the platforms where it works.
|
||||
void CallResolver(WrappingAsyncDnsResolverFactory& factory) {
|
||||
rtc::SocketAddress address("", 0);
|
||||
std::unique_ptr<AsyncDnsResolverInterface> resolver(factory.Create());
|
||||
resolver->Start(address, [&resolver]() { resolver.reset(); });
|
||||
WAIT(!resolver.get(), 10000 /*ms*/);
|
||||
}
|
||||
|
||||
TEST(WrappingAsyncDnsResolverFactoryDeathTest, DestroyResolverInCallback) {
|
||||
rtc::AutoThread main_thread;
|
||||
// TODO(bugs.webrtc.org/12652): Rewrite as death test in loop style when it
|
||||
// works.
|
||||
WrappingAsyncDnsResolverFactory factory(
|
||||
std::make_unique<BasicAsyncResolverFactory>());
|
||||
|
||||
// Since EXPECT_DEATH is thread sensitive, and the resolver creates a thread,
|
||||
// we wrap the whole creation section in EXPECT_DEATH.
|
||||
RTC_EXPECT_DEATH(CallResolver(factory),
|
||||
"Check failed: !within_resolve_result_");
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
// all tests were on deleted APIs
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/wrapping_async_dns_resolver.h"
|
||||
#include "p2p/base/async_stun_tcp_socket.h"
|
||||
#include "rtc_base/async_dns_resolver.h"
|
||||
#include "rtc_base/async_tcp_socket.h"
|
||||
|
@ -181,10 +180,6 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket(
|
|||
return tcp_socket;
|
||||
}
|
||||
|
||||
AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() {
|
||||
return new AsyncResolver();
|
||||
}
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface>
|
||||
BasicPacketSocketFactory::CreateAsyncDnsResolver() {
|
||||
return std::make_unique<webrtc::AsyncDnsResolver>();
|
||||
|
|
|
@ -48,10 +48,6 @@ class RTC_EXPORT BasicPacketSocketFactory : public PacketSocketFactory {
|
|||
const std::string& user_agent,
|
||||
const PacketSocketTcpOptions& tcp_options) override;
|
||||
|
||||
// TODO(bugs.webrtc.org/12598) Remove when downstream stops using it.
|
||||
ABSL_DEPRECATED("Use CreateAsyncDnsResolver")
|
||||
AsyncResolverInterface* CreateAsyncResolver() override;
|
||||
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAsyncDnsResolver()
|
||||
override;
|
||||
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 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 P2P_BASE_MOCK_ASYNC_RESOLVER_H_
|
||||
#define P2P_BASE_MOCK_ASYNC_RESOLVER_H_
|
||||
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
#include "test/gmock.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::InvokeWithoutArgs;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
class [[deprecated]] MockAsyncResolver : public AsyncResolverInterface {
|
||||
#pragma clang diagnostic pop
|
||||
public:
|
||||
MockAsyncResolver() {
|
||||
ON_CALL(*this, Start(_)).WillByDefault(InvokeWithoutArgs([this] {
|
||||
SignalDone(this);
|
||||
}));
|
||||
}
|
||||
~MockAsyncResolver() = default;
|
||||
|
||||
MOCK_METHOD(void, Start, (const rtc::SocketAddress&), (override));
|
||||
MOCK_METHOD(void, Start, (const rtc::SocketAddress&, int family), (override));
|
||||
MOCK_METHOD(bool,
|
||||
GetResolvedAddress,
|
||||
(int family, SocketAddress* addr),
|
||||
(const, override));
|
||||
MOCK_METHOD(int, GetError, (), (const, override));
|
||||
|
||||
// Note that this won't delete the object like AsyncResolverInterface says in
|
||||
// order to avoid sanitizer failures caused by this being a synchronous
|
||||
// implementation. The test code should delete the object instead.
|
||||
MOCK_METHOD(void, Destroy, (bool), (override));
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
class [[deprecated]] MockAsyncResolverFactory : public AsyncResolverFactory {
|
||||
public:
|
||||
MOCK_METHOD(rtc::AsyncResolverInterface*, Create, (), (override));
|
||||
};
|
||||
#pragma clang diagnostic pop
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // P2P_BASE_MOCK_ASYNC_RESOLVER_H_
|
|
@ -28,7 +28,6 @@
|
|||
#include "api/field_trials_view.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "logging/rtc_event_log/ice_logger.h"
|
||||
#include "p2p/base/basic_async_resolver_factory.h"
|
||||
#include "p2p/base/basic_ice_controller.h"
|
||||
#include "p2p/base/connection.h"
|
||||
#include "p2p/base/connection_info.h"
|
||||
|
@ -117,25 +116,11 @@ std::unique_ptr<P2PTransportChannel> P2PTransportChannel::Create(
|
|||
absl::string_view transport_name,
|
||||
int component,
|
||||
webrtc::IceTransportInit init) {
|
||||
// TODO(bugs.webrtc.org/12598): Remove pragma and fallback once
|
||||
// async_resolver_factory is gone
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (init.async_resolver_factory()) {
|
||||
return absl::WrapUnique(new P2PTransportChannel(
|
||||
transport_name, component, init.port_allocator(), nullptr,
|
||||
std::make_unique<webrtc::WrappingAsyncDnsResolverFactory>(
|
||||
init.async_resolver_factory()),
|
||||
init.event_log(), init.ice_controller_factory(),
|
||||
init.active_ice_controller_factory(), init.field_trials()));
|
||||
#pragma clang diagnostic pop
|
||||
} else {
|
||||
return absl::WrapUnique(new P2PTransportChannel(
|
||||
transport_name, component, init.port_allocator(),
|
||||
init.async_dns_resolver_factory(), nullptr, init.event_log(),
|
||||
init.ice_controller_factory(), init.active_ice_controller_factory(),
|
||||
init.field_trials()));
|
||||
}
|
||||
return absl::WrapUnique(new P2PTransportChannel(
|
||||
transport_name, component, init.port_allocator(),
|
||||
init.async_dns_resolver_factory(), nullptr, init.event_log(),
|
||||
init.ice_controller_factory(), init.active_ice_controller_factory(),
|
||||
init.field_trials()));
|
||||
}
|
||||
|
||||
P2PTransportChannel::P2PTransportChannel(
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/candidate.h"
|
||||
#include "api/ice_transport_interface.h"
|
||||
#include "api/rtc_error.h"
|
||||
|
@ -47,7 +46,6 @@
|
|||
#include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h"
|
||||
#include "logging/rtc_event_log/ice_logger.h"
|
||||
#include "p2p/base/active_ice_controller_factory_interface.h"
|
||||
#include "p2p/base/basic_async_resolver_factory.h"
|
||||
#include "p2p/base/candidate_pair_interface.h"
|
||||
#include "p2p/base/connection.h"
|
||||
#include "p2p/base/ice_agent_interface.h"
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "p2p/base/fake_port_allocator.h"
|
||||
#include "p2p/base/ice_transport_internal.h"
|
||||
#include "p2p/base/mock_active_ice_controller.h"
|
||||
#include "p2p/base/mock_async_resolver.h"
|
||||
#include "p2p/base/mock_ice_controller.h"
|
||||
#include "p2p/base/packet_transport_internal.h"
|
||||
#include "p2p/base/test_stun_server.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "p2p/base/connection.h"
|
||||
#include "p2p/base/p2p_constants.h"
|
||||
#include "p2p/base/port_allocator.h"
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/field_trial_parser.h"
|
||||
#include "rtc_base/helpers.h"
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
#include "rtc_base/net_helper.h"
|
||||
#include "rtc_base/network/received_packet.h"
|
||||
#include "rtc_base/rate_tracker.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
namespace cricket {
|
||||
using ::webrtc::SafeTask;
|
||||
|
|
|
@ -2419,6 +2419,7 @@ if (rtc_include_tests && !build_with_chromium) {
|
|||
":webrtc_sdp",
|
||||
"../api:array_view",
|
||||
"../api:audio_options_api",
|
||||
"../api:callfactory_api",
|
||||
"../api:candidate",
|
||||
"../api:create_peerconnection_factory",
|
||||
"../api:dtls_transport_interface",
|
||||
|
|
|
@ -578,31 +578,10 @@ RTCErrorOr<rtc::scoped_refptr<PeerConnection>> PeerConnection::Create(
|
|||
configuration.sdp_semantics == SdpSemantics::kUnifiedPlan;
|
||||
bool dtls_enabled = DtlsEnabled(configuration, options, dependencies);
|
||||
|
||||
// Interim code: If an AsyncResolverFactory is given, but not an
|
||||
// AsyncDnsResolverFactory, wrap it in a WrappingAsyncDnsResolverFactory
|
||||
// If neither is given, create a BasicAsyncDnsResolverFactory.
|
||||
// TODO(bugs.webrtc.org/12598): Remove code once all callers pass a
|
||||
// AsyncDnsResolverFactory.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (dependencies.async_dns_resolver_factory &&
|
||||
dependencies.async_resolver_factory) {
|
||||
RTC_LOG(LS_ERROR)
|
||||
<< "Attempt to set both old and new type of DNS resolver factory";
|
||||
return RTCError(RTCErrorType::INVALID_PARAMETER,
|
||||
"Both old and new type of DNS resolver given");
|
||||
}
|
||||
if (!dependencies.async_dns_resolver_factory) {
|
||||
if (dependencies.async_resolver_factory) {
|
||||
dependencies.async_dns_resolver_factory =
|
||||
std::make_unique<WrappingAsyncDnsResolverFactory>(
|
||||
std::move(dependencies.async_resolver_factory));
|
||||
} else {
|
||||
dependencies.async_dns_resolver_factory =
|
||||
std::make_unique<BasicAsyncDnsResolverFactory>();
|
||||
}
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// The PeerConnection constructor consumes some, but not all, dependencies.
|
||||
auto pc = rtc::make_ref_counted<PeerConnection>(
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <utility>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/call/call_factory_interface.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
|
@ -29,7 +28,6 @@
|
|||
#include "call/audio_state.h"
|
||||
#include "call/rtp_transport_controller_send_factory.h"
|
||||
#include "media/base/media_engine.h"
|
||||
#include "p2p/base/basic_async_resolver_factory.h"
|
||||
#include "p2p/base/basic_packet_socket_factory.h"
|
||||
#include "p2p/base/default_ice_transport_factory.h"
|
||||
#include "p2p/base/port_allocator.h"
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/call/call_factory_interface.h"
|
||||
#include "api/jsep.h"
|
||||
#include "api/jsep_session_description.h"
|
||||
#include "api/peer_connection_interface.h"
|
||||
|
@ -25,7 +25,6 @@
|
|||
#include "api/task_queue/task_queue_factory.h"
|
||||
#include "api/test/mock_async_dns_resolver.h"
|
||||
#include "media/base/media_engine.h"
|
||||
#include "p2p/base/mock_async_resolver.h"
|
||||
#include "p2p/base/port_allocator.h"
|
||||
#include "p2p/client/basic_port_allocator.h"
|
||||
#include "pc/peer_connection.h"
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/async_resolver_factory.h"
|
||||
#include "api/candidate.h"
|
||||
#include "api/crypto/crypto_options.h"
|
||||
#include "api/dtmf_sender_interface.h"
|
||||
|
@ -61,7 +60,6 @@
|
|||
#include "media/base/codec.h"
|
||||
#include "media/base/media_constants.h"
|
||||
#include "media/base/stream_params.h"
|
||||
#include "p2p/base/mock_async_resolver.h"
|
||||
#include "p2p/base/port.h"
|
||||
#include "p2p/base/port_allocator.h"
|
||||
#include "p2p/base/port_interface.h"
|
||||
|
|
|
@ -73,7 +73,6 @@
|
|||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "p2p/base/fake_ice_transport.h"
|
||||
#include "p2p/base/ice_transport_internal.h"
|
||||
#include "p2p/base/mock_async_resolver.h"
|
||||
#include "p2p/base/p2p_constants.h"
|
||||
#include "p2p/base/port.h"
|
||||
#include "p2p/base/port_allocator.h"
|
||||
|
|
|
@ -917,20 +917,6 @@ rtc_library("net_test_helpers") {
|
|||
}
|
||||
}
|
||||
|
||||
rtc_library("async_resolver_interface") {
|
||||
visibility = [ "*" ]
|
||||
sources = [
|
||||
"async_resolver_interface.cc",
|
||||
"async_resolver_interface.h",
|
||||
]
|
||||
deps = [
|
||||
":checks",
|
||||
":socket_address",
|
||||
"system:rtc_export",
|
||||
"third_party/sigslot",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_library("async_dns_resolver") {
|
||||
sources = [
|
||||
"async_dns_resolver.cc",
|
||||
|
@ -1029,8 +1015,6 @@ rtc_library("threading") {
|
|||
visibility = [ "*" ]
|
||||
|
||||
sources = [
|
||||
"async_resolver.cc",
|
||||
"async_resolver.h",
|
||||
"internal/default_socket_server.cc",
|
||||
"internal/default_socket_server.h",
|
||||
"network_monitor.cc",
|
||||
|
@ -1052,7 +1036,6 @@ rtc_library("threading") {
|
|||
]
|
||||
deps = [
|
||||
":async_dns_resolver",
|
||||
":async_resolver_interface",
|
||||
":byte_order",
|
||||
":checks",
|
||||
":criticalsection",
|
||||
|
@ -1754,6 +1737,7 @@ rtc_library("rtc_base_tests_utils") {
|
|||
"../api:make_ref_counted",
|
||||
"../api:refcountedbase",
|
||||
"../api:scoped_refptr",
|
||||
"../api:sequence_checker",
|
||||
"../api/task_queue",
|
||||
"../api/units:time_delta",
|
||||
"../api/units:timestamp",
|
||||
|
|
|
@ -1,239 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 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.
|
||||
*/
|
||||
|
||||
#include "rtc_base/async_resolver.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/ref_counted_base.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
#include <ws2spi.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include "rtc_base/win32.h"
|
||||
#endif
|
||||
#if defined(WEBRTC_POSIX) && !defined(__native_client__)
|
||||
#if defined(WEBRTC_ANDROID)
|
||||
#include "rtc_base/ifaddrs_android.h"
|
||||
#else
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
#endif // defined(WEBRTC_POSIX) && !defined(__native_client__)
|
||||
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
#include "rtc_base/ip_address.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/platform_thread.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/third_party/sigslot/sigslot.h" // for signal_with_thread...
|
||||
|
||||
#if defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
|
||||
#include <dispatch/dispatch.h>
|
||||
#endif
|
||||
|
||||
namespace rtc {
|
||||
|
||||
#if defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
|
||||
namespace {
|
||||
|
||||
void GlobalGcdRunTask(void* context) {
|
||||
std::unique_ptr<absl::AnyInvocable<void() &&>> task(
|
||||
static_cast<absl::AnyInvocable<void() &&>*>(context));
|
||||
std::move (*task)();
|
||||
}
|
||||
|
||||
// Post a task into the system-defined global concurrent queue.
|
||||
void PostTaskToGlobalQueue(
|
||||
std::unique_ptr<absl::AnyInvocable<void() &&>> task) {
|
||||
dispatch_async_f(
|
||||
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||
task.release(), &GlobalGcdRunTask);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
int ResolveHostname(absl::string_view hostname,
|
||||
int family,
|
||||
std::vector<IPAddress>* addresses) {
|
||||
#ifdef __native_client__
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
RTC_LOG(LS_WARNING) << "ResolveHostname() is not implemented for NaCl";
|
||||
return -1;
|
||||
#else // __native_client__
|
||||
if (!addresses) {
|
||||
return -1;
|
||||
}
|
||||
addresses->clear();
|
||||
struct addrinfo* result = nullptr;
|
||||
struct addrinfo hints = {0};
|
||||
hints.ai_family = family;
|
||||
// `family` here will almost always be AF_UNSPEC, because `family` comes from
|
||||
// AsyncResolver::addr_.family(), which comes from a SocketAddress constructed
|
||||
// with a hostname. When a SocketAddress is constructed with a hostname, its
|
||||
// family is AF_UNSPEC. However, if someday in the future we construct
|
||||
// a SocketAddress with both a hostname and a family other than AF_UNSPEC,
|
||||
// then it would be possible to get a specific family value here.
|
||||
|
||||
// The behavior of AF_UNSPEC is roughly "get both ipv4 and ipv6", as
|
||||
// documented by the various operating systems:
|
||||
// Linux: http://man7.org/linux/man-pages/man3/getaddrinfo.3.html
|
||||
// Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/
|
||||
// ms738520(v=vs.85).aspx
|
||||
// Mac: https://developer.apple.com/legacy/library/documentation/Darwin/
|
||||
// Reference/ManPages/man3/getaddrinfo.3.html
|
||||
// Android (source code, not documentation):
|
||||
// https://android.googlesource.com/platform/bionic/+/
|
||||
// 7e0bfb511e85834d7c6cb9631206b62f82701d60/libc/netbsd/net/getaddrinfo.c#1657
|
||||
hints.ai_flags = AI_ADDRCONFIG;
|
||||
int ret =
|
||||
getaddrinfo(std::string(hostname).c_str(), nullptr, &hints, &result);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
struct addrinfo* cursor = result;
|
||||
for (; cursor; cursor = cursor->ai_next) {
|
||||
if (family == AF_UNSPEC || cursor->ai_family == family) {
|
||||
IPAddress ip;
|
||||
if (IPFromAddrInfo(cursor, &ip)) {
|
||||
addresses->push_back(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
freeaddrinfo(result);
|
||||
return 0;
|
||||
#endif // !__native_client__
|
||||
}
|
||||
|
||||
struct AsyncResolver::State : public RefCountedBase {
|
||||
webrtc::Mutex mutex;
|
||||
enum class Status {
|
||||
kLive,
|
||||
kDead
|
||||
} status RTC_GUARDED_BY(mutex) = Status::kLive;
|
||||
};
|
||||
|
||||
AsyncResolver::AsyncResolver() : error_(-1), state_(new State) {}
|
||||
|
||||
AsyncResolver::~AsyncResolver() {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
|
||||
// Ensure the thread isn't using a stale reference to the current task queue,
|
||||
// or calling into ResolveDone post destruction.
|
||||
webrtc::MutexLock lock(&state_->mutex);
|
||||
state_->status = State::Status::kDead;
|
||||
}
|
||||
|
||||
void RunResolution(void* obj) {
|
||||
std::function<void()>* function_ptr =
|
||||
static_cast<std::function<void()>*>(obj);
|
||||
(*function_ptr)();
|
||||
delete function_ptr;
|
||||
}
|
||||
|
||||
void AsyncResolver::Start(const SocketAddress& addr) {
|
||||
Start(addr, addr.family());
|
||||
}
|
||||
|
||||
void AsyncResolver::Start(const SocketAddress& addr, int family) {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK(!destroy_called_);
|
||||
addr_ = addr;
|
||||
auto thread_function = [this, addr, family,
|
||||
caller_task_queue = webrtc::TaskQueueBase::Current(),
|
||||
state = state_] {
|
||||
std::vector<IPAddress> addresses;
|
||||
int error = ResolveHostname(addr.hostname(), family, &addresses);
|
||||
webrtc::MutexLock lock(&state->mutex);
|
||||
if (state->status == State::Status::kLive) {
|
||||
caller_task_queue->PostTask(
|
||||
[this, error, addresses = std::move(addresses), state] {
|
||||
bool live;
|
||||
{
|
||||
// ResolveDone can lead to instance destruction, so make sure
|
||||
// we don't deadlock.
|
||||
webrtc::MutexLock lock(&state->mutex);
|
||||
live = state->status == State::Status::kLive;
|
||||
}
|
||||
if (live) {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
ResolveDone(std::move(addresses), error);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
#if defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
|
||||
PostTaskToGlobalQueue(
|
||||
std::make_unique<absl::AnyInvocable<void() &&>>(thread_function));
|
||||
#else
|
||||
PlatformThread::SpawnDetached(std::move(thread_function), "AsyncResolver");
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AsyncResolver::GetResolvedAddress(int family, SocketAddress* addr) const {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK(!destroy_called_);
|
||||
if (error_ != 0 || addresses_.empty())
|
||||
return false;
|
||||
|
||||
*addr = addr_;
|
||||
for (size_t i = 0; i < addresses_.size(); ++i) {
|
||||
if (family == addresses_[i].family()) {
|
||||
addr->SetResolvedIP(addresses_[i]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int AsyncResolver::GetError() const {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK(!destroy_called_);
|
||||
return error_;
|
||||
}
|
||||
|
||||
void AsyncResolver::Destroy(bool wait) {
|
||||
// Some callers have trouble guaranteeing that Destroy is called on the
|
||||
// sequence guarded by `sequence_checker_`.
|
||||
// RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK(!destroy_called_);
|
||||
destroy_called_ = true;
|
||||
MaybeSelfDestruct();
|
||||
}
|
||||
|
||||
const std::vector<IPAddress>& AsyncResolver::addresses() const {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
RTC_DCHECK(!destroy_called_);
|
||||
return addresses_;
|
||||
}
|
||||
|
||||
void AsyncResolver::ResolveDone(std::vector<IPAddress> addresses, int error) {
|
||||
addresses_ = addresses;
|
||||
error_ = error;
|
||||
recursion_check_ = true;
|
||||
SignalDone(this);
|
||||
MaybeSelfDestruct();
|
||||
}
|
||||
|
||||
void AsyncResolver::MaybeSelfDestruct() {
|
||||
if (!recursion_check_) {
|
||||
delete this;
|
||||
} else {
|
||||
recursion_check_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rtc
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 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 RTC_BASE_ASYNC_RESOLVER_H_
|
||||
#define RTC_BASE_ASYNC_RESOLVER_H_
|
||||
|
||||
#if defined(WEBRTC_POSIX)
|
||||
#include <sys/socket.h>
|
||||
#elif WEBRTC_WIN
|
||||
#include <winsock2.h> // NOLINT
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/sequence_checker.h"
|
||||
#include "api/task_queue/pending_task_safety_flag.h"
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/ip_address.h"
|
||||
#include "rtc_base/socket_address.h"
|
||||
#include "rtc_base/system/no_unique_address.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// AsyncResolver will perform async DNS resolution, signaling the result on
|
||||
// the SignalDone from AsyncResolverInterface when the operation completes.
|
||||
//
|
||||
// This class is thread-compatible, and all methods and destruction needs to
|
||||
// happen from the same rtc::Thread, except for Destroy which is allowed to
|
||||
// happen on another context provided it's not happening concurrently to another
|
||||
// public API call, and is the last access to the object.
|
||||
// TODO(bugs.webrtc.org/12598): Deprecate and remove
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wstrict-aliasing"
|
||||
class [[deprecated("Use AsyncDnsResolver")]] RTC_EXPORT AsyncResolver
|
||||
: public AsyncResolverInterface {
|
||||
#pragma clang diagnostic pop
|
||||
public:
|
||||
AsyncResolver();
|
||||
~AsyncResolver() override;
|
||||
|
||||
void Start(const SocketAddress& addr) override;
|
||||
void Start(const SocketAddress& addr, int family) override;
|
||||
bool GetResolvedAddress(int family, SocketAddress* addr) const override;
|
||||
int GetError() const override;
|
||||
void Destroy(bool wait) override;
|
||||
|
||||
const std::vector<IPAddress>& addresses() const;
|
||||
|
||||
private:
|
||||
// Fwd decl.
|
||||
struct State;
|
||||
|
||||
void ResolveDone(std::vector<IPAddress> addresses, int error)
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(sequence_checker_);
|
||||
void MaybeSelfDestruct();
|
||||
|
||||
SocketAddress addr_ RTC_GUARDED_BY(sequence_checker_);
|
||||
std::vector<IPAddress> addresses_ RTC_GUARDED_BY(sequence_checker_);
|
||||
int error_ RTC_GUARDED_BY(sequence_checker_);
|
||||
bool recursion_check_ =
|
||||
false; // Protects against SignalDone calling into Destroy.
|
||||
bool destroy_called_ = false;
|
||||
scoped_refptr<State> state_;
|
||||
RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker sequence_checker_;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_ASYNC_RESOLVER_H_
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 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.
|
||||
*/
|
||||
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
AsyncResolverInterface::AsyncResolverInterface() {}
|
||||
|
||||
AsyncResolverInterface::~AsyncResolverInterface() = default;
|
||||
|
||||
} // namespace rtc
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 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 RTC_BASE_ASYNC_RESOLVER_INTERFACE_H_
|
||||
#define RTC_BASE_ASYNC_RESOLVER_INTERFACE_H_
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/socket_address.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// This interface defines the methods to resolve the address asynchronously.
|
||||
// TODO(bugs.webrtc.org/12598): Deprecate and remove.
|
||||
class [[deprecated("Use AsyncDnsResolver")]] RTC_EXPORT AsyncResolverInterface {
|
||||
public:
|
||||
AsyncResolverInterface();
|
||||
virtual ~AsyncResolverInterface();
|
||||
|
||||
// Start address resolution of the hostname in `addr`.
|
||||
virtual void Start(const SocketAddress& addr) = 0;
|
||||
// Start address resolution of the hostname in `addr` matching `family`.
|
||||
virtual void Start(const SocketAddress& addr, int family) = 0;
|
||||
// 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, SocketAddress* addr) const = 0;
|
||||
// Returns error from resolver.
|
||||
virtual int GetError() const = 0;
|
||||
// Delete the resolver.
|
||||
virtual void Destroy(bool wait) = 0;
|
||||
// Returns top most resolved IPv4 address if address is resolved successfully.
|
||||
// Otherwise returns address set in SetAddress.
|
||||
SocketAddress address() const {
|
||||
SocketAddress addr;
|
||||
GetResolvedAddress(AF_INET, &addr);
|
||||
return addr;
|
||||
}
|
||||
|
||||
// This signal is fired when address resolve process is completed.
|
||||
sigslot::signal1<AsyncResolverInterface*> SignalDone;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif
|
|
@ -41,8 +41,6 @@
|
|||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "rtc_base/async_resolver.h"
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
#include "rtc_base/deprecated/recursive_critical_section.h"
|
||||
#include "rtc_base/socket_server.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "api/sequence_checker.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/event.h"
|
||||
|
|
|
@ -52,6 +52,7 @@ if (rtc_enable_protobuf) {
|
|||
"../../rtc_base:protobuf_utils",
|
||||
"../../rtc_base:rtc_task_queue",
|
||||
"../../rtc_base:socket_address",
|
||||
"../../rtc_base:socket_server",
|
||||
"../../rtc_base:threading",
|
||||
"../../rtc_base:timeutils",
|
||||
"../../rtc_base/synchronization:mutex",
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
#include "rtc_base/null_socket_server.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "rtc_tools/network_tester/test_controller.h"
|
||||
|
||||
int main(int /*argn*/, char* /*argv*/[]) {
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
#include "p2p/base/basic_packet_socket_factory.h"
|
||||
#include "rtc_base/async_packet_socket.h"
|
||||
#include "rtc_base/socket_address.h"
|
||||
#include "rtc_base/socket_server.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "rtc_base/system/no_unique_address.h"
|
||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
#include "rtc_tools/network_tester/packet_logger.h"
|
||||
#include "rtc_tools/network_tester/packet_sender.h"
|
||||
|
|
Loading…
Reference in a new issue