Commit a63d9726 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

ringdht: bump opendht, msgpack, remember fetched messages

* bump MsgPack to stable release 1.2.0
* bump OpenDHT to latest master supporting MsgPack 1.2.0
* adapt RingAccount to latest OpenDHT API

Issue: #81946
Change-Id: I331626120ca5e1c4c0d6f9a2dcf69e8d2934a636
parent a646cde3
# MSGPACK # MSGPACK
MSGPACK_VERSION := 294aa52c3ad8392ea54331d0ed89299f6a32a798 MSGPACK_VERSION := cpp-1.2.0
MSGPACK_URL := https://github.com/msgpack/msgpack-c/archive/$(MSGPACK_VERSION).tar.gz MSGPACK_URL := https://github.com/msgpack/msgpack-c/archive/$(MSGPACK_VERSION).tar.gz
PKGS += msgpack PKGS += msgpack
...@@ -8,8 +8,8 @@ PKGS_FOUND += msgpack ...@@ -8,8 +8,8 @@ PKGS_FOUND += msgpack
endif endif
MSGPACK_CMAKECONF := -DMSGPACK_CXX11=ON \ MSGPACK_CMAKECONF := -DMSGPACK_CXX11=ON \
-DMSGPACK_BUILD_EXAMPLES=OFF \ -DMSGPACK_BUILD_EXAMPLES=OFF \
-DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_LIBDIR=lib
$(TARBALLS)/msgpack-c-$(MSGPACK_VERSION).tar.gz: $(TARBALLS)/msgpack-c-$(MSGPACK_VERSION).tar.gz:
$(call download,$(MSGPACK_URL)) $(call download,$(MSGPACK_URL))
......
# OPENDHT # OPENDHT
OPENDHT_VERSION := fe3ded9d0f833b953d1eaa4dfdb509c51ae09ef6 OPENDHT_VERSION := 184dc17aa8cf57a9a3e1b26ff2794b2cab4597ba
OPENDHT_URL := https://github.com/savoirfairelinux/opendht/archive/$(OPENDHT_VERSION).tar.gz OPENDHT_URL := https://github.com/savoirfairelinux/opendht/archive/$(OPENDHT_VERSION).tar.gz
PKGS += opendht PKGS += opendht
......
...@@ -716,6 +716,7 @@ RingAccount::doRegister_() ...@@ -716,6 +716,7 @@ RingAccount::doRegister_()
{ {
try { try {
loadTreatedCalls(); loadTreatedCalls();
loadTreatedMessages();
if (dht_.isRunning()) { if (dht_.isRunning()) {
RING_ERR("DHT already running (stopping it first)."); RING_ERR("DHT already running (stopping it first).");
dht_.join(); dht_.join();
...@@ -887,8 +888,13 @@ RingAccount::doRegister_() ...@@ -887,8 +888,13 @@ RingAccount::doRegister_()
inboxKey, inboxKey,
[shared](dht::ImMessage&& v) { [shared](dht::ImMessage&& v) {
auto& this_ = *shared.get(); auto& this_ = *shared.get();
auto res = this_.treatedMessages_.insert(v.id);
this_.saveTreatedMessages();
if (!res.second)
return true;
auto from = v.from.toString(); auto from = v.from.toString();
auto msg = v.im_message; auto msg = v.msg;
RING_DBG("Text message received from DHT ! %s -> %s", from.c_str(), msg.c_str()); RING_DBG("Text message received from DHT ! %s -> %s", from.c_str(), msg.c_str());
emitSignal<DRing::ConfigurationSignal::IncomingAccountMessage>(this_.getAccountID(), from, msg); emitSignal<DRing::ConfigurationSignal::IncomingAccountMessage>(this_.getAccountID(), from, msg);
return true; return true;
...@@ -999,40 +1005,61 @@ RingAccount::getCertificatesByStatus(tls::TrustStore::Status status) ...@@ -999,40 +1005,61 @@ RingAccount::getCertificatesByStatus(tls::TrustStore::Status status)
return trust_.getCertificatesByStatus(status); return trust_.getCertificatesByStatus(status);
} }
std::set<dht::Value::Id>
loadIdList(const std::string& path)
{
std::set<dht::Value::Id> ids;
std::ifstream file(path);
if (!file.is_open()) {
RING_WARN("Could not load %s", path.c_str());
return ids;
}
std::string line;
while (std::getline(file, line)) {
std::istringstream iss(line);
dht::Value::Id vid;
if (!(iss >> std::hex >> vid)) { break; }
ids.insert(vid);
}
return ids;
}
void void
RingAccount::loadTreatedCalls() saveIdList(const std::string& path, const std::set<dht::Value::Id>& ids)
{ {
std::string treatedcallPath = cachePath_+DIR_SEPARATOR_STR "treatedCalls"; std::ofstream file(path, std::ios::trunc);
{ if (!file.is_open()) {
std::ifstream file(treatedcallPath); RING_ERR("Could not save to %s", path.c_str());
if (!file.is_open()) { return;
RING_WARN("Could not load treated calls from %s", treatedcallPath.c_str());
return;
}
std::string line;
while (std::getline(file, line)) {
std::istringstream iss(line);
dht::Value::Id vid;
if (!(iss >> std::hex >> vid)) { break; }
treatedCalls_.insert(vid);
}
} }
for (auto& c : ids)
file << std::hex << c << "\n";
}
void
RingAccount::loadTreatedCalls()
{
treatedCalls_ = loadIdList(cachePath_+DIR_SEPARATOR_STR "treatedCalls");
} }
void void
RingAccount::saveTreatedCalls() const RingAccount::saveTreatedCalls() const
{ {
fileutils::check_dir(cachePath_.c_str()); fileutils::check_dir(cachePath_.c_str());
std::string treatedcallPath = cachePath_+DIR_SEPARATOR_STR "treatedCalls"; saveIdList(cachePath_+DIR_SEPARATOR_STR "treatedCalls", treatedCalls_);
{ }
std::ofstream file(treatedcallPath, std::ios::trunc);
if (!file.is_open()) { void
RING_ERR("Could not save treated calls to %s", treatedcallPath.c_str()); RingAccount::loadTreatedMessages()
return; {
} treatedMessages_ = loadIdList(cachePath_+DIR_SEPARATOR_STR "treatedMessages");
for (auto& c : treatedCalls_) }
file << std::hex << c << "\n";
} void
RingAccount::saveTreatedMessages() const
{
fileutils::check_dir(cachePath_.c_str());
saveIdList(cachePath_+DIR_SEPARATOR_STR "treatedMessages", treatedMessages_);
} }
void RingAccount::saveNodes(const std::vector<dht::Dht::NodeExport>& nodes) const void RingAccount::saveNodes(const std::vector<dht::Dht::NodeExport>& nodes) const
...@@ -1283,9 +1310,10 @@ void ...@@ -1283,9 +1310,10 @@ void
RingAccount::sendTextMessage(const std::string& to, const std::string& message) RingAccount::sendTextMessage(const std::string& to, const std::string& message)
{ {
const std::string& toUri = parseRingUri(to); const std::string& toUri = parseRingUri(to);
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
dht_.putEncrypted(dht::InfoHash::get("inbox:"+toUri), dht_.putEncrypted(dht::InfoHash::get("inbox:"+toUri),
dht::InfoHash(toUri), dht::InfoHash(toUri),
dht::ImMessage(std::string(message))); dht::ImMessage(udist(rand_), std::string(message), now));
} }
} // namespace ring } // namespace ring
...@@ -315,6 +315,7 @@ class RingAccount : public SIPAccountBase { ...@@ -315,6 +315,7 @@ class RingAccount : public SIPAccountBase {
*/ */
std::list<PendingCall> pendingSipCalls_ {}; std::list<PendingCall> pendingSipCalls_ {};
std::set<dht::Value::Id> treatedCalls_ {}; std::set<dht::Value::Id> treatedCalls_ {};
std::set<dht::Value::Id> treatedMessages_ {};
mutable std::mutex callsMutex_ {}; mutable std::mutex callsMutex_ {};
std::string idPath_ {}; std::string idPath_ {};
...@@ -344,6 +345,9 @@ class RingAccount : public SIPAccountBase { ...@@ -344,6 +345,9 @@ class RingAccount : public SIPAccountBase {
void loadTreatedCalls(); void loadTreatedCalls();
void saveTreatedCalls() const; void saveTreatedCalls() const;
void loadTreatedMessages();
void saveTreatedMessages() const;
/** /**
* If privkeyPath_ is a valid private key file (PEM or DER), * If privkeyPath_ is a valid private key file (PEM or DER),
* and certPath_ a valid certificate file, load and returns them. * and certPath_ a valid certificate file, load and returns them.
......
Supports Markdown
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