mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
jamiaccount: fix loading id and dht with JAMS
Change-Id: I0174da20ca3b60814c26168bdaa7d2b24d51cf3e
This commit is contained in:
@ -72,11 +72,9 @@ public:
|
||||
AccountManager(
|
||||
const std::string& path,
|
||||
OnAsync&& onAsync,
|
||||
std::shared_ptr<dht::DhtRunner> dht,
|
||||
const std::string& nameServer)
|
||||
: path_(path)
|
||||
, onAsync_(std::move(onAsync))
|
||||
, dht_(std::move(dht))
|
||||
, nameDir_(NameDirectory::instance(nameServer)) {};
|
||||
|
||||
virtual ~AccountManager() = default;
|
||||
@ -128,6 +126,8 @@ public:
|
||||
const std::vector<uint8_t>& receiptSignature,
|
||||
OnChangeCallback&& onChange);
|
||||
|
||||
void setDht(const std::shared_ptr<dht::DhtRunner>& dht) { dht_ = dht; }
|
||||
|
||||
virtual void startSync() {};
|
||||
|
||||
const AccountInfo* getInfo() const {
|
||||
|
@ -27,12 +27,11 @@ public:
|
||||
|
||||
ArchiveAccountManager(
|
||||
const std::string& path,
|
||||
std::shared_ptr<dht::DhtRunner> dht,
|
||||
OnAsync&& onAsync,
|
||||
OnExportConfig&& onExportConfig,
|
||||
std::string archivePath,
|
||||
const std::string& nameServer)
|
||||
: AccountManager(path, std::move(onAsync), std::move(dht), nameServer)
|
||||
: AccountManager(path, std::move(onAsync), nameServer)
|
||||
, onExportConfig_(std::move(onExportConfig))
|
||||
, archivePath_(std::move(archivePath))
|
||||
{};
|
||||
|
@ -892,14 +892,12 @@ JamiAccount::loadAccount(const std::string& archive_password, const std::string&
|
||||
};
|
||||
if (managerUri_.empty()) {
|
||||
accountManager_.reset(new ArchiveAccountManager(getPath(),
|
||||
dht_,
|
||||
onAsync,
|
||||
[this]() { return getAccountDetails(); },
|
||||
archivePath_.empty() ? "archive.gz" : archivePath_,
|
||||
nameServer_));
|
||||
} else {
|
||||
accountManager_.reset(new ServerAccountManager(getPath(),
|
||||
dht_,
|
||||
onAsync,
|
||||
managerUri_,
|
||||
nameServer_));
|
||||
@ -997,31 +995,6 @@ JamiAccount::loadAccount(const std::string& archive_password, const std::string&
|
||||
receiptSignature_ = std::move(receipt_signature);
|
||||
accountManager_->foundAccountDevice(info.identity.second, ringDeviceName_, clock::now());
|
||||
setRegistrationState(RegistrationState::UNREGISTERED);
|
||||
|
||||
AccountManager::OnChangeCallback callbacks {
|
||||
[this](const std::string& uri, bool confirmed) {
|
||||
dht::ThreadPool::computation().run([this, uri, confirmed] {
|
||||
emitSignal<DRing::ConfigurationSignal::ContactAdded>(getAccountID(), uri, confirmed);
|
||||
});
|
||||
},
|
||||
[this](const std::string& uri, bool banned) {
|
||||
dht::ThreadPool::computation().run([this, uri, banned] {
|
||||
emitSignal<DRing::ConfigurationSignal::ContactRemoved>(getAccountID(), uri, banned);
|
||||
});
|
||||
},
|
||||
[this](const std::string& uri, const std::vector<uint8_t>& payload, time_t received) {
|
||||
dht::ThreadPool::computation().run([this, uri, payload = std::move(payload), received] {
|
||||
emitSignal<DRing::ConfigurationSignal::IncomingTrustRequest>(getAccountID(), uri, payload, received);
|
||||
});
|
||||
},
|
||||
[this]() {
|
||||
dht::ThreadPool::computation().run([this] {
|
||||
emitSignal<DRing::ConfigurationSignal::KnownDevicesChanged>(getAccountID(), getKnownDevices());
|
||||
});
|
||||
},
|
||||
};
|
||||
accountManager_->useIdentity(id_, receipt_, receiptSignature_, std::move(callbacks));
|
||||
|
||||
saveConfig();
|
||||
doRegister();
|
||||
}, [this](AccountManager::AuthError error, const std::string& message)
|
||||
@ -1353,7 +1326,7 @@ JamiAccount::handlePendingCall(PendingCall& pc, bool incoming)
|
||||
// Securize a SIP transport with TLS (on top of ICE tranport) and assign the call with it
|
||||
auto remote_device = pc.from;
|
||||
auto remote_account = pc.from_account;
|
||||
auto id = accountManager_->getInfo()->identity;
|
||||
auto id = id_;
|
||||
if (not id.first or not id.second)
|
||||
throw std::runtime_error("No identity configured for this account.");
|
||||
|
||||
@ -1659,7 +1632,7 @@ JamiAccount::doRegister_()
|
||||
config.dht_config.node_config.network = 0;
|
||||
config.dht_config.node_config.maintain_storage = false;
|
||||
config.dht_config.node_config.persist_path = cachePath_+DIR_SEPARATOR_STR "dhtstate";
|
||||
config.dht_config.id = accountManager_->getInfo()->identity;
|
||||
config.dht_config.id = id_;
|
||||
config.proxy_server = getDhtProxyServer();
|
||||
config.push_node_id = getAccountID();
|
||||
config.threaded = true;
|
||||
@ -1758,6 +1731,7 @@ JamiAccount::doRegister_()
|
||||
for (const auto& bootstrap : loadBootstrap())
|
||||
dht_->bootstrap(bootstrap);
|
||||
|
||||
accountManager_->setDht(dht_);
|
||||
accountManager_->startSync();
|
||||
|
||||
// Listen for incoming calls
|
||||
@ -2257,7 +2231,7 @@ JamiAccount::getContactHeader(pjsip_transport* t)
|
||||
contact_.slen = pj_ansi_snprintf(contact_.ptr, PJSIP_MAX_URL_SIZE,
|
||||
"%s<sips:%s%s%s;transport=dtls>",
|
||||
quotedDisplayName.c_str(),
|
||||
accountManager_->getInfo()->identity.second->getId().toString().c_str(),
|
||||
id_.second->getId().toString().c_str(),
|
||||
(address.empty() ? "" : "@"),
|
||||
address.c_str());
|
||||
} else {
|
||||
@ -2265,7 +2239,7 @@ JamiAccount::getContactHeader(pjsip_transport* t)
|
||||
contact_.slen = pj_ansi_snprintf(contact_.ptr, PJSIP_MAX_URL_SIZE,
|
||||
"%s<sips:%s@ring.dht>",
|
||||
quotedDisplayName.c_str(),
|
||||
accountManager_->getInfo()->identity.second->getId().toString().c_str());
|
||||
id_.second->getId().toString().c_str());
|
||||
}
|
||||
return contact_;
|
||||
}
|
||||
|
@ -38,11 +38,10 @@ constexpr const char* const HTTPS_PROTO {"https"};
|
||||
|
||||
ServerAccountManager::ServerAccountManager(
|
||||
const std::string& path,
|
||||
std::shared_ptr<dht::DhtRunner> dht,
|
||||
OnAsync&& onAsync,
|
||||
const std::string& managerHostname,
|
||||
const std::string& nameServer)
|
||||
: AccountManager(path, std::move(onAsync), std::move(dht), nameServer)
|
||||
: AccountManager(path, std::move(onAsync), nameServer)
|
||||
, managerHostname_(managerHostname)
|
||||
, logger_(std::make_shared<dht::Logger>(
|
||||
[](char const* m, va_list args) { Logger::vlog(LOG_ERR, nullptr, 0, true, m, args); },
|
||||
|
@ -25,7 +25,6 @@ class ServerAccountManager : public AccountManager {
|
||||
public:
|
||||
ServerAccountManager(
|
||||
const std::string& path,
|
||||
std::shared_ptr<dht::DhtRunner> dht,
|
||||
OnAsync&& onAsync,
|
||||
const std::string& managerHostname,
|
||||
const std::string& nameServer);
|
||||
|
Reference in New Issue
Block a user