Commit 1c2d8168 authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin

dring: don't use IDs above 2^53

* avoid using IDs above 2^63 for Java binding compatibility
 (no unsigned integers in Java)
* avoid using IDs above 2^53 for JavaScript binding compatibility
 (no proper integers in JS)

Change-Id: I57bb26d2464edbdca4c9e6fe858894d3b53519dd
parent d7da705a
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
namespace jami { namespace jami {
namespace im { namespace im {
static std::uniform_int_distribution<MessageToken> udist {1};
MessageEngine::MessageEngine(SIPAccountBase& acc, const std::string& path) : account_(acc), savePath_(path) MessageEngine::MessageEngine(SIPAccountBase& acc, const std::string& path) : account_(acc), savePath_(path)
{} {}
...@@ -48,7 +46,7 @@ MessageEngine::sendMessage(const std::string& to, const std::map<std::string, st ...@@ -48,7 +46,7 @@ MessageEngine::sendMessage(const std::string& to, const std::map<std::string, st
std::lock_guard<std::mutex> lock(messagesMutex_); std::lock_guard<std::mutex> lock(messagesMutex_);
auto& peerMessages = messages_[to]; auto& peerMessages = messages_[to];
do { do {
token = udist(account_.rand); token = std::uniform_int_distribution<MessageToken>{1, DRING_ID_MAX_VAL}(account_.rand);
} while (peerMessages.find(token) != peerMessages.end()); } while (peerMessages.find(token) != peerMessages.end());
auto m = peerMessages.emplace(token, Message{}); auto m = peerMessages.emplace(token, Message{});
m.first->second.to = to; m.first->second.to = to;
......
...@@ -2790,13 +2790,12 @@ Manager::removeAccounts() ...@@ -2790,13 +2790,12 @@ Manager::removeAccounts()
std::string std::string
Manager::getNewCallID() Manager::getNewCallID()
{ {
static std::uniform_int_distribution<uint64_t> rand_call_id;
std::ostringstream random_id; std::ostringstream random_id;
// generate something like s7ea037947eb9fb2f // generate something like s7ea037947eb9fb2f
do { do {
random_id.clear(); random_id.clear();
random_id << rand_call_id(pimpl_->rand_); random_id << std::uniform_int_distribution<uint64_t>(1, DRING_ID_MAX_VAL)(pimpl_->rand_);
} while (callFactory.hasCall(random_id.str())); } while (callFactory.hasCall(random_id.str()));
return random_id.str(); return random_id.str();
......
...@@ -57,6 +57,8 @@ class IceTransportFactory; ...@@ -57,6 +57,8 @@ class IceTransportFactory;
class DataTransferFacade; class DataTransferFacade;
class JamiAccount; class JamiAccount;
static constexpr size_t DRING_ID_MAX_VAL = 9007199254740992;
/** Manager (controller) of daemon */ /** Manager (controller) of daemon */
class Manager { class Manager {
public: public:
......
Markdown is supported
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