ice: export enum ice_cand_type
This commit is contained in:
parent
242c3dec01
commit
48ab5ad8db
12 changed files with 76 additions and 61 deletions
|
@ -23,6 +23,14 @@ enum ice_nomination {
|
|||
ICE_NOMINATION_AGGRESSIVE
|
||||
};
|
||||
|
||||
/** ICE Candidate type */
|
||||
enum ice_cand_type {
|
||||
ICE_CAND_TYPE_HOST, /**< Host candidate */
|
||||
ICE_CAND_TYPE_SRFLX, /**< Server Reflexive candidate */
|
||||
ICE_CAND_TYPE_PRFLX, /**< Peer Reflexive candidate */
|
||||
ICE_CAND_TYPE_RELAY /**< Relayed candidate */
|
||||
};
|
||||
|
||||
struct ice;
|
||||
struct icem;
|
||||
|
||||
|
@ -92,3 +100,11 @@ extern const char ice_attr_mismatch[];
|
|||
extern const char ice_attr_pwd[];
|
||||
extern const char ice_attr_remote_cand[];
|
||||
extern const char ice_attr_ufrag[];
|
||||
|
||||
|
||||
const char *ice_cand_type2name(enum ice_cand_type type);
|
||||
enum ice_cand_type ice_cand_name2type(const char *name);
|
||||
|
||||
|
||||
uint32_t ice_cand_calc_prio(enum ice_cand_type type, uint16_t local,
|
||||
uint8_t compid);
|
||||
|
|
|
@ -49,7 +49,7 @@ static int compute_foundation(struct cand *cand)
|
|||
|
||||
|
||||
static int cand_alloc(struct cand **candp, struct icem *icem,
|
||||
enum cand_type type, uint8_t compid,
|
||||
enum ice_cand_type type, uint8_t compid,
|
||||
uint32_t prio, const char *ifname,
|
||||
enum ice_transp transp, const struct sa *addr)
|
||||
{
|
||||
|
@ -98,8 +98,8 @@ int icem_lcand_add_base(struct icem *icem, uint8_t compid, uint16_t lprio,
|
|||
if (!comp)
|
||||
return ENOENT;
|
||||
|
||||
err = cand_alloc(&cand, icem, CAND_TYPE_HOST, compid,
|
||||
ice_calc_prio(CAND_TYPE_HOST, lprio, compid),
|
||||
err = cand_alloc(&cand, icem, ICE_CAND_TYPE_HOST, compid,
|
||||
ice_cand_calc_prio(ICE_CAND_TYPE_HOST, lprio, compid),
|
||||
ifname, transp, addr);
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -113,7 +113,8 @@ int icem_lcand_add_base(struct icem *icem, uint8_t compid, uint16_t lprio,
|
|||
}
|
||||
|
||||
|
||||
int icem_lcand_add(struct icem *icem, struct cand *base, enum cand_type type,
|
||||
int icem_lcand_add(struct icem *icem, struct cand *base,
|
||||
enum ice_cand_type type,
|
||||
const struct sa *addr)
|
||||
{
|
||||
struct cand *cand;
|
||||
|
@ -123,7 +124,7 @@ int icem_lcand_add(struct icem *icem, struct cand *base, enum cand_type type,
|
|||
return EINVAL;
|
||||
|
||||
err = cand_alloc(&cand, icem, type, base->compid,
|
||||
ice_calc_prio(type, 0, base->compid),
|
||||
ice_cand_calc_prio(type, 0, base->compid),
|
||||
base->ifname, base->transp, addr);
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -135,7 +136,7 @@ int icem_lcand_add(struct icem *icem, struct cand *base, enum cand_type type,
|
|||
}
|
||||
|
||||
|
||||
int icem_rcand_add(struct icem *icem, enum cand_type type, uint8_t compid,
|
||||
int icem_rcand_add(struct icem *icem, enum ice_cand_type type, uint8_t compid,
|
||||
uint32_t prio, const struct sa *addr,
|
||||
const struct sa *rel_addr, const struct pl *foundation)
|
||||
{
|
||||
|
@ -182,7 +183,7 @@ int icem_rcand_add_prflx(struct cand **rcp, struct icem *icem, uint8_t compid,
|
|||
|
||||
list_append(&icem->rcandl, &rcand->le, rcand);
|
||||
|
||||
rcand->type = CAND_TYPE_PRFLX;
|
||||
rcand->type = ICE_CAND_TYPE_PRFLX;
|
||||
rcand->compid = compid;
|
||||
rcand->prio = prio;
|
||||
rcand->addr = *addr;
|
||||
|
@ -242,8 +243,8 @@ struct cand *icem_lcand_find_checklist(const struct icem *icem, uint8_t compid)
|
|||
|
||||
switch (cp->lcand->type) {
|
||||
|
||||
case CAND_TYPE_HOST:
|
||||
case CAND_TYPE_RELAY:
|
||||
case ICE_CAND_TYPE_HOST:
|
||||
case ICE_CAND_TYPE_RELAY:
|
||||
return cp->lcand;
|
||||
|
||||
default:
|
||||
|
|
|
@ -222,7 +222,8 @@ void icem_candpair_set_state(struct candpair *cp, enum candpair_state state)
|
|||
/**
|
||||
* Delete all Candidate-Pairs where the Local candidate is of a given type
|
||||
*/
|
||||
void icem_candpairs_flush(struct list *lst, enum cand_type type, uint8_t id)
|
||||
void icem_candpairs_flush(struct list *lst, enum ice_cand_type type,
|
||||
uint8_t id)
|
||||
{
|
||||
struct le *le = list_head(lst);
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ static int candpairs_form(struct icem *icem)
|
|||
/* Replace server reflexive candidates by its base */
|
||||
static const struct sa *cand_srflx_addr(const struct cand *c)
|
||||
{
|
||||
return (CAND_TYPE_SRFLX == c->type) ? &c->base->addr : &c->addr;
|
||||
return (ICE_CAND_TYPE_SRFLX == c->type) ? &c->base->addr : &c->addr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -93,15 +93,15 @@ static struct cand *cand_default(const struct list *lcandl, uint8_t compid)
|
|||
|
||||
switch (cand->type) {
|
||||
|
||||
case CAND_TYPE_RELAY:
|
||||
case ICE_CAND_TYPE_RELAY:
|
||||
return cand;
|
||||
|
||||
case CAND_TYPE_SRFLX:
|
||||
if (!def || CAND_TYPE_SRFLX != def->type)
|
||||
case ICE_CAND_TYPE_SRFLX:
|
||||
if (!def || ICE_CAND_TYPE_SRFLX != def->type)
|
||||
def = cand;
|
||||
break;
|
||||
|
||||
case CAND_TYPE_HOST:
|
||||
case ICE_CAND_TYPE_HOST:
|
||||
if (!def)
|
||||
def = cand;
|
||||
break;
|
||||
|
@ -241,7 +241,7 @@ static void timeout(void *arg)
|
|||
return;
|
||||
|
||||
(void)stun_indication(comp->icem->proto, comp->sock, &cp->rcand->addr,
|
||||
(cp->lcand->type == CAND_TYPE_RELAY) ? 4 : 0,
|
||||
(cp->lcand->type == ICE_CAND_TYPE_RELAY) ? 4 : 0,
|
||||
STUN_METHOD_BINDING, NULL, 0, true, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ static void handle_success(struct icem *icem, struct candpair *cp,
|
|||
laddr);
|
||||
|
||||
err = icem_lcand_add(icem, cp->lcand,
|
||||
CAND_TYPE_PRFLX, laddr);
|
||||
ICE_CAND_TYPE_PRFLX, laddr);
|
||||
if (err) {
|
||||
DEBUG_WARNING("failed to add PRFLX: %m\n", err);
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ int icem_conncheck_send(struct candpair *cp, bool use_cand, bool trigged)
|
|||
"%s:%s", icem->rufrag, ice->lufrag);
|
||||
|
||||
/* PRIORITY and USE-CANDIDATE */
|
||||
prio_prflx = ice_calc_prio(CAND_TYPE_PRFLX, 0, lcand->compid);
|
||||
prio_prflx = ice_cand_calc_prio(ICE_CAND_TYPE_PRFLX, 0, lcand->compid);
|
||||
|
||||
switch (ice->lrole) {
|
||||
|
||||
|
@ -264,7 +264,7 @@ int icem_conncheck_send(struct candpair *cp, bool use_cand, bool trigged)
|
|||
|
||||
switch (lcand->type) {
|
||||
|
||||
case CAND_TYPE_RELAY:
|
||||
case ICE_CAND_TYPE_RELAY:
|
||||
/* Creating Permissions for Relayed Candidates */
|
||||
err = turnc_add_chan(cp->comp->turnc, &cp->rcand->addr,
|
||||
NULL, NULL);
|
||||
|
@ -275,9 +275,9 @@ int icem_conncheck_send(struct candpair *cp, bool use_cand, bool trigged)
|
|||
presz = 4;
|
||||
/*@fallthrough@*/
|
||||
|
||||
case CAND_TYPE_HOST:
|
||||
case CAND_TYPE_SRFLX:
|
||||
case CAND_TYPE_PRFLX:
|
||||
case ICE_CAND_TYPE_HOST:
|
||||
case ICE_CAND_TYPE_SRFLX:
|
||||
case ICE_CAND_TYPE_PRFLX:
|
||||
cp->ct_conn = mem_deref(cp->ct_conn);
|
||||
err = stun_request(&cp->ct_conn, ice->stun, icem->proto,
|
||||
cp->comp->sock, &cp->rcand->addr, presz,
|
||||
|
|
|
@ -81,7 +81,8 @@ static void stun_resp_handler(int err, uint16_t scode, const char *reason,
|
|||
goto out;
|
||||
}
|
||||
|
||||
err = icem_lcand_add(icem, lcand->base, CAND_TYPE_SRFLX, &attr->v.sa);
|
||||
err = icem_lcand_add(icem, lcand->base, ICE_CAND_TYPE_SRFLX,
|
||||
&attr->v.sa);
|
||||
|
||||
out:
|
||||
call_gather_handler(err, icem, scode, reason);
|
||||
|
@ -148,12 +149,12 @@ static void turnc_handler(int err, uint16_t scode, const char *reason,
|
|||
|
||||
if (!sa_cmp(relay, &lcand->base->addr, SA_ALL)) {
|
||||
err = icem_lcand_add(icem, lcand->base,
|
||||
CAND_TYPE_RELAY, relay);
|
||||
ICE_CAND_TYPE_RELAY, relay);
|
||||
}
|
||||
|
||||
if (mapped) {
|
||||
err |= icem_lcand_add(icem, lcand->base,
|
||||
CAND_TYPE_SRFLX, mapped);
|
||||
ICE_CAND_TYPE_SRFLX, mapped);
|
||||
}
|
||||
else {
|
||||
err |= send_binding_request(icem, comp);
|
||||
|
|
|
@ -23,13 +23,6 @@ enum checkl_state {
|
|||
CHECKLIST_FAILED
|
||||
};
|
||||
|
||||
enum cand_type {
|
||||
CAND_TYPE_HOST,
|
||||
CAND_TYPE_SRFLX,
|
||||
CAND_TYPE_PRFLX,
|
||||
CAND_TYPE_RELAY
|
||||
};
|
||||
|
||||
/** Candidate pair states */
|
||||
enum candpair_state {
|
||||
CANDPAIR_FROZEN = 0, /**< Frozen state (default) */
|
||||
|
@ -112,7 +105,7 @@ struct icem {
|
|||
/** Defines a candidate */
|
||||
struct cand {
|
||||
struct le le; /**< List element */
|
||||
enum cand_type type; /**< Candidate type */
|
||||
enum ice_cand_type type; /**< Candidate type */
|
||||
uint32_t prio; /**< Priority of this candidate */
|
||||
char *foundation; /**< Foundation */
|
||||
uint8_t compid; /**< Component ID (1-256) */
|
||||
|
@ -147,9 +140,10 @@ struct candpair {
|
|||
int icem_lcand_add_base(struct icem *icem, uint8_t compid, uint16_t lprio,
|
||||
const char *ifname, enum ice_transp transp,
|
||||
const struct sa *addr);
|
||||
int icem_lcand_add(struct icem *icem, struct cand *base, enum cand_type type,
|
||||
int icem_lcand_add(struct icem *icem, struct cand *base,
|
||||
enum ice_cand_type type,
|
||||
const struct sa *addr);
|
||||
int icem_rcand_add(struct icem *icem, enum cand_type type, uint8_t compid,
|
||||
int icem_rcand_add(struct icem *icem, enum ice_cand_type type, uint8_t compid,
|
||||
uint32_t prio, const struct sa *addr,
|
||||
const struct sa *rel_addr, const struct pl *foundation);
|
||||
int icem_rcand_add_prflx(struct cand **rcp, struct icem *icem, uint8_t compid,
|
||||
|
@ -172,7 +166,8 @@ void icem_candpair_cancel(struct candpair *cp);
|
|||
void icem_candpair_make_valid(struct candpair *cp);
|
||||
void icem_candpair_failed(struct candpair *cp, int err, uint16_t scode);
|
||||
void icem_candpair_set_state(struct candpair *cp, enum candpair_state state);
|
||||
void icem_candpairs_flush(struct list *lst, enum cand_type type, uint8_t id);
|
||||
void icem_candpairs_flush(struct list *lst, enum ice_cand_type type,
|
||||
uint8_t id);
|
||||
bool icem_candpair_iscompleted(const struct candpair *cp);
|
||||
bool icem_candpair_cmp(const struct candpair *cp1, const struct candpair *cp2);
|
||||
bool icem_candpair_cmp_fnd(const struct candpair *cp1,
|
||||
|
@ -224,8 +219,6 @@ int icem_conncheck_send(struct candpair *cp, bool use_cand, bool trigged);
|
|||
|
||||
|
||||
/* icestr */
|
||||
const char *ice_cand_type2name(enum cand_type type);
|
||||
enum cand_type ice_cand_name2type(const struct pl *name);
|
||||
const char *ice_mode2name(enum ice_mode mode);
|
||||
const char *ice_role2name(enum role role);
|
||||
const char *ice_candpair_state2name(enum candpair_state st);
|
||||
|
@ -235,7 +228,6 @@ const char *ice_checkl_state2name(enum checkl_state cst);
|
|||
/* util */
|
||||
typedef void * (list_unique_h)(struct le *le1, struct le *le2);
|
||||
|
||||
uint32_t ice_calc_prio(enum cand_type type, uint16_t local, uint8_t compid);
|
||||
uint64_t ice_calc_pair_prio(uint32_t g, uint32_t d);
|
||||
void ice_switch_local_role(struct ice *ice);
|
||||
uint32_t ice_list_unique(struct list *list, list_unique_h *uh);
|
||||
|
|
|
@ -281,8 +281,8 @@ static void purge_relayed(struct icem *icem, struct icem_comp *comp)
|
|||
* Purge all Candidate-Pairs where the Local candidate
|
||||
* is of type "Relay"
|
||||
*/
|
||||
icem_candpairs_flush(&icem->checkl, CAND_TYPE_RELAY, comp->id);
|
||||
icem_candpairs_flush(&icem->validl, CAND_TYPE_RELAY, comp->id);
|
||||
icem_candpairs_flush(&icem->checkl, ICE_CAND_TYPE_RELAY, comp->id);
|
||||
icem_candpairs_flush(&icem->validl, ICE_CAND_TYPE_RELAY, comp->id);
|
||||
|
||||
comp->turnc = mem_deref(comp->turnc);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ void icem_update(struct icem *icem)
|
|||
/* remove TURN client if not used by local "Selected" */
|
||||
if (comp->cp_sel) {
|
||||
|
||||
if (comp->cp_sel->lcand->type != CAND_TYPE_RELAY)
|
||||
if (comp->cp_sel->lcand->type != ICE_CAND_TYPE_RELAY)
|
||||
purge_relayed(icem, comp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,6 +202,7 @@ static int cand_decode(struct icem *icem, const char *val)
|
|||
struct pl foundation, compid, transp, prio, addr, port, cand_type;
|
||||
struct pl extra = pl_null;
|
||||
struct sa caddr, rel_addr;
|
||||
char type[8];
|
||||
uint8_t cid;
|
||||
int err;
|
||||
|
||||
|
@ -253,7 +254,9 @@ static int cand_decode(struct icem *icem, const char *val)
|
|||
if (icem_cand_find(&icem->rcandl, cid, &caddr))
|
||||
return 0;
|
||||
|
||||
return icem_rcand_add(icem, ice_cand_name2type(&cand_type), cid,
|
||||
(void)pl_strcpy(&cand_type, type, sizeof(type));
|
||||
|
||||
return icem_rcand_add(icem, ice_cand_name2type(type), cid,
|
||||
pl_u32(&prio), &caddr, &rel_addr, &foundation);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,27 +14,27 @@
|
|||
#include "ice.h"
|
||||
|
||||
|
||||
const char *ice_cand_type2name(enum cand_type type)
|
||||
const char *ice_cand_type2name(enum ice_cand_type type)
|
||||
{
|
||||
switch (type) {
|
||||
|
||||
case CAND_TYPE_HOST: return "host";
|
||||
case CAND_TYPE_SRFLX: return "srflx";
|
||||
case CAND_TYPE_PRFLX: return "prflx";
|
||||
case CAND_TYPE_RELAY: return "relay";
|
||||
default: return "???";
|
||||
case ICE_CAND_TYPE_HOST: return "host";
|
||||
case ICE_CAND_TYPE_SRFLX: return "srflx";
|
||||
case ICE_CAND_TYPE_PRFLX: return "prflx";
|
||||
case ICE_CAND_TYPE_RELAY: return "relay";
|
||||
default: return "???";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum cand_type ice_cand_name2type(const struct pl *name)
|
||||
enum ice_cand_type ice_cand_name2type(const char *name)
|
||||
{
|
||||
if (0 == pl_strcasecmp(name, "host")) return CAND_TYPE_HOST;
|
||||
if (0 == pl_strcasecmp(name, "srflx")) return CAND_TYPE_SRFLX;
|
||||
if (0 == pl_strcasecmp(name, "prflx")) return CAND_TYPE_PRFLX;
|
||||
if (0 == pl_strcasecmp(name, "relay")) return CAND_TYPE_RELAY;
|
||||
if (0 == str_casecmp(name, "host")) return ICE_CAND_TYPE_HOST;
|
||||
if (0 == str_casecmp(name, "srflx")) return ICE_CAND_TYPE_SRFLX;
|
||||
if (0 == str_casecmp(name, "prflx")) return ICE_CAND_TYPE_PRFLX;
|
||||
if (0 == str_casecmp(name, "relay")) return ICE_CAND_TYPE_RELAY;
|
||||
|
||||
return (enum cand_type)-1;
|
||||
return (enum ice_cand_type)-1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,20 +36,21 @@ enum {
|
|||
};
|
||||
|
||||
|
||||
static int type_prio(enum cand_type type)
|
||||
static int type_prio(enum ice_cand_type type)
|
||||
{
|
||||
switch (type) {
|
||||
|
||||
case CAND_TYPE_HOST: return CAND_PRIO_HOST;
|
||||
case CAND_TYPE_SRFLX: return CAND_PRIO_SRFLX;
|
||||
case CAND_TYPE_PRFLX: return CAND_PRIO_PRFLX;
|
||||
case CAND_TYPE_RELAY: return CAND_PRIO_RELAY;
|
||||
case ICE_CAND_TYPE_HOST: return CAND_PRIO_HOST;
|
||||
case ICE_CAND_TYPE_SRFLX: return CAND_PRIO_SRFLX;
|
||||
case ICE_CAND_TYPE_PRFLX: return CAND_PRIO_PRFLX;
|
||||
case ICE_CAND_TYPE_RELAY: return CAND_PRIO_RELAY;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ice_calc_prio(enum cand_type type, uint16_t local, uint8_t compid)
|
||||
uint32_t ice_cand_calc_prio(enum ice_cand_type type, uint16_t local,
|
||||
uint8_t compid)
|
||||
{
|
||||
return (uint32_t)type_prio(type)<<24 | local<<8 | (256 - compid);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue