Bug 1554976 - Add methods to register/unregister mDNS hostnames to StunAddrsRequestParent; r=mjf

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dan Minor 2019-08-28 13:11:11 +00:00
Родитель b9e2e7f9b3
Коммит 6803a86c10
3 изменённых файлов: 59 добавлений и 3 удалений

Просмотреть файл

@ -18,6 +18,9 @@ async protocol PStunAddrsRequest
parent: parent:
async GetStunAddrs(); async GetStunAddrs();
async RegisterMDNSHostname(nsCString hostname, nsCString address);
async UnregisterMDNSHostname(nsCString hostname);
async __delete__(); async __delete__();
child: child:

Просмотреть файл

@ -11,12 +11,15 @@
#include "mtransport/nricemediastream.h" // needed only for including nricectx.h #include "mtransport/nricemediastream.h" // needed only for including nricectx.h
#include "mtransport/nricestunaddr.h" #include "mtransport/nricestunaddr.h"
#include "../mdns_service/mdns_service.h"
using namespace mozilla::ipc; using namespace mozilla::ipc;
namespace mozilla { namespace mozilla {
namespace net { namespace net {
StunAddrsRequestParent::StunAddrsRequestParent() : mIPCClosed(false) { StunAddrsRequestParent::StunAddrsRequestParent()
: mIPCClosed(false), mMDNSService(nullptr) {
NS_GetMainThread(getter_AddRefs(mMainThread)); NS_GetMainThread(getter_AddRefs(mMainThread));
nsresult res; nsresult res;
@ -24,6 +27,13 @@ StunAddrsRequestParent::StunAddrsRequestParent() : mIPCClosed(false) {
MOZ_ASSERT(mSTSThread); MOZ_ASSERT(mSTSThread);
} }
StunAddrsRequestParent::~StunAddrsRequestParent() {
if (mMDNSService) {
mdns_service_stop(mMDNSService);
mMDNSService = nullptr;
}
}
mozilla::ipc::IPCResult StunAddrsRequestParent::RecvGetStunAddrs() { mozilla::ipc::IPCResult StunAddrsRequestParent::RecvGetStunAddrs() {
ASSERT_ON_THREAD(mMainThread); ASSERT_ON_THREAD(mMainThread);
@ -39,6 +49,41 @@ mozilla::ipc::IPCResult StunAddrsRequestParent::RecvGetStunAddrs() {
return IPC_OK(); return IPC_OK();
} }
mozilla::ipc::IPCResult StunAddrsRequestParent::RecvRegisterMDNSHostname(
const nsCString& aHostname, const nsCString& aAddress) {
ASSERT_ON_THREAD(mMainThread);
if (mIPCClosed) {
return IPC_OK();
}
if (!mMDNSService) {
mMDNSService = mdns_service_start();
}
if (mMDNSService) {
mdns_service_register_hostname(mMDNSService, aHostname.BeginReading(),
aAddress.BeginReading());
}
return IPC_OK();
}
mozilla::ipc::IPCResult StunAddrsRequestParent::RecvUnregisterMDNSHostname(
const nsCString& aHostname) {
ASSERT_ON_THREAD(mMainThread);
if (mIPCClosed) {
return IPC_OK();
}
if (mMDNSService) {
mdns_service_unregister_hostname(mMDNSService, aHostname.BeginReading());
}
return IPC_OK();
}
mozilla::ipc::IPCResult StunAddrsRequestParent::Recv__delete__() { mozilla::ipc::IPCResult StunAddrsRequestParent::Recv__delete__() {
// see note below in ActorDestroy // see note below in ActorDestroy
mIPCClosed = true; mIPCClosed = true;
@ -79,7 +124,6 @@ void StunAddrsRequestParent::SendStunAddrs_m(const NrIceStunAddrArray& addrs) {
return; return;
} }
mIPCClosed = true;
// send the new addresses back to the child // send the new addresses back to the child
Unused << SendOnStunAddrsAvailable(addrs); Unused << SendOnStunAddrsAvailable(addrs);
} }

Просмотреть файл

@ -7,6 +7,11 @@
#include "mozilla/net/PStunAddrsRequestParent.h" #include "mozilla/net/PStunAddrsRequestParent.h"
#include "nsICancelable.h"
#include "nsIDNSServiceDiscovery.h"
struct MDNSService;
namespace mozilla { namespace mozilla {
namespace net { namespace net {
@ -22,9 +27,11 @@ class StunAddrsRequestParent : public PStunAddrsRequestParent {
mozilla::ipc::IPCResult Recv__delete__() override; mozilla::ipc::IPCResult Recv__delete__() override;
protected: protected:
virtual ~StunAddrsRequestParent() {} virtual ~StunAddrsRequestParent();
virtual mozilla::ipc::IPCResult RecvGetStunAddrs() override; virtual mozilla::ipc::IPCResult RecvGetStunAddrs() override;
virtual mozilla::ipc::IPCResult RecvRegisterMDNSHostname(const nsCString& hostname, const nsCString& address) override;
virtual mozilla::ipc::IPCResult RecvUnregisterMDNSHostname(const nsCString& hostname) override;
virtual void ActorDestroy(ActorDestroyReason why) override; virtual void ActorDestroy(ActorDestroyReason why) override;
nsCOMPtr<nsIThread> mMainThread; nsCOMPtr<nsIThread> mMainThread;
@ -38,6 +45,8 @@ class StunAddrsRequestParent : public PStunAddrsRequestParent {
private: private:
bool mIPCClosed; // true if IPDL channel has been closed (child crash) bool mIPCClosed; // true if IPDL channel has been closed (child crash)
MDNSService* mMDNSService;
}; };
} // namespace net } // namespace net