| Index: webrtc/p2p/base/stunport.cc
|
| diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc
|
| index 1598fe43cea80a91c98b897cf48cb19c07ef2638..fa665de55fa87969aa247bc7b98a60277cd92cd4 100644
|
| --- a/webrtc/p2p/base/stunport.cc
|
| +++ b/webrtc/p2p/base/stunport.cc
|
| @@ -13,6 +13,7 @@
|
| #include "webrtc/p2p/base/common.h"
|
| #include "webrtc/p2p/base/portallocator.h"
|
| #include "webrtc/p2p/base/stun.h"
|
| +#include "webrtc/base/checks.h"
|
| #include "webrtc/base/common.h"
|
| #include "webrtc/base/helpers.h"
|
| #include "webrtc/base/ipaddress.h"
|
| @@ -166,15 +167,19 @@ UDPPort::UDPPort(rtc::Thread* thread,
|
| const std::string& username,
|
| const std::string& password,
|
| const std::string& origin,
|
| - bool emit_localhost_for_anyaddress)
|
| - : Port(thread, factory, network, socket->GetLocalAddress().ipaddr(),
|
| - username, password),
|
| + bool emit_local_for_anyaddress)
|
| + : Port(thread,
|
| + factory,
|
| + network,
|
| + socket->GetLocalAddress().ipaddr(),
|
| + username,
|
| + password),
|
| requests_(thread),
|
| socket_(socket),
|
| error_(0),
|
| ready_(false),
|
| stun_keepalive_delay_(KEEPALIVE_DELAY),
|
| - emit_localhost_for_anyaddress_(emit_localhost_for_anyaddress) {
|
| + emit_local_for_anyaddress_(emit_local_for_anyaddress) {
|
| requests_.set_origin(origin);
|
| }
|
|
|
| @@ -187,7 +192,7 @@ UDPPort::UDPPort(rtc::Thread* thread,
|
| const std::string& username,
|
| const std::string& password,
|
| const std::string& origin,
|
| - bool emit_localhost_for_anyaddress)
|
| + bool emit_local_for_anyaddress)
|
| : Port(thread,
|
| LOCAL_PORT_TYPE,
|
| factory,
|
| @@ -202,7 +207,7 @@ UDPPort::UDPPort(rtc::Thread* thread,
|
| error_(0),
|
| ready_(false),
|
| stun_keepalive_delay_(KEEPALIVE_DELAY),
|
| - emit_localhost_for_anyaddress_(emit_localhost_for_anyaddress) {
|
| + emit_local_for_anyaddress_(emit_local_for_anyaddress) {
|
| requests_.set_origin(origin);
|
| }
|
|
|
| @@ -294,13 +299,11 @@ int UDPPort::GetError() {
|
| void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket,
|
| const rtc::SocketAddress& address) {
|
| // When adapter enumeration is disabled and binding to the any address, the
|
| - // loopback address will be issued as a candidate instead if
|
| - // |emit_localhost_for_anyaddress| is true. This is to allow connectivity on
|
| - // demo pages without STUN/TURN to work.
|
| + // default local address will be issued as a candidate instead if
|
| + // |emit_local_for_anyaddress| is true. This is to allow connectivity for
|
| + // applications which absolutely requires a HOST candidate.
|
| rtc::SocketAddress addr = address;
|
| - if (addr.IsAnyIP() && emit_localhost_for_anyaddress_) {
|
| - addr.SetIP(rtc::GetLoopbackIP(addr.family()));
|
| - }
|
| + MaybeSetDefaultLocalAddress(&addr);
|
|
|
| AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "",
|
| LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, false);
|
| @@ -398,6 +401,19 @@ void UDPPort::SendStunBindingRequest(
|
| }
|
| }
|
|
|
| +void UDPPort::MaybeSetDefaultLocalAddress(rtc::SocketAddress* addr) const {
|
| + if (!addr->IsAnyIP() || !emit_local_for_anyaddress_ ||
|
| + !Network()->default_local_address_provider()) {
|
| + return;
|
| + }
|
| + rtc::IPAddress default_address;
|
| + bool result =
|
| + Network()->default_local_address_provider()->GetDefaultLocalAddress(
|
| + addr->family(), &default_address);
|
| + RTC_DCHECK(result && !default_address.IsNil());
|
| + addr->SetIP(default_address);
|
| +}
|
| +
|
| void UDPPort::OnStunBindingRequestSucceeded(
|
| const rtc::SocketAddress& stun_server_addr,
|
| const rtc::SocketAddress& stun_reflected_addr) {
|
| @@ -415,6 +431,7 @@ void UDPPort::OnStunBindingRequestSucceeded(
|
| !HasCandidateWithAddress(stun_reflected_addr)) {
|
|
|
| rtc::SocketAddress related_address = socket_->GetLocalAddress();
|
| + MaybeSetDefaultLocalAddress(&related_address);
|
| if (!(candidate_filter() & CF_HOST)) {
|
| // If candidate filter doesn't have CF_HOST specified, empty raddr to
|
| // avoid local address leakage.
|
|
|