Bug 933986. (WIP) Switch over from index to an id, and ensure uniqueness when feeding into the candidate priority calculation. draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Mon, 04 Nov 2013 16:50:10 -0800
changeset 340738 e5cfb60fc1342a007463ce1fe255b38f07d163fa
parent 340493 5e14887312d4523ab59c3f6c6c94a679cf42b496
child 516259 68db7f1a4d084014ec887ad2fb55bb83613ae9c8
push id13047
push userdrno@ohlmeier.org
push dateTue, 15 Mar 2016 22:27:39 +0000
bugs933986
milestone48.0a1
Bug 933986. (WIP) Switch over from index to an id, and ensure uniqueness when feeding into the candidate priority calculation. MozReview-Commit-ID: 5LOQJbsnEWN
media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
media/mtransport/third_party/nICEr/src/ice/ice_component.c
media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
media/mtransport/third_party/nICEr/src/ice/ice_ctx.h
--- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
@@ -425,27 +425,27 @@ int nr_ice_candidate_compute_priority(nr
       case RELAYED:
         if(cand->base.protocol == IPPROTO_UDP) {
           if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_RELAYED,&type_preference))
             ABORT(r);
         } else if(cand->base.protocol == IPPROTO_TCP) {
           if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_RELAYED_TCP,&type_preference))
             ABORT(r);
         }
-        stun_priority=31-cand->stun_server->index;
+        stun_priority=31-cand->stun_server->id;
         break;
       case SERVER_REFLEXIVE:
         if(cand->base.protocol == IPPROTO_UDP) {
           if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_SRV_RFLX,&type_preference))
             ABORT(r);
         } else if(cand->base.protocol == IPPROTO_TCP) {
           if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_SRV_RFLX_TCP,&type_preference))
             ABORT(r);
         }
-        stun_priority=31-cand->stun_server->index;
+        stun_priority=31-cand->stun_server->id;
         break;
       case PEER_REFLEXIVE:
         if(cand->base.protocol == IPPROTO_UDP) {
           if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_PEER_RFLX,&type_preference))
             ABORT(r);
         } else if(cand->base.protocol == IPPROTO_TCP) {
           if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_PEER_RFLX_TCP,&type_preference))
             ABORT(r);
--- a/media/mtransport/third_party/nICEr/src/ice/ice_component.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_component.c
@@ -238,16 +238,18 @@ static int nr_ice_component_initialize_u
         cand=0;
 
         /* And a srvrflx candidate for each STUN server */
         for(j=0;j<ctx->stun_server_ct;j++){
           /* Skip non-UDP */
           if(ctx->stun_servers[j].transport!=IPPROTO_UDP)
             continue;
 
+          /* Ensure id is set (nr_ice_ctx_set_stun_servers does not) */
+          ctx->stun_servers[j].id = j;
           if(r=nr_ice_candidate_create(ctx,component,
             isock,sock,SERVER_REFLEXIVE,0,
             &ctx->stun_servers[j],component->component_id,&cand))
             ABORT(r);
           TAILQ_INSERT_TAIL(&component->candidates,cand,entry_comp);
           component->candidate_ct++;
           cand=0;
         }
@@ -267,16 +269,18 @@ static int nr_ice_component_initialize_u
         nr_socket *turn_sock;
         nr_ice_candidate *srvflx_cand=0;
 
         /* Skip non-UDP */
         if (ctx->turn_servers[j].turn_server.transport != IPPROTO_UDP)
           continue;
 
         if (!(ctx->flags & NR_ICE_CTX_FLAGS_RELAY_ONLY)) {
+          /* Ensure id is set with a unique value */
+          ctx->turn_servers[j].turn_server.id = j + ctx->stun_server_ct;
           /* srvrflx */
           if(r=nr_ice_candidate_create(ctx,component,
             isock,sock,SERVER_REFLEXIVE,0,
             &ctx->turn_servers[j].turn_server,component->component_id,&cand))
             ABORT(r);
           cand->state=NR_ICE_CAND_STATE_INITIALIZING; /* Don't start */
           cand->done_cb=nr_ice_gather_finished_cb;
           cand->cb_arg=cand;
--- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
@@ -103,17 +103,16 @@ int nr_ice_fetch_stun_servers(int ct, nr
       if(r=NR_reg_get2_uint2(child,"port",&port)) {
         if (r != R_NOT_FOUND)
           ABORT(r);
         port = 3478;
       }
       if(r=nr_ip4_port_to_transport_addr(ntohl(addr_int), port, IPPROTO_UDP,
         &servers[i].u.addr))
         ABORT(r);
-      servers[i].index=i;
       servers[i].type = NR_ICE_STUN_SERVER_TYPE_ADDR;
       RFREE(addr);
       addr=0;
     }
 
     *out = servers;
 
     _status=0;
@@ -294,18 +293,16 @@ int nr_ice_fetch_turn_servers(int ct, nr
         servers[i].password=RCALLOC(sizeof(*servers[i].password));
         if(!servers[i].password)
           ABORT(R_NO_MEMORY);
         servers[i].password->data = data.data;
         servers[i].password->len = data.len;
         data.data=0;
       }
 
-      servers[i].turn_server.index=i;
-
       RFREE(addr);
       addr=0;
     }
 
     *out = servers;
 
     _status=0;
   abort:
--- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.h
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.h
@@ -56,17 +56,17 @@ typedef struct nr_ice_stun_server_ {
   int type;
   union {
     nr_transport_addr addr;
     struct {
       char host[256];  /* Limit from RFC 1034, plus a 0 byte */
       UINT2 port;
     } dnsname;
   } u;
-  int index;
+  int id;
   int transport;
 } nr_ice_stun_server;
 
 typedef struct nr_ice_turn_server_ {
     nr_ice_stun_server    turn_server;
     char                 *username;
     Data                 *password;
 } nr_ice_turn_server;