Skip to content
Snippets Groups Projects
Commit 35c6eab3 authored by Mohamed Chibani's avatar Mohamed Chibani Committed by Adrien Béraud
Browse files

ice: log the address type of the selected candidate pair

Change-Id: Ie0eec02ad6f1eba6cbd19f198fafc5024e0a6bf7
GitLab: #290
parent 00330fd8
No related branches found
No related tags found
No related merge requests found
......@@ -113,8 +113,10 @@ public:
bool _isRunning() const;
bool _isFailed() const;
const pj_ice_sess_cand* getSelectedCandidate(unsigned comp_id, bool remote) const;
IpAddr getLocalAddress(unsigned comp_id) const;
IpAddr getRemoteAddress(unsigned comp_id) const;
static const char* getCandidateType(const pj_ice_sess_cand* cand);
std::unique_ptr<pj_pool_t, std::function<void(pj_pool_t*)>> pool_ {};
IceTransportCompleteCb on_initdone_cb_ {};
......@@ -591,14 +593,18 @@ IceTransport::Impl::onComplete(pj_ice_strans* ice_st, pj_ice_strans_op op, pj_st
for (unsigned i = 0; i < component_count_; ++i) {
auto laddr = getLocalAddress(i);
auto raddr = getRemoteAddress(i);
if (laddr and raddr) {
out << " [" << i << "] " << laddr.toString(true, true) << " <-> "
<< raddr.toString(true, true) << '\n';
out << " [" << i+1 << "] "
<< laddr.toString(true, true) << " [" << getCandidateType(getSelectedCandidate(i, false)) << "] "
<< " <-> "
<< raddr.toString(true, true) << " [" << getCandidateType(getSelectedCandidate(i, true)) << "] " << '\n';
} else {
out << " [" << i << "] disabled\n";
out << " [" << i+1 << "] disabled\n";
}
}
JAMI_DBG("[ice:%p] %s connection pairs (local <-> remote):\n%s",
JAMI_DBG("[ice:%p] %s connection pairs ([comp id] local [type] <-> remote [type]):\n%s",
this,
(config_.protocol == PJ_ICE_TP_TCP ? "TCP" : "UDP"),
out.str().c_str());
......@@ -645,42 +651,54 @@ IceTransport::Impl::setSlaveSession()
return createIceSession(PJ_ICE_SESS_ROLE_CONTROLLED);
}
IpAddr
IceTransport::Impl::getLocalAddress(unsigned comp_id) const
const pj_ice_sess_cand*
IceTransport::Impl::getSelectedCandidate(unsigned comp_id, bool remote) const
{
// Return the local IP of negotiated connection pair
if (_isRunning()) {
if (auto sess = pj_ice_strans_get_valid_pair(icest_.get(), comp_id + 1))
return sess->lcand->addr;
// Return the selected candidate pair. Might not be the nominated pair if
// ICE has not concluded yet, but should be the nominated pair afterwards.
if (not _isRunning()) {
JAMI_ERR("[ice:%p] ICE transport is not running", this);
return nullptr;
}
const auto* sess = pj_ice_strans_get_valid_pair(icest_.get(), comp_id + 1);
if (sess == nullptr) {
JAMI_ERR("[ice:%p] Component %i has no valid pair", this, comp_id);
return nullptr;
}
if (remote)
return sess->rcand;
else
return {}; // disabled component
} else
JAMI_WARN("[ice:%p] bad call: non-negotiated transport", this);
return sess->lcand;
}
// Return the default IP (could be not nominated and valid after negotiation)
if (_isInitialized())
return cand_[comp_id].addr;
IpAddr
IceTransport::Impl::getLocalAddress(unsigned comp_id) const
{
if (auto cand = getSelectedCandidate(comp_id, false))
return cand->addr;
JAMI_ERR("[ice:%p] bad call: non-initialized transport", this);
JAMI_ERR("[ice:%p] No local address for component %i", this, comp_id);
return {};
}
IpAddr
IceTransport::Impl::getRemoteAddress(unsigned comp_id) const
{
// Return the remote IP of negotiated connection pair
if (_isRunning()) {
if (auto sess = pj_ice_strans_get_valid_pair(icest_.get(), comp_id + 1))
return sess->rcand->addr;
else
return {}; // disabled component
} else
JAMI_WARN("[ice:%p] bad call: non-negotiated transport", this);
if (auto cand = getSelectedCandidate(comp_id, true))
return cand->addr;
JAMI_ERR("[ice:%p] bad call: non-negotiated transport", this);
JAMI_ERR("[ice:%p] No remote address for component %i", this, comp_id);
return {};
}
const char*
IceTransport::Impl::getCandidateType(const pj_ice_sess_cand* cand)
{
auto name = cand ? pj_ice_get_cand_type_name(cand->type) : nullptr;
return name ? name : "?";
}
void
IceTransport::Impl::getUFragPwd()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment