Commit 9f009c7e authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin
Browse files

jamiaccount: protect device list



Change-Id: I6c533621bc21c01601ba2681b0ebea35f8d6cc17
Reviewed-by: Sébastien Blin's avatarSébastien Blin <sebastien.blin@savoirfairelinux.com>
parent 2e2c3850
......@@ -763,7 +763,11 @@ JamiAccount::createRingDevice(const dht::crypto::Identity& id)
ringDeviceName_ = ip_utils::getDeviceName();
if (ringDeviceName_.empty())
ringDeviceName_ = ringDeviceId_.substr(8);
knownDevices_.emplace(deviceId, KnownDevice{dev_id.second, ringDeviceName_, clock::now()});
{
std::lock_guard<std::mutex> devicelock(deviceListMutex_);
knownDevices_.emplace(deviceId, KnownDevice{dev_id.second, ringDeviceName_, clock::now()});
}
receipt_ = makeReceipt(id);
receiptSignature_ = id.first->sign({receipt_.begin(), receipt_.end()});
......@@ -1126,6 +1130,7 @@ JamiAccount::revokeDevice(const std::string& password, const std::string& device
emitSignal<DRing::ConfigurationSignal::DeviceRevocationEnded>(getAccountID(), device, 2);
return;
}
std::lock_guard<std::mutex> lock(deviceListMutex_);
foundAccountDevice(crt);
AccountArchive a;
try {
......@@ -1551,6 +1556,7 @@ JamiAccount::setAccountDetails(const std::map<std::string, std::string>& details
loadAccount(archive_password, archive_pin, archive_path);
// update device name if necessary
std::lock_guard<std::mutex> devicelock(deviceListMutex_);
auto dev = knownDevices_.find(dht::InfoHash(ringDeviceId_));
if (dev != knownDevices_.end()) {
if (dev->second.name != ringDeviceName_) {
......@@ -2200,6 +2206,7 @@ JamiAccount::doRegister_()
dht_.put(h, crl, dht::DoneCallback{}, {}, true);
dht_.listen<DeviceAnnouncement>(h, [this](DeviceAnnouncement&& dev) {
findCertificate(dev.dev, [this](const std::shared_ptr<dht::crypto::Certificate>& crt) {
std::lock_guard<std::mutex> lock(deviceListMutex_);
foundAccountDevice(crt);
});
return true;
......@@ -2277,6 +2284,7 @@ JamiAccount::doRegister_()
JAMI_WARN("Can't find certificate for device %s", sync.from.toString().c_str());
return;
}
std::lock_guard<std::mutex> lock(deviceListMutex_);
if (not foundAccountDevice(cert))
return;
onReceiveDeviceSync(std::move(sync));
......@@ -2319,6 +2327,7 @@ JamiAccount::doRegister_()
dhtPeerConnector_->onDhtConnected(ringDeviceId_);
std::lock_guard<std::mutex> lock(buddyInfoMtx);
for (auto& buddy : trackedBuddies_) {
buddy.second.devices_cnt = 0;
trackPresence(buddy.first, buddy.second);
......@@ -2745,6 +2754,7 @@ JamiAccount::loadKnownDevices()
return;
}
std::lock_guard<std::mutex> lock(deviceListMutex_);
for (const auto& d : knownDevices) {
JAMI_DBG("[Account %s] loading known account device %s %s", getAccountID().c_str(),
d.second.first.c_str(),
......@@ -3266,6 +3276,7 @@ JamiAccount::syncDevices()
}
}
std::lock_guard<std::mutex> lock(deviceListMutex_);
for (const auto& dev : knownDevices_) {
if (dev.first.toString() == ringDeviceId_)
sync_data.devices_known.emplace(dev.first, ringDeviceName_);
......@@ -3302,6 +3313,7 @@ JamiAccount::onReceiveDeviceSync(DeviceSync&& sync)
findCertificate(d.first, [this,d](const std::shared_ptr<dht::crypto::Certificate>& crt) {
if (not crt)
return;
std::lock_guard<std::mutex> lock(deviceListMutex_);
foundAccountDevice(crt, d.second);
});
}
......
......@@ -503,6 +503,8 @@ class JamiAccount : public SIPAccountBase {
bool handlePendingCallList();
bool handlePendingCall(PendingCall& pc, bool incoming);
mutable std::mutex callsMutex_ {};
/**
* DHT calls waiting for ICE negotiation
*/
......@@ -513,7 +515,6 @@ class JamiAccount : public SIPAccountBase {
*/
std::list<PendingCall> pendingSipCalls_;
std::set<dht::Value::Id> treatedCalls_ {};
mutable std::mutex callsMutex_ {};
mutable std::mutex messageMutex_ {};
std::map<dht::Value::Id, PendingMessage> sentMessages_;
......@@ -553,10 +554,11 @@ class JamiAccount : public SIPAccountBase {
std::shared_ptr<dht::Value> announce_;
/* this ring account associated devices */
mutable std::mutex deviceListMutex_ {};
std::map<dht::InfoHash, KnownDevice> knownDevices_;
/* tracked buddies presence */
std::mutex buddyInfoMtx;
mutable std::mutex buddyInfoMtx;
std::map<dht::InfoHash, BuddyInfo> trackedBuddies_;
void loadAccount(const std::string& archive_password = {}, const std::string& archive_pin = {}, const std::string& archive_path = {});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment