| 310 | } |
| 311 | |
| 312 | std::future<void> PersistProfiles () |
| 313 | { |
| 314 | auto ts = i2p::util::GetSecondsSinceEpoch (); |
| 315 | std::list<std::pair<i2p::data::IdentHash, std::shared_ptr<RouterProfile> > > tmp; |
| 316 | { |
| 317 | std::lock_guard<std::mutex> l(g_ProfilesMutex); |
| 318 | for (auto it = g_Profiles.begin (); it != g_Profiles.end ();) |
| 319 | { |
| 320 | if (it->second->IsUpdated () && ts > it->second->GetLastPersistTime () + PEER_PROFILE_PERSIST_INTERVAL) |
| 321 | { |
| 322 | tmp.push_back (*it); |
| 323 | it->second->SetLastPersistTime (ts); |
| 324 | it->second->SetUpdated (false); |
| 325 | } |
| 326 | if (!it->second->IsUpdated () && ts > std::max (it->second->GetLastUpdateTime (), it->second->GetLastAccessTime ()) + PEER_PROFILE_PERSIST_INTERVAL) |
| 327 | it = g_Profiles.erase (it); |
| 328 | else |
| 329 | it++; |
| 330 | } |
| 331 | } |
| 332 | if (!tmp.empty ()) |
| 333 | return std::async (std::launch::async, SaveProfilesToDisk, std::move (tmp)); |
| 334 | return std::future<void>(); |
| 335 | } |
| 336 | |
| 337 | void SaveProfiles () |
| 338 | { |
no test coverage detected