StunAddrsRequestParent.h (2481B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef mozilla_net_StunAddrsRequestParent_h 6 #define mozilla_net_StunAddrsRequestParent_h 7 8 #include "mozilla/net/PStunAddrsRequestParent.h" 9 10 struct MDNSService; 11 12 namespace mozilla::net { 13 14 class StunAddrsRequestParent : public PStunAddrsRequestParent { 15 friend class PStunAddrsRequestParent; 16 17 public: 18 StunAddrsRequestParent(); 19 20 NS_IMETHOD_(MozExternalRefCountType) AddRef(); 21 NS_IMETHOD_(MozExternalRefCountType) Release(); 22 23 mozilla::ipc::IPCResult Recv__delete__() override; 24 25 void OnQueryComplete(const nsACString& hostname, 26 const Maybe<nsCString>& address); 27 28 protected: 29 virtual ~StunAddrsRequestParent(); 30 31 virtual mozilla::ipc::IPCResult RecvGetStunAddrs() override; 32 virtual mozilla::ipc::IPCResult RecvRegisterMDNSHostname( 33 const nsACString& hostname, const nsACString& address) override; 34 virtual mozilla::ipc::IPCResult RecvQueryMDNSHostname( 35 const nsACString& hostname) override; 36 virtual mozilla::ipc::IPCResult RecvUnregisterMDNSHostname( 37 const nsACString& hostname) override; 38 virtual void ActorDestroy(ActorDestroyReason why) override; 39 40 nsCOMPtr<nsIThread> mMainThread; 41 nsCOMPtr<nsISerialEventTarget> mSTSThread; 42 43 void GetStunAddrs_s(); 44 void SendStunAddrs_m(const NrIceStunAddrArray& addrs); 45 46 void OnQueryComplete_m(const nsACString& hostname, 47 const Maybe<nsCString>& address); 48 49 ThreadSafeAutoRefCnt mRefCnt; 50 NS_DECL_OWNINGTHREAD 51 52 private: 53 bool mIPCClosed; // true if IPDL channel has been closed (child crash) 54 55 class MDNSServiceWrapper { 56 public: 57 explicit MDNSServiceWrapper(const std::string& ifaddr); 58 void RegisterHostname(const char* hostname, const char* address); 59 void QueryHostname(void* data, const char* hostname); 60 void UnregisterHostname(const char* hostname); 61 62 NS_IMETHOD_(MozExternalRefCountType) AddRef(); 63 NS_IMETHOD_(MozExternalRefCountType) Release(); 64 65 protected: 66 ThreadSafeAutoRefCnt mRefCnt; 67 NS_DECL_OWNINGTHREAD 68 69 private: 70 virtual ~MDNSServiceWrapper(); 71 void StartIfRequired(); 72 73 std::string ifaddr; 74 MDNSService* mMDNSService = nullptr; 75 }; 76 77 static StaticRefPtr<MDNSServiceWrapper> mSharedMDNSService; 78 }; 79 80 } // namespace mozilla::net 81 82 #endif // mozilla_net_StunAddrsRequestParent_h