diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c index 886c04d94..37a92e2c7 100644 --- a/pjnath/src/pjnath/ice_session.c +++ b/pjnath/src/pjnath/ice_session.c @@ -106,7 +106,8 @@ typedef struct timer_data */ struct msg_data { - pj_bool_t is_request; + pj_bool_t is_request; + unsigned cand_id; union data { struct request_data { @@ -114,10 +115,6 @@ struct msg_data pj_ice_sess_checklist *clist; unsigned ckid; } req; - - struct response_data { - unsigned cand_id; - } res; } data; }; @@ -1400,8 +1397,9 @@ static pj_status_t perform_check(pj_ice_sess *ice, /* Attach data to be retrieved later when STUN request transaction * completes and on_stun_request_complete() callback is called. */ - msg_data = PJ_POOL_ZALLOC_T(check->tdata->pool, struct msg_data); + msg_data = PJ_POOL_ZALLOC_T(ice->pool, struct msg_data); msg_data->is_request = PJ_TRUE; + msg_data->cand_id = lcand - ice->lcand; msg_data->data.req.ice = ice; msg_data->data.req.clist = clist; msg_data->data.req.ckid = check_id; @@ -1667,15 +1665,7 @@ static pj_status_t on_stun_send_msg(pj_stun_session *sess, struct msg_data *msg_data = (struct msg_data*) token; unsigned cand_id; - if (msg_data->is_request) { - pj_ice_sess_checklist *clist = msg_data->data.req.clist; - pj_ice_sess_cand *lcand = clist->checks[msg_data->data.req.ckid].lcand; - - cand_id = lcand - ice->lcand; - - } else { - cand_id = msg_data->data.res.cand_id; - } + cand_id = msg_data->cand_id; return (*ice->cb.on_tx_pkt)(ice, sd->comp_id, cand_id, pkt, pkt_size, dst_addr, addr_len); @@ -1939,7 +1929,7 @@ static pj_status_t on_stun_rx_request(pj_stun_session *sess, unsigned src_addr_len) { stun_data *sd; - unsigned *param_cand_id; + //unsigned *param_cand_id; const pj_stun_msg *msg = rdata->msg; struct msg_data *msg_data; pj_ice_sess *ice; @@ -1961,7 +1951,7 @@ static pj_status_t on_stun_rx_request(pj_stun_session *sess, * in the on_tx_pkt(). The user needs this information to determine * whether to send packet using local socket or the relay. */ - param_cand_id = (unsigned*)token; + //param_cand_id = (unsigned*)token; /* Reject any requests except Binding request */ if (msg->hdr.type != PJ_STUN_BINDING_REQUEST) { @@ -2072,9 +2062,9 @@ static pj_status_t on_stun_rx_request(pj_stun_session *sess, PJ_TRUE, src_addr, src_addr_len); /* Create a msg_data to be associated with this response */ - msg_data = PJ_POOL_ZALLOC_T(tdata->pool, struct msg_data); + msg_data = PJ_POOL_ZALLOC_T(ice->pool, struct msg_data); msg_data->is_request = PJ_FALSE; - msg_data->data.res.cand_id = *param_cand_id; + msg_data->cand_id = ((struct msg_data*)token)->cand_id; /* Send the response */ status = pj_stun_session_send_msg(sess, msg_data, PJ_TRUE, PJ_TRUE, @@ -2388,6 +2378,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_on_rx_pkt(pj_ice_sess *ice, { pj_status_t status = PJ_SUCCESS; pj_ice_sess_comp *comp; + struct msg_data *msg_data; pj_status_t stun_status; PJ_ASSERT_RETURN(ice, PJ_EINVAL); @@ -2400,11 +2391,15 @@ PJ_DEF(pj_status_t) pj_ice_sess_on_rx_pkt(pj_ice_sess *ice, goto on_return; } + msg_data = PJ_POOL_ZALLOC_T(ice->pool, struct msg_data); + msg_data->is_request = PJ_FALSE; + msg_data->cand_id = cand_id; + stun_status = pj_stun_msg_check((const pj_uint8_t*)pkt, pkt_size, PJ_STUN_IS_DATAGRAM); if (stun_status == PJ_SUCCESS) { status = pj_stun_session_on_rx_pkt(comp->stun_sess, pkt, pkt_size, - PJ_STUN_IS_DATAGRAM, &cand_id, + PJ_STUN_IS_DATAGRAM, msg_data, NULL, src_addr, src_addr_len); if (status != PJ_SUCCESS) { pj_strerror(status, ice->tmp.errmsg, sizeof(ice->tmp.errmsg)); diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c index 59647a98b..21a8c4bf6 100644 --- a/pjnath/src/pjnath/ice_strans.c +++ b/pjnath/src/pjnath/ice_strans.c @@ -953,6 +953,14 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, continue; } + /* Skip if candidate has no address */ + if (!pj_sockaddr_has_addr(&cand->addr)) { + PJ_LOG(5,(ice_st->obj_name, + "Candidate %d in component %d is not added", + j, i)); + continue; + } + if (cand->type == PJ_ICE_CAND_TYPE_RELAYED) { local_addr = &cand->addr; relay_addr = &cand->addr; @@ -963,7 +971,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, status = pj_ice_sess_add_cand(ice_st->ice, comp->comp_id, cand->type, cand->local_pref, &cand->foundation, &cand->addr, - &comp->local_addr, NULL, + local_addr, relay_addr, sizeof(pj_sockaddr_in), (unsigned*)&cand->ice_cand_id); if (status != PJ_SUCCESS) @@ -1315,6 +1323,11 @@ static void turn_on_rx_data(pj_turn_sock *turn_sock, return; } + if (comp->ice_st->ice == NULL) { + /* The session is gone */ + return; + } + /* Find candidate ID for this packet */ for (cand_id=0; cand_idcand_cnt; ++cand_id) { if (comp->cand_list[cand_id].type == PJ_ICE_CAND_TYPE_RELAYED) diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index d5f166103..65abc816b 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -22,15 +22,24 @@ #define THIS_FILE "pjsua_app.c" #define NO_LIMIT (int)0x7FFFFFFF -#if 1 +#if 0 #define TURN_SERVER "turn.pjsip.org" #define TURN_PORT 34780 -#define TURN_TCP 0 #define TURN_REALM "pjsip.org" #define TURN_USER "700" #define TURN_PASSWD "700" #endif +#if 1 +/* Eyeball test */ +#define TURN_SERVER "216.187.87.78" +#define TURN_PORT 3478 +#define TURN_REALM "test.eyeball.com" +#define TURN_USER "sipit6" +#define TURN_PASSWD "password" +#endif + + //#define STEREO_DEMO @@ -239,11 +248,11 @@ static void usage(void) /* Set default config. */ static void default_config(struct app_config *cfg) { - char tmp[80]; + char tmp[120]; unsigned i; pjsua_config_default(&cfg->cfg); - pj_ansi_sprintf(tmp, "PJSUA v%s/%s", pj_get_version(), PJ_OS_NAME); + pj_ansi_sprintf(tmp, "PJSUA v%s/%s (http://pjsip.org)", pj_get_version(), PJ_OS_NAME); pj_strdup2_with_null(app_config.pool, &cfg->cfg.user_agent, tmp); pjsua_logging_config_default(&cfg->log_cfg);