Skip to content
Snippets Groups Projects
Unverified Commit 3f598a6a authored by Sébastien Blin's avatar Sébastien Blin
Browse files

pjproject: avoid to declare check valid too soon

The relay candidate was declared as suceeded even if not in the valid list.
Because of this, some negotiations were successful but no valid candidates
were given to the app.

Moreover, the connection timeout checks were using the wrong timer. This
avoids to cancel successful negotiations to check a connection timeout.

Finally, some clean is done with this patch

Change-Id: Iacfbf3b9f5faafe1bd05f66157485226761c30bf
Gitlab: #256
parent 9c58e4f0
No related branches found
No related tags found
No related merge requests found
Copyright (C) 2018-2019 Savoir-faire Linux Inc. Copyright (C) 2018-2020 Savoir-faire Linux Inc.
ice: rfc6544 support ice: rfc6544 support
...@@ -18,8 +18,9 @@ on behalf of Savoir-faire Linux. ...@@ -18,8 +18,9 @@ on behalf of Savoir-faire Linux.
Rebased for pjsip 2.10 by Peymane Marandi Rebased for pjsip 2.10 by Peymane Marandi
<paymon@savoirfairelinux.com> <paymon@savoirfairelinux.com>
on behalf of Savoir-faire Linux. on behalf of Savoir-faire Linux.
--- ---
pjnath/include/pjnath/ice_session.h | 173 +++- pjnath/include/pjnath/ice_session.h | 151 +++-
pjnath/include/pjnath/ice_strans.h | 21 + pjnath/include/pjnath/ice_strans.h | 21 +
pjnath/include/pjnath/stun_session.h | 75 +- pjnath/include/pjnath/stun_session.h | 75 +-
pjnath/include/pjnath/stun_sock.h | 67 +- pjnath/include/pjnath/stun_sock.h | 67 +-
...@@ -27,8 +28,8 @@ on behalf of Savoir-faire Linux. ...@@ -27,8 +28,8 @@ on behalf of Savoir-faire Linux.
pjnath/src/pjnath-test/concur_test.c | 5 +- pjnath/src/pjnath-test/concur_test.c | 5 +-
pjnath/src/pjnath-test/sess_auth.c | 14 +- pjnath/src/pjnath-test/sess_auth.c | 14 +-
pjnath/src/pjnath-test/stun_sock_test.c | 7 +- pjnath/src/pjnath-test/stun_sock_test.c | 7 +-
pjnath/src/pjnath/ice_session.c | 515 ++++++++++- pjnath/src/pjnath/ice_session.c | 491 +++++++++--
pjnath/src/pjnath/ice_strans.c | 773 +++++++++++++--- pjnath/src/pjnath/ice_strans.c | 745 +++++++++++++---
pjnath/src/pjnath/nat_detect.c | 7 +- pjnath/src/pjnath/nat_detect.c | 7 +-
pjnath/src/pjnath/stun_session.c | 15 +- pjnath/src/pjnath/stun_session.c | 15 +-
pjnath/src/pjnath/stun_sock.c | 1075 +++++++++++++++++++---- pjnath/src/pjnath/stun_sock.c | 1075 +++++++++++++++++++----
...@@ -40,10 +41,10 @@ on behalf of Savoir-faire Linux. ...@@ -40,10 +41,10 @@ on behalf of Savoir-faire Linux.
pjnath/src/pjturn-srv/server.c | 2 +- pjnath/src/pjturn-srv/server.c | 2 +-
pjsip-apps/src/samples/icedemo.c | 116 ++- pjsip-apps/src/samples/icedemo.c | 116 ++-
pjsip/src/pjsua-lib/pjsua_core.c | 2 +- pjsip/src/pjsua-lib/pjsua_core.c | 2 +-
21 files changed, 2510 insertions(+), 403 deletions(-) 21 files changed, 2430 insertions(+), 409 deletions(-)
diff --git a/pjnath/include/pjnath/ice_session.h b/pjnath/include/pjnath/ice_session.h diff --git a/pjnath/include/pjnath/ice_session.h b/pjnath/include/pjnath/ice_session.h
index 8971220f0..39c197c29 100644 index 8971220f0..4cccd7c64 100644
--- a/pjnath/include/pjnath/ice_session.h --- a/pjnath/include/pjnath/ice_session.h
+++ b/pjnath/include/pjnath/ice_session.h +++ b/pjnath/include/pjnath/ice_session.h
@@ -163,6 +163,52 @@ typedef enum pj_ice_cand_type @@ -163,6 +163,52 @@ typedef enum pj_ice_cand_type
...@@ -147,7 +148,7 @@ index 8971220f0..39c197c29 100644 ...@@ -147,7 +148,7 @@ index 8971220f0..39c197c29 100644
/** /**
* A check has not been performed for this pair, and can be * A check has not been performed for this pair, and can be
* performed as soon as it is the highest priority Waiting pair on * performed as soon as it is the highest priority Waiting pair on
@@ -520,6 +593,52 @@ typedef struct pj_ice_sess_cb @@ -520,6 +593,41 @@ typedef struct pj_ice_sess_cb
void *pkt, pj_size_t size, void *pkt, pj_size_t size,
const pj_sockaddr_t *src_addr, const pj_sockaddr_t *src_addr,
unsigned src_addr_len); unsigned src_addr_len);
...@@ -164,17 +165,6 @@ index 8971220f0..39c197c29 100644 ...@@ -164,17 +165,6 @@ index 8971220f0..39c197c29 100644
+ unsigned check_id); + unsigned check_id);
+ +
+ /** + /**
+ * Select incoming TURN dataconn
+ *
+ * @param ice The ICE session.
+ * @param clist The ICE connection list
+ * @param check_id The wanted check.
+ */
+ pj_status_t (*select_turn_dataconn)(pj_ice_sess *ice,
+ pj_ice_sess_checklist *clist,
+ unsigned check_id);
+
+ /**
+ * Reconnect a resetted TCP connection and send connectivity check + * Reconnect a resetted TCP connection and send connectivity check
+ * cf. PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY + * cf. PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY
+ * + *
...@@ -200,7 +190,7 @@ index 8971220f0..39c197c29 100644 ...@@ -200,7 +190,7 @@ index 8971220f0..39c197c29 100644
} pj_ice_sess_cb; } pj_ice_sess_cb;
@@ -636,6 +755,7 @@ struct pj_ice_sess @@ -636,6 +744,7 @@ struct pj_ice_sess
pj_bool_t valid_pair_found; /**< First pair found */ pj_bool_t valid_pair_found; /**< First pair found */
pj_status_t ice_status; /**< Error status. */ pj_status_t ice_status; /**< Error status. */
pj_timer_entry timer; /**< ICE timer. */ pj_timer_entry timer; /**< ICE timer. */
...@@ -208,7 +198,7 @@ index 8971220f0..39c197c29 100644 ...@@ -208,7 +198,7 @@ index 8971220f0..39c197c29 100644
pj_ice_sess_cb cb; /**< Callback. */ pj_ice_sess_cb cb; /**< Callback. */
pj_stun_config stun_cfg; /**< STUN settings. */ pj_stun_config stun_cfg; /**< STUN settings. */
@@ -855,6 +975,7 @@ PJ_DECL(pj_status_t) pj_ice_sess_set_prefs(pj_ice_sess *ice, @@ -855,6 +964,7 @@ PJ_DECL(pj_status_t) pj_ice_sess_set_prefs(pj_ice_sess *ice,
* @param rel_addr Optional related address. * @param rel_addr Optional related address.
* @param addr_len Length of addresses. * @param addr_len Length of addresses.
* @param p_cand_id Optional pointer to receive the candidate ID. * @param p_cand_id Optional pointer to receive the candidate ID.
...@@ -216,7 +206,7 @@ index 8971220f0..39c197c29 100644 ...@@ -216,7 +206,7 @@ index 8971220f0..39c197c29 100644
* *
* @return PJ_SUCCESS if candidate is successfully added. * @return PJ_SUCCESS if candidate is successfully added.
*/ */
@@ -868,7 +989,8 @@ PJ_DECL(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice, @@ -868,7 +978,8 @@ PJ_DECL(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice,
const pj_sockaddr_t *base_addr, const pj_sockaddr_t *base_addr,
const pj_sockaddr_t *rel_addr, const pj_sockaddr_t *rel_addr,
int addr_len, int addr_len,
...@@ -226,7 +216,7 @@ index 8971220f0..39c197c29 100644 ...@@ -226,7 +216,7 @@ index 8971220f0..39c197c29 100644
/** /**
* Find default candidate for the specified component ID, using this * Find default candidate for the specified component ID, using this
@@ -980,6 +1102,55 @@ PJ_DECL(pj_status_t) pj_ice_sess_on_rx_pkt(pj_ice_sess *ice, @@ -980,6 +1091,44 @@ PJ_DECL(pj_status_t) pj_ice_sess_on_rx_pkt(pj_ice_sess *ice,
const pj_sockaddr_t *src_addr, const pj_sockaddr_t *src_addr,
int src_addr_len); int src_addr_len);
...@@ -268,17 +258,6 @@ index 8971220f0..39c197c29 100644 ...@@ -268,17 +258,6 @@ index 8971220f0..39c197c29 100644
+PJ_DECL(void) ice_sess_on_peer_packet(pj_ice_sess *ice, +PJ_DECL(void) ice_sess_on_peer_packet(pj_ice_sess *ice,
+ pj_uint8_t transport_id, + pj_uint8_t transport_id,
+ pj_sockaddr_t* remote_addr); + pj_sockaddr_t* remote_addr);
+
+/**
+ * Select dataconn from TURN
+ *
+ * @param ice The ICE session.
+ * @param clist The ice check list
+ * @param check_id The wanted check
+ */
+PJ_DECL(void) ice_select_incoming_turn(pj_ice_sess *ice,
+ pj_ice_sess_checklist *clist,
+ unsigned check_id);
/** /**
...@@ -669,7 +648,7 @@ index fff4fad26..e7f8b84eb 100644 ...@@ -669,7 +648,7 @@ index fff4fad26..e7f8b84eb 100644
if (status != PJ_SUCCESS && status != PJ_EPENDING) { if (status != PJ_SUCCESS && status != PJ_EPENDING) {
app_perror(" error: server sending data", status); app_perror(" error: server sending data", status);
diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
index 2a4125bc5..85d3234c9 100644 index 2a4125bc5..c3a06fbc4 100644
--- a/pjnath/src/pjnath/ice_session.c --- a/pjnath/src/pjnath/ice_session.c
+++ b/pjnath/src/pjnath/ice_session.c +++ b/pjnath/src/pjnath/ice_session.c
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
...@@ -728,7 +707,15 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -728,7 +707,15 @@ index 2a4125bc5..85d3234c9 100644
if (status != PJ_SUCCESS) if (status != PJ_SUCCESS)
return status; return status;
@@ -717,7 +726,8 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice, @@ -359,6 +368,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_create(pj_stun_config *stun_cfg,
pj_ice_sess_options_default(&ice->opt);
pj_timer_entry_init(&ice->timer, TIMER_NONE, (void*)ice, &on_timer);
+ pj_timer_entry_init(&ice->timer_connect, TIMER_NONE, (void*)ice, &on_timer);
pj_ansi_snprintf(ice->obj_name, sizeof(ice->obj_name),
name, ice);
@@ -717,7 +727,8 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice,
const pj_sockaddr_t *base_addr, const pj_sockaddr_t *base_addr,
const pj_sockaddr_t *rel_addr, const pj_sockaddr_t *rel_addr,
int addr_len, int addr_len,
...@@ -738,7 +725,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -738,7 +725,7 @@ index 2a4125bc5..85d3234c9 100644
{ {
pj_ice_sess_cand *lcand; pj_ice_sess_cand *lcand;
pj_status_t status = PJ_SUCCESS; pj_status_t status = PJ_SUCCESS;
@@ -740,6 +750,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice, @@ -740,6 +751,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice,
lcand->comp_id = (pj_uint8_t)comp_id; lcand->comp_id = (pj_uint8_t)comp_id;
lcand->transport_id = (pj_uint8_t)transport_id; lcand->transport_id = (pj_uint8_t)transport_id;
lcand->type = type; lcand->type = type;
...@@ -746,7 +733,17 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -746,7 +733,17 @@ index 2a4125bc5..85d3234c9 100644
pj_strdup(ice->pool, &lcand->foundation, foundation); pj_strdup(ice->pool, &lcand->foundation, foundation);
lcand->prio = CALC_CAND_PRIO(ice, type, local_pref, lcand->comp_id); lcand->prio = CALC_CAND_PRIO(ice, type, local_pref, lcand->comp_id);
pj_sockaddr_cp(&lcand->addr, addr); pj_sockaddr_cp(&lcand->addr, addr);
@@ -1081,6 +1092,17 @@ static pj_status_t prune_checklist(pj_ice_sess *ice, @@ -961,7 +973,8 @@ static void check_set_state(pj_ice_sess *ice, pj_ice_sess_check *check,
pj_ice_sess_check_state st,
pj_status_t err_code)
{
- pj_assert(check->state < PJ_ICE_SESS_CHECK_STATE_SUCCEEDED);
+ if (check->state >= PJ_ICE_SESS_CHECK_STATE_SUCCEEDED)
+ return;
LOG5((ice->obj_name, "Check %s: state changed from %s to %s",
dump_check(ice->tmp.txt, sizeof(ice->tmp.txt), &ice->clist, check),
@@ -1081,6 +1094,17 @@ static pj_status_t prune_checklist(pj_ice_sess *ice,
return PJNATH_EICENOHOSTCAND; return PJNATH_EICENOHOSTCAND;
} }
} }
...@@ -764,7 +761,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -764,7 +761,7 @@ index 2a4125bc5..85d3234c9 100644
} }
/* Next remove a pair if its local and remote candidates are identical /* Next remove a pair if its local and remote candidates are identical
@@ -1183,6 +1205,9 @@ static void on_timer(pj_timer_heap_t *th, pj_timer_entry *te) @@ -1183,6 +1207,9 @@ static void on_timer(pj_timer_heap_t *th, pj_timer_entry *te)
case TIMER_KEEP_ALIVE: case TIMER_KEEP_ALIVE:
ice_keep_alive(ice, PJ_TRUE); ice_keep_alive(ice, PJ_TRUE);
break; break;
...@@ -774,13 +771,13 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -774,13 +771,13 @@ index 2a4125bc5..85d3234c9 100644
case TIMER_NONE: case TIMER_NONE:
/* Nothing to do, just to get rid of gcc warning */ /* Nothing to do, just to get rid of gcc warning */
break; break;
@@ -1619,6 +1644,43 @@ static pj_bool_t on_check_complete(pj_ice_sess *ice, @@ -1619,6 +1646,43 @@ static pj_bool_t on_check_complete(pj_ice_sess *ice,
return PJ_FALSE; return PJ_FALSE;
} }
+static void on_tcp_connect_timeout(pj_ice_sess* ice) +static void on_tcp_connect_timeout(pj_ice_sess* ice)
+{ +{
+ pj_timer_heap_cancel_if_active(ice->stun_cfg.timer_heap,&ice->timer, + pj_timer_heap_cancel_if_active(ice->stun_cfg.timer_heap,&ice->timer_connect,
+ TIMER_NONE); + TIMER_NONE);
+ +
+ pj_bool_t first_found = PJ_FALSE, set_timer = PJ_FALSE; + pj_bool_t first_found = PJ_FALSE, set_timer = PJ_FALSE;
...@@ -802,7 +799,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -802,7 +799,7 @@ index 2a4125bc5..85d3234c9 100644
+ } + }
+ } + }
+ +
+ if (set_timer && ice->timer.id == TIMER_NONE) { + if (set_timer && ice->timer_connect.id == TIMER_NONE) {
+ /* Reschedule */ + /* Reschedule */
+ pj_time_val delay = { + pj_time_val delay = {
+ .sec = 0, + .sec = 0,
...@@ -810,7 +807,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -810,7 +807,7 @@ index 2a4125bc5..85d3234c9 100644
+ }; + };
+ pj_time_val_normalize(&delay); + pj_time_val_normalize(&delay);
+ pj_timer_heap_schedule_w_grp_lock(ice->stun_cfg.timer_heap, + pj_timer_heap_schedule_w_grp_lock(ice->stun_cfg.timer_heap,
+ &ice->timer, &delay, + &ice->timer_connect, &delay,
+ TIMER_CONNECTION_TIMEOUT, + TIMER_CONNECTION_TIMEOUT,
+ ice->grp_lock); + ice->grp_lock);
+ } + }
...@@ -818,7 +815,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -818,7 +815,7 @@ index 2a4125bc5..85d3234c9 100644
/* Create checklist by pairing local candidates with remote candidates */ /* Create checklist by pairing local candidates with remote candidates */
PJ_DEF(pj_status_t) pj_ice_sess_create_check_list( PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
@@ -1705,6 +1767,30 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list( @@ -1705,6 +1769,30 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
continue; continue;
} }
...@@ -849,7 +846,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -849,7 +846,7 @@ index 2a4125bc5..85d3234c9 100644
chk->lcand = lcand; chk->lcand = lcand;
chk->rcand = rcand; chk->rcand = rcand;
@@ -1749,6 +1835,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list( @@ -1749,6 +1837,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
td = PJ_POOL_ZALLOC_T(ice->pool, timer_data); td = PJ_POOL_ZALLOC_T(ice->pool, timer_data);
td->ice = ice; td->ice = ice;
td->clist = clist; td->clist = clist;
...@@ -857,7 +854,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -857,7 +854,7 @@ index 2a4125bc5..85d3234c9 100644
clist->timer.user_data = (void*)td; clist->timer.user_data = (void*)td;
clist->timer.cb = &periodic_timer; clist->timer.cb = &periodic_timer;
@@ -1761,6 +1848,36 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list( @@ -1761,6 +1850,36 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
return PJ_SUCCESS; return PJ_SUCCESS;
} }
...@@ -894,7 +891,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -894,7 +891,7 @@ index 2a4125bc5..85d3234c9 100644
/* Perform check on the specified candidate pair. */ /* Perform check on the specified candidate pair. */
static pj_status_t perform_check(pj_ice_sess *ice, static pj_status_t perform_check(pj_ice_sess *ice,
pj_ice_sess_checklist *clist, pj_ice_sess_checklist *clist,
@@ -1771,19 +1888,17 @@ static pj_status_t perform_check(pj_ice_sess *ice, @@ -1771,19 +1890,17 @@ static pj_status_t perform_check(pj_ice_sess *ice,
pj_ice_msg_data *msg_data; pj_ice_msg_data *msg_data;
pj_ice_sess_check *check; pj_ice_sess_check *check;
const pj_ice_sess_cand *lcand; const pj_ice_sess_cand *lcand;
...@@ -915,7 +912,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -915,7 +912,7 @@ index 2a4125bc5..85d3234c9 100644
/* Create request */ /* Create request */
status = pj_stun_session_create_req(comp->stun_sess, status = pj_stun_session_create_req(comp->stun_sess,
@@ -1831,32 +1946,92 @@ static pj_status_t perform_check(pj_ice_sess *ice, @@ -1831,32 +1948,71 @@ static pj_status_t perform_check(pj_ice_sess *ice,
&ice->tie_breaker); &ice->tie_breaker);
} else { } else {
...@@ -929,10 +926,6 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -929,10 +926,6 @@ index 2a4125bc5..85d3234c9 100644
+#if PJ_HAS_TCP +#if PJ_HAS_TCP
+ switch (lcand->transport) { + switch (lcand->transport) {
+ case PJ_CAND_UDP:
+ status = send_connectivity_check(ice, clist, check_id,
+ nominate, msg_data);
+ break;
+ case PJ_CAND_TCP_ACTIVE: + case PJ_CAND_TCP_ACTIVE:
+ switch (check->state) { + switch (check->state) {
+ case PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY: + case PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY:
...@@ -944,9 +937,9 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -944,9 +937,9 @@ index 2a4125bc5..85d3234c9 100644
+ break; + break;
+ default: + default:
+ pj_timer_heap_cancel_if_active(ice->stun_cfg.timer_heap, + pj_timer_heap_cancel_if_active(ice->stun_cfg.timer_heap,
+ &ice->timer, TIMER_NONE); + &ice->timer_connect, TIMER_NONE);
+ status = (*ice->cb.wait_tcp_connection)(ice, clist, check_id); + status = (*ice->cb.wait_tcp_connection)(ice, clist, check_id);
+ if (ice->timer.id != TIMER_NONE) { + if (ice->timer_connect.id != TIMER_NONE) {
+ pj_assert(!"Not expected any timer active"); + pj_assert(!"Not expected any timer active");
+ } else { + } else {
+ pj_time_val delay = { + pj_time_val delay = {
...@@ -955,7 +948,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -955,7 +948,7 @@ index 2a4125bc5..85d3234c9 100644
+ }; + };
+ pj_time_val_normalize(&delay); + pj_time_val_normalize(&delay);
+ pj_timer_heap_schedule_w_grp_lock(ice->stun_cfg.timer_heap, + pj_timer_heap_schedule_w_grp_lock(ice->stun_cfg.timer_heap,
+ &ice->timer, &delay, + &ice->timer_connect, &delay,
+ TIMER_CONNECTION_TIMEOUT, + TIMER_CONNECTION_TIMEOUT,
+ ice->grp_lock); + ice->grp_lock);
+ } + }
...@@ -964,26 +957,9 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -964,26 +957,9 @@ index 2a4125bc5..85d3234c9 100644
+ break; + break;
+ case PJ_CAND_TCP_PASSIVE: + case PJ_CAND_TCP_PASSIVE:
+ case PJ_CAND_TCP_SO: + case PJ_CAND_TCP_SO:
+ case PJ_CAND_UDP:
+ default: + default:
+ if (lcand->type == PJ_ICE_CAND_TYPE_RELAYED) { + status = send_connectivity_check(ice, clist, check_id, nominate, msg_data);
+ status = (*ice->cb.select_turn_dataconn)(ice, clist, check_id);
+ if (ice->timer.id == TIMER_NONE) {
+ pj_timer_heap_cancel_if_active(ice->stun_cfg.timer_heap,
+ &ice->timer, TIMER_NONE);
+ pj_time_val delay = {
+ .sec = 0,
+ .msec = 1500
+ };
+ pj_time_val_normalize(&delay);
+ pj_timer_heap_schedule_w_grp_lock(ice->stun_cfg.timer_heap,
+ &ice->timer, &delay,
+ TIMER_CONNECTION_TIMEOUT,
+ ice->grp_lock);
+ }
+ } else {
+ status = send_connectivity_check(ice, clist, check_id,
+ nominate, msg_data);
+ }
+ break; + break;
+ } + }
+#else +#else
...@@ -1024,7 +1000,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -1024,7 +1000,7 @@ index 2a4125bc5..85d3234c9 100644
} }
@@ -1893,39 +2068,95 @@ static pj_status_t start_periodic_check(pj_timer_heap_t *th, @@ -1893,39 +2049,95 @@ static pj_status_t start_periodic_check(pj_timer_heap_t *th,
pj_log_push_indent(); pj_log_push_indent();
/* Send STUN Binding request for check with highest priority on /* Send STUN Binding request for check with highest priority on
...@@ -1136,7 +1112,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -1136,7 +1112,7 @@ index 2a4125bc5..85d3234c9 100644
++start_count; ++start_count;
break; break;
} }
@@ -1933,14 +2164,14 @@ static pj_status_t start_periodic_check(pj_timer_heap_t *th, @@ -1933,14 +2145,14 @@ static pj_status_t start_periodic_check(pj_timer_heap_t *th,
} }
/* Cannot start check because there's no suitable candidate pair. /* Cannot start check because there's no suitable candidate pair.
...@@ -1153,7 +1129,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -1153,7 +1129,7 @@ index 2a4125bc5..85d3234c9 100644
} }
pj_grp_lock_release(ice->grp_lock); pj_grp_lock_release(ice->grp_lock);
@@ -2181,6 +2412,192 @@ static pj_status_t on_stun_send_msg(pj_stun_session *sess, @@ -2181,6 +2393,179 @@ static pj_status_t on_stun_send_msg(pj_stun_session *sess,
return status; return status;
} }
...@@ -1326,27 +1302,14 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -1326,27 +1302,14 @@ index 2a4125bc5..85d3234c9 100644
+ +
+ const pj_ice_sess_cand *rcand = check->rcand; + const pj_ice_sess_cand *rcand = check->rcand;
+ if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED) { + if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED) {
+ check->state = PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS;
+ check_set_state(ice, check, + check_set_state(ice, check,
+ PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS, PJ_SUCCESS); + PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS, PJ_SUCCESS);
+ } + }
+}
+
+
+void ice_select_incoming_turn(pj_ice_sess *ice,
+ pj_ice_sess_checklist *clist,
+ unsigned check_id)
+{
+ check_set_state(ice, &clist->checks[check_id],
+ PJ_ICE_SESS_CHECK_STATE_SUCCEEDED, PJ_SUCCESS);
+ update_comp_check(ice, clist->checks[check_id].lcand->comp_id,
+ &clist->checks[check_id]);
+ on_check_complete(ice, &clist->checks[check_id]);
+} +}
/* This callback is called when outgoing STUN request completed */ /* This callback is called when outgoing STUN request completed */
static void on_stun_request_complete(pj_stun_session *stun_sess, static void on_stun_request_complete(pj_stun_session *stun_sess,
@@ -2411,7 +2828,9 @@ static void on_stun_request_complete(pj_stun_session *stun_sess, @@ -2411,7 +2796,9 @@ static void on_stun_request_complete(pj_stun_session *stun_sess,
&check->lcand->base_addr, &check->lcand->base_addr,
&check->lcand->base_addr, &check->lcand->base_addr,
pj_sockaddr_get_len(&xaddr->sockaddr), pj_sockaddr_get_len(&xaddr->sockaddr),
...@@ -1357,7 +1320,20 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -1357,7 +1320,20 @@ index 2a4125bc5..85d3234c9 100644
if (status != PJ_SUCCESS) { if (status != PJ_SUCCESS) {
check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED,
status); status);
@@ -2673,7 +3092,9 @@ static pj_status_t on_stun_rx_request(pj_stun_session *sess, @@ -2474,11 +2861,7 @@ static void on_stun_request_complete(pj_stun_session *stun_sess,
/* Perform 7.1.2.2.2. Updating Pair States.
* This may terminate ICE processing.
*/
- if (on_check_complete(ice, check)) {
- /* ICE complete! */
- pj_grp_lock_release(ice->grp_lock);
- return;
- }
+ on_check_complete(ice, check);
pj_grp_lock_release(ice->grp_lock);
}
@@ -2673,7 +3056,9 @@ static pj_status_t on_stun_rx_request(pj_stun_session *sess,
msg_data->has_req_data = PJ_FALSE; msg_data->has_req_data = PJ_FALSE;
/* Send the response */ /* Send the response */
...@@ -1368,7 +1344,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -1368,7 +1344,7 @@ index 2a4125bc5..85d3234c9 100644
src_addr, src_addr_len, tdata); src_addr, src_addr_len, tdata);
@@ -2794,12 +3215,12 @@ static void handle_incoming_check(pj_ice_sess *ice, @@ -2794,12 +3179,12 @@ static void handle_incoming_check(pj_ice_sess *ice,
/* Just get candidate with the highest priority and same transport ID /* Just get candidate with the highest priority and same transport ID
* for the specified component ID in the checklist. * for the specified component ID in the checklist.
*/ */
...@@ -1387,7 +1363,7 @@ index 2a4125bc5..85d3234c9 100644 ...@@ -1387,7 +1363,7 @@ index 2a4125bc5..85d3234c9 100644
} }
} }
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 3cb350c2a..bf7f98096 100644 index 3cb350c2a..d29c1f0db 100644
--- a/pjnath/src/pjnath/ice_strans.c --- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c +++ b/pjnath/src/pjnath/ice_strans.c
@@ -69,6 +69,7 @@ enum tp_type @@ -69,6 +69,7 @@ enum tp_type
...@@ -1413,7 +1389,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1413,7 +1389,7 @@ index 3cb350c2a..bf7f98096 100644
/* ICE callbacks */ /* ICE callbacks */
static void on_ice_complete(pj_ice_sess *ice, pj_status_t status); static void on_ice_complete(pj_ice_sess *ice, pj_status_t status);
@@ -103,6 +112,24 @@ static void ice_rx_data(pj_ice_sess *ice, @@ -103,6 +112,20 @@ static void ice_rx_data(pj_ice_sess *ice,
const pj_sockaddr_t *src_addr, const pj_sockaddr_t *src_addr,
unsigned src_addr_len); unsigned src_addr_len);
...@@ -1422,10 +1398,6 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1422,10 +1398,6 @@ index 3cb350c2a..bf7f98096 100644
+ pj_ice_sess_checklist *clist, + pj_ice_sess_checklist *clist,
+ unsigned check_id); + unsigned check_id);
+ +
+static pj_status_t ice_select_turn_dataconn(pj_ice_sess *ice,
+ pj_ice_sess_checklist *clist,
+ unsigned check_id);
+
+static pj_status_t ice_reconnect_tcp_connection(pj_ice_sess *ice, +static pj_status_t ice_reconnect_tcp_connection(pj_ice_sess *ice,
+ pj_ice_sess_checklist *clist, + pj_ice_sess_checklist *clist,
+ unsigned check_id); + unsigned check_id);
...@@ -1438,7 +1410,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1438,7 +1410,7 @@ index 3cb350c2a..bf7f98096 100644
/* STUN socket callbacks */ /* STUN socket callbacks */
/* Notification when incoming packet has been received. */ /* Notification when incoming packet has been received. */
@@ -182,6 +209,16 @@ typedef struct pj_ice_strans_comp @@ -182,6 +205,16 @@ typedef struct pj_ice_strans_comp
} pj_ice_strans_comp; } pj_ice_strans_comp;
...@@ -1455,7 +1427,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1455,7 +1427,7 @@ index 3cb350c2a..bf7f98096 100644
/* Pending send buffer */ /* Pending send buffer */
typedef struct pending_send typedef struct pending_send
{ {
@@ -225,6 +262,13 @@ struct pj_ice_strans @@ -225,6 +258,13 @@ struct pj_ice_strans
pj_bool_t destroy_req;/**< Destroy has been called? */ pj_bool_t destroy_req;/**< Destroy has been called? */
pj_bool_t cb_called; /**< Init error callback called?*/ pj_bool_t cb_called; /**< Init error callback called?*/
pj_bool_t call_send_cb;/**< Need to call send cb? */ pj_bool_t call_send_cb;/**< Need to call send cb? */
...@@ -1469,7 +1441,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1469,7 +1441,7 @@ index 3cb350c2a..bf7f98096 100644
}; };
@@ -261,6 +305,7 @@ PJ_DEF(void) pj_ice_strans_cfg_default(pj_ice_strans_cfg *cfg) @@ -261,6 +301,7 @@ PJ_DEF(void) pj_ice_strans_cfg_default(pj_ice_strans_cfg *cfg)
pj_bzero(cfg, sizeof(*cfg)); pj_bzero(cfg, sizeof(*cfg));
cfg->af = pj_AF_INET(); cfg->af = pj_AF_INET();
...@@ -1477,7 +1449,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1477,7 +1449,7 @@ index 3cb350c2a..bf7f98096 100644
pj_stun_config_init(&cfg->stun_cfg, NULL, 0, NULL, NULL); pj_stun_config_init(&cfg->stun_cfg, NULL, 0, NULL, NULL);
pj_ice_strans_stun_cfg_default(&cfg->stun); pj_ice_strans_stun_cfg_default(&cfg->stun);
pj_ice_strans_turn_cfg_default(&cfg->turn); pj_ice_strans_turn_cfg_default(&cfg->turn);
@@ -278,6 +323,7 @@ PJ_DEF(void) pj_ice_strans_stun_cfg_default(pj_ice_strans_stun_cfg *cfg) @@ -278,6 +319,7 @@ PJ_DEF(void) pj_ice_strans_stun_cfg_default(pj_ice_strans_stun_cfg *cfg)
pj_bzero(cfg, sizeof(*cfg)); pj_bzero(cfg, sizeof(*cfg));
cfg->af = pj_AF_INET(); cfg->af = pj_AF_INET();
...@@ -1485,7 +1457,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1485,7 +1457,7 @@ index 3cb350c2a..bf7f98096 100644
cfg->port = PJ_STUN_PORT; cfg->port = PJ_STUN_PORT;
cfg->max_host_cands = 64; cfg->max_host_cands = 64;
cfg->ignore_stun_error = PJ_FALSE; cfg->ignore_stun_error = PJ_FALSE;
@@ -421,6 +467,9 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st, @@ -421,6 +463,9 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st,
cand->transport_id = tp_id; cand->transport_id = tp_id;
cand->comp_id = (pj_uint8_t) comp->comp_id; cand->comp_id = (pj_uint8_t) comp->comp_id;
new_cand = PJ_TRUE; new_cand = PJ_TRUE;
...@@ -1495,7 +1467,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1495,7 +1467,7 @@ index 3cb350c2a..bf7f98096 100644
} }
/* Allocate and initialize TURN socket data */ /* Allocate and initialize TURN socket data */
@@ -428,6 +477,10 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st, @@ -428,6 +473,10 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st,
data->comp = comp; data->comp = comp;
data->transport_id = cand->transport_id; data->transport_id = cand->transport_id;
...@@ -1506,7 +1478,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1506,7 +1478,7 @@ index 3cb350c2a..bf7f98096 100644
/* Create the TURN transport */ /* Create the TURN transport */
status = pj_turn_sock_create(&ice_st->cfg.stun_cfg, turn_cfg->af, status = pj_turn_sock_create(&ice_st->cfg.stun_cfg, turn_cfg->af,
turn_cfg->conn_type, turn_cfg->conn_type,
@@ -465,7 +518,7 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st, @@ -465,7 +514,7 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st,
return PJ_SUCCESS; return PJ_SUCCESS;
} }
...@@ -1515,7 +1487,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1515,7 +1487,7 @@ index 3cb350c2a..bf7f98096 100644
pj_ice_sess_cand *rcand) pj_ice_sess_cand *rcand)
{ {
if (lcand == NULL && rcand == NULL){ if (lcand == NULL && rcand == NULL){
@@ -474,23 +527,23 @@ static pj_bool_t ice_cand_equals(pj_ice_sess_cand *lcand, @@ -474,23 +523,23 @@ static pj_bool_t ice_cand_equals(pj_ice_sess_cand *lcand,
if (lcand == NULL || rcand == NULL){ if (lcand == NULL || rcand == NULL){
return PJ_FALSE; return PJ_FALSE;
} }
...@@ -1542,7 +1514,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1542,7 +1514,7 @@ index 3cb350c2a..bf7f98096 100644
static pj_status_t add_stun_and_host(pj_ice_strans *ice_st, static pj_status_t add_stun_and_host(pj_ice_strans *ice_st,
pj_ice_strans_comp *comp, pj_ice_strans_comp *comp,
unsigned idx, unsigned idx,
@@ -541,6 +594,9 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st, @@ -541,6 +590,9 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st,
cand->local_pref = SRFLX_PREF; cand->local_pref = SRFLX_PREF;
cand->transport_id = CREATE_TP_ID(TP_STUN, idx); cand->transport_id = CREATE_TP_ID(TP_STUN, idx);
cand->comp_id = (pj_uint8_t) comp->comp_id; cand->comp_id = (pj_uint8_t) comp->comp_id;
...@@ -1552,7 +1524,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1552,7 +1524,7 @@ index 3cb350c2a..bf7f98096 100644
/* Allocate and initialize STUN socket data */ /* Allocate and initialize STUN socket data */
data = PJ_POOL_ZALLOC_T(ice_st->pool, sock_user_data); data = PJ_POOL_ZALLOC_T(ice_st->pool, sock_user_data);
@@ -549,8 +605,9 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st, @@ -549,8 +601,9 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st,
/* Create the STUN transport */ /* Create the STUN transport */
status = pj_stun_sock_create(&ice_st->cfg.stun_cfg, NULL, status = pj_stun_sock_create(&ice_st->cfg.stun_cfg, NULL,
...@@ -1564,7 +1536,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1564,7 +1536,7 @@ index 3cb350c2a..bf7f98096 100644
if (status != PJ_SUCCESS) if (status != PJ_SUCCESS)
return status; return status;
@@ -635,105 +692,154 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st, @@ -635,105 +688,154 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st,
} }
for (i = 0; i < stun_sock_info.alias_cnt && for (i = 0; i < stun_sock_info.alias_cnt &&
...@@ -1778,7 +1750,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1778,7 +1750,7 @@ index 3cb350c2a..bf7f98096 100644
+ +
+ pj_ice_calc_foundation(ice_st->pool, &cand->foundation, + pj_ice_calc_foundation(ice_st->pool, &cand->foundation,
+ cand->type, &cand->base_addr); + cand->type, &cand->base_addr);
+
+ /* Set default candidate with the preferred default + /* Set default candidate with the preferred default
+ * address family + * address family
+ */ + */
...@@ -1789,7 +1761,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1789,7 +1761,7 @@ index 3cb350c2a..bf7f98096 100644
+ { + {
+ comp->default_cand = (unsigned)(cand - comp->cand_list); + comp->default_cand = (unsigned)(cand - comp->cand_list);
+ } + }
+
+ if (transport == PJ_CAND_TCP_ACTIVE) { + if (transport == PJ_CAND_TCP_ACTIVE) {
+ // Use the port 9 (DISCARD Protocol) for TCP active candidates. + // Use the port 9 (DISCARD Protocol) for TCP active candidates.
+ pj_sockaddr_set_port(&cand->addr, 9); + pj_sockaddr_set_port(&cand->addr, 9);
...@@ -1806,7 +1778,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1806,7 +1778,7 @@ index 3cb350c2a..bf7f98096 100644
/* /*
* Create the component. * Create the component.
@@ -816,7 +922,7 @@ static pj_status_t alloc_send_buf(pj_ice_strans *ice_st, unsigned buf_size) @@ -816,7 +918,7 @@ static pj_status_t alloc_send_buf(pj_ice_strans *ice_st, unsigned buf_size)
{ {
if (buf_size > ice_st->buf_size) { if (buf_size > ice_st->buf_size) {
unsigned i; unsigned i;
...@@ -1815,7 +1787,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1815,7 +1787,7 @@ index 3cb350c2a..bf7f98096 100644
if (ice_st->is_pending) { if (ice_st->is_pending) {
/* The current buffer is insufficient, but still currently used.*/ /* The current buffer is insufficient, but still currently used.*/
return PJ_EBUSY; return PJ_EBUSY;
@@ -839,7 +945,7 @@ static pj_status_t alloc_send_buf(pj_ice_strans *ice_st, unsigned buf_size) @@ -839,7 +941,7 @@ static pj_status_t alloc_send_buf(pj_ice_strans *ice_st, unsigned buf_size)
} }
ice_st->buf_idx = ice_st->empty_idx = 0; ice_st->buf_idx = ice_st->empty_idx = 0;
} }
...@@ -1824,7 +1796,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1824,7 +1796,7 @@ index 3cb350c2a..bf7f98096 100644
return PJ_SUCCESS; return PJ_SUCCESS;
} }
@@ -906,7 +1012,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_create( const char *name, @@ -906,7 +1008,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_create( const char *name,
/* To maintain backward compatibility, check if old/deprecated setting is set /* To maintain backward compatibility, check if old/deprecated setting is set
* and the new setting is not, copy the value to the new setting. * and the new setting is not, copy the value to the new setting.
*/ */
...@@ -1833,7 +1805,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1833,7 +1805,7 @@ index 3cb350c2a..bf7f98096 100644
(cfg->stun.server.slen || cfg->stun.max_host_cands)) (cfg->stun.server.slen || cfg->stun.max_host_cands))
{ {
ice_st->cfg.stun_tp_cnt = 1; ice_st->cfg.stun_tp_cnt = 1;
@@ -1105,7 +1211,7 @@ static void sess_init_update(pj_ice_strans *ice_st) @@ -1105,7 +1207,7 @@ static void sess_init_update(pj_ice_strans *ice_st)
pj_ice_get_cand_type_name(cand->type))); pj_ice_get_cand_type_name(cand->type)));
return; return;
} }
...@@ -1842,7 +1814,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1842,7 +1814,7 @@ index 3cb350c2a..bf7f98096 100644
if (status == PJ_EUNKNOWN) { if (status == PJ_EUNKNOWN) {
status = cand->status; status = cand->status;
} else { } else {
@@ -1114,7 +1220,7 @@ static void sess_init_update(pj_ice_strans *ice_st) @@ -1114,7 +1216,7 @@ static void sess_init_update(pj_ice_strans *ice_st)
status = PJ_SUCCESS; status = PJ_SUCCESS;
} }
} }
...@@ -1851,20 +1823,19 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1851,20 +1823,19 @@ index 3cb350c2a..bf7f98096 100644
if (status != PJ_SUCCESS) if (status != PJ_SUCCESS)
break; break;
} }
@@ -1207,6 +1313,12 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, @@ -1207,6 +1309,11 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
ice_cb.on_ice_complete = &on_ice_complete; ice_cb.on_ice_complete = &on_ice_complete;
ice_cb.on_rx_data = &ice_rx_data; ice_cb.on_rx_data = &ice_rx_data;
ice_cb.on_tx_pkt = &ice_tx_pkt; ice_cb.on_tx_pkt = &ice_tx_pkt;
+#if PJ_HAS_TCP +#if PJ_HAS_TCP
+ ice_cb.wait_tcp_connection = &ice_wait_tcp_connection; + ice_cb.wait_tcp_connection = &ice_wait_tcp_connection;
+ ice_cb.select_turn_dataconn = &ice_select_turn_dataconn;
+ ice_cb.reconnect_tcp_connection = &ice_reconnect_tcp_connection; + ice_cb.reconnect_tcp_connection = &ice_reconnect_tcp_connection;
+ ice_cb.close_tcp_connection = &ice_close_tcp_connection; + ice_cb.close_tcp_connection = &ice_close_tcp_connection;
+#endif +#endif
/* Create! */ /* Create! */
status = pj_ice_sess_create(&ice_st->cfg.stun_cfg, ice_st->obj_name, role, status = pj_ice_sess_create(&ice_st->cfg.stun_cfg, ice_st->obj_name, role,
@@ -1282,7 +1394,8 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, @@ -1282,7 +1389,8 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
&cand->foundation, &cand->addr, &cand->foundation, &cand->addr,
&cand->base_addr, &cand->rel_addr, &cand->base_addr, &cand->rel_addr,
pj_sockaddr_get_len(&cand->addr), pj_sockaddr_get_len(&cand->addr),
...@@ -1874,7 +1845,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1874,7 +1845,7 @@ index 3cb350c2a..bf7f98096 100644
if (status != PJ_SUCCESS) if (status != PJ_SUCCESS)
goto on_error; goto on_error;
} }
@@ -1544,7 +1657,7 @@ pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st, @@ -1544,7 +1652,7 @@ pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st,
PJ_DEF(pj_status_t) pj_ice_strans_stop_ice(pj_ice_strans *ice_st) PJ_DEF(pj_status_t) pj_ice_strans_stop_ice(pj_ice_strans *ice_st)
{ {
PJ_ASSERT_RETURN(ice_st, PJ_EINVAL); PJ_ASSERT_RETURN(ice_st, PJ_EINVAL);
...@@ -1883,7 +1854,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1883,7 +1854,7 @@ index 3cb350c2a..bf7f98096 100644
/* Protect with group lock, since this may cause race condition with /* Protect with group lock, since this may cause race condition with
* pj_ice_strans_sendto2(). * pj_ice_strans_sendto2().
* See ticket #1877. * See ticket #1877.
@@ -1578,7 +1691,7 @@ static pj_status_t use_buffer( pj_ice_strans *ice_st, @@ -1578,7 +1686,7 @@ static pj_status_t use_buffer( pj_ice_strans *ice_st,
status = alloc_send_buf(ice_st, data_len); status = alloc_send_buf(ice_st, data_len);
if (status != PJ_SUCCESS) if (status != PJ_SUCCESS)
return status; return status;
...@@ -1892,7 +1863,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1892,7 +1863,7 @@ index 3cb350c2a..bf7f98096 100644
if (ice_st->is_pending && ice_st->empty_idx == ice_st->buf_idx) { if (ice_st->is_pending && ice_st->empty_idx == ice_st->buf_idx) {
/* We don't use buffer or there's no more empty buffer. */ /* We don't use buffer or there's no more empty buffer. */
return PJ_EBUSY; return PJ_EBUSY;
@@ -1593,12 +1706,12 @@ static pj_status_t use_buffer( pj_ice_strans *ice_st, @@ -1593,12 +1701,12 @@ static pj_status_t use_buffer( pj_ice_strans *ice_st,
pj_sockaddr_cp(&ice_st->send_buf[idx].dst_addr, dst_addr); pj_sockaddr_cp(&ice_st->send_buf[idx].dst_addr, dst_addr);
ice_st->send_buf[idx].dst_addr_len = dst_addr_len; ice_st->send_buf[idx].dst_addr_len = dst_addr_len;
*buffer = ice_st->send_buf[idx].buffer; *buffer = ice_st->send_buf[idx].buffer;
...@@ -1907,7 +1878,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1907,7 +1878,7 @@ index 3cb350c2a..bf7f98096 100644
ice_st->is_pending = PJ_TRUE; ice_st->is_pending = PJ_TRUE;
ice_st->buf_idx = idx; ice_st->buf_idx = idx;
@@ -1651,6 +1764,9 @@ static pj_status_t send_data(pj_ice_strans *ice_st, @@ -1651,6 +1759,9 @@ static pj_status_t send_data(pj_ice_strans *ice_st,
} }
} }
...@@ -1917,7 +1888,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1917,7 +1888,7 @@ index 3cb350c2a..bf7f98096 100644
/* If ICE is available, send data with ICE, otherwise send with the /* If ICE is available, send data with ICE, otherwise send with the
* default candidate selected during initialization. * default candidate selected during initialization.
* *
@@ -1659,16 +1775,37 @@ static pj_status_t send_data(pj_ice_strans *ice_st, @@ -1659,16 +1770,37 @@ static pj_status_t send_data(pj_ice_strans *ice_st,
*/ */
if (ice_st->ice && ice_st->state == PJ_ICE_STRANS_STATE_RUNNING) { if (ice_st->ice && ice_st->state == PJ_ICE_STRANS_STATE_RUNNING) {
status = pj_ice_sess_send_data(ice_st->ice, comp_id, buf, data_len); status = pj_ice_sess_send_data(ice_st->ice, comp_id, buf, data_len);
...@@ -1960,7 +1931,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1960,7 +1931,7 @@ index 3cb350c2a..bf7f98096 100644
if (def_cand->status == PJ_SUCCESS) { if (def_cand->status == PJ_SUCCESS) {
unsigned tp_idx = GET_TP_IDX(def_cand->transport_id); unsigned tp_idx = GET_TP_IDX(def_cand->transport_id);
@@ -1730,6 +1867,11 @@ static pj_status_t send_data(pj_ice_strans *ice_st, @@ -1730,6 +1862,11 @@ static pj_status_t send_data(pj_ice_strans *ice_st,
status = pj_stun_sock_sendto(comp->stun[tp_idx].sock, NULL, buf, status = pj_stun_sock_sendto(comp->stun[tp_idx].sock, NULL, buf,
(unsigned)data_len, 0, dest_addr, (unsigned)data_len, 0, dest_addr,
dest_addr_len); dest_addr_len);
...@@ -1972,7 +1943,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1972,7 +1943,7 @@ index 3cb350c2a..bf7f98096 100644
goto on_return; goto on_return;
} }
@@ -1738,8 +1880,14 @@ static pj_status_t send_data(pj_ice_strans *ice_st, @@ -1738,8 +1875,14 @@ static pj_status_t send_data(pj_ice_strans *ice_st,
on_return: on_return:
/* We continue later in on_data_sent() callback. */ /* We continue later in on_data_sent() callback. */
...@@ -1988,7 +1959,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1988,7 +1959,7 @@ index 3cb350c2a..bf7f98096 100644
if (call_cb) { if (call_cb) {
on_data_sent(ice_st, (status == PJ_SUCCESS? data_len: -status)); on_data_sent(ice_st, (status == PJ_SUCCESS? data_len: -status));
@@ -1771,7 +1919,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st, @@ -1771,7 +1914,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st,
dst_addr_len, PJ_TRUE, PJ_FALSE); dst_addr_len, PJ_TRUE, PJ_FALSE);
if (status == PJ_EPENDING) if (status == PJ_EPENDING)
status = PJ_SUCCESS; status = PJ_SUCCESS;
...@@ -1997,7 +1968,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -1997,7 +1968,7 @@ index 3cb350c2a..bf7f98096 100644
return status; return status;
} }
#endif #endif
@@ -1842,7 +1990,22 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) @@ -1842,7 +1985,22 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status)
sizeof(lip), 3); sizeof(lip), 3);
pj_sockaddr_print(&check->rcand->addr, rip, pj_sockaddr_print(&check->rcand->addr, rip,
sizeof(rip), 3); sizeof(rip), 3);
...@@ -2021,7 +1992,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2021,7 +1992,7 @@ index 3cb350c2a..bf7f98096 100644
if (tp_typ == TP_TURN) { if (tp_typ == TP_TURN) {
/* Activate channel binding for the remote address /* Activate channel binding for the remote address
* for more efficient data transfer using TURN. * for more efficient data transfer using TURN.
@@ -1936,6 +2099,29 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice, @@ -1936,6 +2094,29 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
pj_sockaddr_get_port(dst_addr), pj_sockaddr_get_port(dst_addr),
tp_typ)); tp_typ));
...@@ -2051,7 +2022,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2051,7 +2022,7 @@ index 3cb350c2a..bf7f98096 100644
if (tp_typ == TP_TURN) { if (tp_typ == TP_TURN) {
if (comp->turn[tp_idx].sock) { if (comp->turn[tp_idx].sock) {
status = pj_turn_sock_sendto(comp->turn[tp_idx].sock, status = pj_turn_sock_sendto(comp->turn[tp_idx].sock,
@@ -1958,7 +2144,7 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice, @@ -1958,7 +2139,7 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
if (status != PJ_SUCCESS) { if (status != PJ_SUCCESS) {
goto on_return; goto on_return;
} }
...@@ -2060,7 +2031,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2060,7 +2031,7 @@ index 3cb350c2a..bf7f98096 100644
pj_sockaddr_cp(&comp->dst_addr, dst_addr); pj_sockaddr_cp(&comp->dst_addr, dst_addr);
comp->synth_addr_len = pj_sockaddr_get_len(&comp->synth_addr); comp->synth_addr_len = pj_sockaddr_get_len(&comp->synth_addr);
} }
@@ -1969,9 +2155,13 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice, @@ -1969,9 +2150,13 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
dest_addr_len = dst_addr_len; dest_addr_len = dst_addr_len;
} }
...@@ -2077,7 +2048,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2077,7 +2048,7 @@ index 3cb350c2a..bf7f98096 100644
} else { } else {
pj_assert(!"Invalid transport ID"); pj_assert(!"Invalid transport ID");
status = PJ_EINVALIDOP; status = PJ_EINVALIDOP;
@@ -2017,7 +2207,7 @@ static void check_pending_send(pj_ice_strans *ice_st) @@ -2017,7 +2202,7 @@ static void check_pending_send(pj_ice_strans *ice_st)
if (ice_st->num_buf > 0) if (ice_st->num_buf > 0)
ice_st->buf_idx = (ice_st->buf_idx + 1) % ice_st->num_buf; ice_st->buf_idx = (ice_st->buf_idx + 1) % ice_st->num_buf;
...@@ -2086,7 +2057,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2086,7 +2057,7 @@ index 3cb350c2a..bf7f98096 100644
if (ice_st->num_buf > 0 && ice_st->buf_idx != ice_st->empty_idx) { if (ice_st->num_buf > 0 && ice_st->buf_idx != ice_st->empty_idx) {
/* There's some pending send. Send it one by one. */ /* There's some pending send. Send it one by one. */
pending_send *ps = &ice_st->send_buf[ice_st->buf_idx]; pending_send *ps = &ice_st->send_buf[ice_st->buf_idx];
@@ -2031,6 +2221,237 @@ static void check_pending_send(pj_ice_strans *ice_st) @@ -2031,6 +2216,214 @@ static void check_pending_send(pj_ice_strans *ice_st)
} }
} }
...@@ -2228,29 +2199,6 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2228,29 +2199,6 @@ index 3cb350c2a..bf7f98096 100644
+ return PJ_EINVAL; + return PJ_EINVAL;
+} +}
+ +
+static pj_status_t ice_select_turn_dataconn(pj_ice_sess *ice,
+ pj_ice_sess_checklist *clist,
+ unsigned check_id)
+{
+ pj_ice_sess_check *check = &clist->checks[check_id];
+ const pj_ice_sess_cand *lcand = check->lcand;
+ const pj_ice_sess_cand *rcand = check->rcand;
+ pj_ice_strans *ice_st = (pj_ice_strans *)ice->user_data;
+ pj_ice_strans_comp *st_comp = ice_st->comp[lcand->comp_id - 1];
+
+ for (int i=0; i<ice_st->cfg.turn_tp_cnt; ++i) {
+ pj_turn_session_info info;
+ pj_turn_sock_get_info(st_comp->turn[i].sock, &info);
+ if (st_comp->turn[i].sock
+ && pj_turn_sock_has_dataconn(st_comp->turn[i].sock, &rcand->addr)) {
+ ice_select_incoming_turn(ice, clist, check_id);
+ return PJ_SUCCESS; // Already connected via TURN
+ }
+ }
+
+ return PJ_EINVAL;
+}
+
+static pj_status_t ice_reconnect_tcp_connection(pj_ice_sess *ice, +static pj_status_t ice_reconnect_tcp_connection(pj_ice_sess *ice,
+ pj_ice_sess_checklist *clist, + pj_ice_sess_checklist *clist,
+ unsigned check_id) + unsigned check_id)
...@@ -2324,7 +2272,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2324,7 +2272,7 @@ index 3cb350c2a..bf7f98096 100644
/* Notifification when asynchronous send operation via STUN/TURN /* Notifification when asynchronous send operation via STUN/TURN
* has completed. * has completed.
*/ */
@@ -2039,7 +2460,8 @@ static pj_bool_t on_data_sent(pj_ice_strans *ice_st, pj_ssize_t sent) @@ -2039,7 +2432,8 @@ static pj_bool_t on_data_sent(pj_ice_strans *ice_st, pj_ssize_t sent)
if (ice_st->destroy_req || !ice_st->is_pending) if (ice_st->destroy_req || !ice_st->is_pending)
return PJ_TRUE; return PJ_TRUE;
...@@ -2334,7 +2282,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2334,7 +2282,7 @@ index 3cb350c2a..bf7f98096 100644
(*ice_st->cb.on_data_sent)(ice_st, sent); (*ice_st->cb.on_data_sent)(ice_st, sent);
} }
@@ -2196,7 +2618,7 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, @@ -2196,7 +2590,7 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
{ {
/* We get an IPv4 mapped address for our IPv6 /* We get an IPv4 mapped address for our IPv6
* host address. * host address.
...@@ -2343,7 +2291,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2343,7 +2291,7 @@ index 3cb350c2a..bf7f98096 100644
comp->ipv4_mapped = PJ_TRUE; comp->ipv4_mapped = PJ_TRUE;
/* Find other host candidates with the same (IPv6) /* Find other host candidates with the same (IPv6)
@@ -2208,7 +2630,7 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, @@ -2208,7 +2602,7 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
if (comp->cand_list[i].type != PJ_ICE_CAND_TYPE_HOST) if (comp->cand_list[i].type != PJ_ICE_CAND_TYPE_HOST)
continue; continue;
...@@ -2352,7 +2300,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2352,7 +2300,7 @@ index 3cb350c2a..bf7f98096 100644
a1 = &comp->cand_list[i].addr; a1 = &comp->cand_list[i].addr;
a2 = &cand->base_addr; a2 = &cand->base_addr;
if (pj_memcmp(pj_sockaddr_get_addr(a1), if (pj_memcmp(pj_sockaddr_get_addr(a1),
@@ -2225,7 +2647,7 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, @@ -2225,7 +2619,7 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
pj_sockaddr_cp(&cand->base_addr, &info.mapped_addr); pj_sockaddr_cp(&cand->base_addr, &info.mapped_addr);
pj_sockaddr_cp(&cand->rel_addr, &info.mapped_addr); pj_sockaddr_cp(&cand->rel_addr, &info.mapped_addr);
} }
...@@ -2361,7 +2309,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2361,7 +2309,7 @@ index 3cb350c2a..bf7f98096 100644
/* Eliminate the srflx candidate if the address is /* Eliminate the srflx candidate if the address is
* equal to other (host) candidates. * equal to other (host) candidates.
*/ */
@@ -2268,11 +2690,11 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, @@ -2268,11 +2662,11 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
sizeof(ipaddr), 3))); sizeof(ipaddr), 3)));
sess_init_update(ice_st); sess_init_update(ice_st);
...@@ -2375,7 +2323,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2375,7 +2323,7 @@ index 3cb350c2a..bf7f98096 100644
PJ_ICE_STRANS_OP_ADDR_CHANGE, PJ_ICE_STRANS_OP_ADDR_CHANGE,
status); status);
} }
@@ -2318,6 +2740,10 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, @@ -2318,6 +2712,10 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
} }
} }
break; break;
...@@ -2386,7 +2334,7 @@ index 3cb350c2a..bf7f98096 100644 ...@@ -2386,7 +2334,7 @@ index 3cb350c2a..bf7f98096 100644
} }
return pj_grp_lock_dec_ref(ice_st->grp_lock)? PJ_FALSE : PJ_TRUE; return pj_grp_lock_dec_ref(ice_st->grp_lock)? PJ_FALSE : PJ_TRUE;
@@ -2358,14 +2784,103 @@ static void turn_on_rx_data(pj_turn_sock *turn_sock, @@ -2358,14 +2756,103 @@ static void turn_on_rx_data(pj_turn_sock *turn_sock,
} else { } else {
/* Hand over the packet to ICE */ /* Hand over the packet to ICE */
...@@ -2567,7 +2515,7 @@ index f2b4f7058..ed17b904f 100644 ...@@ -2567,7 +2515,7 @@ index f2b4f7058..ed17b904f 100644
+ return sess ? sess->conn_type : PJ_STUN_TP_UDP; + return sess ? sess->conn_type : PJ_STUN_TP_UDP;
+} +}
diff --git a/pjnath/src/pjnath/stun_sock.c b/pjnath/src/pjnath/stun_sock.c diff --git a/pjnath/src/pjnath/stun_sock.c b/pjnath/src/pjnath/stun_sock.c
index 5fe825cf5..c4cd9b224 100644 index 5fe825cf5..05461676e 100644
--- a/pjnath/src/pjnath/stun_sock.c --- a/pjnath/src/pjnath/stun_sock.c
+++ b/pjnath/src/pjnath/stun_sock.c +++ b/pjnath/src/pjnath/stun_sock.c
@@ -40,6 +40,36 @@ @@ -40,6 +40,36 @@
...@@ -4165,4 +4113,5 @@ index 474a8d07c..9257f07a4 100644 ...@@ -4165,4 +4113,5 @@ index 474a8d07c..9257f07a4 100644
if (status != PJ_SUCCESS) { if (status != PJ_SUCCESS) {
char errmsg[PJ_ERR_MSG_SIZE]; char errmsg[PJ_ERR_MSG_SIZE];
-- --
2.26.2 2.25.4
...@@ -530,6 +530,7 @@ IceTransport::Impl::onComplete(pj_ice_strans* ice_st, pj_ice_strans_op op, pj_st ...@@ -530,6 +530,7 @@ IceTransport::Impl::onComplete(pj_ice_strans* ice_st, pj_ice_strans_op op, pj_st
JAMI_ERR("[ice:%p] %s %s failed: %s", this, (config_.protocol == PJ_ICE_TP_TCP? "TCP" : "UDP"), opname, last_errmsg_.c_str()); JAMI_ERR("[ice:%p] %s %s failed: %s", this, (config_.protocol == PJ_ICE_TP_TCP? "TCP" : "UDP"), opname, last_errmsg_.c_str());
} }
{ {
std::lock_guard<std::mutex> lk(iceMutex_); std::lock_guard<std::mutex> lk(iceMutex_);
if (!icest_.get()) if (!icest_.get())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment