diff --git a/include/opendht/securedht.h b/include/opendht/securedht.h index a5fccc0e4..4005eef1b 100644 --- a/include/opendht/securedht.h +++ b/include/opendht/securedht.h @@ -53,7 +53,7 @@ class OPENDHT_PUBLIC SecureDht final : public DhtInterface { * id: the identity to use for the crypto layer and to compute * our own hash on the Dht. */ - SecureDht(std::unique_ptr dht, Config config, const IdentityAnnouncedCb& iacb = {}); + SecureDht(std::unique_ptr dht, Config config, IdentityAnnouncedCb iacb = {}); virtual ~SecureDht(); @@ -348,8 +348,6 @@ class OPENDHT_PUBLIC SecureDht final : public DhtInterface { ValueCallback getCallbackFilter(const ValueCallback&, Value::Filter&&); GetCallback getCallbackFilter(const GetCallback&, Value::Filter&&); - IdentityAnnouncedCb iacb_ {}; - Sp key_ {}; Sp certificate_ {}; diff --git a/src/securedht.cpp b/src/securedht.cpp index 69ece0941..149ba4bbe 100644 --- a/src/securedht.cpp +++ b/src/securedht.cpp @@ -36,8 +36,8 @@ extern "C" { namespace dht { -SecureDht::SecureDht(std::unique_ptr dht, SecureDht::Config conf, const IdentityAnnouncedCb& iacb) -: dht_(std::move(dht)), key_(conf.id.first), certificate_(conf.id.second), enableCache_(conf.cert_cache_all), iacb_(iacb) +SecureDht::SecureDht(std::unique_ptr dht, SecureDht::Config conf, IdentityAnnouncedCb iacb) +: dht_(std::move(dht)), key_(conf.id.first), certificate_(conf.id.second), enableCache_(conf.cert_cache_all) { if (!dht_) return; for (const auto& type : DEFAULT_TYPES) @@ -53,16 +53,15 @@ SecureDht::SecureDht(std::unique_ptr dht, SecureDht::Config conf, if (key_ and certId != key_->getPublicKey().getId()) throw DhtException("SecureDht: provided certificate doesn't match private key."); - dht_->addOnConnectedCallback([&]{ + dht_->addOnConnectedCallback([&, cb=std::move(iacb)]{ dht_->put(certId, Value { CERTIFICATE_TYPE, *certificate_, 1 - }, [this, certId](bool ok) { - if (iacb_) iacb_(ok); - if (ok) - if (logger_) - logger_->d(certId, "SecureDht: public key announced successfully"); + }, [this, certId, cb=std::move(cb)](bool ok) { + if (cb) cb(ok); + if (logger_) + logger_->d(certId, "SecureDht: certificate announcement %s", ok ? "succeeded" : "failed"); }, {}, true); }); }