Bug 1295552 - restart ice ctx needs stun/turn/dns setup to match original ctx. r=drno
authorMichael Froman <mfroman@mozilla.com>
Thu, 18 Aug 2016 17:29:49 -0500
changeset 310871 60145a6103eec57335e5825be86bdbd68ceefc88
parent 310870 a215678635e0f7ac78f8da5e723a1e09d37c3f97
child 310872 1da74b9e700014b87290c3fd43001ad679853549
push id31657
push userryanvm@gmail.com
push dateWed, 24 Aug 2016 14:08:00 +0000
treeherderautoland@60145a6103ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1295552
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1295552 - restart ice ctx needs stun/turn/dns setup to match original ctx. r=drno MozReview-Commit-ID: H8o3gEnFfzQ
media/mtransport/nricectxhandler.cpp
media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
media/mtransport/third_party/nICEr/src/ice/ice_ctx.h
--- a/media/mtransport/nricectxhandler.cpp
+++ b/media/mtransport/nricectxhandler.cpp
@@ -6,16 +6,17 @@
 extern "C" {
 #include "nr_api.h"
 #include "ice_ctx.h"
 }
 
 // Local includes
 #include "nricectxhandler.h"
 #include "nricemediastream.h"
+#include "nriceresolver.h"
 
 namespace mozilla {
 
 MOZ_MTLOG_MODULE("mtransport")
 
 NrIceCtxHandler::NrIceCtxHandler(const std::string& name,
                                  bool offerer,
                                  NrIceCtx::Policy policy)
@@ -80,16 +81,48 @@ NrIceCtxHandler::CreateCtx(const std::st
   if (new_ctx == nullptr) {
     return nullptr;
   }
 
   if (!new_ctx->Initialize(hide_non_default, ufrag, pwd)) {
     return nullptr;
   }
 
+  // copy the stun, and turn servers from the current context
+  int r = nr_ice_ctx_set_stun_servers(new_ctx->ctx_,
+                                      this->current_ctx->ctx_->stun_servers,
+                                      this->current_ctx->ctx_->stun_server_ct);
+  if (r) {
+    MOZ_MTLOG(ML_ERROR, "Error while setting STUN servers in CreateCtx"
+                        << " (likely ice restart related)");
+    return nullptr;
+  }
+
+  r = nr_ice_ctx_copy_turn_servers(new_ctx->ctx_,
+                                   this->current_ctx->ctx_->turn_servers,
+                                   this->current_ctx->ctx_->turn_server_ct);
+  if (r) {
+    MOZ_MTLOG(ML_ERROR, "Error while copying TURN servers in CreateCtx"
+                        << " (likely ice restart related)");
+    return nullptr;
+  }
+
+  // grab the NrIceResolver stashed in the nr_resolver and allocate another
+  // for the new ctx.  Note: there may not be an nr_resolver.
+  if (this->current_ctx->ctx_->resolver) {
+    NrIceResolver* resolver =
+      static_cast<NrIceResolver*>(this->current_ctx->ctx_->resolver->obj);
+    if (!resolver ||
+        NS_FAILED(new_ctx->SetResolver(resolver->AllocateResolver()))) {
+      MOZ_MTLOG(ML_ERROR, "Error while setting dns resolver in CreateCtx"
+                          << " (likely ice restart related)");
+      return nullptr;
+    }
+  }
+
   return new_ctx;
 }
 
 
 bool
 NrIceCtxHandler::BeginIceRestart(RefPtr<NrIceCtx> new_ctx)
 {
   MOZ_ASSERT(!old_ctx, "existing ice restart in progress");
--- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
@@ -163,16 +163,41 @@ int nr_ice_ctx_set_turn_servers(nr_ice_c
       ctx->turn_server_ct = ct;
     }
 
     _status=0;
  abort:
     return(_status);
   }
 
+int nr_ice_ctx_copy_turn_servers(nr_ice_ctx *ctx, nr_ice_turn_server *servers, int ct)
+  {
+    int _status, i, r;
+
+    if (r = nr_ice_ctx_set_turn_servers(ctx, servers, ct)) {
+      ABORT(r);
+    }
+
+    // make copies of the username and password so they aren't freed twice
+    for (i = 0; i < ct; ++i) {
+      if (!(ctx->turn_servers[i].username = r_strdup(servers[i].username))) {
+        ABORT(R_NO_MEMORY);
+      }
+      if (r = r_data_create(&ctx->turn_servers[i].password,
+                            servers[i].password->data,
+                            servers[i].password->len)) {
+        ABORT(r);
+      }
+    }
+
+    _status=0;
+   abort:
+    return(_status);
+  }
+
 static int nr_ice_ctx_set_local_addrs(nr_ice_ctx *ctx,nr_local_addr *addrs,int ct)
   {
     int _status,i,r;
 
     if(ctx->local_addrs) {
       RFREE(ctx->local_addrs);
       ctx->local_addr_ct=0;
       ctx->local_addrs=0;
--- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.h
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.h
@@ -173,16 +173,17 @@ int nr_ice_add_media_stream(nr_ice_ctx *
 int nr_ice_remove_media_stream(nr_ice_ctx *ctx,nr_ice_media_stream **streamp);
 int nr_ice_get_global_attributes(nr_ice_ctx *ctx,char ***attrsp, int *attrctp);
 int nr_ice_ctx_deliver_packet(nr_ice_ctx *ctx, nr_ice_component *comp, nr_transport_addr *source_addr, UCHAR *data, int len);
 int nr_ice_ctx_is_known_id(nr_ice_ctx *ctx, UCHAR id[12]);
 int nr_ice_ctx_remember_id(nr_ice_ctx *ctx, nr_stun_message *msg);
 int nr_ice_ctx_finalize(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx);
 int nr_ice_ctx_set_stun_servers(nr_ice_ctx *ctx,nr_ice_stun_server *servers, int ct);
 int nr_ice_ctx_set_turn_servers(nr_ice_ctx *ctx,nr_ice_turn_server *servers, int ct);
+int nr_ice_ctx_copy_turn_servers(nr_ice_ctx *ctx, nr_ice_turn_server *servers, int ct);
 int nr_ice_ctx_set_resolver(nr_ice_ctx *ctx, nr_resolver *resolver);
 int nr_ice_ctx_set_interface_prioritizer(nr_ice_ctx *ctx, nr_interface_prioritizer *prioritizer);
 int nr_ice_ctx_set_turn_tcp_socket_wrapper(nr_ice_ctx *ctx, nr_socket_wrapper_factory *wrapper);
 void nr_ice_ctx_set_socket_factory(nr_ice_ctx *ctx, nr_socket_factory *factory);
 int nr_ice_ctx_set_trickle_cb(nr_ice_ctx *ctx, nr_ice_trickle_candidate_cb cb, void *cb_arg);
 int nr_ice_ctx_hide_candidate(nr_ice_ctx *ctx, nr_ice_candidate *cand);
 int nr_ice_get_new_ice_ufrag(char** ufrag);
 int nr_ice_get_new_ice_pwd(char** pwd);