Use AsyncDnsResolver in TurnPort class
Bug: webrtc:12598 Change-Id: Ie53c27d3a614521f4a8b665fd321b1db53dc70b1 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/234261 Reviewed-by: Markus Handell <handellm@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35148}
This commit is contained in:
parent
b7b306bab5
commit
c9f43f8f81
@ -230,7 +230,6 @@ TurnPort::TurnPort(rtc::Thread* thread,
|
||||
tls_cert_verifier_(nullptr),
|
||||
credentials_(credentials),
|
||||
socket_(socket),
|
||||
resolver_(NULL),
|
||||
error_(0),
|
||||
stun_dscp_value_(rtc::DSCP_NO_CHANGE),
|
||||
request_manager_(thread),
|
||||
@ -272,7 +271,6 @@ TurnPort::TurnPort(rtc::Thread* thread,
|
||||
tls_cert_verifier_(tls_cert_verifier),
|
||||
credentials_(credentials),
|
||||
socket_(NULL),
|
||||
resolver_(NULL),
|
||||
error_(0),
|
||||
stun_dscp_value_(rtc::DSCP_NO_CHANGE),
|
||||
request_manager_(thread),
|
||||
@ -297,9 +295,6 @@ TurnPort::~TurnPort() {
|
||||
while (!entries_.empty()) {
|
||||
DestroyEntry(entries_.front());
|
||||
}
|
||||
if (resolver_) {
|
||||
resolver_->Destroy(false);
|
||||
}
|
||||
if (!SharedSocket()) {
|
||||
delete socket_;
|
||||
}
|
||||
@ -797,44 +792,43 @@ void TurnPort::ResolveTurnAddress(const rtc::SocketAddress& address) {
|
||||
|
||||
RTC_LOG(LS_INFO) << ToString() << ": Starting TURN host lookup for "
|
||||
<< address.ToSensitiveString();
|
||||
resolver_ = socket_factory()->CreateAsyncResolver();
|
||||
resolver_->SignalDone.connect(this, &TurnPort::OnResolveResult);
|
||||
resolver_->Start(address);
|
||||
}
|
||||
resolver_ = socket_factory()->CreateAsyncDnsResolver();
|
||||
resolver_->Start(address, [this] {
|
||||
// If DNS resolve is failed when trying to connect to the server using TCP,
|
||||
// one of the reason could be due to DNS queries blocked by firewall.
|
||||
// In such cases we will try to connect to the server with hostname,
|
||||
// assuming socket layer will resolve the hostname through a HTTP proxy (if
|
||||
// any).
|
||||
auto& result = resolver_->result();
|
||||
if (result.GetError() != 0 && (server_address_.proto == PROTO_TCP ||
|
||||
server_address_.proto == PROTO_TLS)) {
|
||||
if (!CreateTurnClientSocket()) {
|
||||
OnAllocateError(SERVER_NOT_REACHABLE_ERROR,
|
||||
"TURN host lookup received error.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void TurnPort::OnResolveResult(rtc::AsyncResolverInterface* resolver) {
|
||||
RTC_DCHECK(resolver == resolver_);
|
||||
// If DNS resolve is failed when trying to connect to the server using TCP,
|
||||
// one of the reason could be due to DNS queries blocked by firewall.
|
||||
// In such cases we will try to connect to the server with hostname, assuming
|
||||
// socket layer will resolve the hostname through a HTTP proxy (if any).
|
||||
if (resolver_->GetError() != 0 && (server_address_.proto == PROTO_TCP ||
|
||||
server_address_.proto == PROTO_TLS)) {
|
||||
if (!CreateTurnClientSocket()) {
|
||||
// Copy the original server address in `resolved_address`. For TLS based
|
||||
// sockets we need hostname along with resolved address.
|
||||
rtc::SocketAddress resolved_address = server_address_.address;
|
||||
if (result.GetError() != 0 ||
|
||||
!result.GetResolvedAddress(Network()->GetBestIP().family(),
|
||||
&resolved_address)) {
|
||||
RTC_LOG(LS_WARNING) << ToString() << ": TURN host lookup received error "
|
||||
<< result.GetError();
|
||||
error_ = result.GetError();
|
||||
OnAllocateError(SERVER_NOT_REACHABLE_ERROR,
|
||||
"TURN host lookup received error.");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy the original server address in `resolved_address`. For TLS based
|
||||
// sockets we need hostname along with resolved address.
|
||||
rtc::SocketAddress resolved_address = server_address_.address;
|
||||
if (resolver_->GetError() != 0 ||
|
||||
!resolver_->GetResolvedAddress(Network()->GetBestIP().family(),
|
||||
&resolved_address)) {
|
||||
RTC_LOG(LS_WARNING) << ToString() << ": TURN host lookup received error "
|
||||
<< resolver_->GetError();
|
||||
error_ = resolver_->GetError();
|
||||
OnAllocateError(SERVER_NOT_REACHABLE_ERROR,
|
||||
"TURN host lookup received error.");
|
||||
return;
|
||||
}
|
||||
// Signal needs both resolved and unresolved address. After signal is sent
|
||||
// we can copy resolved address back into `server_address_`.
|
||||
SignalResolvedServerAddress(this, server_address_.address, resolved_address);
|
||||
server_address_.address = resolved_address;
|
||||
PrepareAddress();
|
||||
// Signal needs both resolved and unresolved address. After signal is sent
|
||||
// we can copy resolved address back into `server_address_`.
|
||||
SignalResolvedServerAddress(this, server_address_.address,
|
||||
resolved_address);
|
||||
server_address_.address = resolved_address;
|
||||
PrepareAddress();
|
||||
});
|
||||
}
|
||||
|
||||
void TurnPort::OnSendStunPacket(const void* data,
|
||||
|
||||
@ -21,10 +21,10 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "p2p/base/port.h"
|
||||
#include "p2p/client/basic_port_allocator.h"
|
||||
#include "rtc_base/async_packet_socket.h"
|
||||
#include "rtc_base/async_resolver_interface.h"
|
||||
#include "rtc_base/ssl_certificate.h"
|
||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||
|
||||
@ -392,7 +392,7 @@ class TurnPort : public Port {
|
||||
|
||||
rtc::AsyncPacketSocket* socket_;
|
||||
SocketOptionsMap socket_options_;
|
||||
rtc::AsyncResolverInterface* resolver_;
|
||||
std::unique_ptr<webrtc::AsyncDnsResolverInterface> resolver_;
|
||||
int error_;
|
||||
rtc::DiffServCodePoint stun_dscp_value_;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user