Skip to content
Snippets Groups Projects
Commit f9842016 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

test: add test for trimming ice candidates

Change-Id: I29830dcdcf91b98a75d90a001596a332f256ccd9
parent b71c65d4
Branches
No related tags found
No related merge requests found
...@@ -58,11 +58,13 @@ private: ...@@ -58,11 +58,13 @@ private:
void testRawIceConnection(); void testRawIceConnection();
void testTurnMasterIceConnection(); void testTurnMasterIceConnection();
void testTurnSlaveIceConnection(); void testTurnSlaveIceConnection();
void testReceiveTooManyCandidates();
CPPUNIT_TEST_SUITE(IceTest); CPPUNIT_TEST_SUITE(IceTest);
CPPUNIT_TEST(testRawIceConnection); CPPUNIT_TEST(testRawIceConnection);
CPPUNIT_TEST(testTurnMasterIceConnection); CPPUNIT_TEST(testTurnMasterIceConnection);
CPPUNIT_TEST(testTurnSlaveIceConnection); CPPUNIT_TEST(testTurnSlaveIceConnection);
CPPUNIT_TEST(testReceiveTooManyCandidates);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -405,6 +407,111 @@ IceTest::testTurnSlaveIceConnection() ...@@ -405,6 +407,111 @@ IceTest::testTurnSlaveIceConnection()
CPPUNIT_ASSERT(ice_slave->getLocalAddress(1).toString(false) == turnV4_->toString(false)); CPPUNIT_ASSERT(ice_slave->getLocalAddress(1).toString(false) == turnV4_->toString(false));
} }
void
IceTest::testReceiveTooManyCandidates()
{
const auto& addr4 = dht_->getPublicAddress(AF_INET);
CPPUNIT_ASSERT(addr4.size() != 0);
CPPUNIT_ASSERT(turnV4_);
IceTransportOptions ice_config;
ice_config.upnpEnable = true;
ice_config.tcpEnable = true;
std::shared_ptr<IceTransport> ice_master, ice_slave;
std::mutex mtx, mtx_create, mtx_resp, mtx_init;
std::unique_lock<std::mutex> lk {mtx}, lk_create {mtx_create}, lk_resp {mtx_resp},
lk_init {mtx_init};
std::condition_variable cv, cv_create, cv_resp, cv_init;
std::string init = {};
std::string response = {};
bool iceMasterReady = false, iceSlaveReady = false;
ice_config.onInitDone = [&](bool ok) {
CPPUNIT_ASSERT(ok);
dht::ThreadPool::io().run([&] {
CPPUNIT_ASSERT(cv_create.wait_for(lk_create, std::chrono::seconds(10), [&] {
return ice_master != nullptr;
}));
auto iceAttributes = ice_master->getLocalAttributes();
std::stringstream icemsg;
icemsg << iceAttributes.ufrag << "\n";
icemsg << iceAttributes.pwd << "\n";
for (const auto& addr : ice_master->getLocalCandidates(1)) {
icemsg << addr << "\n";
JAMI_DBG() << "Added local ICE candidate " << addr;
}
init = icemsg.str();
cv_init.notify_one();
CPPUNIT_ASSERT(cv_resp.wait_for(lk_resp, std::chrono::seconds(10), [&] {
return !response.empty();
}));
auto sdp = ice_master->parseIceCandidates(response);
CPPUNIT_ASSERT(
ice_master->startIce({sdp.rem_ufrag, sdp.rem_pwd}, std::move(sdp.rem_candidates)));
});
};
ice_config.onNegoDone = [&](bool ok) {
iceMasterReady = ok;
cv.notify_one();
};
ice_config.accountPublicAddr = IpAddr(*addr4[0].get());
ice_config.accountLocalAddr = ip_utils::getLocalAddr(AF_INET);
ice_config.turnServers.emplace_back(TurnServerInfo()
.setUri(turnV4_->toString(true))
.setUsername("ring")
.setPassword("ring")
.setRealm("ring"));
ice_config.master = true;
ice_config.streamsCount = 1;
ice_config.compCountPerStream = 1;
ice_master = Manager::instance().getIceTransportFactory().createTransport("master ICE",
ice_config);
cv_create.notify_all();
ice_config.onInitDone = [&](bool ok) {
CPPUNIT_ASSERT(ok);
dht::ThreadPool::io().run([&] {
CPPUNIT_ASSERT(cv_create.wait_for(lk_create, std::chrono::seconds(10), [&] {
return ice_slave != nullptr;
}));
auto iceAttributes = ice_slave->getLocalAttributes();
std::stringstream icemsg;
icemsg << iceAttributes.ufrag << "\n";
icemsg << iceAttributes.pwd << "\n";
for (const auto& addr : ice_master->getLocalCandidates(1)) {
icemsg << addr << "\n";
JAMI_DBG() << "Added local ICE candidate " << addr;
}
for (auto i = 0; i < std::min(256, PJ_ICE_ST_MAX_CAND); ++i) {
icemsg << "Hc0a800a5 1 TCP 2130706431 192.168.0." << i
<< " 43613 typ host tcptype passive"
<< "\n";
icemsg << "Hc0a800a5 1 TCP 2130706431 192.168.0." << i
<< " 9 typ host tcptype active"
<< "\n";
}
response = icemsg.str();
cv_resp.notify_one();
CPPUNIT_ASSERT(
cv_init.wait_for(lk_resp, std::chrono::seconds(10), [&] { return !init.empty(); }));
auto sdp = ice_slave->parseIceCandidates(init);
CPPUNIT_ASSERT(
ice_slave->startIce({sdp.rem_ufrag, sdp.rem_pwd}, std::move(sdp.rem_candidates)));
});
};
ice_config.onNegoDone = [&](bool ok) {
iceSlaveReady = ok;
cv.notify_one();
};
ice_config.master = false;
ice_config.streamsCount = 1;
ice_config.compCountPerStream = 1;
ice_slave = Manager::instance().getIceTransportFactory().createTransport("slave ICE",
ice_config);
cv_create.notify_all();
CPPUNIT_ASSERT(
cv.wait_for(lk, std::chrono::seconds(10), [&] { return iceMasterReady && iceSlaveReady; }));
}
} // namespace test } // namespace test
} // namespace jami } // namespace jami
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment