Bug 906990: Part 9. Add correlator for ICE candidates. r=ekr

This commit is contained in:
Byron Campen [:bwc] 2013-10-25 16:47:14 -07:00
parent ca07ff7e63
commit c4453b1dc3
7 changed files with 41 additions and 11 deletions

View File

@ -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;
}

View File

@ -77,6 +77,7 @@ struct NrIceCandidate {
std::string host;
uint16_t port;
Type type;
std::string codeword;
};
struct NrIceCandidatePair {

View File

@ -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;
}

View File

@ -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)

View File

@ -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);

View File

@ -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;
}

View File

@ -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;