aports/testing/jami-daemon/opendht-3.1.6-compat-2.patch

381 lines
15 KiB
Diff

Adapted from https://git.jami.net/savoirfairelinux/jami-daemon/-/commit/723368082b62f19da80401971d6ee0e4000c1948
--
From 723368082b62f19da80401971d6ee0e4000c1948 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Mon, 11 Dec 2023 11:58:00 -0500
Subject: [PATCH] update opendht, dhtnet, remove dht::crypto::random_device
Change-Id: I8502119ce7ff540275c9a273b6896cbbedaf9cbb
---
contrib/src/dhtnet/package.json | 2 +-
contrib/src/dhtnet/rules.mak | 2 +-
contrib/src/opendht/SHA512SUMS | 3 +--
contrib/src/opendht/package.json | 2 +-
contrib/src/opendht/rules.mak | 4 ++--
src/account.cpp | 1 -
src/data_transfer.cpp | 16 ++++++++-------
src/data_transfer.h | 4 ++--
src/jamidht/archive_account_manager.cpp | 2 +-
src/jamidht/conversation.cpp | 3 ++-
src/jamidht/conversationrepository.cpp | 13 ++++++------
src/jamidht/eth/libdevcore/CMakeLists.txt | 1 -
src/jamidht/eth/libdevcore/FixedHash.cpp | 24 -----------------------
src/jamidht/eth/libdevcore/FixedHash.h | 8 ++++----
src/jamidht/eth/libdevcore/Makefile.am | 1 -
src/jamidht/jamiaccount.cpp | 6 ++++--
src/manager.cpp | 1 -
src/meson.build | 1 -
src/sip/sdp.cpp | 3 +--
19 files changed, 35 insertions(+), 62 deletions(-)
delete mode 100644 src/jamidht/eth/libdevcore/FixedHash.cpp
diff --git a/contrib/src/dhtnet/package.json b/contrib/src/dhtnet/package.json
index 11c3a5cf4b..62edc2bf6f 100644
--- a/contrib/src/dhtnet/package.json
+++ b/contrib/src/dhtnet/package.json
@@ -1,6 +1,6 @@
{
"name": "dhtnet",
- "version": "4796de15ed32b41949489c328bc250d17c431c80",
+ "version": "21990ef01887f164a88fd81fa8647cfd92174f1c",
"url": "https://review.jami.net/plugins/gitiles/dhtnet/+archive/__VERSION__.tar.gz",
"deps": [
"opendht",
diff --git a/contrib/src/dhtnet/rules.mak b/contrib/src/dhtnet/rules.mak
index 714ae7e069..9432f08fee 100644
--- a/contrib/src/dhtnet/rules.mak
+++ b/contrib/src/dhtnet/rules.mak
@@ -1,5 +1,5 @@
# DHTNET
-DHTNET_VERSION := 4796de15ed32b41949489c328bc250d17c431c80
+DHTNET_VERSION := 21990ef01887f164a88fd81fa8647cfd92174f1c
DHTNET_URL := https://review.jami.net/plugins/gitiles/dhtnet/+archive/$(DHTNET_VERSION).tar.gz
PKGS += dhtnet
diff --git a/src/account.cpp b/src/account.cpp
index ca588b5326..4a42824896 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -38,7 +38,6 @@
#include "manager.h"
#include <opendht/rng.h>
-using random_device = dht::crypto::random_device;
#include "client/ring_signal.h"
#include "account_schema.h"
diff --git a/src/data_transfer.cpp b/src/data_transfer.cpp
index 73a329cb10..3d379f34ba 100644
--- a/src/data_transfer.cpp
+++ b/src/data_transfer.cpp
@@ -41,10 +41,9 @@
namespace jami {
libjami::DataTransferId
-generateUID()
+generateUID(std::mt19937_64& engine)
{
- thread_local dht::crypto::random_device rd;
- return std::uniform_int_distribution<libjami::DataTransferId> {1, JAMI_ID_MAX_VAL}(rd);
+ return std::uniform_int_distribution<libjami::DataTransferId> {1, JAMI_ID_MAX_VAL}(engine);
}
FileInfo::FileInfo(const std::shared_ptr<dhtnet::ChannelSocket>& channel,
@@ -236,9 +235,10 @@ IncomingFile::process()
class TransferManager::Impl
{
public:
- Impl(const std::string& accountId, const std::string& to)
+ Impl(const std::string& accountId, const std::string& to, const std::mt19937_64& rand)
: accountId_(accountId)
, to_(to)
+ , rand_(rand)
{
if (!to_.empty()) {
conversationDataPath_ = fileutils::get_data_dir() / accountId_ / "conversation_data" / to_;
@@ -290,10 +290,12 @@ public:
std::map<std::shared_ptr<dhtnet::ChannelSocket>, std::shared_ptr<OutgoingFile>> outgoings_ {};
std::map<std::string, std::shared_ptr<IncomingFile>> incomings_ {};
std::map<std::pair<std::string, std::string>, std::shared_ptr<IncomingFile>> vcards_ {};
+
+ std::mt19937_64 rand_;
};
-TransferManager::TransferManager(const std::string& accountId, const std::string& to)
- : pimpl_ {std::make_unique<Impl>(accountId, to)}
+TransferManager::TransferManager(const std::string& accountId, const std::string& to, const std::mt19937_64& rand)
+ : pimpl_ {std::make_unique<Impl>(accountId, to, rand)}
{}
TransferManager::~TransferManager() {}
@@ -514,7 +516,7 @@ TransferManager::onIncomingProfile(const std::shared_ptr<dhtnet::ChannelSocket>&
return;
}
- auto tid = generateUID();
+ auto tid = generateUID(pimpl_->rand_);
libjami::DataTransferInfo info;
info.accountId = pimpl_->accountId_;
info.conversationId = pimpl_->to_;
diff --git a/src/data_transfer.h b/src/data_transfer.h
index b1c737106f..8ba13fee05 100644
--- a/src/data_transfer.h
+++ b/src/data_transfer.h
@@ -33,7 +33,7 @@
namespace jami {
-libjami::DataTransferId generateUID();
+libjami::DataTransferId generateUID(std::mt19937_64& engine);
class Stream;
@@ -123,7 +123,7 @@ private:
class TransferManager : public std::enable_shared_from_this<TransferManager>
{
public:
- TransferManager(const std::string& accountId, const std::string& to);
+ TransferManager(const std::string& accountId, const std::string& to, const std::mt19937_64& rand);
~TransferManager();
/**
diff --git a/src/jamidht/archive_account_manager.cpp b/src/jamidht/archive_account_manager.cpp
index 0e90c1a2a2..53e588c4b6 100644
--- a/src/jamidht/archive_account_manager.cpp
+++ b/src/jamidht/archive_account_manager.cpp
@@ -667,7 +667,7 @@ std::string
generatePIN(size_t length = 16, size_t split = 8)
{
static constexpr const char alphabet[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- dht::crypto::random_device rd;
+ std::random_device rd;
std::uniform_int_distribution<size_t> dis(0, sizeof(alphabet) - 2);
std::string ret;
ret.reserve(length);
diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp
index b54efd5cc0..88a493b3f4 100644
--- a/src/jamidht/conversation.cpp
+++ b/src/jamidht/conversation.cpp
@@ -176,7 +176,8 @@ public:
swarmManager_->setMobility(shared->isMobile());
accountId_ = shared->getAccountID();
transferManager_ = std::make_shared<TransferManager>(shared->getAccountID(),
- repository_->id());
+ repository_->id(),
+ Manager::instance().getSeededRandomEngine());
conversationDataPath_ = fileutils::get_data_dir() / shared->getAccountID()
/ "conversation_data" / repository_->id();
fetchedPath_ = conversationDataPath_ / "fetched";
diff --git a/src/jamidht/conversationrepository.cpp b/src/jamidht/conversationrepository.cpp
index f749854128..283a560366 100644
--- a/src/jamidht/conversationrepository.cpp
+++ b/src/jamidht/conversationrepository.cpp
@@ -26,8 +26,6 @@
#include "client/ring_signal.h"
#include "vcard.h"
-using random_device = dht::crypto::random_device;
-
#include <ctime>
#include <fstream>
#include <future>
@@ -2557,11 +2555,10 @@ ConversationRepository::createConversation(const std::shared_ptr<JamiAccount>& a
const std::string& otherMember)
{
// Create temporary directory because we can't know the first hash for now
- std::uniform_int_distribution<uint64_t> dist {0, std::numeric_limits<uint64_t>::max()};
- random_device rdev;
+ std::uniform_int_distribution<uint64_t> dist;
auto conversationsPath = fileutils::get_data_dir() / account->getAccountID() / "conversations";
dhtnet::fileutils::check_dir(conversationsPath);
- auto tmpPath = conversationsPath / std::to_string(dist(rdev));
+ auto tmpPath = conversationsPath / std::to_string(dist(account->rand));
if (std::filesystem::is_directory(tmpPath)) {
JAMI_ERROR("{} already exists. Abort create conversations", tmpPath);
return {};
@@ -2592,8 +2589,10 @@ ConversationRepository::createConversation(const std::shared_ptr<JamiAccount>& a
// Move to wanted directory
auto newPath = conversationsPath / id;
- if (std::rename(tmpPath.string().c_str(), newPath.string().c_str())) {
- JAMI_ERROR("Couldn't move {} in {}", tmpPath, newPath);
+ std::error_code ec;
+ std::filesystem::rename(tmpPath, newPath, ec);
+ if (ec) {
+ JAMI_ERROR("Couldn't move {} in {}: {}", tmpPath, newPath, ec.message());
dhtnet::fileutils::removeAll(tmpPath, true);
return {};
}
diff --git a/src/jamidht/eth/libdevcore/CMakeLists.txt b/src/jamidht/eth/libdevcore/CMakeLists.txt
index 70924025f0..0d5f481486 100644
--- a/src/jamidht/eth/libdevcore/CMakeLists.txt
+++ b/src/jamidht/eth/libdevcore/CMakeLists.txt
@@ -6,7 +6,6 @@ list (APPEND Source_Files__jamidht__eth__libdevcore
"${CMAKE_CURRENT_SOURCE_DIR}/Common.h"
"${CMAKE_CURRENT_SOURCE_DIR}/CommonData.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/CommonData.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/FixedHash.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/FixedHash.h"
"${CMAKE_CURRENT_SOURCE_DIR}/Makefile.am"
"${CMAKE_CURRENT_SOURCE_DIR}/SHA3.cpp"
diff --git a/src/jamidht/eth/libdevcore/FixedHash.cpp b/src/jamidht/eth/libdevcore/FixedHash.cpp
deleted file mode 100644
index f5ee65752a..0000000000
--- a/src/jamidht/eth/libdevcore/FixedHash.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "FixedHash.h"
-
-namespace dev {
-
-dht::crypto::random_device s_fixedHashEngine;
-
-}
diff --git a/src/jamidht/eth/libdevcore/FixedHash.h b/src/jamidht/eth/libdevcore/FixedHash.h
index 1f8b2060b2..63e768cd7e 100644
--- a/src/jamidht/eth/libdevcore/FixedHash.h
+++ b/src/jamidht/eth/libdevcore/FixedHash.h
@@ -45,8 +45,6 @@ struct StaticLog2<1>
enum { result = 0 };
};
-extern dht::crypto::random_device s_fixedHashEngine;
-
/// Fixed-size raw-byte array container type, with an API optimised for storing hashes.
/// Transparently converts to/from the corresponding arithmetic type; this will
/// assume the data contained in the hash is big-endian.
@@ -246,7 +244,8 @@ public:
static FixedHash random()
{
FixedHash ret;
- ret.randomize(s_fixedHashEngine);
+ std::random_device rd;
+ ret.randomize(rd);
return ret;
}
@@ -466,7 +465,8 @@ public:
static SecureFixedHash<T> random()
{
SecureFixedHash<T> ret;
- ret.randomize(s_fixedHashEngine);
+ std::random_device rd;
+ ret.randomize(rd);
return ret;
}
using FixedHash<T>::firstBitSet;
diff --git a/src/jamidht/eth/libdevcore/Makefile.am b/src/jamidht/eth/libdevcore/Makefile.am
index c73f77d002..ee106a89d8 100644
--- a/src/jamidht/eth/libdevcore/Makefile.am
+++ b/src/jamidht/eth/libdevcore/Makefile.am
@@ -1,7 +1,6 @@
noinst_LTLIBRARIES += libdevcore.la
libdevcore_la_SOURCES = \
- ./jamidht/eth/libdevcore/FixedHash.cpp \
./jamidht/eth/libdevcore/SHA3.cpp \
./jamidht/eth/libdevcore/CommonData.cpp
diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 73557c281a..d462c5e0b5 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -277,7 +277,7 @@ JamiAccount::JamiAccount(const std::string& accountId)
, certStore_ {std::make_unique<dhtnet::tls::CertificateStore>(idPath_, Logger::dhtLogger())}
, dht_(new dht::DhtRunner)
, connectionManager_ {}
- , nonSwarmTransferManager_(std::make_shared<TransferManager>(accountId, ""))
+ , nonSwarmTransferManager_(std::make_shared<TransferManager>(accountId, "", dht::crypto::getDerivedRandomEngine(rand)))
{}
JamiAccount::~JamiAccount() noexcept
@@ -1853,6 +1853,7 @@ JamiAccount::doRegister_()
}
dht::DhtRunner::Context context {};
context.peerDiscovery = peerDiscovery_;
+ context.rng = std::make_unique<std::mt19937_64>(dht::crypto::getDerivedRandomEngine(rand));
auto dht_log_level = Manager::instance().dhtLogLevel.load();
if (dht_log_level > 0) {
@@ -4025,7 +4026,7 @@ JamiAccount::sendFile(const std::string& conversationId,
dht::ThreadPool::computation().run([w = weak(), conversationId, path, name, replyTo]() {
if (auto shared = w.lock()) {
Json::Value value;
- auto tid = jami::generateUID();
+ auto tid = jami::generateUID(shared->rand);
value["tid"] = std::to_string(tid);
value["displayName"] = name.empty() ? path.filename().string() : name;
value["totalSize"] = std::to_string(fileutils::size(path));
@@ -4236,6 +4237,7 @@ JamiAccount::initConnectionManager()
connectionManagerConfig->logger = Logger::dhtLogger();
connectionManagerConfig->factory = Manager::instance().getIceTransportFactory();
connectionManagerConfig->turnCache = turnCache_;
+ connectionManagerConfig->rng = std::make_unique<std::mt19937_64>(dht::crypto::getDerivedRandomEngine(rand));
connectionManager_ = std::make_unique<dhtnet::ConnectionManager>(connectionManagerConfig);
channelHandlers_[Uri::Scheme::SWARM]
= std::make_unique<SwarmChannelHandler>(shared(), *connectionManager_.get());
diff --git a/src/manager.cpp b/src/manager.cpp
index 54722f24bc..af81c70fb5 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -45,7 +45,6 @@
#include "jamidht/jamiaccount.h"
#include "account.h"
#include <opendht/rng.h>
-using random_device = dht::crypto::random_device;
#include "call_factory.h"
diff --git a/src/meson.build b/src/meson.build
index b80a4447be..0fc5befc9d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -22,7 +22,6 @@ libjami_sources = files(
'im/instant_messaging.cpp',
'im/message_engine.cpp',
'jamidht/eth/libdevcore/CommonData.cpp',
- 'jamidht/eth/libdevcore/FixedHash.cpp',
'jamidht/eth/libdevcore/SHA3.cpp',
'jamidht/eth/libdevcrypto/Common.cpp',
'jamidht/account_manager.cpp',
diff --git a/src/sip/sdp.cpp b/src/sip/sdp.cpp
index 0802a99d2e..b2f18eeffe 100644
--- a/src/sip/sdp.cpp
+++ b/src/sip/sdp.cpp
@@ -41,7 +41,6 @@
#include "compiler_intrinsics.h" // for UNUSED
#include <opendht/rng.h>
-using random_device = dht::crypto::random_device;
#include <algorithm>
#include <cassert>
@@ -123,7 +122,7 @@ static void
randomFill(std::vector<uint8_t>& dest)
{
std::uniform_int_distribution<int> rand_byte {0, std::numeric_limits<uint8_t>::max()};
- random_device rdev;
+ std::random_device rdev;
std::generate(dest.begin(), dest.end(), std::bind(rand_byte, std::ref(rdev)));
}
--
GitLab