diff --git a/include/opendht/callbacks.h b/include/opendht/callbacks.h index 21288556260f7f6af21da34762526dac001a542b..6738c3079efcc476679e7cb64b55257ccbccd0a7 100644 --- a/include/opendht/callbacks.h +++ b/include/opendht/callbacks.h @@ -131,8 +131,8 @@ using CertificateStoreQuery = std::function<std::vector<std::shared_ptr<crypto:: typedef bool (*GetCallbackRaw)(std::shared_ptr<Value>, void *user_data); -OPENDHT_PUBLIC GetCallbackSimple bindGetCb(GetCallbackRaw raw_cb, void* user_data); -OPENDHT_PUBLIC GetCallback bindGetCb(GetCallbackSimple cb); +OPENDHT_PUBLIC GetCallbackSimple bindGetCb(const GetCallbackRaw& raw_cb, void* user_data); +OPENDHT_PUBLIC GetCallback bindGetCb(const GetCallbackSimple& cb); using DoneCallback = std::function<void(bool success, const std::vector<std::shared_ptr<Node>>& nodes)>; typedef void (*DoneCallbackRaw)(bool, std::vector<std::shared_ptr<Node>>*, void *user_data); @@ -142,10 +142,10 @@ typedef bool (*FilterRaw)(const Value&, void *user_data); using DoneCallbackSimple = std::function<void(bool success)>; -OPENDHT_PUBLIC ShutdownCallback bindShutdownCb(ShutdownCallbackRaw shutdown_cb_raw, void* user_data); +OPENDHT_PUBLIC ShutdownCallback bindShutdownCb(const ShutdownCallbackRaw& shutdown_cb_raw, void* user_data); OPENDHT_PUBLIC DoneCallback bindDoneCb(DoneCallbackSimple donecb); -OPENDHT_PUBLIC DoneCallback bindDoneCb(DoneCallbackRaw raw_cb, void* user_data); -OPENDHT_PUBLIC DoneCallbackSimple bindDoneCbSimple(DoneCallbackSimpleRaw raw_cb, void* user_data); -OPENDHT_PUBLIC Value::Filter bindFilterRaw(FilterRaw raw_filter, void* user_data); +OPENDHT_PUBLIC DoneCallback bindDoneCb(const DoneCallbackRaw& raw_cb, void* user_data); +OPENDHT_PUBLIC DoneCallbackSimple bindDoneCbSimple(const DoneCallbackSimpleRaw& raw_cb, void* user_data); +OPENDHT_PUBLIC Value::Filter bindFilterRaw(const FilterRaw& raw_filter, void* user_data); } diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h index 96c492a205d2e5082d8c4b96dc3eb5aced05adb8..badb0c757144336247094b4534a1863cdcc20474 100644 --- a/include/opendht/crypto.h +++ b/include/opendht/crypto.h @@ -431,7 +431,7 @@ struct OPENDHT_PUBLIC Certificate { void addRevocationList(RevocationList&&); void addRevocationList(std::shared_ptr<RevocationList>); - static Certificate generate(const PrivateKey& key, const std::string& name = "dhtnode", Identity ca = {}, bool is_ca = false); + static Certificate generate(const PrivateKey& key, const std::string& name = "dhtnode", const Identity& ca = {}, bool is_ca = false); gnutls_x509_crt_t getCopy() const { if (not cert) @@ -503,7 +503,7 @@ struct OPENDHT_PUBLIC TrustList TrustList(TrustList&& o) noexcept : trust(std::move(o.trust)) { o.trust = nullptr; } - TrustList& operator=(TrustList&& o); + TrustList& operator=(TrustList&& o) noexcept; ~TrustList(); void add(const Certificate& crt); void add(const RevocationList& crl); @@ -611,11 +611,11 @@ using SecureBlob = secure_vector<uint8_t>; * If not set, the generated certificate will be a self-signed CA. * @param key_length stength of the generated private key (bits). */ -OPENDHT_PUBLIC Identity generateIdentity(const std::string& name, Identity ca, unsigned key_length, bool is_ca); -OPENDHT_PUBLIC Identity generateIdentity(const std::string& name = "dhtnode", Identity ca = {}, unsigned key_length = 4096); +OPENDHT_PUBLIC Identity generateIdentity(const std::string& name, const Identity& ca, unsigned key_length, bool is_ca); +OPENDHT_PUBLIC Identity generateIdentity(const std::string& name = "dhtnode", const Identity& ca = {}, unsigned key_length = 4096); -OPENDHT_PUBLIC Identity generateEcIdentity(const std::string& name, Identity ca, bool is_ca); -OPENDHT_PUBLIC Identity generateEcIdentity(const std::string& name = "dhtnode", Identity ca = {}); +OPENDHT_PUBLIC Identity generateEcIdentity(const std::string& name, const Identity& ca, bool is_ca); +OPENDHT_PUBLIC Identity generateEcIdentity(const std::string& name = "dhtnode", const Identity& ca = {}); /** diff --git a/include/opendht/default_types.h b/include/opendht/default_types.h index 48f0b9b6f96e5f6c2d3cac7f8943975a984302c0..47932755747e4f7028fa9e0b25eecce9143da753 100644 --- a/include/opendht/default_types.h +++ b/include/opendht/default_types.h @@ -38,7 +38,7 @@ class OPENDHT_PUBLIC DhtMessage : public Value::Serializable<DhtMessage> public: static const ValueType TYPE; - DhtMessage(std::string s = {}, Blob msg = {}) : service(s), data(msg) {} + DhtMessage(const std::string& s = {}, const Blob& msg = {}) : service(s), data(msg) {} std::string getService() const { return service; @@ -48,7 +48,7 @@ public: static bool storePolicy(InfoHash key, std::shared_ptr<Value>& value, const InfoHash& from, const SockAddr&); - static Value::Filter ServiceFilter(std::string s); + static Value::Filter ServiceFilter(const std::string& s); /** print value for debugging */ friend std::ostream& operator<< (std::ostream&, const DhtMessage&); diff --git a/include/opendht/dht.h b/include/opendht/dht.h index e0f6795c87fc7568fcaaa7c2eb595dfdb071d955..d8b6b7e8d473537f9e9ec8969505e1418929a16c 100644 --- a/include/opendht/dht.h +++ b/include/opendht/dht.h @@ -68,7 +68,7 @@ public: * Initialise the Dht with two open sockets (for IPv4 and IP6) * and an ID for the node. */ - Dht(const int& s, const int& s6, Config config); + Dht(const int& s, const int& s6, const Config& config); virtual ~Dht(); /** @@ -430,7 +430,7 @@ private: * nodes. */ void dataPersistence(InfoHash id); - size_t maintainStorage(decltype(store)::value_type&, bool force=false, DoneCallback donecb=nullptr); + size_t maintainStorage(decltype(store)::value_type&, bool force=false, const DoneCallback& donecb={}); // Buckets RoutingTable& buckets(sa_family_t af) { return af == AF_INET ? buckets4 : buckets6; } diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index 32ba4431398c02ceceaed50245a5f277387ab860..73774c76c1bd9ff2c035784f9f9f515a7d32649a 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -364,7 +364,7 @@ public: /*.push_node_id = */"" }); } - void run(in_port_t port, Config config); + void run(in_port_t port, const Config& config); /** * @param local4: Local IPv4 address and port to bind. Can be null. @@ -374,12 +374,12 @@ public: * @param threaded: If false, loop() must be called periodically. Otherwise a thread is launched. * @param cb: Optional callback to receive general state information. */ - void run(const SockAddr& local4, const SockAddr& local6, Config config); + void run(const SockAddr& local4, const SockAddr& local6, const Config& config); /** * Same as @run(sockaddr_in, sockaddr_in6, Identity, bool, StatusCallback), but with string IP addresses and service (port). */ - void run(const char* ip4, const char* ip6, const char* service, Config config); + void run(const char* ip4, const char* ip6, const char* service, const Config& config); void setOnStatusChanged(StatusCallback&& cb) { statusCb = std::move(cb); diff --git a/include/opendht/network_engine.h b/include/opendht/network_engine.h index 032f49c53a94c9a33c4ef83114b190a65305d268..6fb1611fc153e1c6b79ac4477223f2a3d63e7ac4 100644 --- a/include/opendht/network_engine.h +++ b/include/opendht/network_engine.h @@ -206,15 +206,15 @@ public: NetworkEngine(Logger& log, Scheduler& scheduler, const int& s = -1, const int& s6 = -1); NetworkEngine(InfoHash& myid, NetId net, const int& s, const int& s6, Logger& log, Scheduler& scheduler, - decltype(NetworkEngine::onError) onError, - decltype(NetworkEngine::onNewNode) onNewNode, - decltype(NetworkEngine::onReportedAddr) onReportedAddr, - decltype(NetworkEngine::onPing) onPing, - decltype(NetworkEngine::onFindNode) onFindNode, - decltype(NetworkEngine::onGetValues) onGetValues, - decltype(NetworkEngine::onListen) onListen, - decltype(NetworkEngine::onAnnounce) onAnnounce, - decltype(NetworkEngine::onRefresh) onRefresh); + decltype(NetworkEngine::onError)&& onError, + decltype(NetworkEngine::onNewNode)&& onNewNode, + decltype(NetworkEngine::onReportedAddr)&& onReportedAddr, + decltype(NetworkEngine::onPing)&& onPing, + decltype(NetworkEngine::onFindNode)&& onFindNode, + decltype(NetworkEngine::onGetValues)&& onGetValues, + decltype(NetworkEngine::onListen)&& onListen, + decltype(NetworkEngine::onAnnounce)&& onAnnounce, + decltype(NetworkEngine::onRefresh)&& onRefresh); virtual ~NetworkEngine(); diff --git a/include/opendht/securedht.h b/include/opendht/securedht.h index 6e2339af558dddcf68355ddce4c969a406921467..5c6eb0b3b8e636f6655aaf89d03aef469bb58ed2 100644 --- a/include/opendht/securedht.h +++ b/include/opendht/securedht.h @@ -37,9 +37,9 @@ public: using Config = SecureDhtConfig; - static dht::Config& getConfig(SecureDht::Config& conf) + static dht::Config getConfig(const SecureDht::Config& conf) { - auto& c = conf.node_config; + auto c = conf.node_config; if (not c.node_id and conf.id.second) c.node_id = InfoHash::get("node:"+conf.id.second->getId().toString()); return c; @@ -127,8 +127,8 @@ public: Value decrypt(const Value& v); - void findCertificate(const InfoHash& node, std::function<void(const Sp<crypto::Certificate>)> cb); - void findPublicKey(const InfoHash& node, std::function<void(const Sp<const crypto::PublicKey>)> cb); + void findCertificate(const InfoHash& node, const std::function<void(const Sp<crypto::Certificate>)>& cb); + void findPublicKey(const InfoHash& node, const std::function<void(const Sp<const crypto::PublicKey>)>& cb); const Sp<crypto::Certificate> registerCertificate(const InfoHash& node, const Blob& cert); void registerCertificate(Sp<crypto::Certificate>& cert); @@ -332,8 +332,8 @@ private: SecureDht& operator=(const SecureDht&) = delete; Sp<Value> checkValue(const Sp<Value>& v); - ValueCallback getCallbackFilter(ValueCallback, Value::Filter&&); - GetCallback getCallbackFilter(GetCallback, Value::Filter&&); + ValueCallback getCallbackFilter(const ValueCallback&, Value::Filter&&); + GetCallback getCallbackFilter(const GetCallback&, Value::Filter&&); Sp<crypto::PrivateKey> key_ {}; Sp<crypto::Certificate> certificate_ {}; diff --git a/include/opendht/value.h b/include/opendht/value.h index 9867745fc6726b738b9d4aa9e0f59698faa1e4a0..0d5d620738892b9a79197fa0843078b458794012 100644 --- a/include/opendht/value.h +++ b/include/opendht/value.h @@ -79,7 +79,7 @@ static constexpr const size_t MAX_VALUE_SIZE {1024 * 64}; struct OPENDHT_PUBLIC ValueType { typedef uint16_t Id; - static bool DEFAULT_STORE_POLICY(InfoHash, std::shared_ptr<Value>& v, const InfoHash&, const SockAddr&); + static bool DEFAULT_STORE_POLICY(InfoHash, const std::shared_ptr<Value>& v, const InfoHash&, const SockAddr&); static bool DEFAULT_EDIT_POLICY(InfoHash, const std::shared_ptr<Value>&, std::shared_ptr<Value>&, const InfoHash&, const SockAddr&) { return false; } @@ -947,7 +947,7 @@ struct OPENDHT_PUBLIC Query */ struct OPENDHT_PUBLIC FieldValueIndex { FieldValueIndex() {} - FieldValueIndex(const Value& v, Select s = {}); + FieldValueIndex(const Value& v, const Select& s = {}); /** * Tells if all the fields of this are contained in the other * FieldValueIndex with the same value. diff --git a/src/callbacks.cpp b/src/callbacks.cpp index be6bec9a3dd39c0739be486c54f1b499052e28c5..7dd963613d7b7dcba8e758a5d07e142bb11be031 100644 --- a/src/callbacks.cpp +++ b/src/callbacks.cpp @@ -4,7 +4,7 @@ namespace dht { GetCallbackSimple -bindGetCb(GetCallbackRaw raw_cb, void* user_data) +bindGetCb(const GetCallbackRaw& raw_cb, void* user_data) { if (not raw_cb) return {}; return [=](const std::shared_ptr<Value>& value) { @@ -13,7 +13,7 @@ bindGetCb(GetCallbackRaw raw_cb, void* user_data) } GetCallback -bindGetCb(GetCallbackSimple cb) +bindGetCb(const GetCallbackSimple& cb) { if (not cb) return {}; return [=](const std::vector<std::shared_ptr<Value>>& values) { @@ -25,7 +25,7 @@ bindGetCb(GetCallbackSimple cb) } ShutdownCallback -bindShutdownCb(ShutdownCallbackRaw shutdown_cb_raw, void* user_data) +bindShutdownCb(const ShutdownCallbackRaw& shutdown_cb_raw, void* user_data) { return [=]() { shutdown_cb_raw(user_data); }; } @@ -39,7 +39,7 @@ bindDoneCb(DoneCallbackSimple donecb) } DoneCallback -bindDoneCb(DoneCallbackRaw raw_cb, void* user_data) +bindDoneCb(const DoneCallbackRaw& raw_cb, void* user_data) { if (not raw_cb) return {}; return [=](bool success, const std::vector<std::shared_ptr<Node>>& nodes) { @@ -48,7 +48,7 @@ bindDoneCb(DoneCallbackRaw raw_cb, void* user_data) } DoneCallbackSimple -bindDoneCbSimple(DoneCallbackSimpleRaw raw_cb, void* user_data) { +bindDoneCbSimple(const DoneCallbackSimpleRaw& raw_cb, void* user_data) { if (not raw_cb) return {}; return [=](bool success) { raw_cb(success, user_data); diff --git a/src/crypto.cpp b/src/crypto.cpp index 0f667054eed3930674e646c5e1e065344b4a7d2f..0704d6883d8eb6db825b3d1aeb614235163ce3f8 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -896,7 +896,7 @@ PrivateKey::generateEC() } Identity -generateIdentity(const std::string& name, crypto::Identity ca, unsigned key_length, bool is_ca) +generateIdentity(const std::string& name, const Identity& ca, unsigned key_length, bool is_ca) { auto key = std::make_shared<PrivateKey>(PrivateKey::generate(key_length)); auto cert = std::make_shared<Certificate>(Certificate::generate(*key, name, ca, is_ca)); @@ -905,12 +905,12 @@ generateIdentity(const std::string& name, crypto::Identity ca, unsigned key_leng Identity -generateIdentity(const std::string& name, Identity ca, unsigned key_length) { +generateIdentity(const std::string& name, const Identity& ca, unsigned key_length) { return generateIdentity(name, ca, key_length, !ca.first || !ca.second); } Identity -generateEcIdentity(const std::string& name, crypto::Identity ca, bool is_ca) +generateEcIdentity(const std::string& name, const Identity& ca, bool is_ca) { auto key = std::make_shared<PrivateKey>(PrivateKey::generateEC()); auto cert = std::make_shared<Certificate>(Certificate::generate(*key, name, ca, is_ca)); @@ -918,12 +918,12 @@ generateEcIdentity(const std::string& name, crypto::Identity ca, bool is_ca) } Identity -generateEcIdentity(const std::string& name, Identity ca) { +generateEcIdentity(const std::string& name, const Identity& ca) { return generateEcIdentity(name, ca, !ca.first || !ca.second); } Certificate -Certificate::generate(const PrivateKey& key, const std::string& name, Identity ca, bool is_ca) +Certificate::generate(const PrivateKey& key, const std::string& name, const Identity& ca, bool is_ca) { gnutls_x509_crt_t cert; if (not key.x509_key or gnutls_x509_crt_init(&cert) != GNUTLS_E_SUCCESS) @@ -1228,11 +1228,11 @@ TrustList::~TrustList() { } TrustList& -TrustList::operator=(TrustList&& o) +TrustList::operator=(TrustList&& o) noexcept { if (trust) gnutls_x509_trust_list_deinit(trust, true); - trust = std::move(o.trust); + trust = o.trust; o.trust = nullptr; return *this; } diff --git a/src/default_types.cpp b/src/default_types.cpp index 8b4bcc7a903d4f035be128247315c93b5e23a0bc..6bf39f3d537b6ecdfc7d3ec43882c8aaedc6829b 100644 --- a/src/default_types.cpp +++ b/src/default_types.cpp @@ -38,7 +38,7 @@ DhtMessage::storePolicy(InfoHash h, std::shared_ptr<Value>& v, const InfoHash& f } Value::Filter -DhtMessage::ServiceFilter(std::string s) +DhtMessage::ServiceFilter(const std::string& s) { return Value::Filter::chain( Value::TypeFilter(TYPE), diff --git a/src/dht.cpp b/src/dht.cpp index aacb235b0c1b245849ca719251d9acd6757d6b69..4862a067aaf82c6b8229e0e837305a21ef9f6b8c 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -1714,7 +1714,7 @@ Dht::~Dht() Dht::Dht() : store(), network_engine(DHT_LOG, scheduler) {} -Dht::Dht(const int& s, const int& s6, Config config) +Dht::Dht(const int& s, const int& s6, const Config& config) : myid(config.node_id ? config.node_id : InfoHash::getRandom()), store(), store_quota(), network_engine(myid, config.network, s, s6, DHT_LOG, scheduler, std::bind(&Dht::onError, this, _1, _2), @@ -1846,8 +1846,8 @@ Dht::bucketMaintenance(RoutingTable& list) } DHT_LOG.d(id, n->id, "[node %s] sending find %s for bucket maintenance", n->toString().c_str(), id.toString().c_str()); - auto start = scheduler.time(); - network_engine.sendFindNode(n, id, want, nullptr, [this,start,n](const net::Request&, bool over) { + //auto start = scheduler.time(); + network_engine.sendFindNode(n, id, want, nullptr, [this,n](const net::Request&, bool over) { if (over) { const auto& end = scheduler.time(); // using namespace std::chrono; @@ -1877,7 +1877,7 @@ Dht::dataPersistence(InfoHash id) } size_t -Dht::maintainStorage(decltype(store)::value_type& storage, bool force, DoneCallback donecb) +Dht::maintainStorage(decltype(store)::value_type& storage, bool force, const DoneCallback& donecb) { const auto& now = scheduler.time(); size_t announce_per_af = 0; diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index 92de36d5fe98d787e5a35c392e6c9be0a675d309..659cb9f9bc5ed567195bfe101b8619a4d838e5fe 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -75,7 +75,7 @@ DhtRunner::~DhtRunner() } void -DhtRunner::run(in_port_t port, DhtRunner::Config config) +DhtRunner::run(in_port_t port, const DhtRunner::Config& config) { SockAddr sin4; sin4.setFamily(AF_INET); @@ -87,7 +87,7 @@ DhtRunner::run(in_port_t port, DhtRunner::Config config) } void -DhtRunner::run(const char* ip4, const char* ip6, const char* service, DhtRunner::Config config) +DhtRunner::run(const char* ip4, const char* ip6, const char* service, const DhtRunner::Config& config) { auto res4 = SockAddr::resolve(ip4, service); auto res6 = SockAddr::resolve(ip6, service); @@ -96,7 +96,7 @@ DhtRunner::run(const char* ip4, const char* ip6, const char* service, DhtRunner: } void -DhtRunner::run(const SockAddr& local4, const SockAddr& local6, DhtRunner::Config config) +DhtRunner::run(const SockAddr& local4, const SockAddr& local6, const DhtRunner::Config& config) { if (running) return; @@ -629,7 +629,7 @@ DhtRunner::get(InfoHash hash, GetCallback vcb, DoneCallback dcb, Value::Filter f { std::lock_guard<std::mutex> lck(storage_mtx); pending_ops.emplace([=](SecureDht& dht) mutable { - dht.get(hash, vcb, dcb, std::move(f), std::move(w)); + dht.get(hash, std::move(vcb), std::move(dcb), std::move(f), std::move(w)); }); } cv.notify_all(); @@ -638,14 +638,14 @@ DhtRunner::get(InfoHash hash, GetCallback vcb, DoneCallback dcb, Value::Filter f void DhtRunner::get(const std::string& key, GetCallback vcb, DoneCallbackSimple dcb, Value::Filter f, Where w) { - get(InfoHash::get(key), vcb, dcb, f, w); + get(InfoHash::get(key), std::move(vcb), std::move(dcb), std::move(f), std::move(w)); } void DhtRunner::query(const InfoHash& hash, QueryCallback cb, DoneCallback done_cb, Query q) { { std::lock_guard<std::mutex> lck(storage_mtx); pending_ops.emplace([=](SecureDht& dht) mutable { - dht.query(hash, cb, done_cb, std::move(q)); + dht.query(hash, std::move(cb), std::move(done_cb), std::move(q)); }); } cv.notify_all(); @@ -678,7 +678,7 @@ DhtRunner::listen(InfoHash hash, ValueCallback vcb, Value::Filter f, Where w) listeners_.emplace(tokenbGlobal, std::move(listener)); ret_token->set_value(tokenbGlobal); #else - ret_token->set_value(dht.listen(hash, vcb, f, w)); + ret_token->set_value(dht.listen(hash, std::move(vcb), std::move(f), std::move(w))); #endif }); } @@ -689,7 +689,7 @@ DhtRunner::listen(InfoHash hash, ValueCallback vcb, Value::Filter f, Where w) std::future<size_t> DhtRunner::listen(const std::string& key, GetCallback vcb, Value::Filter f, Where w) { - return listen(InfoHash::get(key), vcb, f, w); + return listen(InfoHash::get(key), std::move(vcb), std::move(f), std::move(w)); } void @@ -768,7 +768,7 @@ DhtRunner::put(InfoHash hash, std::shared_ptr<Value> value, DoneCallback cb, tim void DhtRunner::put(const std::string& key, Value&& value, DoneCallbackSimple cb, time_point created, bool permanent) { - put(InfoHash::get(key), std::forward<Value>(value), cb, created, permanent); + put(InfoHash::get(key), std::forward<Value>(value), std::move(cb), created, permanent); } void @@ -798,13 +798,13 @@ DhtRunner::putSigned(InfoHash hash, std::shared_ptr<Value> value, DoneCallback c void DhtRunner::putSigned(InfoHash hash, Value&& value, DoneCallback cb) { - putSigned(hash, std::make_shared<Value>(std::move(value)), cb); + putSigned(hash, std::make_shared<Value>(std::move(value)), std::move(cb)); } void DhtRunner::putSigned(const std::string& key, Value&& value, DoneCallbackSimple cb) { - putSigned(InfoHash::get(key), std::forward<Value>(value), cb); + putSigned(InfoHash::get(key), std::forward<Value>(value), std::move(cb)); } void @@ -822,13 +822,13 @@ DhtRunner::putEncrypted(InfoHash hash, InfoHash to, std::shared_ptr<Value> value void DhtRunner::putEncrypted(InfoHash hash, InfoHash to, Value&& value, DoneCallback cb) { - putEncrypted(hash, to, std::make_shared<Value>(std::move(value)), cb); + putEncrypted(hash, to, std::make_shared<Value>(std::move(value)), std::move(cb)); } void DhtRunner::putEncrypted(const std::string& key, InfoHash to, Value&& value, DoneCallback cb) { - putEncrypted(InfoHash::get(key), to, std::forward<Value>(value), cb); + putEncrypted(InfoHash::get(key), to, std::forward<Value>(value), std::move(cb)); } void diff --git a/src/network_engine.cpp b/src/network_engine.cpp index d3ea1293956f441a5f49045ac7464599794303c8..6eed6584d71754e1bb360f675bb580d2d00ceb4a 100644 --- a/src/network_engine.cpp +++ b/src/network_engine.cpp @@ -142,19 +142,27 @@ RequestAnswer::RequestAnswer(ParsedMessage&& msg) NetworkEngine::NetworkEngine(Logger& log, Scheduler& scheduler, const int& s, const int& s6) : myid(zeroes), dht_socket(s), dht_socket6(s6), DHT_LOG(log), scheduler(scheduler) {} + NetworkEngine::NetworkEngine(InfoHash& myid, NetId net, const int& s, const int& s6, Logger& log, Scheduler& scheduler, - decltype(NetworkEngine::onError) onError, - decltype(NetworkEngine::onNewNode) onNewNode, - decltype(NetworkEngine::onReportedAddr) onReportedAddr, - decltype(NetworkEngine::onPing) onPing, - decltype(NetworkEngine::onFindNode) onFindNode, - decltype(NetworkEngine::onGetValues) onGetValues, - decltype(NetworkEngine::onListen) onListen, - decltype(NetworkEngine::onAnnounce) onAnnounce, - decltype(NetworkEngine::onRefresh) onRefresh) : - onError(onError), onNewNode(onNewNode), onReportedAddr(onReportedAddr), onPing(onPing), onFindNode(onFindNode), - onGetValues(onGetValues), onListen(onListen), onAnnounce(onAnnounce), onRefresh(onRefresh), myid(myid), - network(net), dht_socket(s), dht_socket6(s6), DHT_LOG(log), scheduler(scheduler) + decltype(NetworkEngine::onError)&& onError, + decltype(NetworkEngine::onNewNode)&& onNewNode, + decltype(NetworkEngine::onReportedAddr)&& onReportedAddr, + decltype(NetworkEngine::onPing)&& onPing, + decltype(NetworkEngine::onFindNode)&& onFindNode, + decltype(NetworkEngine::onGetValues)&& onGetValues, + decltype(NetworkEngine::onListen)&& onListen, + decltype(NetworkEngine::onAnnounce)&& onAnnounce, + decltype(NetworkEngine::onRefresh)&& onRefresh) : + onError(std::move(onError)), + onNewNode(std::move(onNewNode)), + onReportedAddr(std::move(onReportedAddr)), + onPing(std::move(onPing)), + onFindNode(std::move(onFindNode)), + onGetValues(std::move(onGetValues)), + onListen(std::move(onListen)), + onAnnounce(std::move(onAnnounce)), + onRefresh(std::move(onRefresh)), + myid(myid), network(net), dht_socket(s), dht_socket6(s6), DHT_LOG(log), scheduler(scheduler) { if (dht_socket >= 0) { if (!set_nonblocking(dht_socket, 1)) diff --git a/src/node.cpp b/src/node.cpp index 2f4c3044f5eb18a4bcc08cc656a1a3ab864154cf..f1217da84d9ab573db6a2da60675f26eb5da2503 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -49,7 +49,7 @@ Node::isGood(time_point now) const bool Node::isPendingMessage() const { - for (auto r : requests_) { + for (const auto& r : requests_) { if (r.second->pending()) return true; } @@ -60,7 +60,7 @@ size_t Node::getPendingMessageCount() const { size_t count {0}; - for (auto r : requests_) { + for (const auto& r : requests_) { if (r.second->pending()) count++; } diff --git a/src/op_cache.cpp b/src/op_cache.cpp index b6091274481ddbebd43a7a20c64759e08fa30e36..d995e46523a4974d0d129c82d89fb7edeb7d7992 100644 --- a/src/op_cache.cpp +++ b/src/op_cache.cpp @@ -160,7 +160,7 @@ SearchCache::getOp(const Sp<Query>& q) const } size_t -SearchCache::listen(ValueCallback get_cb, Sp<Query> q, Value::Filter filter, OnListen onListen) +SearchCache::listen(const ValueCallback& get_cb, const Sp<Query>& q, const Value::Filter& filter, const OnListen& onListen) { // find exact match auto op = getOp(q); @@ -192,7 +192,7 @@ SearchCache::cancelListen(size_t gtoken, const time_point& now) { } void -SearchCache::cancelAll(std::function<void(size_t)> onCancel) { +SearchCache::cancelAll(const std::function<void(size_t)>& onCancel) { for (auto& op : ops) { auto cache = std::move(op.second); cache->removeAll(); @@ -202,7 +202,7 @@ SearchCache::cancelAll(std::function<void(size_t)> onCancel) { } time_point -SearchCache::expire(const time_point& now, std::function<void(size_t)> onCancel) { +SearchCache::expire(const time_point& now, const std::function<void(size_t)>& onCancel) { nextExpiration_ = time_point::max(); auto ret = nextExpiration_; for (auto it = ops.begin(); it != ops.end();) { diff --git a/src/op_cache.h b/src/op_cache.h index 6caa337644be2299c9111d13adb66dda30361e0e..ac64a4beee7fe93d6e87b9d13c6f2244896462c5 100644 --- a/src/op_cache.h +++ b/src/op_cache.h @@ -104,7 +104,7 @@ public: void onValuesAdded(const std::vector<Sp<Value>>& vals); void onValuesExpired(const std::vector<Sp<Value>>& vals); - bool addListener(size_t token, ValueCallback cb, Sp<Query> q, Value::Filter filter) { + bool addListener(size_t token, const ValueCallback& cb, const Sp<Query>& q, const Value::Filter& filter) { listeners.emplace(token, LocalListener{q, filter, cb}); auto cached = cache.get(filter); if (not cached.empty()) { @@ -163,12 +163,12 @@ public: SearchCache(SearchCache&&) = default; using OnListen = std::function<size_t(Sp<Query>, ValueCallback, SyncCallback)>; - size_t listen(ValueCallback get_cb, Sp<Query> q, Value::Filter filter, OnListen onListen); + size_t listen(const ValueCallback& get_cb, const Sp<Query>& q, const Value::Filter& filter, const OnListen& onListen); bool cancelListen(size_t gtoken, const time_point& now); - void cancelAll(std::function<void(size_t)> onCancel); + void cancelAll(const std::function<void(size_t)>& onCancel); - time_point expire(const time_point& now, std::function<void(size_t)> onCancel); + time_point expire(const time_point& now, const std::function<void(size_t)>& onCancel); time_point getExpiration() const { return nextExpiration_; } diff --git a/src/search.h b/src/search.h index ebedcc170b417f9de63b2832c321fa46c77a4835..da80f1af722373c10364e6ac7dd971b9aa8179b2 100644 --- a/src/search.h +++ b/src/search.h @@ -488,7 +488,7 @@ struct Dht::Search { bool isAnnounced(Value::Id id) const; bool isListening(time_point now) const; - void get(Value::Filter f, const Sp<Query>& q, const QueryCallback& qcb, const GetCallback& gcb, const DoneCallback& dcb, Scheduler& scheduler) { + void get(const Value::Filter& f, const Sp<Query>& q, const QueryCallback& qcb, const GetCallback& gcb, const DoneCallback& dcb, Scheduler& scheduler) { if (gcb or qcb) { if (not cache.get(f, q, gcb, dcb)) { const auto& now = scheduler.time(); @@ -498,7 +498,7 @@ struct Dht::Search { } } - size_t listen(ValueCallback cb, Value::Filter f, const Sp<Query>& q, Scheduler& scheduler) { + size_t listen(const ValueCallback& cb, const Value::Filter& f, const Sp<Query>& q, Scheduler& scheduler) { //DHT_LOG.e(id, "[search %s IPv%c] listen", id.toString().c_str(), (af == AF_INET) ? '4' : '6'); return cache.listen(cb, q, f, [&](const Sp<Query>& q, ValueCallback vcb, SyncCallback scb){ done = false; diff --git a/src/securedht.cpp b/src/securedht.cpp index 382a54b4ed40375bb4eb1e934262753a58cc6453..c24b38d08f7a7133d20fc92ee326214d8d9d3ae3 100644 --- a/src/securedht.cpp +++ b/src/securedht.cpp @@ -166,7 +166,7 @@ SecureDht::registerCertificate(Sp<crypto::Certificate>& cert) } void -SecureDht::findCertificate(const InfoHash& node, std::function<void(const Sp<crypto::Certificate>)> cb) +SecureDht::findCertificate(const InfoHash& node, const std::function<void(const Sp<crypto::Certificate>)>& cb) { Sp<crypto::Certificate> b = getCertificate(node); if (b && *b) { @@ -207,7 +207,7 @@ SecureDht::findCertificate(const InfoHash& node, std::function<void(const Sp<cry } void -SecureDht::findPublicKey(const InfoHash& node, std::function<void(const Sp<const crypto::PublicKey>)> cb) +SecureDht::findPublicKey(const InfoHash& node, const std::function<void(const Sp<const crypto::PublicKey>)>& cb) { auto pk = getPublicKey(node); if (pk && *pk) { @@ -280,7 +280,7 @@ SecureDht::checkValue(const Sp<Value>& v) } ValueCallback -SecureDht::getCallbackFilter(ValueCallback cb, Value::Filter&& filter) +SecureDht::getCallbackFilter(const ValueCallback& cb, Value::Filter&& filter) { return [=](const std::vector<Sp<Value>>& values, bool expired) { std::vector<Sp<Value>> tmpvals {}; @@ -299,7 +299,7 @@ SecureDht::getCallbackFilter(ValueCallback cb, Value::Filter&& filter) GetCallback -SecureDht::getCallbackFilter(GetCallback cb, Value::Filter&& filter) +SecureDht::getCallbackFilter(const GetCallback& cb, Value::Filter&& filter) { return [=](const std::vector<Sp<Value>>& values) { std::vector<Sp<Value>> tmpvals {}; diff --git a/src/value.cpp b/src/value.cpp index 34e6ba1332f6bc5098a7e81e94bf055ac4ffdf66..2f004e35507137554b73555db895ebf79c643061 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -78,7 +78,7 @@ std::ostream& operator<< (std::ostream& s, const Value& v) const ValueType ValueType::USER_DATA = {0, "User Data"}; bool -ValueType::DEFAULT_STORE_POLICY(InfoHash, std::shared_ptr<Value>& v, const InfoHash&, const SockAddr&) +ValueType::DEFAULT_STORE_POLICY(InfoHash, const std::shared_ptr<Value>& v, const InfoHash&, const SockAddr&) { return v->size() <= MAX_VALUE_SIZE; } @@ -292,7 +292,7 @@ FieldValue::getLocalFilter() const } } -FieldValueIndex::FieldValueIndex(const Value& v, Select s) +FieldValueIndex::FieldValueIndex(const Value& v, const Select& s) { auto selection = s.getSelection(); if (not selection.empty()) { @@ -399,8 +399,8 @@ FieldValueIndex::msgpack_unpack_fields(const std::set<Value::Field>& fields, con } void trim_str(std::string& str) { - auto first = std::min(str.size(), str.find_first_not_of(" ")); - auto last = std::min(str.size(), str.find_last_not_of(" ")); + auto first = std::min(str.size(), str.find_first_not_of(' ')); + auto last = std::min(str.size(), str.find_last_not_of(' ')); str = str.substr(first, last - first + 1); } diff --git a/tests/tests_runner.cpp b/tests/tests_runner.cpp index 87803bc37eb99824c79e84b19b80b240d09079c0..a380bee1a4ecd49c94a4084f0b0bcb0e9b1a87ff 100644 --- a/tests/tests_runner.cpp +++ b/tests/tests_runner.cpp @@ -21,7 +21,7 @@ #include <cppunit/CompilerOutputter.h> #include <iostream> -int main(int argc, char** argv) { +int main(int /*argc*/, char** /*argv*/) { CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); CppUnit::Test *suite = registry.makeTest(); if (suite->countTestCases() == 0) { diff --git a/tools/dhtnode.cpp b/tools/dhtnode.cpp index f14c1f9b43aa324f748744433bb8b2aa48007966..189fb6375c849075063dfa03a64c292ec1402434 100644 --- a/tools/dhtnode.cpp +++ b/tools/dhtnode.cpp @@ -307,7 +307,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params }, [start](bool ok) { auto end = std::chrono::high_resolution_clock::now(); std::cout << "Get: " << (ok ? "completed" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl; - }, {}, dht::Where {std::move(rem)}); + }, {}, dht::Where {rem}); } else if (op == "q") { std::string rem; @@ -322,7 +322,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params }, [start](bool ok) { auto end = std::chrono::high_resolution_clock::now(); std::cout << "Query: " << (ok ? "completed" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl; - }, dht::Query {std::move(rem)}); + }, dht::Query {rem}); } else if (op == "l") { std::string rem; @@ -332,7 +332,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params for (const auto& value : values) std::cout << "\t" << *value << std::endl; return true; - }, {}, dht::Where {std::move(rem)}); + }, {}, dht::Where {rem}); auto t = token.get(); std::cout << "Listening, token: " << t << std::endl; } @@ -431,7 +431,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params << p.toString() << std::endl << " hash: " << p.hash() << std::endl; std::cout << " entries:" << std::endl; - for (auto v : vals) + for (const auto& v : vals) std::cout << " " << v->first.toString() << "[vid: " << v->second << "]" << std::endl; }, [start](bool ok) {