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

connectionmanager: erase infos on negotiation failures

This avoid to keep opened files.

Change-Id: Ib72f124090715a02150277898aee5f65dff4cda0
parent 324d49ce
No related branches found
No related tags found
No related merge requests found
......@@ -387,6 +387,15 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
}
}
// Note: used when the ice negotiation fails to erase
// all stored structures.
auto eraseInfo = [w, cbId] {
if (auto shared = w.lock()) {
std::lock_guard<std::mutex> lk(shared->infosMtx_);
shared->infos_.erase(cbId);
}
};
// If no socket exists, we need to initiate an ICE connection.
auto& iceTransportFactory = Manager::instance().getIceTransportFactory();
auto ice_config = sthis->account.getIceOptions();
......@@ -396,7 +405,8 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
deviceId = std::move(deviceId),
name = std::move(name),
cert = std::move(cert),
vid](bool ok) {
vid,
eraseInfo](bool ok) {
auto sthis = w.lock();
if (!sthis)
return;
......@@ -404,6 +414,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
JAMI_ERR("Cannot initialize ICE session.");
if (auto cb = sthis->getPendingCallback(cbId))
cb(nullptr, deviceId);
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
return;
}
......@@ -418,7 +429,8 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
deviceId = std::move(deviceId),
name = std::move(name),
cert = std::move(cert),
vid](bool ok) {
vid,
eraseInfo](bool ok) {
auto sthis = w.lock();
if (!sthis)
return;
......@@ -426,6 +438,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
JAMI_ERR("ICE negotiation failed.");
if (auto cb = sthis->getPendingCallback(cbId))
cb(nullptr, deviceId);
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
return;
}
......@@ -457,6 +470,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
JAMI_ERR("Cannot initialize ICE session.");
if (auto cb = sthis->getPendingCallback(cbId))
cb(nullptr, deviceId);
eraseInfo();
return;
}
});
......@@ -684,10 +698,19 @@ ConnectionManager::Impl::onDhtPeerRequest(const PeerConnectionRequest& req,
return;
}
// Note: used when the ice negotiation fails to erase
// all stored structures.
auto eraseInfo = [w = weak(), id = req.id, from = req.from] {
if (auto shared = w.lock()) {
std::lock_guard<std::mutex> lk(shared->infosMtx_);
shared->infos_.erase({from, id});
}
};
// Because the connection is accepted, create an ICE socket.
auto ice_config = account.getIceOptions();
ice_config.tcpEnable = true;
ice_config.onInitDone = [w = weak(), req](bool ok) {
ice_config.onInitDone = [w = weak(), req, eraseInfo](bool ok) {
auto shared = w.lock();
if (!shared)
return;
......@@ -695,6 +718,7 @@ ConnectionManager::Impl::onDhtPeerRequest(const PeerConnectionRequest& req,
JAMI_ERR("Cannot initialize ICE session.");
if (shared->connReadyCb_)
shared->connReadyCb_(req.from, "", nullptr);
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
return;
}
......@@ -706,7 +730,7 @@ ConnectionManager::Impl::onDhtPeerRequest(const PeerConnectionRequest& req,
});
};
ice_config.onNegoDone = [w = weak(), req](bool ok) {
ice_config.onNegoDone = [w = weak(), req, eraseInfo](bool ok) {
auto shared = w.lock();
if (!shared)
return;
......@@ -714,6 +738,7 @@ ConnectionManager::Impl::onDhtPeerRequest(const PeerConnectionRequest& req,
JAMI_ERR("ICE negotiation failed");
if (shared->connReadyCb_)
shared->connReadyCb_(req.from, "", nullptr);
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
return;
}
......@@ -737,6 +762,7 @@ ConnectionManager::Impl::onDhtPeerRequest(const PeerConnectionRequest& req,
JAMI_ERR("Cannot initialize ICE session.");
if (connReadyCb_)
connReadyCb_(req.from, "", nullptr);
eraseInfo();
return;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment