mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1554976 - Generate mDNS addresses in nricectx; r=mjf
Differential Revision: https://phabricator.services.mozilla.com/D38493 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
6285d788cc
commit
6c39c9271f
@ -30,8 +30,10 @@ class StunAddrsRequestParent : public PStunAddrsRequestParent {
|
|||||||
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 RecvRegisterMDNSHostname(
|
||||||
virtual mozilla::ipc::IPCResult RecvUnregisterMDNSHostname(const nsCString& hostname) override;
|
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;
|
||||||
|
@ -57,6 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "nsComponentManagerUtils.h"
|
#include "nsComponentManagerUtils.h"
|
||||||
#include "nsError.h"
|
#include "nsError.h"
|
||||||
#include "nsIEventTarget.h"
|
#include "nsIEventTarget.h"
|
||||||
|
#include "nsIUUIDGenerator.h"
|
||||||
#include "nsNetCID.h"
|
#include "nsNetCID.h"
|
||||||
#include "nsComponentManagerUtils.h"
|
#include "nsComponentManagerUtils.h"
|
||||||
#include "nsServiceManagerUtils.h"
|
#include "nsServiceManagerUtils.h"
|
||||||
@ -427,10 +428,14 @@ void NrIceCtx::trickle_cb(void* arg, nr_ice_ctx* ice_ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!candidate) {
|
if (!candidate) {
|
||||||
s->SignalCandidate(s, "", stream->ufrag);
|
s->SignalCandidate(s, "", stream->ufrag, "", "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string actual_addr;
|
||||||
|
std::string mdns_addr;
|
||||||
|
ctx->GenerateObfuscatedAddress(candidate, &mdns_addr, &actual_addr);
|
||||||
|
|
||||||
// Format the candidate.
|
// Format the candidate.
|
||||||
char candidate_str[NR_ICE_MAX_ATTRIBUTE_SIZE];
|
char candidate_str[NR_ICE_MAX_ATTRIBUTE_SIZE];
|
||||||
int r = nr_ice_format_candidate_attribute(candidate, candidate_str,
|
int r = nr_ice_format_candidate_attribute(candidate, candidate_str,
|
||||||
@ -441,7 +446,7 @@ void NrIceCtx::trickle_cb(void* arg, nr_ice_ctx* ice_ctx,
|
|||||||
MOZ_MTLOG(ML_INFO, "NrIceCtx(" << ctx->name_ << "): trickling candidate "
|
MOZ_MTLOG(ML_INFO, "NrIceCtx(" << ctx->name_ << "): trickling candidate "
|
||||||
<< candidate_str);
|
<< candidate_str);
|
||||||
|
|
||||||
s->SignalCandidate(s, candidate_str, stream->ufrag);
|
s->SignalCandidate(s, candidate_str, stream->ufrag, mdns_addr, actual_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NrIceCtx::InitializeGlobals(bool allow_loopback, bool tcp_enabled,
|
void NrIceCtx::InitializeGlobals(bool allow_loopback, bool tcp_enabled,
|
||||||
@ -860,6 +865,7 @@ void NrIceCtx::SetCtxFlags(bool default_route_only, bool proxy_only) {
|
|||||||
|
|
||||||
nsresult NrIceCtx::StartGathering(bool default_route_only, bool proxy_only) {
|
nsresult NrIceCtx::StartGathering(bool default_route_only, bool proxy_only) {
|
||||||
ASSERT_ON_THREAD(sts_target_);
|
ASSERT_ON_THREAD(sts_target_);
|
||||||
|
|
||||||
SetGatheringState(ICE_CTX_GATHER_STARTED);
|
SetGatheringState(ICE_CTX_GATHER_STARTED);
|
||||||
|
|
||||||
SetCtxFlags(default_route_only, proxy_only);
|
SetCtxFlags(default_route_only, proxy_only);
|
||||||
@ -1033,6 +1039,52 @@ void NrIceCtx::SetGatheringState(GatheringState state) {
|
|||||||
SignalGatheringStateChange(this, state);
|
SignalGatheringStateChange(this, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NrIceCtx::GenerateObfuscatedAddress(nr_ice_candidate* candidate,
|
||||||
|
std::string* mdns_address,
|
||||||
|
std::string* actual_address) {
|
||||||
|
if (candidate->type == HOST) {
|
||||||
|
int r;
|
||||||
|
char addr[64];
|
||||||
|
if ((r = nr_transport_addr_get_addrstring(&candidate->addr, addr,
|
||||||
|
sizeof(addr)))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*actual_address = addr;
|
||||||
|
|
||||||
|
const auto& iter = obfuscated_host_addresses_.find(*actual_address);
|
||||||
|
if (iter != obfuscated_host_addresses_.end()) {
|
||||||
|
*mdns_address = iter->second;
|
||||||
|
} else {
|
||||||
|
nsresult rv;
|
||||||
|
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
||||||
|
do_GetService("@mozilla.org/uuid-generator;1", &rv);
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsID id;
|
||||||
|
rv = uuidgen->GenerateUUIDInPlace(&id);
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char chars[NSID_LENGTH];
|
||||||
|
id.ToProvidedString(chars);
|
||||||
|
|
||||||
|
std::ostringstream o;
|
||||||
|
chars[NSID_LENGTH - 2] = 0; // trim trailing } from uuid
|
||||||
|
o << &chars[1] << ".local"; // trim leading { from uuid
|
||||||
|
*mdns_address = o.str();
|
||||||
|
|
||||||
|
obfuscated_host_addresses_[*actual_address] = *mdns_address;
|
||||||
|
}
|
||||||
|
candidate->mdns_addr = r_strdup(mdns_address->c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
// Reimplement nr_ice_compute_codeword to avoid copyright issues
|
// Reimplement nr_ice_compute_codeword to avoid copyright issues
|
||||||
|
@ -376,6 +376,10 @@ class NrIceCtx {
|
|||||||
// Set the state
|
// Set the state
|
||||||
void SetGatheringState(GatheringState state);
|
void SetGatheringState(GatheringState state);
|
||||||
|
|
||||||
|
void GenerateObfuscatedAddress(nr_ice_candidate* candidate,
|
||||||
|
std::string* mdns_address,
|
||||||
|
std::string* actual_address);
|
||||||
|
|
||||||
ConnectionState connection_state_;
|
ConnectionState connection_state_;
|
||||||
GatheringState gathering_state_;
|
GatheringState gathering_state_;
|
||||||
const std::string name_;
|
const std::string name_;
|
||||||
@ -391,6 +395,7 @@ class NrIceCtx {
|
|||||||
RefPtr<TestNat> nat_;
|
RefPtr<TestNat> nat_;
|
||||||
std::shared_ptr<NrSocketProxyConfig> proxy_config_;
|
std::shared_ptr<NrSocketProxyConfig> proxy_config_;
|
||||||
bool proxy_only_;
|
bool proxy_only_;
|
||||||
|
std::map<std::string, std::string> obfuscated_host_addresses_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
@ -194,7 +194,8 @@ class NrIceMediaStream {
|
|||||||
// the candidate belongs to.
|
// the candidate belongs to.
|
||||||
const std::string& GetId() const { return id_; }
|
const std::string& GetId() const { return id_; }
|
||||||
|
|
||||||
sigslot::signal3<NrIceMediaStream*, const std::string&, const std::string&>
|
sigslot::signal5<NrIceMediaStream*, const std::string&, const std::string&,
|
||||||
|
const std::string&, const std::string&>
|
||||||
SignalCandidate; // A new ICE candidate:
|
SignalCandidate; // A new ICE candidate:
|
||||||
|
|
||||||
sigslot::signal1<NrIceMediaStream*> SignalReady; // Candidate pair ready.
|
sigslot::signal1<NrIceMediaStream*> SignalReady; // Candidate pair ready.
|
||||||
|
@ -984,7 +984,9 @@ class IceTestPeer : public sigslot::has_slots<> {
|
|||||||
|
|
||||||
void CandidateInitialized(NrIceMediaStream* stream,
|
void CandidateInitialized(NrIceMediaStream* stream,
|
||||||
const std::string& raw_candidate,
|
const std::string& raw_candidate,
|
||||||
const std::string& ufrag) {
|
const std::string& ufrag,
|
||||||
|
const std::string& mdns_addr,
|
||||||
|
const std::string& actual_addr) {
|
||||||
std::string candidate(FilterCandidate(raw_candidate));
|
std::string candidate(FilterCandidate(raw_candidate));
|
||||||
if (candidate.empty()) {
|
if (candidate.empty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -634,7 +634,8 @@ class TransportTestPeer : public sigslot::has_slots<> {
|
|||||||
|
|
||||||
// New candidate
|
// New candidate
|
||||||
void GotCandidate(NrIceMediaStream* stream, const std::string& candidate,
|
void GotCandidate(NrIceMediaStream* stream, const std::string& candidate,
|
||||||
const std::string& ufrag) {
|
const std::string& ufrag, const std::string& mdns_addr,
|
||||||
|
const std::string& actual_addr) {
|
||||||
std::cerr << "Got candidate " << candidate << " (ufrag=" << ufrag << ")"
|
std::cerr << "Got candidate " << candidate << " (ufrag=" << ufrag << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
@ -947,8 +947,14 @@ int nr_ice_format_candidate_attribute(nr_ice_candidate *cand, char *attr, int ma
|
|||||||
assert(!strcmp(nr_ice_candidate_type_names[HOST], "host"));
|
assert(!strcmp(nr_ice_candidate_type_names[HOST], "host"));
|
||||||
assert(!strcmp(nr_ice_candidate_type_names[RELAYED], "relay"));
|
assert(!strcmp(nr_ice_candidate_type_names[RELAYED], "relay"));
|
||||||
|
|
||||||
if(r=nr_transport_addr_get_addrstring(&cand->addr,addr,sizeof(addr)))
|
if (cand->mdns_addr) {
|
||||||
ABORT(r);
|
/* mdns_addr is NSID_LENGTH which is 39, - 2 for removing the "{" and "}"
|
||||||
|
+ 6 for ".local" for a total of 43. */
|
||||||
|
strncpy(addr, cand->mdns_addr, sizeof(addr) - 1);
|
||||||
|
} else {
|
||||||
|
if(r=nr_transport_addr_get_addrstring(&cand->addr,addr,sizeof(addr)))
|
||||||
|
ABORT(r);
|
||||||
|
}
|
||||||
if(r=nr_transport_addr_get_port(&cand->addr,&port))
|
if(r=nr_transport_addr_get_port(&cand->addr,&port))
|
||||||
ABORT(r);
|
ABORT(r);
|
||||||
/* https://tools.ietf.org/html/rfc6544#section-4.5 */
|
/* https://tools.ietf.org/html/rfc6544#section-4.5 */
|
||||||
|
Loading…
Reference in New Issue
Block a user