Bug 1605815 - Defer registering hostnames until StartIceChecks; r=mjf

Currently we register mDNS hostnames when we gather the local interfaces. By
waiting until StartIceChecks is called, it is less likely that we will end up
starting the mdns_service for a site which is not using WebRTC for
communication. This is more efficient, and avoids surprises like triggering
the Windows Firewall dialog for sites which are using WebRTC to gather local
IP addresses.

Differential Revision: https://phabricator.services.mozilla.com/D59765

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dan Minor 2020-01-13 23:05:25 +00:00
parent fff6c9e1ac
commit 65d8a501e7
2 changed files with 30 additions and 8 deletions

View File

@ -282,6 +282,18 @@ nsresult PeerConnectionMedia::UpdateMediaPipelines() {
}
void PeerConnectionMedia::StartIceChecks(const JsepSession& aSession) {
ASSERT_ON_THREAD(mMainThread);
if (!mCanRegisterMDNSHostnamesDirectly) {
for (auto& pair : mMDNSHostnamesToRegister) {
mRegisteredMDNSHostnames.insert(pair.first);
mStunAddrsRequest->SendRegisterMDNSHostname(
nsCString(pair.first.c_str()), nsCString(pair.second.c_str()));
}
mMDNSHostnamesToRegister.clear();
mCanRegisterMDNSHostnamesDirectly = true;
}
std::vector<std::string> attributes;
if (aSession.RemoteIsIceLite()) {
attributes.push_back("ice-lite");
@ -835,15 +847,20 @@ void PeerConnectionMedia::OnCandidateFound_m(
if (mStunAddrsRequest && !aCandidateInfo.mMDNSAddress.empty()) {
MOZ_ASSERT(!aCandidateInfo.mActualAddress.empty());
auto itor = mRegisteredMDNSHostnames.find(aCandidateInfo.mMDNSAddress);
if (mCanRegisterMDNSHostnamesDirectly) {
auto itor = mRegisteredMDNSHostnames.find(aCandidateInfo.mMDNSAddress);
// We'll see the address twice if we're generating both UDP and TCP
// candidates.
if (itor == mRegisteredMDNSHostnames.end()) {
mRegisteredMDNSHostnames.insert(aCandidateInfo.mMDNSAddress);
mStunAddrsRequest->SendRegisterMDNSHostname(
nsCString(aCandidateInfo.mMDNSAddress.c_str()),
nsCString(aCandidateInfo.mActualAddress.c_str()));
// We'll see the address twice if we're generating both UDP and TCP
// candidates.
if (itor == mRegisteredMDNSHostnames.end()) {
mRegisteredMDNSHostnames.insert(aCandidateInfo.mMDNSAddress);
mStunAddrsRequest->SendRegisterMDNSHostname(
nsCString(aCandidateInfo.mMDNSAddress.c_str()),
nsCString(aCandidateInfo.mActualAddress.c_str()));
}
} else {
mMDNSHostnamesToRegister.emplace(aCandidateInfo.mMDNSAddress,
aCandidateInfo.mActualAddress);
}
}

View File

@ -241,6 +241,11 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
// Set to true when the object is going to be released.
bool mDestroyed;
// Keep track of local hostnames to register. Registration is deferred
// until StartIceChecks has run. Accessed on main thread only.
std::map<std::string, std::string> mMDNSHostnamesToRegister;
bool mCanRegisterMDNSHostnamesDirectly = false;
// Used to store the mDNS hostnames that we have registered
std::set<std::string> mRegisteredMDNSHostnames;