Пример #1
0
static void turnc_handler(int err, uint16_t scode, const char *reason,
			  const struct sa *relay, const struct sa *mapped,
			  const struct stun_msg *msg, void *arg)
{
	struct icem_comp *comp = arg;
	struct icem *icem = comp->icem;
	struct cand *lcand;
	(void)msg;

	--icem->nstun;

	/* TURN failed, so we destroy the client */
	if (err || scode) {
		comp->turnc = mem_deref(comp->turnc);
	}

	if (err) {
		DEBUG_WARNING("{%s.%u} TURN Client error: %m\n",
			      icem->name, comp->id, err);
		goto out;
	}

	if (scode) {
		DEBUG_WARNING("{%s.%u} TURN Client error: %u %s\n",
			      icem->name, comp->id, scode, reason);
		err = send_binding_request(icem, comp);
		if (err)
			goto out;
		return;
	}

	lcand = icem_cand_find(&icem->lcandl, comp->id, NULL);
	if (!lcand)
		goto out;

	if (!sa_cmp(relay, &lcand->base->addr, SA_ALL)) {
		err = icem_lcand_add(icem, lcand->base,
				     CAND_TYPE_RELAY, relay);
	}

	if (mapped) {
		err |= icem_lcand_add(icem, lcand->base,
				      CAND_TYPE_SRFLX, mapped);
	}
	else {
		err |= send_binding_request(icem, comp);
	}

 out:
	call_gather_handler(err, icem, scode, reason);
}
Пример #2
0
static void handle_success(struct icem *icem, struct ice_candpair *cp,
			   const struct sa *laddr)
{
	if (!icem_cand_find(&icem->lcandl, cp->lcand->compid, laddr)) {

		int err;

		icecomp_printf(cp->comp, "adding local PRFLX Candidate: %J\n",
			       laddr);

		err = icem_lcand_add(icem, cp->lcand,
				     ICE_CAND_TYPE_PRFLX, laddr);
		if (err) {
			DEBUG_WARNING("failed to add PRFLX: %m\n", err);
		}
	}

	cp = construct_valid_pair(icem, cp, laddr, &cp->rcand->addr);
	if (!cp) {
		DEBUG_WARNING("{%s} no valid candidate pair for %J\n",
			      icem->name, laddr);
		return;
	}

	icem_candpair_make_valid(cp);
	icem_comp_set_selected(cp->comp, cp);

	cp->nominated = true;

#if 0
	/* stop conncheck now -- conclude */
	icem_conncheck_stop(icem, 0);
#endif
}
Пример #3
0
static void stun_resp_handler(int err, uint16_t scode, const char *reason,
			      const struct stun_msg *msg, void *arg)
{
	struct icem_comp *comp = arg;
	struct icem *icem = comp->icem;
	struct stun_attr *attr;
	struct cand *lcand;

	--icem->nstun;

	if (err || scode > 0) {
		DEBUG_WARNING("{%s.%u} STUN Request failed: %m\n",
			      icem->name, comp->id, err);
		goto out;
	}

	lcand = icem_cand_find(&icem->lcandl, comp->id, NULL);
	if (!lcand)
		goto out;

	attr = stun_msg_attr(msg, STUN_ATTR_XOR_MAPPED_ADDR);
	if (!attr)
		attr = stun_msg_attr(msg, STUN_ATTR_MAPPED_ADDR);
	if (!attr) {
		DEBUG_WARNING("no Mapped Address in Response\n");
		err = EPROTO;
		goto out;
	}

	err = icem_lcand_add(icem, lcand->base, CAND_TYPE_SRFLX, &attr->v.sa);

 out:
	call_gather_handler(err, icem, scode, reason);
}