mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1554976 - Use mdns_service to generate UUIDs; r=mjf
With the move to the socket process, the UUID service is no longer available in nricectx. This adds a pair of helper functions to mdns_service to generate UUIDs and uses them to generate hostnames inside nricectx. Differential Revision: https://phabricator.services.mozilla.com/D42150 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b07a76f4bd
commit
d54770d4a5
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1754,6 +1754,7 @@ dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"socket2 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -10,3 +10,4 @@ dns-parser = "0.8.0"
|
||||
log = "0.4"
|
||||
mio = "0.6"
|
||||
socket2 = { version = "0.3.9", features = ["reuseport"] }
|
||||
uuid = { version = "0.7", features = ["v4"] }
|
||||
|
@ -16,4 +16,8 @@ void mdns_service_stop(MDNSService* serv);
|
||||
|
||||
void mdns_service_unregister_hostname(MDNSService* serv, const char* hostname);
|
||||
|
||||
const char* mdns_service_generate_uuid();
|
||||
|
||||
void mdns_service_free_uuid(const char* uuid);
|
||||
|
||||
} // extern "C"
|
||||
|
@ -7,12 +7,14 @@ use get_if_addrs;
|
||||
use socket2::{Domain, Socket, Type};
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::CStr;
|
||||
use std::ffi::CString;
|
||||
use std::io;
|
||||
use std::net;
|
||||
use std::os::raw::c_char;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
@ -301,3 +303,21 @@ pub extern "C" fn mdns_service_unregister_hostname(
|
||||
(*serv).unregister_hostname(&hostname);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mdns_service_generate_uuid() -> *const c_char {
|
||||
let uuid = Uuid::new_v4().to_hyphenated().to_string();
|
||||
match CString::new(uuid) {
|
||||
Ok(uuid) => {
|
||||
uuid.into_raw()
|
||||
}
|
||||
Err(_) => unreachable!() // UUID should not contain 0 byte
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mdns_service_free_uuid(uuid: *mut c_char) {
|
||||
unsafe {
|
||||
CString::from_raw(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,10 @@ extern "C" {
|
||||
#include "rlogconnector.h"
|
||||
#include "test_nr_socket.h"
|
||||
|
||||
extern "C" {
|
||||
#include "mdns_service/mdns_service.h"
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
using std::shared_ptr;
|
||||
@ -1060,28 +1064,11 @@ void NrIceCtx::GenerateObfuscatedAddress(nr_ice_candidate* candidate,
|
||||
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);
|
||||
|
||||
const char* uuid = mdns_service_generate_uuid();
|
||||
std::ostringstream o;
|
||||
chars[NSID_LENGTH - 2] = 0; // trim trailing } from uuid
|
||||
o << &chars[1] << ".local"; // trim leading { from uuid
|
||||
o << uuid << ".local";
|
||||
*mdns_address = o.str();
|
||||
mdns_service_free_uuid(uuid);
|
||||
|
||||
obfuscated_host_addresses_[*actual_address] = *mdns_address;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user