File 0015-update-local-preference-for-peer-reflexive-candidate.patch of Package pjproject
From 9150099c0b45345cde9d738d7f0f344ade4788cc Mon Sep 17 00:00:00 2001
From: nanangizz <nanang@teluu.com>
Date: Tue, 11 Aug 2020 11:36:08 +0700
Subject: [PATCH 3/3] - update local preference for peer reflexive candidate -
also update PRIORITY field value in performing connectivity check (must use
peer reflexive type and local pref must be unique, is this necessary?) - fix
local preference mask for non-standard ICE prio calculation
---
pjnath/include/pjnath/ice_session.h | 5 +++++
pjnath/src/pjnath/ice_session.c | 27 ++++++++++++++++++---------
pjnath/src/pjnath/ice_strans.c | 6 +++---
3 files changed, 26 insertions(+), 12 deletions(-)
Index: pjproject-2.10/pjnath/include/pjnath/ice_session.h
===================================================================
--- pjproject-2.10.orig/pjnath/include/pjnath/ice_session.h
+++ pjproject-2.10/pjnath/include/pjnath/ice_session.h
@@ -284,6 +284,11 @@ typedef struct pj_ice_msg_data
typedef struct pj_ice_sess_cand
{
/**
+ * The candidate ID.
+ */
+ unsigned id;
+
+ /**
* The candidate type, as described in #pj_ice_cand_type enumeration.
*/
pj_ice_cand_type type;
Index: pjproject-2.10/pjnath/src/pjnath/ice_session.c
===================================================================
--- pjproject-2.10.orig/pjnath/src/pjnath/ice_session.c
+++ pjproject-2.10/pjnath/src/pjnath/ice_session.c
@@ -711,9 +711,9 @@ static pj_uint32_t CALC_CAND_PRIO(pj_ice
(((256 - comp_id) & 0xFF) << 0);
#else
enum {
- type_mask = ((2 << PJ_ICE_CAND_TYPE_PREF_BITS) - 1),
- local_mask = ((2 << PJ_ICE_LOCAL_PREF_BITS) - 1),
- comp_mask = ((2 << PJ_ICE_COMP_BITS) - 1),
+ type_mask = ((1 << PJ_ICE_CAND_TYPE_PREF_BITS) - 1),
+ local_mask = ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1),
+ comp_mask = ((1 << PJ_ICE_COMP_BITS) - 1),
comp_shift = 0,
local_shift = (PJ_ICE_COMP_BITS),
@@ -924,11 +924,13 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand
}
lcand = &ice->lcand[ice->lcand_cnt];
+ lcand->id = ice->lcand_cnt;
lcand->comp_id = (pj_uint8_t)comp_id;
lcand->transport_id = (pj_uint8_t)transport_id;
lcand->type = type;
lcand->transport = transport;
pj_strdup(ice->pool, &lcand->foundation, foundation);
+ lcand->local_pref = local_pref;
lcand->prio = CALC_CAND_PRIO(ice, type, local_pref, lcand->comp_id);
pj_sockaddr_cp(&lcand->addr, addr);
pj_sockaddr_cp(&lcand->base_addr, base_addr);
@@ -956,7 +958,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand
LOG4((ice->obj_name,
"Candidate %d added: comp_id=%d, type=%s, foundation=%.*s, "
"addr=%s:%d, base=%s:%d, prio=0x%x (%u)",
- ice->lcand_cnt,
+ lcand->id,
lcand->comp_id,
cand_type_names[lcand->type],
(int)lcand->foundation.slen,
@@ -968,7 +970,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand
lcand->prio, lcand->prio));
if (p_cand_id)
- *p_cand_id = ice->lcand_cnt;
+ *p_cand_id = lcand->id;
++ice->lcand_cnt;
@@ -1938,7 +1940,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_c
pj_memcpy(cn, &rem_cand[i], sizeof(pj_ice_sess_cand));
pj_strdup(ice->pool, &cn->foundation, &rem_cand[i].foundation);
- ice->rcand_cnt++;
+ cn->id = ice->rcand_cnt++;
}
/* Generate checklist */
@@ -2122,10 +2124,11 @@ static pj_status_t perform_check(pj_ice_
/* Add PRIORITY */
#if PJNATH_ICE_PRIO_STD
- prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 65535,
+ prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 65535 - lcand->id,
lcand->comp_id);
#else
- prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 0,
+ prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX,
+ ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1) - lcand->id,
lcand->comp_id);
#endif
pj_stun_msg_add_uint_attr(check->tdata->pool, check->tdata->msg,
@@ -2992,7 +2995,13 @@ static void on_stun_request_complete(pj_
status = pj_ice_sess_add_cand(ice, check->lcand->comp_id,
msg_data->transport_id,
PJ_ICE_CAND_TYPE_PRFLX,
- 65535, &foundation,
+#if PJNATH_ICE_PRIO_STD
+ 65535 - ice->lcand_cnt,
+#else
+ ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1) -
+ ice->lcand_cnt,
+#endif
+ &foundation,
&xaddr->sockaddr,
&check->lcand->base_addr,
&check->lcand->base_addr,
Index: pjproject-2.10/pjnath/src/pjnath/ice_strans.c
===================================================================
--- pjproject-2.10.orig/pjnath/src/pjnath/ice_strans.c
+++ pjproject-2.10/pjnath/src/pjnath/ice_strans.c
@@ -64,9 +64,9 @@ enum tp_type
# define HOST_PREF 65535
# define RELAY_PREF 65535
#else
-# define SRFLX_PREF 0
-# define HOST_PREF 0
-# define RELAY_PREF 0
+# define SRFLX_PREF ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1)
+# define HOST_PREF ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1)
+# define RELAY_PREF ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1)
#endif
#define MAX_RTP_SIZE 65536