static keys table

This commit is contained in:
orignal 2023-04-30 20:05:35 -04:00
parent 2af4a2b58d
commit 7c535159bc
5 changed files with 49 additions and 0 deletions

View file

@ -301,5 +301,33 @@ namespace data
}
}
}
// static keys
struct StaticKeyProfile
{
i2p::data::IdentHash ident;
boost::posix_time::ptime lastUpdateTime;
};
//static i2p::fs::HashedStorage g_StaticKeysProfilesStorage("statickeysProfiles", "s", "statickey-", "txt");
static std::unordered_map<i2p::data::Tag<32>, std::shared_ptr<StaticKeyProfile> > g_StaticKeysProfiles;
static std::mutex g_StaticKeysProfilesMutex;
bool CheckStaticKey (const i2p::data::Tag<32>& staticKey, const i2p::data::IdentHash& ident)
{
std::unique_lock<std::mutex> l(g_StaticKeysProfilesMutex);
auto it = g_StaticKeysProfiles.find (staticKey);
if (it != g_StaticKeysProfiles.end ())
return it->second->ident == ident;
return true;
}
void UpdateStaticKey (const i2p::data::Tag<32>& staticKey, const i2p::data::IdentHash& ident)
{
std::unique_lock<std::mutex> l(g_StaticKeysProfilesMutex);
auto res = g_StaticKeysProfiles.emplace (staticKey, std::make_shared<StaticKeyProfile>(StaticKeyProfile{ident, GetTime ()}));
if (!res.second)
res.first->second->lastUpdateTime = GetTime ();
}
}
}