Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sobomax committed Jul 23, 2024
1 parent 29de0b9 commit 86d2f53
Showing 1 changed file with 47 additions and 33 deletions.
80 changes: 47 additions & 33 deletions modules/ice_lite/rtpp_ice_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ udp_local_get(const struct udp_sock *us, struct sa *local)
}

static struct ice_lite_agent_cfg *
ice_lite_data_ctor(const struct rtpp_subc_ctx *ctxp,
const rtpp_str_t *ice_rufrag, const rtpp_str_t *ice_rpwd)
ice_lite_data_ctor(int lufrag_len, int lpwd_len)
{
struct ice_lite_agent_cfg *ila_c;
rtpp_str_mutble_t lufrag, lpwd;
Expand All @@ -293,13 +292,13 @@ ice_lite_data_ctor(const struct rtpp_subc_ctx *ctxp,
if (ila_c == NULL)
goto e0;
atomic_init(&ila_c->completed, false);
lufrag.s = alloca(ice_rufrag->len + 1);
lpwd.s = alloca(ice_rpwd->len + 1);
lufrag.s = alloca(lufrag_len + 1);
lpwd.s = alloca(lpwd_len + 1);
if (lufrag.s == NULL || lpwd.s == NULL)
goto e1;
lufrag.len = ice_rufrag->len;
lufrag.len = lufrag_len;
generate_random_string(lufrag.s, lufrag.len);
lpwd.len = ice_rpwd->len;
lpwd.len = lpwd_len;
generate_random_string(lpwd.s, lpwd.len);
if (icem_alloc(&ila_c->icem, ICE_MODE_LITE, ICE_ROLE_CONTROLLED, IPPROTO_UDP, 0,
tiebrk, lufrag.s, lpwd.s, NULL, NULL) != 0)
Expand All @@ -315,8 +314,6 @@ ice_lite_data_ctor(const struct rtpp_subc_ctx *ctxp,
goto e4;
if (pthread_mutex_init(&ila_c->state_lock, NULL) != 0)
goto e5;
icem_sdp_decode(ila_c->icem, "ice-ufrag", ice_rufrag->s);
icem_sdp_decode(ila_c->icem, "ice-pwd", ice_rpwd->s);
RC_INCREF(RTPP_MOD_SELF.module_rcnt);
CALL_SMETHOD(ila_c->rcnt, attach, (rtpp_refcnt_dtor_t)ice_lite_data_dtor, ila_c);
return (ila_c);
Expand All @@ -334,10 +331,24 @@ ice_lite_data_ctor(const struct rtpp_subc_ctx *ctxp,
return (NULL);
}

static void
ila_set_rauth(struct ice_lite_agent_cfg *ila_c, const rtpp_str_t *ice_rufrag,
const rtpp_str_t *ice_rpwd)
{

pthread_mutex_lock(&ila_c->state_lock);
icem_sdp_decode(ila_c->icem, "ice-ufrag", ice_rufrag->s);
icem_sdp_decode(ila_c->icem, "ice-pwd", ice_rpwd->s);
pthread_mutex_unlock(&ila_c->state_lock);
}

enum ril_cmd {RIL_CMD_A, RIL_CMD_C, RIL_CMD_S, RIL_CMD_D, RIL_CMD_U};
#define ICE_COMPID_RTP 1
#define ICE_COMPID_RTCP 2

#define ICE_LUFRAG_LEN 4
#define ICE_LPWD_LEN 24

static int
ice_lite_candidate(struct ice_lite_agent_cfg *ila_c, int c, const rtpp_str_t *v)
{
Expand Down Expand Up @@ -411,12 +422,12 @@ ice_lite_start(struct ice_lite_agent_cfg *ila_c, struct rtpp_stream *isp,

static struct ice_lite_agent_cfg *
ice_lite_activate(struct rtpp_module_priv *pvt, const struct rtpp_subc_ctx *ctxp,
struct rtpp_stream *ice_strmp, const rtpp_str_t *rufrag, const rtpp_str_t *rpwd)
struct rtpp_stream *ice_strmp, int lufrag_len, int lpwd_len)
{
struct ice_lite_agent_cfg *ila_c;
struct packet_processor_if stun_poi;

ila_c = ice_lite_data_ctor(ctxp, rufrag, rpwd);
ila_c = ice_lite_data_ctor(lufrag_len, lpwd_len);
if (ila_c == NULL) {
goto e0;
}
Expand Down Expand Up @@ -569,10 +580,11 @@ rtpp_ice_lite_handle_command(struct rtpp_module_priv *pvt,
ila_c = stun_poi.arg;
}

if (ril_cmd == RIL_CMD_D || ril_cmd == RIL_CMD_U) {
if (lookup_res == 0) {
switch (ril_cmd) {
case RIL_CMD_D:
case RIL_CMD_U:
if (lookup_res == 0)
return (-1);
}
RTPP_OBJ_INCREF(ila_c); /* for the unlock */
pthread_mutex_lock(&ila_c->state_lock);
CALL_SMETHOD(ila_c->rtcp_mx_ctx.unreg, unreg, pvt + 2);
Expand All @@ -581,35 +593,37 @@ rtpp_ice_lite_handle_command(struct rtpp_module_priv *pvt,
CALL_SMETHOD(ice_strmp, latch_setmode, RTPLM_NORMAL);
pthread_mutex_unlock(&ila_c->state_lock);
RTPP_OBJ_DECREF(ila_c);
goto out;
}

if ((ril_cmd == RIL_CMD_C || ril_cmd == RIL_CMD_S) && lookup_res == 0) {
return (-1);
}
break;

if (ril_cmd == RIL_CMD_C) {
if (ice_lite_candidate(ila_c, argc - 1, argv + 1) != 0) {
case RIL_CMD_C:
if (lookup_res == 0)
return (-1);
if (ice_lite_candidate(ila_c, argc - 1, argv + 1) != 0)
goto e0;
}
goto out;
}
break;

if (ril_cmd == RIL_CMD_S) {
case RIL_CMD_S:
if (lookup_res == 0) {
ila_c = ice_lite_activate(pvt, ctxp, ice_strmp, ICE_LUFRAG_LEN, ICE_LPWD_LEN);
if (ila_c == NULL)
return (-1);
}
rtpp_str_mutble_t resp = {.s = ctxp->resp->buf_t, .len = sizeof(ctxp->resp->buf_t)};
if (ice_lite_start(ila_c, ice_strmp, &resp) != 0) {
goto e0;
}
goto out;
}
break;

if (ril_cmd == RIL_CMD_A && lookup_res == 0) {
ila_c = ice_lite_activate(pvt, ctxp, ice_strmp, rufrag, rpwd);
if (ila_c == NULL) {
return (-1);
case RIL_CMD_A:
if (lookup_res == 0) {
ila_c = ice_lite_activate(pvt, ctxp, ice_strmp, rufrag->len, rpwd->len);
if (ila_c == NULL)
return (-1);
}
}
out:
ila_set_rauth(ila_c, rufrag, rpwd);
break;
}

RTPP_OBJ_DECREF(ila_c);
return (0);

Expand Down

0 comments on commit 86d2f53

Please sign in to comment.