From bd4d500bd5c553353c1a802270a57afed53c80da Mon Sep 17 00:00:00 2001 From: "Byron Campen [:bwc]" Date: Fri, 25 Oct 2013 16:47:14 -0700 Subject: [PATCH] Bug 906990: Part 9. Add correlator for ICE candidates. r=ekr --- media/mtransport/nricemediastream.cpp | 1 + media/mtransport/nricemediastream.h | 1 + media/mtransport/test/ice_unittest.cpp | 8 +++++++- .../third_party/nICEr/src/ice/ice_candidate.c | 20 +++++++++++++++++++ .../third_party/nICEr/src/ice/ice_candidate.h | 2 ++ .../nICEr/src/ice/ice_candidate_pair.c | 18 ++++++++--------- .../third_party/nICEr/src/ice/ice_parser.c | 2 ++ 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/media/mtransport/nricemediastream.cpp b/media/mtransport/nricemediastream.cpp index 5559cc8540fe..1479438258de 100644 --- a/media/mtransport/nricemediastream.cpp +++ b/media/mtransport/nricemediastream.cpp @@ -112,6 +112,7 @@ static bool ToNrIceCandidate(const nr_ice_candidate& candc, out->host = addr; out->port = port; out->type = type; + out->codeword = candc.codeword; return true; } diff --git a/media/mtransport/nricemediastream.h b/media/mtransport/nricemediastream.h index 8d5e8432fad6..ba82eb717daf 100644 --- a/media/mtransport/nricemediastream.h +++ b/media/mtransport/nricemediastream.h @@ -77,6 +77,7 @@ struct NrIceCandidate { std::string host; uint16_t port; Type type; + std::string codeword; }; struct NrIceCandidatePair { diff --git a/media/mtransport/test/ice_unittest.cpp b/media/mtransport/test/ice_unittest.cpp index 69e7b343af4f..c37f6fa67515 100644 --- a/media/mtransport/test/ice_unittest.cpp +++ b/media/mtransport/test/ice_unittest.cpp @@ -87,6 +87,9 @@ bool operator<(const NrIceCandidate& lhs, const NrIceCandidate& rhs) { if (lhs.host == rhs.host) { if (lhs.port == rhs.port) { + if (lhs.type == rhs.type) { + return lhs.codeword < rhs.codeword; + } return lhs.type < rhs.type; } return lhs.port < rhs.port; @@ -98,7 +101,8 @@ bool operator==(const NrIceCandidate& lhs, const NrIceCandidate& rhs) { return lhs.host == rhs.host && lhs.port == rhs.port && - lhs.type == rhs.type; + lhs.type == rhs.type && + lhs.codeword == rhs.codeword; } class IceCandidatePairCompare { @@ -371,6 +375,8 @@ class IceTestPeer : public sigslot::has_slots<> { << cand.host << ":" << cand.port + << " codeword=" + << cand.codeword << std::endl; } diff --git a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c index a6e4df81868a..66dc32f5e1a7 100644 --- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c +++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c @@ -57,6 +57,7 @@ static char *RCSSTRING __UNUSED__="$Id: ice_candidate.c,v 1.2 2008/04/28 17:59:0 #include "turn_client_ctx.h" #include "ice_ctx.h" #include "ice_candidate.h" +#include "ice_codeword.h" #include "ice_reg.h" #include "ice_util.h" #include "nr_socket_turn.h" @@ -74,6 +75,19 @@ static void nr_ice_turn_allocated_cb(NR_SOCKET sock, int how, void *cb_arg); static int nr_ice_candidate_resolved_cb(void *cb_arg, nr_transport_addr *addr); #endif /* USE_TURN */ +void nr_ice_candidate_compute_codeword(nr_ice_candidate *cand) + { + char as_string[1024]; + + snprintf(as_string, + sizeof(as_string), + "%s(%s)", + cand->addr.as_string, + cand->label); + + nr_ice_compute_codeword(as_string,strlen(as_string),cand->codeword); + } + char *nr_ice_candidate_type_names[]={0,"host","srflx","prflx","relay",0}; static const char *nr_ctype_name(nr_ice_candidate_type ctype) { @@ -176,6 +190,8 @@ int nr_ice_candidate_create(nr_ice_ctx *ctx,nr_ice_component *comp,nr_ice_socket /* Add the candidate to the isock list*/ TAILQ_INSERT_TAIL(&isock->candidates,cand,entry_sock); + nr_ice_candidate_compute_codeword(cand); + r_log(LOG_ICE,LOG_DEBUG,"ICE(%s): created candidate %s with type %s", ctx->label,cand->label,nr_ctype_name(ctype)); @@ -222,6 +238,8 @@ int nr_ice_peer_peer_rflx_candidate_create(nr_ice_ctx *ctx,char *label, nr_ice_c if(!(cand->foundation=r_strdup(cand->addr.as_string))) ABORT(r); + nr_ice_candidate_compute_codeword(cand); + *candp=cand; _status=0; @@ -484,6 +502,8 @@ int nr_ice_candidate_initialize(nr_ice_candidate *cand, NR_async_cb ready_cb, vo ABORT(R_INTERNAL); } + nr_ice_candidate_compute_codeword(cand); + _status=0; abort: if(_status && _status!=R_WOULDBLOCK) diff --git a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.h b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.h index 8af1737bef56..6f63ea83fd94 100644 --- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.h +++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.h @@ -43,6 +43,7 @@ typedef enum {HOST=1, SERVER_REFLEXIVE, PEER_REFLEXIVE, RELAYED, CTYPE_MAX} nr_i struct nr_ice_candidate_ { char *label; + char codeword[5]; int state; #define NR_ICE_CAND_STATE_CREATED 1 #define NR_ICE_CAND_STATE_INITIALIZING 2 @@ -100,6 +101,7 @@ extern char *nr_ice_candidate_type_names[]; int nr_ice_candidate_create(struct nr_ice_ctx_ *ctx,nr_ice_component *component, nr_ice_socket *isock, nr_socket *osock, nr_ice_candidate_type ctype, nr_ice_stun_server *stun_server, UCHAR component_id, nr_ice_candidate **candp); int nr_ice_candidate_initialize(nr_ice_candidate *cand, NR_async_cb ready_cb, void *cb_arg); +void nr_ice_candidate_compute_codeword(nr_ice_candidate *cand); int nr_ice_candidate_process_stun(nr_ice_candidate *cand, UCHAR *msg, int len, nr_transport_addr *faddr); int nr_ice_candidate_destroy(nr_ice_candidate **candp); void nr_ice_candidate_destroy_cb(NR_SOCKET s, int h, void *cb_arg); diff --git a/media/mtransport/third_party/nICEr/src/ice/ice_candidate_pair.c b/media/mtransport/third_party/nICEr/src/ice/ice_candidate_pair.c index 0866416a120f..f0389fbdd36d 100644 --- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate_pair.c +++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate_pair.c @@ -576,18 +576,16 @@ static void nr_ice_candidate_pair_restart_stun_controlled_cb(NR_SOCKET s, int ho static void nr_ice_candidate_pair_compute_codeword(nr_ice_cand_pair *pair, nr_ice_candidate *lcand, nr_ice_candidate *rcand) { - int r,_status; - char *as_string=0; + char as_string[2048]; - if(r=nr_concat_strings(&as_string,lcand->addr.as_string,"|", - rcand->addr.as_string,"(",lcand->label,"|",rcand->label,")",NULL)) - ABORT(r); + snprintf(as_string, + sizeof(as_string), + "%s|%s(%s|%s)", + lcand->addr.as_string, + rcand->addr.as_string, + lcand->label, + rcand->label); nr_ice_compute_codeword(as_string,strlen(as_string),pair->codeword); - - _status=0; - abort: - RFREE(as_string); -return; } diff --git a/media/mtransport/third_party/nICEr/src/ice/ice_parser.c b/media/mtransport/third_party/nICEr/src/ice/ice_parser.c index 817da9621212..a4e99a5eeb38 100644 --- a/media/mtransport/third_party/nICEr/src/ice/ice_parser.c +++ b/media/mtransport/third_party/nICEr/src/ice/ice_parser.c @@ -332,6 +332,8 @@ nr_ice_peer_candidate_from_attribute(nr_ice_ctx *ctx,char *orig,nr_ice_media_str } #endif + nr_ice_candidate_compute_codeword(cand); + *candp=cand; _status=0;