зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1253706: Create NrIceCtx::SetIceConfig. r=mjf
Used to be part of NrIceCtx::Init, but needed to be broken out. Differential Revision: https://phabricator.services.mozilla.com/D135367
This commit is contained in:
Родитель
ceadcbdb8e
Коммит
11a44236c6
|
@ -272,7 +272,7 @@ nsresult NrIceTurnServer::ToNicerTurnStruct(nr_ice_turn_server* server) const {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NrIceCtx::NrIceCtx(const std::string& name, const Config& aConfig)
|
||||
NrIceCtx::NrIceCtx(const std::string& name)
|
||||
: connection_state_(ICE_CTX_INIT),
|
||||
gathering_state_(ICE_CTX_GATHER_INIT),
|
||||
name_(name),
|
||||
|
@ -283,15 +283,14 @@ NrIceCtx::NrIceCtx(const std::string& name, const Config& aConfig)
|
|||
ice_handler_vtbl_(nullptr),
|
||||
ice_handler_(nullptr),
|
||||
trickle_(true),
|
||||
config_(aConfig),
|
||||
config_(),
|
||||
nat_(nullptr),
|
||||
proxy_config_(nullptr),
|
||||
obfuscate_host_addresses_(false) {}
|
||||
|
||||
/* static */
|
||||
RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& aName,
|
||||
const Config& aConfig) {
|
||||
RefPtr<NrIceCtx> ctx = new NrIceCtx(aName, aConfig);
|
||||
RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& aName) {
|
||||
RefPtr<NrIceCtx> ctx = new NrIceCtx(aName);
|
||||
|
||||
if (!ctx->Initialize()) {
|
||||
return nullptr;
|
||||
|
@ -300,6 +299,50 @@ RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& aName,
|
|||
return ctx;
|
||||
}
|
||||
|
||||
nsresult NrIceCtx::SetIceConfig(const Config& aConfig) {
|
||||
config_ = aConfig;
|
||||
switch (config_.mPolicy) {
|
||||
case ICE_POLICY_RELAY:
|
||||
MOZ_MTLOG(ML_DEBUG, "SetIceConfig: relay only");
|
||||
nr_ice_ctx_remove_flags(ctx_, NR_ICE_CTX_FLAGS_HIDE_HOST_CANDIDATES);
|
||||
nr_ice_ctx_add_flags(ctx_, NR_ICE_CTX_FLAGS_RELAY_ONLY);
|
||||
break;
|
||||
case ICE_POLICY_NO_HOST:
|
||||
MOZ_MTLOG(ML_DEBUG, "SetIceConfig: no host");
|
||||
nr_ice_ctx_add_flags(ctx_, NR_ICE_CTX_FLAGS_HIDE_HOST_CANDIDATES);
|
||||
nr_ice_ctx_remove_flags(ctx_, NR_ICE_CTX_FLAGS_RELAY_ONLY);
|
||||
break;
|
||||
case ICE_POLICY_ALL:
|
||||
MOZ_MTLOG(ML_DEBUG, "SetIceConfig: all");
|
||||
nr_ice_ctx_remove_flags(ctx_, NR_ICE_CTX_FLAGS_HIDE_HOST_CANDIDATES);
|
||||
nr_ice_ctx_remove_flags(ctx_, NR_ICE_CTX_FLAGS_RELAY_ONLY);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: Support re-configuring the test NAT someday?
|
||||
if (!nat_ && config_.mNatSimulatorConfig.isSome()) {
|
||||
TestNat* test_nat = new TestNat;
|
||||
test_nat->filtering_type_ = TestNat::ToNatBehavior(
|
||||
config_.mNatSimulatorConfig->mFilteringType.get());
|
||||
test_nat->mapping_type_ =
|
||||
TestNat::ToNatBehavior(config_.mNatSimulatorConfig->mMappingType.get());
|
||||
test_nat->block_udp_ = config_.mNatSimulatorConfig->mBlockUdp;
|
||||
test_nat->block_tcp_ = config_.mNatSimulatorConfig->mBlockTcp;
|
||||
test_nat->block_tls_ = config_.mNatSimulatorConfig->mBlockTls;
|
||||
test_nat->error_code_for_drop_ =
|
||||
config_.mNatSimulatorConfig->mErrorCodeForDrop;
|
||||
if (config_.mNatSimulatorConfig->mRedirectAddress.Length()) {
|
||||
test_nat
|
||||
->stun_redirect_map_[config_.mNatSimulatorConfig->mRedirectAddress] =
|
||||
config_.mNatSimulatorConfig->mRedirectTargets;
|
||||
}
|
||||
test_nat->enabled_ = true;
|
||||
SetNat(test_nat);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<NrIceMediaStream> NrIceCtx::CreateStream(const std::string& id,
|
||||
const std::string& name,
|
||||
int components) {
|
||||
|
@ -566,17 +609,6 @@ bool NrIceCtx::Initialize() {
|
|||
int r;
|
||||
|
||||
UINT4 flags = NR_ICE_CTX_FLAGS_AGGRESSIVE_NOMINATION;
|
||||
switch (config_.mPolicy) {
|
||||
case ICE_POLICY_RELAY:
|
||||
flags |= NR_ICE_CTX_FLAGS_RELAY_ONLY;
|
||||
break;
|
||||
case ICE_POLICY_NO_HOST:
|
||||
flags |= NR_ICE_CTX_FLAGS_HIDE_HOST_CANDIDATES;
|
||||
break;
|
||||
case ICE_POLICY_ALL:
|
||||
break;
|
||||
}
|
||||
|
||||
r = nr_ice_ctx_create(const_cast<char*>(name_.c_str()), flags, &ctx_);
|
||||
|
||||
if (r) {
|
||||
|
@ -615,26 +647,6 @@ bool NrIceCtx::Initialize() {
|
|||
}
|
||||
}
|
||||
|
||||
if (config_.mNatSimulatorConfig.isSome()) {
|
||||
TestNat* test_nat = new TestNat;
|
||||
test_nat->filtering_type_ = TestNat::ToNatBehavior(
|
||||
config_.mNatSimulatorConfig->mFilteringType.get());
|
||||
test_nat->mapping_type_ =
|
||||
TestNat::ToNatBehavior(config_.mNatSimulatorConfig->mMappingType.get());
|
||||
test_nat->block_udp_ = config_.mNatSimulatorConfig->mBlockUdp;
|
||||
test_nat->block_tcp_ = config_.mNatSimulatorConfig->mBlockTcp;
|
||||
test_nat->block_tls_ = config_.mNatSimulatorConfig->mBlockTls;
|
||||
test_nat->error_code_for_drop_ =
|
||||
config_.mNatSimulatorConfig->mErrorCodeForDrop;
|
||||
if (config_.mNatSimulatorConfig->mRedirectAddress.Length()) {
|
||||
test_nat
|
||||
->stun_redirect_map_[config_.mNatSimulatorConfig->mRedirectAddress] =
|
||||
config_.mNatSimulatorConfig->mRedirectTargets;
|
||||
}
|
||||
test_nat->enabled_ = true;
|
||||
SetNat(test_nat);
|
||||
}
|
||||
|
||||
// Create the handler objects
|
||||
ice_handler_vtbl_ = new nr_ice_handler_vtbl();
|
||||
ice_handler_vtbl_->select_pair = &NrIceCtx::select_pair;
|
||||
|
@ -928,7 +940,7 @@ bool NrIceCtx::HasStreamsToConnect() const {
|
|||
nsresult NrIceCtx::StartChecks() {
|
||||
int r;
|
||||
if (!HasStreamsToConnect()) {
|
||||
// Nothing to do
|
||||
MOZ_MTLOG(ML_INFO, "In StartChecks, nothing to do on " << name_);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -226,8 +226,9 @@ class NrIceCtx {
|
|||
Maybe<NatSimulatorConfig> mNatSimulatorConfig;
|
||||
};
|
||||
|
||||
static RefPtr<NrIceCtx> Create(const std::string& aName,
|
||||
const Config& aConfig);
|
||||
static RefPtr<NrIceCtx> Create(const std::string& aName);
|
||||
|
||||
nsresult SetIceConfig(const Config& aConfig);
|
||||
|
||||
RefPtr<NrIceMediaStream> CreateStream(const std::string& id,
|
||||
const std::string& name,
|
||||
|
@ -365,7 +366,7 @@ class NrIceCtx {
|
|||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceCtx)
|
||||
|
||||
private:
|
||||
NrIceCtx(const std::string& name, const Config& aConfig);
|
||||
explicit NrIceCtx(const std::string& name);
|
||||
|
||||
virtual ~NrIceCtx();
|
||||
|
||||
|
|
|
@ -359,7 +359,7 @@ class IceTestPeer : public sigslot::has_slots<> {
|
|||
IceTestPeer(const std::string& name, MtransportTestUtils* utils, bool offerer,
|
||||
const NrIceCtx::Config& config)
|
||||
: name_(name),
|
||||
ice_ctx_(NrIceCtx::Create(name, config)),
|
||||
ice_ctx_(NrIceCtx::Create(name)),
|
||||
offerer_(offerer),
|
||||
candidates_(),
|
||||
stream_counter_(0),
|
||||
|
@ -387,6 +387,8 @@ class IceTestPeer : public sigslot::has_slots<> {
|
|||
ice_ctx_->SignalConnectionStateChange.connect(
|
||||
this, &IceTestPeer::ConnectionStateChange);
|
||||
|
||||
ice_ctx_->SetIceConfig(config);
|
||||
|
||||
consent_timestamp_.tv_sec = 0;
|
||||
consent_timestamp_.tv_usec = 0;
|
||||
int r = ice_ctx_->SetNat(nat_);
|
||||
|
@ -1934,7 +1936,7 @@ class WebRtcIcePacketFilterTest : public StunTest {
|
|||
NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig());
|
||||
|
||||
// Set up enough of the ICE ctx to allow the packet filter to work
|
||||
ice_ctx_ = NrIceCtx::Create("test", NrIceCtx::Config());
|
||||
ice_ctx_ = NrIceCtx::Create("test");
|
||||
|
||||
nsCOMPtr<nsISocketFilterHandler> udp_handler =
|
||||
do_GetService(NS_STUN_UDP_SOCKET_FILTER_HANDLER_CONTRACTID);
|
||||
|
|
|
@ -44,7 +44,7 @@ class MultiTcpSocketTest : public MtransportTest {
|
|||
MtransportTest::SetUp();
|
||||
|
||||
NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig());
|
||||
ice_ctx_ = NrIceCtx::Create("stun", NrIceCtx::Config());
|
||||
ice_ctx_ = NrIceCtx::Create("stun");
|
||||
|
||||
test_utils_->sts_target()->Dispatch(
|
||||
WrapRunnableNM(&TestStunTcpServer::GetInstance, AF_INET),
|
||||
|
|
|
@ -451,7 +451,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
|
|||
disabled_cipersuites_(),
|
||||
test_utils_(utils) {
|
||||
NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig());
|
||||
ice_ctx_ = NrIceCtx::Create(name, NrIceCtx::Config());
|
||||
ice_ctx_ = NrIceCtx::Create(name);
|
||||
std::vector<NrIceStunServer> stun_servers;
|
||||
UniquePtr<NrIceStunServer> server(NrIceStunServer::Create(
|
||||
std::string((char*)"stun.services.mozilla.com"), 3478));
|
||||
|
|
Загрузка…
Ссылка в новой задаче