Skip to content
Snippets Groups Projects
Commit 9b3b9df3 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

namedirectory: catch parsing errors

Change-Id: Ia92378315f88051de76311d23156c1eb85c07770
parent f4993c88
No related branches found
No related tags found
No related merge requests found
......@@ -476,6 +476,10 @@ NameDirectory::saveCache()
dhtnet::fileutils::recursive_mkdir(fileutils::get_cache_dir() / CACHE_DIRECTORY);
std::lock_guard lock(dhtnet::fileutils::getFileLock(cachePath_));
std::ofstream file(cachePath_, std::ios::trunc | std::ios::binary);
if (!file.is_open()) {
JAMI_ERROR("Unable to save cache to {}", cachePath_);
return;
}
{
std::lock_guard l(cacheLock_);
msgpack::pack(file, nameCache_);
......@@ -505,13 +509,20 @@ NameDirectory::loadCache()
}
}
// load values
std::lock_guard l(cacheLock_);
msgpack::object_handle oh;
if (pac.next(oh))
oh.get().convert(nameCache_);
for (const auto& m : nameCache_)
addrCache_.emplace(m.second.second, m.second);
try {
// load values
std::lock_guard l(cacheLock_);
msgpack::object_handle oh;
if (pac.next(oh))
oh.get().convert(nameCache_);
for (const auto& m : nameCache_)
addrCache_.emplace(m.second.second, m.second);
} catch (const msgpack::parse_error& e) {
JAMI_ERROR("Error when parsing msgpack object: {}", e.what());
} catch (const std::bad_cast& e) {
JAMI_ERROR("Error when loading cache: {}", e.what());
}
JAMI_DEBUG("Loaded {:d} name-address mappings", nameCache_.size());
}
......
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