From 1f83de3d042477bcd6e08958028c9b68a2cca99e Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Wed, 29 Jul 2020 18:14:45 +0200 Subject: [PATCH] more entropy --- message_cache.cc | 6 ++++-- message_cache.hh | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/message_cache.cc b/message_cache.cc index 71ce28f..6ca47cf 100644 --- a/message_cache.cc +++ b/message_cache.cc @@ -10,7 +10,8 @@ namespace pEp { { std::random_device r; std::default_random_engine e(r()); - std::uniform_int_distribution u(1, 0x0100000000000000L); + std::uniform_int_distribution u(1, LLONG_MAX >> 1); + id_range = u(e); next_id = u(e); } @@ -374,8 +375,9 @@ namespace pEp { if (_msg && emptystr(_msg->id)) { free(_msg->id); + std::string _range = std::to_string(id_range); std::string _id = std::to_string(next_id++); - _msg->id = strdup((std::string("pEp_auto_id_") + _id).c_str()); + _msg->id = strdup((std::string("pEp_auto_id_") + _range + _id).c_str()); assert(_msg->id); if (!_msg->id) throw std::bad_alloc(); diff --git a/message_cache.hh b/message_cache.hh index fec9b63..fa01536 100644 --- a/message_cache.hh +++ b/message_cache.hh @@ -20,6 +20,7 @@ namespace pEp { cache _cache; std::mutex _mtx; + long long id_range = 42; long long next_id = 23; public: