diff --git a/.clang-tidy b/.clang-tidy index 5d635f09e..234f1e1d9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,2 +1,2 @@ HeaderFilterRegex: 'llarp/.*' -Checks: 'readability-else-after-return,clang-analyzer-core-*' +Checks: 'readability-else-after-return,clang-analyzer-core-*,modernize-*' diff --git a/cmake/win32.cmake b/cmake/win32.cmake index 31f826968..dc8040722 100644 --- a/cmake/win32.cmake +++ b/cmake/win32.cmake @@ -8,6 +8,10 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) if (MSVC OR MSVC_VERSION) add_compile_options(/EHca /arch:AVX2 /MD) add_definitions(-D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING) + + if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + add_compile_options(-Wno-nonportable-system-include-path) + endif() endif() if(NOT MSVC_VERSION) diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index 6ed3ee297..b28f4b5b7 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -27,10 +27,8 @@ namespace llarp { return ptr; } - else - { - return val; - } + + return val; } template <> @@ -43,10 +41,8 @@ namespace llarp { return std::atoi(ptr); } - else - { - return val; - } + + return val; } template <> @@ -59,10 +55,8 @@ namespace llarp { return std::atoi(ptr); } - else - { - return val; - } + + return val; } template <> @@ -75,10 +69,8 @@ namespace llarp { return std::atoll(ptr); } - else - { - return val; - } + + return val; } template <> @@ -92,10 +84,8 @@ namespace llarp { return IsTrueValue(ptr); } - else - { - return val; - } + + return val; } class RouterConfig diff --git a/llarp/constants/link_layer.hpp b/llarp/constants/link_layer.hpp index 7fa0f6082..b09ee5e4c 100644 --- a/llarp/constants/link_layer.hpp +++ b/llarp/constants/link_layer.hpp @@ -2,7 +2,7 @@ #define LLARP_LINK_LAYER_HPP #include -#include +#include constexpr size_t MAX_LINK_MSG_SIZE = 8192; constexpr llarp_time_t DefaultLinkSessionLifetime = 60 * 1000; diff --git a/llarp/context.cpp b/llarp/context.cpp index 9817a3956..ab989ec53 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #if(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) #include @@ -27,9 +27,7 @@ namespace llarp { - Context::Context() - { - } + Context::Context() = default; Context::~Context() { @@ -421,8 +419,8 @@ extern "C" { cSetLogLevel(eLogDebug); } - llarp_main *m = new llarp_main; - m->ctx = std::make_unique< llarp::Context >(); + auto *m = new llarp_main; + m->ctx = std::make_unique< llarp::Context >(); if(!m->ctx->LoadConfig(fname)) { m->ctx->Close(); diff --git a/llarp/crypto/constants.hpp b/llarp/crypto/constants.hpp index 81e45f9d1..d0331f279 100644 --- a/llarp/crypto/constants.hpp +++ b/llarp/crypto/constants.hpp @@ -1,7 +1,7 @@ #ifndef LLARP_CRYPTO_CONSTANTS_HPP #define LLARP_CRYPTO_CONSTANTS_HPP -#include +#include #include diff --git a/llarp/crypto/crypto.hpp b/llarp/crypto/crypto.hpp index d248062d5..f97bdbfc7 100644 --- a/llarp/crypto/crypto.hpp +++ b/llarp/crypto/crypto.hpp @@ -8,8 +8,8 @@ #include #include -#include -#include + +#include /** * crypto.hpp @@ -89,9 +89,7 @@ namespace llarp pqe_encrypt(PQCipherBlock &, SharedSecret &, const PQPubKey &) = 0; }; - inline Crypto::~Crypto() - { - } + inline Crypto::~Crypto() = default; /// return random 64bit unsigned interger uint64_t diff --git a/llarp/crypto/crypto_libsodium.cpp b/llarp/crypto/crypto_libsodium.cpp index 9402af1ed..aab38665e 100644 --- a/llarp/crypto/crypto_libsodium.cpp +++ b/llarp/crypto/crypto_libsodium.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include extern "C" { diff --git a/llarp/crypto/crypto_libsodium.hpp b/llarp/crypto/crypto_libsodium.hpp index 4a06a3054..a2eebe0e4 100644 --- a/llarp/crypto/crypto_libsodium.hpp +++ b/llarp/crypto/crypto_libsodium.hpp @@ -11,9 +11,7 @@ namespace llarp { CryptoLibSodium(); - ~CryptoLibSodium() - { - } + ~CryptoLibSodium() override = default; /// xchacha symmetric cipher bool diff --git a/llarp/crypto/crypto_noop.hpp b/llarp/crypto/crypto_noop.hpp index 28373f2dd..177515258 100644 --- a/llarp/crypto/crypto_noop.hpp +++ b/llarp/crypto/crypto_noop.hpp @@ -20,7 +20,7 @@ namespace llarp { } - ~NoOpCrypto() = default; + ~NoOpCrypto() override = default; bool xchacha20(const llarp_buffer_t &, const SharedSecret &, diff --git a/llarp/crypto/encrypted_frame.hpp b/llarp/crypto/encrypted_frame.hpp index f8d1ae644..bbd7537da 100644 --- a/llarp/crypto/encrypted_frame.hpp +++ b/llarp/crypto/encrypted_frame.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -60,8 +61,7 @@ namespace llarp static void Decrypt(void* user) { - AsyncFrameDecrypter< User >* ctx = - static_cast< AsyncFrameDecrypter< User >* >(user); + auto* ctx = static_cast< AsyncFrameDecrypter< User >* >(user); if(ctx->target.DecryptInPlace(ctx->seckey)) { @@ -75,7 +75,7 @@ namespace llarp } AsyncFrameDecrypter(const SecretKey& secretkey, DecryptHandler h) - : result(h), seckey(secretkey) + : result(std::move(h)), seckey(secretkey) { } diff --git a/llarp/dht/bucket.hpp b/llarp/dht/bucket.hpp index d796bc480..ab2e069e9 100644 --- a/llarp/dht/bucket.hpp +++ b/llarp/dht/bucket.hpp @@ -19,7 +19,8 @@ namespace llarp using BucketStorage_t = std::map< Key_t, Val_t, XorMetric >; using Random_t = std::function< uint64_t() >; - Bucket(const Key_t& us, Random_t r) : nodes(XorMetric(us)), random(r) + Bucket(const Key_t& us, Random_t r) + : nodes(XorMetric(us)), random(std::move(r)) { } diff --git a/llarp/dht/context.cpp b/llarp/dht/context.cpp index 56b8683e4..0a77440e8 100644 --- a/llarp/dht/context.cpp +++ b/llarp/dht/context.cpp @@ -26,17 +26,13 @@ namespace llarp { namespace dht { - AbstractContext::~AbstractContext() - { - } + AbstractContext::~AbstractContext() = default; struct Context final : public AbstractContext { Context(); - ~Context() - { - } + ~Context() override = default; util::StatusObject ExtractStatus() const override; @@ -167,7 +163,7 @@ namespace llarp void Explore(size_t N = 3); - llarp::AbstractRouter* router; + llarp::AbstractRouter* router{nullptr}; // for router contacts std::unique_ptr< Bucket< RCNode > > _nodes; @@ -180,7 +176,7 @@ namespace llarp return _services.get(); } - bool allowTransit; + bool allowTransit{false}; bool& AllowTransit() override @@ -308,7 +304,7 @@ namespace llarp Key_t ourKey; }; - Context::Context() : router(nullptr), allowTransit(false) + Context::Context() { randombytes((byte_t*)&ids, sizeof(uint64_t)); } @@ -346,7 +342,7 @@ namespace llarp { if(left) return; - Context* ctx = static_cast< Context* >(u); + auto* ctx = static_cast< Context* >(u); const auto num = std::min(ctx->router->NumberOfConnectedRouters(), size_t(4)); if(num) @@ -361,7 +357,7 @@ namespace llarp { if(left) return; - Context* ctx = static_cast< Context* >(u); + auto* ctx = static_cast< Context* >(u); // clean up transactions ctx->CleanupTX(); diff --git a/llarp/dht/dht.h b/llarp/dht/dht.h index 24b84468c..c7854085c 100644 --- a/llarp/dht/dht.h +++ b/llarp/dht/dht.h @@ -33,7 +33,7 @@ llarp_dht_context_start(struct llarp_dht_context* ctx, const byte_t* key); // remove this? dns needs it atm struct llarp_router_lookup_job; -typedef void (*llarp_router_lookup_handler)(struct llarp_router_lookup_job*); +using llarp_router_lookup_handler = void (*)(struct llarp_router_lookup_job*); struct llarp_router_lookup_job { diff --git a/llarp/dht/message.cpp b/llarp/dht/message.cpp index 98786fd66..04889f1b2 100644 --- a/llarp/dht/message.cpp +++ b/llarp/dht/message.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -46,29 +47,29 @@ namespace llarp switch(*strbuf.base) { case 'F': - msg.reset(new FindIntroMessage(From, relayed)); + msg = std::make_unique< FindIntroMessage >(From, relayed); break; case 'R': if(relayed) - msg.reset(new RelayedFindRouterMessage(From)); + msg = std::make_unique< RelayedFindRouterMessage >(From); else - msg.reset(new FindRouterMessage(From)); + msg = std::make_unique< FindRouterMessage >(From); break; case 'S': - msg.reset(new GotRouterMessage(From, relayed)); + msg = std::make_unique< GotRouterMessage >(From, relayed); break; case 'I': - msg.reset(new PublishIntroMessage()); + msg = std::make_unique< PublishIntroMessage >(); break; case 'G': if(relayed) { - msg.reset(new RelayedGotIntroMessage()); + msg = std::make_unique< RelayedGotIntroMessage >(); break; } else { - msg.reset(new GotIntroMessage(From)); + msg = std::make_unique< GotIntroMessage >(From); break; } default: diff --git a/llarp/dht/message.hpp b/llarp/dht/message.hpp index e5aa63ff5..cf5adf199 100644 --- a/llarp/dht/message.hpp +++ b/llarp/dht/message.hpp @@ -16,9 +16,7 @@ namespace llarp struct IMessage { - virtual ~IMessage() - { - } + virtual ~IMessage() = default; /// construct IMessage(const Key_t& from) : From(from) diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index 8240385d6..ad654f33c 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -7,9 +7,7 @@ namespace llarp { namespace dht { - FindIntroMessage::~FindIntroMessage() - { - } + FindIntroMessage::~FindIntroMessage() = default; bool FindIntroMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val) diff --git a/llarp/dht/messages/findintro.hpp b/llarp/dht/messages/findintro.hpp index e16946bda..bf510aadc 100644 --- a/llarp/dht/messages/findintro.hpp +++ b/llarp/dht/messages/findintro.hpp @@ -45,7 +45,7 @@ namespace llarp R = 1; } - ~FindIntroMessage(); + ~FindIntroMessage() override; bool BEncode(llarp_buffer_t* buf) const override; diff --git a/llarp/dht/messages/findrouter.cpp b/llarp/dht/messages/findrouter.cpp index 8828a4e91..d2cef6c0d 100644 --- a/llarp/dht/messages/findrouter.cpp +++ b/llarp/dht/messages/findrouter.cpp @@ -57,9 +57,7 @@ namespace llarp return true; } - FindRouterMessage::~FindRouterMessage() - { - } + FindRouterMessage::~FindRouterMessage() = default; bool FindRouterMessage::BEncode(llarp_buffer_t *buf) const @@ -183,8 +181,8 @@ namespace llarp replies.emplace_back(new GotRouterMessage(k, txid, {found}, false)); return true; } - else - dht.LookupRouterRelayed(From, txid, k, !iterative, replies); + + dht.LookupRouterRelayed(From, txid, k, !iterative, replies); return true; } } // namespace dht diff --git a/llarp/dht/messages/findrouter.hpp b/llarp/dht/messages/findrouter.hpp index 903925dac..cb4f0a824 100644 --- a/llarp/dht/messages/findrouter.hpp +++ b/llarp/dht/messages/findrouter.hpp @@ -25,7 +25,7 @@ namespace llarp K.Randomize(); } - ~FindRouterMessage(); + ~FindRouterMessage() override; bool BEncode(llarp_buffer_t* buf) const override; @@ -33,7 +33,7 @@ namespace llarp bool DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override; - virtual bool + bool HandleMessage( llarp_dht_context* ctx, std::vector< std::unique_ptr< IMessage > >& replies) const override; @@ -55,7 +55,7 @@ namespace llarp /// handle a relayed FindRouterMessage, do a lookup on the dht and inform /// the path of the result /// TODO: smart path expiration logic needs to be implemented - virtual bool + bool HandleMessage(llarp_dht_context* ctx, std::vector< IMessage::Ptr_t >& replies) const override; }; diff --git a/llarp/dht/messages/gotintro.cpp b/llarp/dht/messages/gotintro.cpp index 49db69753..8556d398f 100644 --- a/llarp/dht/messages/gotintro.cpp +++ b/llarp/dht/messages/gotintro.cpp @@ -1,29 +1,27 @@ #include #include +#include #include #include #include +#include namespace llarp { namespace dht { - GotIntroMessage::GotIntroMessage( - const std::vector< llarp::service::IntroSet > &results, uint64_t tx) - : IMessage({}), I(results), T(tx) - { - } - - GotIntroMessage::~GotIntroMessage() + GotIntroMessage::GotIntroMessage(std::vector< service::IntroSet > results, + uint64_t tx) + : IMessage({}), I(std::move(results)), T(tx) { } bool GotIntroMessage::HandleMessage( llarp_dht_context *ctx, - __attribute__((unused)) - std::vector< std::unique_ptr< IMessage > > &replies) const + ABSL_ATTRIBUTE_UNUSED std::vector< std::unique_ptr< IMessage > > + &replies) const { auto &dht = *ctx->impl; @@ -31,7 +29,7 @@ namespace llarp { if(!introset.Verify(dht.Now())) { - llarp::LogWarn( + LogWarn( "Invalid introset while handling direct GotIntro " "from ", From); @@ -59,7 +57,7 @@ namespace llarp } return true; } - llarp::LogError("no pending TX for GIM from ", From, " txid=", T); + LogError("no pending TX for GIM from ", From, " txid=", T); return false; } @@ -77,7 +75,7 @@ namespace llarp auto copy = std::make_shared< const RelayedGotIntroMessage >(*this); return pathset->HandleGotIntroMessage(copy); } - llarp::LogWarn("No path for got intro message pathid=", pathID); + LogWarn("No path for got intro message pathid=", pathID); return false; } @@ -92,7 +90,7 @@ namespace llarp { if(K) // duplicate key? return false; - K.reset(new dht::Key_t()); + K = std::make_unique< dht::Key_t >(); return K->BDecode(buf); } bool read = false; diff --git a/llarp/dht/messages/gotintro.hpp b/llarp/dht/messages/gotintro.hpp index bee067055..42a1e5ffb 100644 --- a/llarp/dht/messages/gotintro.hpp +++ b/llarp/dht/messages/gotintro.hpp @@ -15,7 +15,7 @@ namespace llarp struct GotIntroMessage : public IMessage { /// the found introsets - std::vector< llarp::service::IntroSet > I; + std::vector< service::IntroSet > I; /// txid uint64_t T = 0; /// the key of a router closer in keyspace if iterative lookup @@ -41,10 +41,9 @@ namespace llarp } /// for recursive reply - GotIntroMessage(const std::vector< llarp::service::IntroSet >& results, - uint64_t txid); + GotIntroMessage(std::vector< service::IntroSet > results, uint64_t txid); - ~GotIntroMessage(); + ~GotIntroMessage() override = default; bool BEncode(llarp_buffer_t* buf) const override; @@ -52,7 +51,7 @@ namespace llarp bool DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override; - virtual bool + bool HandleMessage(llarp_dht_context* ctx, std::vector< IMessage::Ptr_t >& replies) const override; }; diff --git a/llarp/dht/messages/gotrouter.cpp b/llarp/dht/messages/gotrouter.cpp index 9d73f4639..bcc2a9b1e 100644 --- a/llarp/dht/messages/gotrouter.cpp +++ b/llarp/dht/messages/gotrouter.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -8,9 +9,7 @@ namespace llarp { namespace dht { - GotRouterMessage::~GotRouterMessage() - { - } + GotRouterMessage::~GotRouterMessage() = default; bool GotRouterMessage::BEncode(llarp_buffer_t *buf) const @@ -56,7 +55,7 @@ namespace llarp { if(K) // duplicate key? return false; - K.reset(new dht::Key_t()); + K = std::make_unique< dht::Key_t >(); return K->BDecode(val); } if(key == "N") diff --git a/llarp/dht/messages/gotrouter.hpp b/llarp/dht/messages/gotrouter.hpp index 173b91936..4bb174410 100644 --- a/llarp/dht/messages/gotrouter.hpp +++ b/llarp/dht/messages/gotrouter.hpp @@ -1,8 +1,11 @@ #ifndef LLARP_DHT_MESSAGES_GOT_ROUTER_HPP #define LLARP_DHT_MESSAGES_GOT_ROUTER_HPP + #include #include #include +#include +#include namespace llarp { @@ -15,9 +18,8 @@ namespace llarp { } GotRouterMessage(const Key_t& from, uint64_t id, - const std::vector< RouterContact >& results, - bool tunneled) - : IMessage(from), R(results), txid(id), relayed(tunneled) + std::vector< RouterContact > results, bool tunneled) + : IMessage(from), R(std::move(results)), txid(id), relayed(tunneled) { } @@ -27,9 +29,9 @@ namespace llarp { } - GotRouterMessage(uint64_t id, const std::vector< RouterID >& near, + GotRouterMessage(uint64_t id, std::vector< RouterID > _near, bool tunneled) - : IMessage({}), N(near), txid(id), relayed(tunneled) + : IMessage({}), N(std::move(_near)), txid(id), relayed(tunneled) { } @@ -44,7 +46,7 @@ namespace llarp version = other.version; } - ~GotRouterMessage(); + ~GotRouterMessage() override; bool BEncode(llarp_buffer_t* buf) const override; @@ -52,7 +54,7 @@ namespace llarp bool DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override; - virtual bool + bool HandleMessage( llarp_dht_context* ctx, std::vector< std::unique_ptr< IMessage > >& replies) const override; diff --git a/llarp/dht/messages/pubintro.cpp b/llarp/dht/messages/pubintro.cpp index 5c0e231b9..ce7a10768 100644 --- a/llarp/dht/messages/pubintro.cpp +++ b/llarp/dht/messages/pubintro.cpp @@ -10,9 +10,7 @@ namespace llarp { namespace dht { - PublishIntroMessage::~PublishIntroMessage() - { - } + PublishIntroMessage::~PublishIntroMessage() = default; bool PublishIntroMessage::DecodeKey(const llarp_buffer_t &key, diff --git a/llarp/dht/messages/pubintro.hpp b/llarp/dht/messages/pubintro.hpp index 6854965d1..9cf34f9d1 100644 --- a/llarp/dht/messages/pubintro.hpp +++ b/llarp/dht/messages/pubintro.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace llarp @@ -22,14 +23,14 @@ namespace llarp } PublishIntroMessage(const llarp::service::IntroSet& i, uint64_t tx, - uint64_t s, const std::vector< Key_t >& exclude = {}) - : IMessage({}), E(exclude), txID(tx) + uint64_t s, std::vector< Key_t > exclude = {}) + : IMessage({}), E(std::move(exclude)), txID(tx) { I = i; S = s; } - ~PublishIntroMessage(); + ~PublishIntroMessage() override; bool BEncode(llarp_buffer_t* buf) const override; @@ -37,7 +38,7 @@ namespace llarp bool DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override; - virtual bool + bool HandleMessage( llarp_dht_context* ctx, std::vector< std::unique_ptr< IMessage > >& replies) const override; diff --git a/llarp/dht/node.hpp b/llarp/dht/node.hpp index 59cb96372..1c8dac67d 100644 --- a/llarp/dht/node.hpp +++ b/llarp/dht/node.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace llarp { @@ -47,7 +48,7 @@ namespace llarp ID.Zero(); } - ISNode(const service::IntroSet& other) : introset(other) + ISNode(service::IntroSet other) : introset(std::move(other)) { introset.A.CalculateAddress(ID.as_array()); } diff --git a/llarp/dht/publishservicejob.cpp b/llarp/dht/publishservicejob.cpp index 12a9a7752..22e130d31 100644 --- a/llarp/dht/publishservicejob.cpp +++ b/llarp/dht/publishservicejob.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace llarp { @@ -10,11 +11,11 @@ namespace llarp PublishServiceJob::PublishServiceJob(const TXOwner &asker, const service::IntroSet &introset, AbstractContext *ctx, uint64_t s, - const std::set< Key_t > &exclude) + std::set< Key_t > exclude) : TX< service::Address, service::IntroSet >(asker, introset.A.Addr(), ctx) , S(s) - , dontTell(exclude) + , dontTell(std::move(exclude)) , I(introset) { } diff --git a/llarp/dht/publishservicejob.hpp b/llarp/dht/publishservicejob.hpp index 52da0993e..b86bdf912 100644 --- a/llarp/dht/publishservicejob.hpp +++ b/llarp/dht/publishservicejob.hpp @@ -20,7 +20,7 @@ namespace llarp PublishServiceJob(const TXOwner &asker, const service::IntroSet &introset, AbstractContext *ctx, uint64_t s, - const std::set< Key_t > &exclude); + std::set< Key_t > exclude); bool Validate(const service::IntroSet &introset) const override; diff --git a/llarp/dht/recursiverouterlookup.cpp b/llarp/dht/recursiverouterlookup.cpp index 11468d659..ae7b44ede 100644 --- a/llarp/dht/recursiverouterlookup.cpp +++ b/llarp/dht/recursiverouterlookup.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace llarp { @@ -13,7 +14,7 @@ namespace llarp AbstractContext *ctx, RouterLookupHandler result) : TX< RouterID, RouterContact >(_whoasked, _target, ctx) - , resultHandler(result) + , resultHandler(std::move(result)) { peersAsked.insert(ctx->OurKey()); diff --git a/llarp/dht/recursiverouterlookup.hpp b/llarp/dht/recursiverouterlookup.hpp index 653f94a6a..b7f56e063 100644 --- a/llarp/dht/recursiverouterlookup.hpp +++ b/llarp/dht/recursiverouterlookup.hpp @@ -28,7 +28,7 @@ namespace llarp void Start(const TXOwner &peer) override; - virtual void + void SendReply() override; }; } // namespace dht diff --git a/llarp/dht/serviceaddresslookup.cpp b/llarp/dht/serviceaddresslookup.cpp index 99f358a1d..958deb972 100644 --- a/llarp/dht/serviceaddresslookup.cpp +++ b/llarp/dht/serviceaddresslookup.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace llarp { @@ -13,7 +14,7 @@ namespace llarp AbstractContext *ctx, uint64_t r, service::IntroSetLookupHandler handler) : TX< service::Address, service::IntroSet >(asker, addr, ctx) - , handleResult(handler) + , handleResult(std::move(handler)) , R(r) { peersAsked.insert(ctx->OurKey()); diff --git a/llarp/dht/serviceaddresslookup.hpp b/llarp/dht/serviceaddresslookup.hpp index 122ea31a0..7e3626585 100644 --- a/llarp/dht/serviceaddresslookup.hpp +++ b/llarp/dht/serviceaddresslookup.hpp @@ -34,7 +34,7 @@ namespace llarp void DoNextRequest(const Key_t &ask) override; - virtual void + void SendReply() override; }; } // namespace dht diff --git a/llarp/dht/tx.hpp b/llarp/dht/tx.hpp index 1edc36200..e8b4239fa 100644 --- a/llarp/dht/tx.hpp +++ b/llarp/dht/tx.hpp @@ -29,9 +29,7 @@ namespace llarp { } - virtual ~TX() - { - } + virtual ~TX() = default; void OnFound(const Key_t& askedPeer, const V& value); diff --git a/llarp/dns.cpp b/llarp/dns.cpp index e3e4c36ab..0fb3abd4f 100644 --- a/llarp/dns.cpp +++ b/llarp/dns.cpp @@ -96,7 +96,7 @@ getDNSstring(const char *const buffer, uint32_t *pos) } void -code_domain(char *&buffer, const std::string &domain) throw() +code_domain(char *&buffer, const std::string &domain) noexcept { std::string::size_type start(0); std::string::size_type end; // indexes @@ -124,7 +124,7 @@ code_domain(char *&buffer, const std::string &domain) throw() } void -vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) throw() +vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) noexcept { std::string::size_type start(0); std::string::size_type end; // indexes @@ -153,7 +153,7 @@ vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) throw() // expects host order void -vput16bits(std::vector< byte_t > &bytes, uint16_t value) throw() +vput16bits(std::vector< byte_t > &bytes, uint16_t value) noexcept { char buf[2] = {0}; char *write_buffer = buf; @@ -164,7 +164,7 @@ vput16bits(std::vector< byte_t > &bytes, uint16_t value) throw() // expects host order void -vput32bits(std::vector< byte_t > &bytes, uint32_t value) throw() +vput32bits(std::vector< byte_t > &bytes, uint32_t value) noexcept { char buf[4] = {0}; char *write_buffer = buf; @@ -178,7 +178,7 @@ vput32bits(std::vector< byte_t > &bytes, uint32_t value) throw() void dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record) { - llarp::dns::type_1a *type1a = dynamic_cast< llarp::dns::type_1a * >(record); + auto *type1a = dynamic_cast< llarp::dns::type_1a * >(record); if(type1a) { std::vector< byte_t > more_bytes = type1a->to_bytes(); @@ -186,8 +186,7 @@ dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record) bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end()); } - llarp::dns::type_2ns *type2ns = - dynamic_cast< llarp::dns::type_2ns * >(record); + auto *type2ns = dynamic_cast< llarp::dns::type_2ns * >(record); if(type2ns) { std::vector< byte_t > more_bytes = type2ns->to_bytes(); @@ -195,8 +194,7 @@ dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record) bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end()); } - llarp::dns::type_5cname *type5cname = - dynamic_cast< llarp::dns::type_5cname * >(record); + auto *type5cname = dynamic_cast< llarp::dns::type_5cname * >(record); if(type5cname) { std::vector< byte_t > more_bytes = type5cname->to_bytes(); @@ -204,24 +202,21 @@ dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record) bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end()); } - llarp::dns::type_12ptr *type12ptr = - dynamic_cast< llarp::dns::type_12ptr * >(record); + auto *type12ptr = dynamic_cast< llarp::dns::type_12ptr * >(record); if(type12ptr) { std::vector< byte_t > more_bytes = type12ptr->to_bytes(); llarp::LogDebug("[12]Adding ", more_bytes.size()); bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end()); } - llarp::dns::type_15mx *type15mx = - dynamic_cast< llarp::dns::type_15mx * >(record); + auto *type15mx = dynamic_cast< llarp::dns::type_15mx * >(record); if(type15mx) { std::vector< byte_t > more_bytes = type15mx->to_bytes(); llarp::LogDebug("[15]Adding ", more_bytes.size()); bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end()); } - llarp::dns::type_16txt *type16txt = - dynamic_cast< llarp::dns::type_16txt * >(record); + auto *type16txt = dynamic_cast< llarp::dns::type_16txt * >(record); if(type16txt) { std::vector< byte_t > more_bytes = type16txt->to_bytes(); @@ -292,7 +287,7 @@ packet2bytes(dns_packet &in) extern "C" { uint16_t - get16bits(const char *&buffer) throw() + get16bits(const char *&buffer) noexcept { uint16_t value = bufbe16toh(buffer); buffer += 2; @@ -300,7 +295,7 @@ extern "C" } uint32_t - get32bits(const char *&buffer) throw() + get32bits(const char *&buffer) noexcept { uint32_t value = bufbe32toh(buffer); buffer += 4; @@ -350,7 +345,7 @@ extern "C" dns_msg_question * decode_question(const char *buffer, uint32_t *pos) { - dns_msg_question *question = new dns_msg_question; + auto *question = new dns_msg_question; std::string m_qName = getDNSstring(buffer, pos); llarp::LogDebug("Got question name: ", m_qName); @@ -369,7 +364,7 @@ extern "C" dns_msg_answer * decode_answer(const char *const buffer, uint32_t *pos) { - dns_msg_answer *answer = new dns_msg_answer; + auto *answer = new dns_msg_answer; /* llarp_buffer_t bob; bob.base = (unsigned char *)buffer; @@ -589,14 +584,14 @@ extern "C" } void - put16bits(char *&buffer, uint16_t value) throw() + put16bits(char *&buffer, uint16_t value) noexcept { htobe16buf(buffer, value); buffer += 2; } void - put32bits(char *&buffer, uint32_t value) throw() + put32bits(char *&buffer, uint32_t value) noexcept { htobe32buf(buffer, value); buffer += 4; diff --git a/llarp/dns.h b/llarp/dns.h index 728009a37..a2eee4a42 100644 --- a/llarp/dns.h +++ b/llarp/dns.h @@ -14,7 +14,7 @@ extern "C" // fwd declr struct dnsc_answer_request; - typedef void (*dnsc_answer_hook_func)(dnsc_answer_request *request); + using dnsc_answer_hook_func = void (*)(dnsc_answer_request *); #ifdef __cplusplus } diff --git a/llarp/dns.hpp b/llarp/dns.hpp index a0edeeaf5..b290994b5 100644 --- a/llarp/dns.hpp +++ b/llarp/dns.hpp @@ -111,24 +111,24 @@ std::string getDNSstring(const char *const buffer, uint32_t *pos); void -code_domain(char *&buffer, const std::string &domain) throw(); +code_domain(char *&buffer, const std::string &domain) noexcept; void -vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) throw(); +vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) noexcept; void -vput16bits(std::vector< byte_t > &bytes, uint16_t value) throw(); +vput16bits(std::vector< byte_t > &bytes, uint16_t value) noexcept; void -vput32bits(std::vector< byte_t > &bytes, uint32_t value) throw(); +vput32bits(std::vector< byte_t > &bytes, uint32_t value) noexcept; extern "C" { uint16_t - get16bits(const char *&buffer) throw(); + get16bits(const char *&buffer) noexcept; uint32_t - get32bits(const char *&buffer) throw(); + get32bits(const char *&buffer) noexcept; bool decode_hdr(llarp_buffer_t *buffer, dns_msg_header *hdr); @@ -140,10 +140,10 @@ extern "C" decode_answer(const char *const buffer, uint32_t *pos); void - put16bits(char *&buffer, uint16_t value) throw(); + put16bits(char *&buffer, uint16_t value) noexcept; void - put32bits(char *&buffer, uint32_t value) throw(); + put32bits(char *&buffer, uint32_t value) noexcept; void llarp_handle_dns_recvfrom(struct llarp_udp_io *udp, diff --git a/llarp/dns/dns.hpp b/llarp/dns/dns.hpp index 921b16f38..cfcd5ee9c 100644 --- a/llarp/dns/dns.hpp +++ b/llarp/dns/dns.hpp @@ -1,7 +1,7 @@ #ifndef LLARP_DNS_DNS_HPP #define LLARP_DNS_DNS_HPP -#include +#include namespace llarp { diff --git a/llarp/dns/name.cpp b/llarp/dns/name.cpp index f23e2c1c9..ad51ad6c3 100644 --- a/llarp/dns/name.cpp +++ b/llarp/dns/name.cpp @@ -107,11 +107,11 @@ namespace llarp ip = net::IPPacket::ExpandV4(llarp::ipaddr_ipv4_bits(a, b, c, d)); return true; } - else if(numdots == 32 && isV6) + if(numdots == 32 && isV6) { size_t idx = 0; uint8_t lo, hi; - uint8_t* ptr = (uint8_t*)&ip.h; + auto* ptr = (uint8_t*)&ip.h; while(idx < 16) { pos = sub.find('.'); diff --git a/llarp/dns/rectypes.cpp b/llarp/dns/rectypes.cpp index a552b7509..d2771cb3c 100644 --- a/llarp/dns/rectypes.cpp +++ b/llarp/dns/rectypes.cpp @@ -5,9 +5,7 @@ namespace llarp { namespace dns { - record::~record() - { - } + record::~record() = default; bool record::parse(std::vector< byte_t > bytes) diff --git a/llarp/dns/rectypes.hpp b/llarp/dns/rectypes.hpp index a56b4f89d..4d651f4a7 100644 --- a/llarp/dns/rectypes.hpp +++ b/llarp/dns/rectypes.hpp @@ -13,9 +13,7 @@ namespace llarp struct record { virtual ~record() = 0; - record() - { - } + record() = default; virtual bool parse(std::vector< byte_t > bytes) = 0; @@ -28,9 +26,7 @@ namespace llarp { huint32_t ipaddr; - virtual ~type_1a() - { - } + ~type_1a() override = default; type_1a(); bool @@ -44,9 +40,7 @@ namespace llarp { std::string ns; - virtual ~type_2ns() - { - } + ~type_2ns() override = default; type_2ns(); bool @@ -66,9 +60,7 @@ namespace llarp uint32_t expire; uint32_t minimum; - virtual ~type_6soa() - { - } + ~type_6soa() override = default; type_6soa(); bool @@ -82,9 +74,7 @@ namespace llarp { std::string cname; - virtual ~type_5cname() - { - } + ~type_5cname() override = default; type_5cname(); bool @@ -98,9 +88,7 @@ namespace llarp { std::string revname; - virtual ~type_12ptr() - { - } + ~type_12ptr() override = default; type_12ptr(); bool @@ -115,9 +103,7 @@ namespace llarp std::string mx; uint16_t priority; - virtual ~type_15mx() - { - } + ~type_15mx() override = default; type_15mx(); bool @@ -131,9 +117,7 @@ namespace llarp { std::string txt; - virtual ~type_16txt() - { - } + ~type_16txt() override = default; type_16txt(); bool diff --git a/llarp/dns/serialize.cpp b/llarp/dns/serialize.cpp index f6c32239a..70a29c356 100644 --- a/llarp/dns/serialize.cpp +++ b/llarp/dns/serialize.cpp @@ -5,9 +5,7 @@ namespace llarp { namespace dns { - Serialize::~Serialize() - { - } + Serialize::~Serialize() = default; bool EncodeRData(llarp_buffer_t* buf, const std::vector< byte_t >& v) diff --git a/llarp/dns/server.cpp b/llarp/dns/server.cpp index 6ea3394e1..eae005b8b 100644 --- a/llarp/dns/server.cpp +++ b/llarp/dns/server.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace llarp { @@ -11,10 +12,10 @@ namespace llarp Proxy::Proxy(llarp_ev_loop_ptr serverLoop, Logic_ptr serverLogic, llarp_ev_loop_ptr clientLoop, Logic_ptr clientLogic, IQueryHandler* h) - : m_ServerLoop(serverLoop) - , m_ClientLoop(clientLoop) - , m_ServerLogic(serverLogic) - , m_ClientLogic(clientLogic) + : m_ServerLoop(std::move(serverLoop)) + , m_ClientLoop(std::move(clientLoop)) + , m_ServerLogic(std::move(serverLogic)) + , m_ClientLogic(std::move(clientLogic)) , m_QueryHandler(h) { m_Client.user = this; diff --git a/llarp/dns/server.hpp b/llarp/dns/server.hpp index b7d9aa195..f2f66ab5a 100644 --- a/llarp/dns/server.hpp +++ b/llarp/dns/server.hpp @@ -16,9 +16,7 @@ namespace llarp /// handler of dns query hooking struct IQueryHandler { - virtual ~IQueryHandler() - { - } + virtual ~IQueryHandler() = default; /// return true if we should hook this message virtual bool diff --git a/llarp/dnsc.cpp b/llarp/dnsc.cpp index 3e1034849..37cf990eb 100644 --- a/llarp/dnsc.cpp +++ b/llarp/dnsc.cpp @@ -10,12 +10,12 @@ #include /* close */ #endif -#include /* exit */ -#include /* memset */ +#include /* exit */ +#include /* memset */ #include #include // for std::find_if -#include // sprintf +#include // sprintf dns_tracker dns_udp_tracker; @@ -36,8 +36,8 @@ struct dns_query struct dns_query * build_dns_packet(char *url, uint16_t id, uint16_t reqType) { - dns_query *dnsQuery = new dns_query; - dnsQuery->length = 12; + auto *dnsQuery = new dns_query; + dnsQuery->length = 12; // ID // buffer[0] = (value & 0xFF00) >> 8; // buffer[1] = value & 0xFF; @@ -505,7 +505,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, } else if(answer->type == 15) { - llarp::dns::type_15mx *record = + auto *record = dynamic_cast< llarp::dns::type_15mx * >(answer->record.get()); llarp::LogDebug("Resolving MX ", record->mx, "@", record->priority); request->found = true; @@ -639,7 +639,7 @@ raw_resolve_host(struct dnsc_context *const dnsc, const char *url, llarp::LogInfo("response header says it belongs to id #", hdr.id); // if we sent this out, then there's an id - struct dns_tracker *tracker = (struct dns_tracker *)dnsc->tracker; + auto *tracker = (struct dns_tracker *)dnsc->tracker; struct dnsc_answer_request *request = tracker->client_request[hdr.id].get(); if(request) @@ -675,7 +675,7 @@ llarp_handle_dnsc_recvfrom(struct llarp_udp_io *const udp, llarp::LogDebug("Header got client responses for id: ", hdr.id); // if we sent this out, then there's an id - struct dns_tracker *tracker = (struct dns_tracker *)udp->user; + auto *tracker = (struct dns_tracker *)udp->user; struct dnsc_answer_request *request = tracker->client_request[hdr.id].get(); // sometimes we'll get double responses @@ -766,8 +766,8 @@ llarp_resolve_host(struct dnsc_context *const dnsc, const char *url, void llarp_host_resolved(dnsc_answer_request *const request) { - dns_tracker *tracker = (dns_tracker *)request->context->tracker; - auto val = std::find_if( + auto *tracker = (dns_tracker *)request->context->tracker; + auto val = std::find_if( tracker->client_request.begin(), tracker->client_request.end(), [request]( std::pair< const uint32_t, std::unique_ptr< dnsc_answer_request > > diff --git a/llarp/dnsc.hpp b/llarp/dnsc.hpp index f67ddd54a..7ae53da5b 100644 --- a/llarp/dnsc.hpp +++ b/llarp/dnsc.hpp @@ -26,7 +26,7 @@ build_dns_packet(char *url, uint16_t id, uint16_t reqType); /// hook function to handle an dns client request // should we pass by llarp::Addr // not as long as we're supporting raw -typedef void (*dnsc_answer_hook_func)(dnsc_answer_request *request); +using dnsc_answer_hook_func = void (*)(dnsc_answer_request *); /// struct for dns client requests struct dnsc_answer_request diff --git a/llarp/dnsd.cpp b/llarp/dnsd.cpp index 813c98cde..6f8eb7a42 100644 --- a/llarp/dnsd.cpp +++ b/llarp/dnsd.cpp @@ -27,7 +27,7 @@ ssize_t llarp_sendto_dns_hook_func(void *sock, const struct sockaddr *from, ManagedBuffer buf) { - struct llarp_udp_io *udp = (struct llarp_udp_io *)sock; + auto *udp = (struct llarp_udp_io *)sock; if(!udp) { llarp::LogWarn("couldnt cast to udp"); @@ -333,8 +333,7 @@ writesend_dnss_txtresponse(std::string txt, const struct sockaddr *from, void handle_dnsc_result(dnsc_answer_request *client_request) { - dnsd_question_request *server_request = - (dnsd_question_request *)client_request->user; + auto *server_request = (dnsd_question_request *)client_request->user; if(!server_request) { llarp::LogError("Couldn't map client requser user to a server request"); @@ -522,7 +521,7 @@ llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp, return; } // create new request - dnsd_question_request *llarp_dns_request = new dnsd_question_request; + auto *llarp_dns_request = new dnsd_question_request; llarp_dns_request->context = dns_udp_tracker.dnsd; // set context llarp_dns_request->from = new sockaddr(*saddr); // make a copy of the sockaddr @@ -543,7 +542,7 @@ raw_handle_recvfrom(int *sockfd, const struct sockaddr *saddr, llarp::LogError("No tracker set in dnsd context"); return; } - dnsd_question_request *llarp_dns_request = new dnsd_question_request; + auto *llarp_dns_request = new dnsd_question_request; llarp_dns_request->context = dns_udp_tracker.dnsd; // set context llarp_dns_request->from = new sockaddr(*saddr); // make a copy of the sockaddr diff --git a/llarp/ev/ev.h b/llarp/ev/ev.h index 71e772071..961dcbcc9 100644 --- a/llarp/ev/ev.h +++ b/llarp/ev/ev.h @@ -23,9 +23,9 @@ typedef SSIZE_T ssize_t; #endif #include -#include -#include -#include + +#include +#include #if !defined(WIN32) #include diff --git a/llarp/ev/ev.hpp b/llarp/ev/ev.hpp index e53e125b3..0a4de55fa 100644 --- a/llarp/ev/ev.hpp +++ b/llarp/ev/ev.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -305,7 +306,7 @@ namespace llarp struct GetNow { llarp_ev_loop_ptr loop; - GetNow(llarp_ev_loop_ptr l) : loop(l) + GetNow(llarp_ev_loop_ptr l) : loop(std::move(l)) { } @@ -319,7 +320,7 @@ namespace llarp struct PutTime { llarp_ev_loop_ptr loop; - PutTime(llarp_ev_loop_ptr l) : loop(l) + PutTime(llarp_ev_loop_ptr l) : loop(std::move(l)) { } void @@ -570,9 +571,7 @@ namespace llarp tcp.close = &DoClose; } - virtual ~tcp_conn() - { - } + ~tcp_conn() override = default; /// start connecting void @@ -631,10 +630,10 @@ namespace llarp errno = 0; } - virtual ssize_t + ssize_t do_write(void* buf, size_t sz) override; - virtual int + int read(byte_t* buf, size_t sz) override; bool @@ -652,7 +651,7 @@ namespace llarp } bool - tick() + tick() override { if(tcp->tick) tcp->tick(tcp); @@ -660,8 +659,8 @@ namespace llarp } /// actually does accept() :^) - virtual int - read(byte_t*, size_t); + int + read(byte_t*, size_t) override; }; } // namespace llarp @@ -784,9 +783,7 @@ struct llarp_ev_loop return conn && add_ev(conn, true); } - virtual ~llarp_ev_loop() - { - } + virtual ~llarp_ev_loop() = default; std::list< std::unique_ptr< llarp::ev_io > > handlers; diff --git a/llarp/ev/ev_libuv.cpp b/llarp/ev/ev_libuv.cpp index 224f0a1aa..6588832ee 100644 --- a/llarp/ev/ev_libuv.cpp +++ b/llarp/ev/ev_libuv.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include namespace libuv { @@ -65,7 +65,7 @@ namespace libuv static void OnOutboundConnect(uv_connect_t* c, int status) { - conn_glue* self = static_cast< conn_glue* >(c->data); + auto* self = static_cast< conn_glue* >(c->data); self->HandleConnectResult(status); c->data = nullptr; } @@ -181,9 +181,9 @@ namespace libuv { m_WriteQueue.emplace_back(sz); std::copy_n(data, sz, m_WriteQueue.back().begin()); - auto buf = uv_buf_init(m_WriteQueue.back().data(), sz); - uv_write_t* req = new uv_write_t(); - req->data = this; + auto buf = uv_buf_init(m_WriteQueue.back().data(), sz); + auto* req = new uv_write_t(); + req->data = this; return uv_write(req, Stream(), &buf, 1, &OnWritten) == 0 ? sz : 0; } @@ -196,8 +196,8 @@ namespace libuv static void FullClose(uv_handle_t* h) { - conn_glue* self = static_cast< conn_glue* >(h->data); - h->data = nullptr; + auto* self = static_cast< conn_glue* >(h->data); + h->data = nullptr; delete self; llarp::LogInfo("deleted"); } @@ -225,7 +225,7 @@ namespace libuv OnShutdown(uv_shutdown_t* shut, int code) { llarp::LogDebug("shut down ", code); - conn_glue* self = static_cast< conn_glue* >(shut->data); + auto* self = static_cast< conn_glue* >(shut->data); uv_close((uv_handle_t*)&self->m_Handle, &OnClosed); delete shut; } @@ -236,8 +236,8 @@ namespace libuv llarp::LogDebug("close tcp connection"); uv_check_stop(&m_Ticker); uv_read_stop(Stream()); - uv_shutdown_t* shut = new uv_shutdown_t(); - shut->data = this; + auto* shut = new uv_shutdown_t(); + shut->data = this; uv_shutdown(shut, Stream(), &OnShutdown); } @@ -285,7 +285,7 @@ namespace libuv { if(m_Accept && m_Accept->accepted) { - conn_glue* child = new conn_glue(this); + auto* child = new conn_glue(this); llarp::LogDebug("accepted new connection"); child->m_Conn.impl = child; child->m_Conn.loop = m_Accept->loop; @@ -375,7 +375,7 @@ namespace libuv static int SendTo(llarp_udp_io* udp, const sockaddr* to, const byte_t* ptr, size_t sz) { - udp_glue* self = static_cast< udp_glue* >(udp->impl); + auto* self = static_cast< udp_glue* >(udp->impl); if(self == nullptr) return -1; uv_buf_t buf = uv_buf_init((char*)ptr, sz); @@ -410,7 +410,7 @@ namespace libuv static void OnClosed(uv_handle_t* h) { - udp_glue* glue = static_cast< udp_glue* >(h->data); + auto* glue = static_cast< udp_glue* >(h->data); if(glue) { h->data = nullptr; @@ -443,7 +443,7 @@ namespace libuv readpkt = false; } - ~tun_glue() + ~tun_glue() override { tuntap_destroy(m_Device); } @@ -488,7 +488,7 @@ namespace libuv static void OnClosed(uv_handle_t* h) { - tun_glue* self = static_cast< tun_glue* >(h->data); + auto* self = static_cast< tun_glue* >(h->data); if(self) { self->m_Tun->impl = nullptr; @@ -597,8 +597,8 @@ namespace libuv bool Loop::tcp_connect(llarp_tcp_connecter* tcp, const sockaddr* addr) { - conn_glue* impl = new conn_glue(m_Impl.get(), tcp, addr); - tcp->impl = impl; + auto* impl = new conn_glue(m_Impl.get(), tcp, addr); + tcp->impl = impl; if(impl->ConnectAsync()) return true; delete impl; @@ -656,8 +656,8 @@ namespace libuv bool Loop::udp_listen(llarp_udp_io* udp, const sockaddr* src) { - udp_glue* impl = new udp_glue(m_Impl.get(), udp, src); - udp->impl = impl; + auto* impl = new udp_glue(m_Impl.get(), udp, src); + udp->impl = impl; if(impl->Bind()) { return true; @@ -671,7 +671,7 @@ namespace libuv { if(udp == nullptr) return false; - udp_glue* glue = static_cast< udp_glue* >(udp->impl); + auto* glue = static_cast< udp_glue* >(udp->impl); if(glue == nullptr) return false; glue->Close(); @@ -681,8 +681,8 @@ namespace libuv bool Loop::tun_listen(llarp_tun_io* tun) { - tun_glue* glue = new tun_glue(tun); - tun->impl = glue; + auto* glue = new tun_glue(tun); + tun->impl = glue; if(glue->Init(m_Impl.get())) { return true; @@ -694,8 +694,8 @@ namespace libuv bool Loop::tcp_listen(llarp_tcp_acceptor* tcp, const sockaddr* addr) { - conn_glue* glue = new conn_glue(m_Impl.get(), tcp, addr); - tcp->impl = glue; + auto* glue = new conn_glue(m_Impl.get(), tcp, addr); + tcp->impl = glue; if(glue->Server()) return true; tcp->impl = nullptr; diff --git a/llarp/ev/pipe.cpp b/llarp/ev/pipe.cpp index b92f5ba0b..76d141a9e 100644 --- a/llarp/ev/pipe.cpp +++ b/llarp/ev/pipe.cpp @@ -1,4 +1,5 @@ #include +#include #ifndef _MSC_VER #include @@ -6,7 +7,7 @@ #include llarp_ev_pkt_pipe::llarp_ev_pkt_pipe(llarp_ev_loop_ptr loop) - : llarp::ev_io(-1, new LosslessWriteQueue_t()), m_Loop(loop) + : llarp::ev_io(-1, new LosslessWriteQueue_t()), m_Loop(std::move(loop)) { } diff --git a/llarp/ev/pipe.hpp b/llarp/ev/pipe.hpp index 6800b1b8b..0bf1953fc 100644 --- a/llarp/ev/pipe.hpp +++ b/llarp/ev/pipe.hpp @@ -25,7 +25,7 @@ struct llarp_ev_pkt_pipe : public llarp::ev_io ssize_t do_write(void* buf, size_t sz) override; - virtual bool + bool tick() override; int diff --git a/llarp/exit/context.cpp b/llarp/exit/context.cpp index f8e995c92..b8560ba2c 100644 --- a/llarp/exit/context.cpp +++ b/llarp/exit/context.cpp @@ -1,4 +1,5 @@ #include +#include namespace llarp { @@ -7,9 +8,7 @@ namespace llarp Context::Context(AbstractRouter* r) : m_Router(r) { } - Context::~Context() - { - } + Context::~Context() = default; void Context::Tick(llarp_time_t now) @@ -112,7 +111,7 @@ namespace llarp } std::unique_ptr< handlers::ExitEndpoint > endpoint; // make new endpoint - endpoint.reset(new handlers::ExitEndpoint(name, m_Router)); + endpoint = std::make_unique< handlers::ExitEndpoint >(name, m_Router); // configure { auto itr = conf.begin(); diff --git a/llarp/exit/exit_messages.hpp b/llarp/exit/exit_messages.hpp index 168c3833e..6f7ffffbb 100644 --- a/llarp/exit/exit_messages.hpp +++ b/llarp/exit/exit_messages.hpp @@ -14,20 +14,18 @@ namespace llarp struct ObtainExitMessage final : public IMessage { std::vector< llarp::exit::Policy > B; - uint64_t E; + uint64_t E{0}; llarp::PubKey I; - uint64_t T; + uint64_t T{0}; std::vector< llarp::exit::Policy > W; - llarp_time_t X; + llarp_time_t X{0}; llarp::Signature Z; - ObtainExitMessage() : IMessage(), E(0), T(0), X(0) + ObtainExitMessage() : IMessage() { } - ~ObtainExitMessage() - { - } + ~ObtainExitMessage() override = default; void Clear() override @@ -132,7 +130,7 @@ namespace llarp Nonce_t Y; llarp::Signature Z; - ~UpdateExitVerifyMessage() = default; + ~UpdateExitVerifyMessage() override = default; void Clear() override diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index 9ae0b5d01..4d4296b90 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace llarp { @@ -17,7 +18,7 @@ namespace llarp AbstractRouter* r, size_t numpaths, size_t hoplen, bool bundleRC) : llarp::path::Builder(r, numpaths, hoplen) , m_ExitRouter(routerId) - , m_WritePacket(writepkt) + , m_WritePacket(std::move(writepkt)) , m_Counter(0) , m_LastUse(0) , m_BundleRC(bundleRC) @@ -25,9 +26,7 @@ namespace llarp CryptoManager::instance()->identity_keygen(m_ExitIdentity); } - BaseSession::~BaseSession() - { - } + BaseSession::~BaseSession() = default; void BaseSession::HandlePathDied(path::Path_ptr p) diff --git a/llarp/exit/session.hpp b/llarp/exit/session.hpp index 449c2fb77..550173ce6 100644 --- a/llarp/exit/session.hpp +++ b/llarp/exit/session.hpp @@ -31,7 +31,7 @@ namespace llarp AbstractRouter* r, size_t numpaths, size_t hoplen, bool bundleRC); - virtual ~BaseSession(); + ~BaseSession() override; std::shared_ptr< path::PathSet > GetSelf() override @@ -51,7 +51,7 @@ namespace llarp return m_BundleRC; } - virtual void + void ResetInternalState() override; bool UrgentBuild(llarp_time_t) const override; @@ -175,13 +175,13 @@ namespace llarp { } - ~ExitSession() = default; + ~ExitSession() override = default; std::string Name() const override; protected: - virtual void + void PopulateRequest(llarp::routing::ObtainExitMessage& msg) const override { // TODO: set expiration time @@ -197,7 +197,7 @@ namespace llarp AbstractRouter* r, size_t numpaths, size_t hoplen, bool useRouterSNodeKey, bool bundleRC); - ~SNodeSession() = default; + ~SNodeSession() override = default; std::string Name() const override; diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index 18524ceec..4ec317e00 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -29,7 +29,8 @@ namespace llarp , m_Resolver(std::make_shared< dns::Proxy >( r->netloop(), r->logic(), r->netloop(), r->logic(), this)) , m_Name(name) - , m_Tun{{0}, 0, {0}, 0, 0, 0, 0, 0, 0, 0, 0} + , m_Tun{{0}, 0, {0}, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr} , m_LocalResolverAddr("127.0.0.1", 53) , m_InetToNetwork(name + "_exit_rx", r->netloop(), r->netloop()) @@ -40,9 +41,7 @@ namespace llarp m_ShouldInitTun = true; } - ExitEndpoint::~ExitEndpoint() - { - } + ExitEndpoint::~ExitEndpoint() = default; util::StatusObject ExitEndpoint::ExtractStatus() const diff --git a/llarp/handlers/exit.hpp b/llarp/handlers/exit.hpp index d8d6abbab..21a499160 100644 --- a/llarp/handlers/exit.hpp +++ b/llarp/handlers/exit.hpp @@ -14,7 +14,7 @@ namespace llarp struct ExitEndpoint : public dns::IQueryHandler { ExitEndpoint(const std::string& name, AbstractRouter* r); - ~ExitEndpoint(); + ~ExitEndpoint() override; void Tick(llarp_time_t now); diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index d796fd033..2292ff1ee 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -31,7 +31,7 @@ namespace llarp static void tunifTick(llarp_tun_io *tun) { - TunEndpoint *self = static_cast< TunEndpoint * >(tun->user); + auto *self = static_cast< TunEndpoint * >(tun->user); self->Flush(); } @@ -412,7 +412,7 @@ namespace llarp } else { - dns::Message *replyMsg = new dns::Message(std::move(msg)); + auto *replyMsg = new dns::Message(std::move(msg)); using service::Address; using service::OutboundContext; return EnsurePathToService( @@ -432,7 +432,7 @@ namespace llarp } else { - dns::Message *replyMsg = new dns::Message(std::move(msg)); + auto *replyMsg = new dns::Message(std::move(msg)); EnsurePathToSNode(addr.as_array(), [=](const RouterID &, exit::BaseSession_ptr s) { SendDNSReply(addr, s, replyMsg, reply, true, @@ -577,7 +577,7 @@ namespace llarp return false; } - struct addrinfo hint, *res = NULL; + struct addrinfo hint, *res = nullptr; int ret; memset(&hint, 0, sizeof hint); @@ -585,7 +585,7 @@ namespace llarp hint.ai_family = PF_UNSPEC; hint.ai_flags = AI_NUMERICHOST; - ret = getaddrinfo(tunif.ifaddr, NULL, &hint, &res); + ret = getaddrinfo(tunif.ifaddr, nullptr, &hint, &res); if(ret) { llarp::LogError(Name(), @@ -909,7 +909,7 @@ namespace llarp TunEndpoint::tunifBeforeWrite(llarp_tun_io *tun) { // called in the isolated network thread - TunEndpoint *self = static_cast< TunEndpoint * >(tun->user); + auto *self = static_cast< TunEndpoint * >(tun->user); // flush user to network self->FlushSend(); // flush exit traffic queues if it's there @@ -928,15 +928,13 @@ namespace llarp TunEndpoint::tunifRecvPkt(llarp_tun_io *tun, const llarp_buffer_t &b) { // called for every packet read from user in isolated network thread - TunEndpoint *self = static_cast< TunEndpoint * >(tun->user); + auto *self = static_cast< TunEndpoint * >(tun->user); const ManagedBuffer buf(b); self->m_UserToNetworkPktQueue.EmplaceIf( [&buf](net::IPPacket &pkt) -> bool { return pkt.Load(buf); }); } - TunEndpoint::~TunEndpoint() - { - } + TunEndpoint::~TunEndpoint() = default; } // namespace handlers } // namespace llarp diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 98d47daf7..8af830e07 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -21,7 +21,7 @@ namespace llarp { TunEndpoint(const std::string& nickname, AbstractRouter* r, llarp::service::Context* parent); - ~TunEndpoint(); + ~TunEndpoint() override; path::PathSet_ptr GetSelf() override @@ -29,10 +29,10 @@ namespace llarp return shared_from_this(); } - virtual bool + bool SetOption(const std::string& k, const std::string& v) override; - virtual void + void Tick(llarp_time_t now) override; util::StatusObject @@ -165,7 +165,7 @@ namespace llarp void Flush(); - virtual void + void ResetInternalState() override; protected: diff --git a/llarp/hook/ihook.hpp b/llarp/hook/ihook.hpp index 83d57d0fa..553de68e0 100644 --- a/llarp/hook/ihook.hpp +++ b/llarp/hook/ihook.hpp @@ -26,9 +26,7 @@ namespace llarp using Backend_ptr = std::shared_ptr< IBackend >; - inline IBackend::~IBackend() - { - } + inline IBackend::~IBackend() = default; } // namespace hooks } // namespace llarp diff --git a/llarp/iwp/linklayer.cpp b/llarp/iwp/linklayer.cpp index 2f0af3226..8a984d7c4 100644 --- a/llarp/iwp/linklayer.cpp +++ b/llarp/iwp/linklayer.cpp @@ -13,9 +13,7 @@ namespace llarp m_FlowCookie.Randomize(); } - LinkLayer::~LinkLayer() - { - } + LinkLayer::~LinkLayer() = default; void LinkLayer::Pump() diff --git a/llarp/iwp/linklayer.hpp b/llarp/iwp/linklayer.hpp index 50f9f3557..e7265188e 100644 --- a/llarp/iwp/linklayer.hpp +++ b/llarp/iwp/linklayer.hpp @@ -19,7 +19,7 @@ namespace llarp SessionRenegotiateHandler reneg, SignBufferFunc sign, TimeoutHandler timeout, SessionClosedHandler closed); - ~LinkLayer(); + ~LinkLayer() override; bool Start(std::shared_ptr< Logic > l) override; diff --git a/llarp/iwp/outermessage.cpp b/llarp/iwp/outermessage.cpp index bb3b9b724..3d7ad2af7 100644 --- a/llarp/iwp/outermessage.cpp +++ b/llarp/iwp/outermessage.cpp @@ -1,4 +1,5 @@ #include +#include namespace llarp { @@ -15,9 +16,7 @@ namespace llarp Clear(); } - OuterMessage::~OuterMessage() - { - } + OuterMessage::~OuterMessage() = default; void OuterMessage::Clear() @@ -131,7 +130,7 @@ namespace llarp return false; if(buf->size_left() == Zsig.size() + 32) { - A.reset(new AlignedBuffer< 32 >()); + A = std::make_unique< AlignedBuffer< 32 > >(); if(!buf->read_into(A->begin(), A->end())) return false; } diff --git a/llarp/link/link_manager.hpp b/llarp/link/link_manager.hpp index 4e9296781..17f29f8c3 100644 --- a/llarp/link/link_manager.hpp +++ b/llarp/link/link_manager.hpp @@ -18,7 +18,7 @@ namespace llarp struct LinkManager final : public ILinkManager { public: - ~LinkManager() = default; + ~LinkManager() override = default; LinkLayer_ptr GetCompatibleLink(const RouterContact &rc) const override; @@ -71,7 +71,7 @@ namespace llarp void CheckPersistingSessions(llarp_time_t now) override; - virtual util::StatusObject + util::StatusObject ExtractStatus() const override; void diff --git a/llarp/link/server.cpp b/llarp/link/server.cpp index ec6da7c3d..73da6dcb3 100644 --- a/llarp/link/server.cpp +++ b/llarp/link/server.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace llarp { @@ -12,20 +13,18 @@ namespace llarp SessionEstablishedHandler establishedSession, SessionRenegotiateHandler reneg, TimeoutHandler timeout, SessionClosedHandler closed) - : HandleMessage(handler) - , HandleTimeout(timeout) - , Sign(signbuf) - , GetOurRC(getrc) - , SessionEstablished(establishedSession) - , SessionClosed(closed) - , SessionRenegotiate(reneg) + : HandleMessage(std::move(handler)) + , HandleTimeout(std::move(timeout)) + , Sign(std::move(signbuf)) + , GetOurRC(std::move(getrc)) + , SessionEstablished(std::move(establishedSession)) + , SessionClosed(std::move(closed)) + , SessionRenegotiate(std::move(reneg)) , m_RouterEncSecret(routerEncSecret) { } - ILinkLayer::~ILinkLayer() - { - } + ILinkLayer::~ILinkLayer() = default; bool ILinkLayer::HasSessionTo(const RouterID& id) diff --git a/llarp/link/session.hpp b/llarp/link/session.hpp index 5b904f633..39dc1ae96 100644 --- a/llarp/link/session.hpp +++ b/llarp/link/session.hpp @@ -16,9 +16,7 @@ namespace llarp struct ILinkSession { - virtual ~ILinkSession() - { - } + virtual ~ILinkSession() = default; /// delivery status of a message enum class DeliveryStatus diff --git a/llarp/messages/dht_immediate.hpp b/llarp/messages/dht_immediate.hpp index 88f4e765d..31afbba9e 100644 --- a/llarp/messages/dht_immediate.hpp +++ b/llarp/messages/dht_immediate.hpp @@ -10,8 +10,8 @@ namespace llarp { struct DHTImmediateMessage final : public ILinkMessage { - DHTImmediateMessage() = default; - ~DHTImmediateMessage() = default; + DHTImmediateMessage() = default; + ~DHTImmediateMessage() override = default; std::vector< std::unique_ptr< dht::IMessage > > msgs; diff --git a/llarp/messages/link_intro.cpp b/llarp/messages/link_intro.cpp index b414d95d4..a4f3c8d1c 100644 --- a/llarp/messages/link_intro.cpp +++ b/llarp/messages/link_intro.cpp @@ -31,7 +31,7 @@ namespace llarp { return bencode_read_integer(buf, &P); } - else if(key == "r") + if(key == "r") { if(rc.BDecode(buf)) return true; @@ -39,7 +39,7 @@ namespace llarp llarp::DumpBuffer(*buf); return false; } - else if(key == "v") + if(key == "v") { if(!bencode_read_integer(buf, &version)) return false; @@ -52,15 +52,13 @@ namespace llarp llarp::LogDebug("LIM version ", version); return true; } - else if(key == "z") + if(key == "z") { return Z.BDecode(buf); } - else - { - llarp::LogWarn("invalid LIM key: ", *key.cur); - return false; - } + + llarp::LogWarn("invalid LIM key: ", *key.cur); + return false; } bool diff --git a/llarp/messages/link_message_parser.cpp b/llarp/messages/link_message_parser.cpp index 3e8859ad5..e7fd1b16b 100644 --- a/llarp/messages/link_message_parser.cpp +++ b/llarp/messages/link_message_parser.cpp @@ -37,9 +37,7 @@ namespace llarp { } - LinkMessageParser::~LinkMessageParser() - { - } + LinkMessageParser::~LinkMessageParser() = default; bool LinkMessageParser::operator()(llarp_buffer_t* buffer, llarp_buffer_t* key) diff --git a/llarp/messages/relay_commit.cpp b/llarp/messages/relay_commit.cpp index d0a19bd55..a269590be 100644 --- a/llarp/messages/relay_commit.cpp +++ b/llarp/messages/relay_commit.cpp @@ -171,9 +171,9 @@ namespace llarp struct LRCMFrameDecrypt { - typedef llarp::path::PathContext Context; - typedef llarp::path::TransitHop Hop; - typedef AsyncFrameDecrypter< LRCMFrameDecrypt > Decrypter; + using Context = llarp::path::PathContext; + using Hop = llarp::path::TransitHop; + using Decrypter = AsyncFrameDecrypter< LRCMFrameDecrypt >; using Decrypter_ptr = std::unique_ptr< Decrypter >; Decrypter_ptr decrypter; std::array< EncryptedFrame, 8 > frames; @@ -193,9 +193,7 @@ namespace llarp hop->info.downstream = commit->session->GetPubKey(); } - ~LRCMFrameDecrypt() - { - } + ~LRCMFrameDecrypt() = default; static void OnForwardLRCMResult(AbstractRouter* router, const PathID_t pathid, diff --git a/llarp/messages/relay_commit.hpp b/llarp/messages/relay_commit.hpp index 86abf5d95..7c54349fc 100644 --- a/llarp/messages/relay_commit.hpp +++ b/llarp/messages/relay_commit.hpp @@ -9,6 +9,7 @@ #include #include +#include namespace llarp { @@ -49,14 +50,14 @@ namespace llarp { std::array< EncryptedFrame, 8 > frames; - LR_CommitMessage(const std::array< EncryptedFrame, 8 > &_frames) - : ILinkMessage(), frames(_frames) + LR_CommitMessage(std::array< EncryptedFrame, 8 > _frames) + : ILinkMessage(), frames(std::move(_frames)) { } LR_CommitMessage() = default; - ~LR_CommitMessage() = default; + ~LR_CommitMessage() override = default; void Clear() override; diff --git a/llarp/messages/relay_status.cpp b/llarp/messages/relay_status.cpp index 5ca6b07d1..d72e41d87 100644 --- a/llarp/messages/relay_status.cpp +++ b/llarp/messages/relay_status.cpp @@ -12,6 +12,7 @@ #include #include +#include namespace llarp { @@ -25,10 +26,12 @@ namespace llarp HopHandler_ptr path; AbstractRouter* router; - LRSM_AsyncHandler(const std::array< EncryptedFrame, 8 >& _frames, - uint64_t _status, HopHandler_ptr _path, - AbstractRouter* _router) - : frames(_frames), status(_status), path(_path), router(_router) + LRSM_AsyncHandler(std::array< EncryptedFrame, 8 > _frames, uint64_t _status, + HopHandler_ptr _path, AbstractRouter* _router) + : frames(std::move(_frames)) + , status(_status) + , path(std::move(_path)) + , router(_router) { } @@ -57,7 +60,7 @@ namespace llarp { return BEncodeReadArray(frames, buf); } - else if(key == "p") + if(key == "p") { if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf)) { diff --git a/llarp/messages/relay_status.hpp b/llarp/messages/relay_status.hpp index fd8684123..2e744f8dd 100644 --- a/llarp/messages/relay_status.hpp +++ b/llarp/messages/relay_status.hpp @@ -9,6 +9,7 @@ #include #include +#include namespace llarp { @@ -56,14 +57,14 @@ namespace llarp uint64_t status = 0; - LR_StatusMessage(const std::array< EncryptedFrame, 8 > &_frames) - : ILinkMessage(), frames(_frames) + LR_StatusMessage(std::array< EncryptedFrame, 8 > _frames) + : ILinkMessage(), frames(std::move(_frames)) { } LR_StatusMessage() = default; - ~LR_StatusMessage() = default; + ~LR_StatusMessage() override = default; void Clear() override; diff --git a/llarp/metrics/json_publisher.hpp b/llarp/metrics/json_publisher.hpp index d0cc2b06c..b684a2495 100644 --- a/llarp/metrics/json_publisher.hpp +++ b/llarp/metrics/json_publisher.hpp @@ -8,6 +8,7 @@ #include #include +#include namespace llarp { @@ -22,13 +23,11 @@ namespace llarp PublishFunction m_publish; public: - JsonPublisher(const PublishFunction& publish) : m_publish(publish) + JsonPublisher(PublishFunction publish) : m_publish(std::move(publish)) { } - ~JsonPublisher() - { - } + ~JsonPublisher() override = default; void publish(const Sample& values) override; diff --git a/llarp/metrics/metrictank_publisher.hpp b/llarp/metrics/metrictank_publisher.hpp index 23fbb699f..044b4ec87 100644 --- a/llarp/metrics/metrictank_publisher.hpp +++ b/llarp/metrics/metrictank_publisher.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace llarp @@ -32,9 +33,7 @@ namespace llarp { } - ~MetricTankPublisherInterface() - { - } + ~MetricTankPublisherInterface() override = default; static std::string makeSuffix(const Tags& tags); @@ -66,16 +65,16 @@ namespace llarp work(); public: - MetricTankPublisher(const Tags& tags, const std::string& host, short port) + MetricTankPublisher(const Tags& tags, std::string host, short port) : MetricTankPublisherInterface(tags) - , m_host(host) + , m_host(std::move(host)) , m_port(port) , m_queue(100) , m_worker(&MetricTankPublisher::work, this) { } - ~MetricTankPublisher() + ~MetricTankPublisher() override { // Push back a signal value onto the queue m_queue.pushBack(StopStruct()); diff --git a/llarp/metrics/stream_publisher.hpp b/llarp/metrics/stream_publisher.hpp index a50ebe686..4fbb9ff7a 100644 --- a/llarp/metrics/stream_publisher.hpp +++ b/llarp/metrics/stream_publisher.hpp @@ -18,7 +18,7 @@ namespace llarp { } - ~StreamPublisher() = default; + ~StreamPublisher() override = default; void publish(const Sample& values) override; diff --git a/llarp/net/address_info.cpp b/llarp/net/address_info.cpp index 6a81f7490..1ae3a7c1c 100644 --- a/llarp/net/address_info.cpp +++ b/llarp/net/address_info.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include namespace llarp { diff --git a/llarp/net/address_info.hpp b/llarp/net/address_info.hpp index 48ec5f6d1..401571fe6 100644 --- a/llarp/net/address_info.hpp +++ b/llarp/net/address_info.hpp @@ -8,7 +8,6 @@ #include #include -#include /** * address_info.hpp diff --git a/llarp/net/exit_info.cpp b/llarp/net/exit_info.cpp index 9c4435356..be1e6efd3 100644 --- a/llarp/net/exit_info.cpp +++ b/llarp/net/exit_info.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include namespace llarp { diff --git a/llarp/net/exit_info.hpp b/llarp/net/exit_info.hpp index b7355abee..c1fe6f678 100644 --- a/llarp/net/exit_info.hpp +++ b/llarp/net/exit_info.hpp @@ -23,9 +23,7 @@ namespace llarp PubKey pubkey; uint64_t version = LLARP_PROTO_VERSION; - ExitInfo() - { - } + ExitInfo() = default; ExitInfo(const PubKey &pk, const nuint32_t &ipv4_exit) : pubkey(pk) { diff --git a/llarp/net/ip.cpp b/llarp/net/ip.cpp index 8723d7636..80df045e3 100644 --- a/llarp/net/ip.cpp +++ b/llarp/net/ip.cpp @@ -71,8 +71,8 @@ namespace llarp { if(IsV6()) return In6ToHUInt(HeaderV6()->srcaddr); - else - return ExpandV4(srcv4()); + + return ExpandV4(srcv4()); } huint128_t @@ -80,8 +80,8 @@ namespace llarp { if(IsV6()) return In6ToHUInt(HeaderV6()->dstaddr); - else - return ExpandV4(dstv4()); + + return ExpandV4(dstv4()); } bool diff --git a/llarp/net/ip.hpp b/llarp/net/ip.hpp index 49f062e2b..83ddf3714 100644 --- a/llarp/net/ip.hpp +++ b/llarp/net/ip.hpp @@ -88,6 +88,7 @@ struct ipv6_header #include #include +#include struct llarp_ev_loop; @@ -136,7 +137,7 @@ namespace llarp struct PutTime { llarp_ev_loop_ptr loop; - PutTime(llarp_ev_loop_ptr evloop) : loop(evloop) + PutTime(llarp_ev_loop_ptr evloop) : loop(std::move(evloop)) { } void @@ -149,7 +150,7 @@ namespace llarp struct GetNow { llarp_ev_loop_ptr loop; - GetNow(llarp_ev_loop_ptr evloop) : loop(evloop) + GetNow(llarp_ev_loop_ptr evloop) : loop(std::move(evloop)) { } llarp_time_t @@ -224,10 +225,10 @@ namespace llarp { if(IsV4()) return service::eProtocolTrafficV4; - else if(IsV6()) + if(IsV6()) return service::eProtocolTrafficV6; - else - return service::eProtocolControl; + + return service::eProtocolControl; } huint128_t diff --git a/llarp/net/net.cpp b/llarp/net/net.cpp index 010797d3c..f55916912 100644 --- a/llarp/net/net.cpp +++ b/llarp/net/net.cpp @@ -786,7 +786,7 @@ llarp_getifaddr(const char* ifname, int af, struct sockaddr* addr) if(af == AF_INET6) { // set scope id - sockaddr_in6* ip6addr = (sockaddr_in6*)addr; + auto* ip6addr = (sockaddr_in6*)addr; ip6addr->sin6_scope_id = if_nametoindex(ifname); ip6addr->sin6_flowinfo = 0; } @@ -861,8 +861,8 @@ namespace llarp const auto fam = i->ifa_addr->sa_family; if(fam != AF_INET) return; - sockaddr_in* addr = (sockaddr_in*)i->ifa_addr; - sockaddr_in* mask = (sockaddr_in*)i->ifa_netmask; + auto* addr = (sockaddr_in*)i->ifa_addr; + auto* mask = (sockaddr_in*)i->ifa_netmask; nuint32_t ifaddr{addr->sin_addr.s_addr}; nuint32_t ifmask{mask->sin_addr.s_addr}; currentRanges.emplace_back( @@ -926,7 +926,7 @@ namespace llarp GetIFAddr(const std::string& ifname, Addr& addr, int af) { sockaddr_storage s; - sockaddr* sptr = (sockaddr*)&s; + auto* sptr = (sockaddr*)&s; if(!llarp_getifaddr(ifname.c_str(), af, sptr)) return false; addr = *sptr; diff --git a/llarp/net/net.h b/llarp/net/net.h index 55b349cad..fbcb02411 100644 --- a/llarp/net/net.h +++ b/llarp/net/net.h @@ -25,7 +25,7 @@ typedef unsigned int in_addr_t; #include #include #endif -#include + #include bool diff --git a/llarp/net/net.hpp b/llarp/net/net.hpp index f9848c948..044e512f6 100644 --- a/llarp/net/net.hpp +++ b/llarp/net/net.hpp @@ -11,7 +11,7 @@ #include #include -#include // for itoa +#include // for itoa #include // for addrinfo diff --git a/llarp/net/net_addr.cpp b/llarp/net/net_addr.cpp index de2387e51..bed44a9c6 100644 --- a/llarp/net/net_addr.cpp +++ b/llarp/net/net_addr.cpp @@ -16,12 +16,8 @@ namespace llarp { - Addr::Addr() - { - } - Addr::~Addr() - { - } + Addr::Addr() = default; + Addr::~Addr() = default; void Addr::port(uint16_t port) @@ -87,7 +83,7 @@ namespace llarp this->port(port); } Zero(&_addr, sizeof(sockaddr_in6)); - struct addrinfo hint, *res = NULL; + struct addrinfo hint, *res = nullptr; int ret; memset(&hint, '\0', sizeof hint); @@ -98,11 +94,11 @@ namespace llarp if(pPosition != string_view::npos) { ret = getaddrinfo(std::string(in.begin(), in.begin() + pPosition).c_str(), - NULL, &hint, &res); + nullptr, &hint, &res); } else { - ret = getaddrinfo(std::string(in).c_str(), NULL, &hint, &res); + ret = getaddrinfo(std::string(in).c_str(), nullptr, &hint, &res); } if(ret) @@ -152,7 +148,7 @@ namespace llarp { Zero(&_addr, sizeof(sockaddr_in6)); struct in_addr* addr = &_addr4.sin_addr; - unsigned char* ip = (unsigned char*)&(addr->s_addr); + auto* ip = (unsigned char*)&(addr->s_addr); _addr.sin6_family = AF_INET; // set ipv4 mode _addr4.sin_family = AF_INET; @@ -311,11 +307,11 @@ namespace llarp { case AF_INET: { - sockaddr_in* ipv4_dst = (sockaddr_in*)other; - dst = (void*)&ipv4_dst->sin_addr.s_addr; - src = (void*)&_addr4.sin_addr.s_addr; - ptr = &((sockaddr_in*)other)->sin_port; - slen = sizeof(in_addr); + auto* ipv4_dst = (sockaddr_in*)other; + dst = (void*)&ipv4_dst->sin_addr.s_addr; + src = (void*)&_addr4.sin_addr.s_addr; + ptr = &((sockaddr_in*)other)->sin_port; + slen = sizeof(in_addr); break; } case AF_INET6: diff --git a/llarp/net/net_inaddr.cpp b/llarp/net/net_inaddr.cpp index 45af70628..1617bf3a3 100644 --- a/llarp/net/net_inaddr.cpp +++ b/llarp/net/net_inaddr.cpp @@ -32,7 +32,7 @@ namespace llarp this->reset(); // maybe refactor the family detection out - struct addrinfo hint, *res = NULL; + struct addrinfo hint, *res = nullptr; int ret; memset(&hint, '\0', sizeof hint); @@ -40,7 +40,7 @@ namespace llarp hint.ai_family = PF_UNSPEC; hint.ai_flags = AI_NUMERICHOST; - ret = getaddrinfo(str, NULL, &hint, &res); + ret = getaddrinfo(str, nullptr, &hint, &res); if(ret) { llarp::LogError("failed to determine address family: ", str); diff --git a/llarp/net/net_int.hpp b/llarp/net/net_int.hpp index 5a64093ce..5421abc4d 100644 --- a/llarp/net/net_int.hpp +++ b/llarp/net/net_int.hpp @@ -14,7 +14,7 @@ #include -#include // for itoa +#include // for itoa #include #include #include diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 9d7134258..9490f37e7 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -12,12 +12,13 @@ #include #include +#include static const char skiplist_subdirs[] = "0123456789abcdef"; static const std::string RC_FILE_EXT = ".signed"; -llarp_nodedb::NetDBEntry::NetDBEntry(const llarp::RouterContact &value) - : rc(value), inserted(llarp::time_now_ms()) +llarp_nodedb::NetDBEntry::NetDBEntry(llarp::RouterContact value) + : rc(std::move(value)), inserted(llarp::time_now_ms()) { } @@ -151,7 +152,7 @@ llarp_nodedb::UpdateAsyncIfNewer(llarp::RouterContact rc, InsertAsync(rc, logic, completionHandler); return true; } - else if(itr != entries.end()) + if(itr != entries.end()) { // insertion time is set on...insertion. But it should be updated here // even if there is no insertion of a new RC, to show that the existing one @@ -362,8 +363,7 @@ llarp_nodedb::Save() void logic_threadworker_callback(void *user) { - llarp_async_verify_rc *verify_request = - static_cast< llarp_async_verify_rc * >(user); + auto *verify_request = static_cast< llarp_async_verify_rc * >(user); if(verify_request->hook) verify_request->hook(verify_request); } @@ -382,8 +382,7 @@ disk_threadworker_setRC(llarp_async_verify_rc *verify_request) void crypto_threadworker_verifyrc(void *user) { - llarp_async_verify_rc *verify_request = - static_cast< llarp_async_verify_rc * >(user); + auto *verify_request = static_cast< llarp_async_verify_rc * >(user); llarp::RouterContact rc = verify_request->rc; verify_request->valid = rc.Verify(llarp::time_now_ms()); // if it's valid we need to set it @@ -404,14 +403,14 @@ crypto_threadworker_verifyrc(void *user) void nodedb_inform_load_rc(void *user) { - llarp_async_load_rc *job = static_cast< llarp_async_load_rc * >(user); + auto *job = static_cast< llarp_async_load_rc * >(user); job->hook(job); } void nodedb_async_load_rc(void *user) { - llarp_async_load_rc *job = static_cast< llarp_async_load_rc * >(user); + auto *job = static_cast< llarp_async_load_rc * >(user); auto fpath = job->nodedb->getRCFilePath(job->pubkey); job->loaded = job->nodedb->loadfile(fpath); diff --git a/llarp/nodedb.hpp b/llarp/nodedb.hpp index 29d29faa7..d88eda827 100644 --- a/llarp/nodedb.hpp +++ b/llarp/nodedb.hpp @@ -10,6 +10,7 @@ #include #include +#include #ifdef _MSC_VER #include @@ -45,7 +46,7 @@ struct llarp_nodedb_iter struct llarp_nodedb { explicit llarp_nodedb(std::shared_ptr< llarp::thread::ThreadPool > diskworker) - : disk(diskworker) + : disk(std::move(diskworker)) { } @@ -62,7 +63,7 @@ struct llarp_nodedb const llarp::RouterContact rc; llarp_time_t inserted; - NetDBEntry(const llarp::RouterContact &data); + NetDBEntry(llarp::RouterContact data); }; using NetDBMap_t = diff --git a/llarp/path/ihophandler.hpp b/llarp/path/ihophandler.hpp index f3a4e5685..ea672d74b 100644 --- a/llarp/path/ihophandler.hpp +++ b/llarp/path/ihophandler.hpp @@ -22,9 +22,7 @@ namespace llarp { struct IHopHandler { - virtual ~IHopHandler() - { - } + virtual ~IHopHandler() = default; virtual bool Expired(llarp_time_t now) const = 0; diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index c3585cff1..7b56876c2 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -215,7 +215,7 @@ namespace llarp m_PathSet->HandlePathBuildFailed(shared_from_this()); return; } - else if(st == ePathExpired && _status == ePathBuilding) + if(st == ePathExpired && _status == ePathBuilding) { _status = st; m_PathSet->HandlePathBuildTimeout(shared_from_this()); diff --git a/llarp/path/pathbuilder.hpp b/llarp/path/pathbuilder.hpp index fe49954f5..8e35f89d8 100644 --- a/llarp/path/pathbuilder.hpp +++ b/llarp/path/pathbuilder.hpp @@ -53,18 +53,18 @@ namespace llarp util::StatusObject ExtractStatus() const; - virtual bool + bool SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev, RouterContact& cur, size_t hop, PathRole roles) override; - virtual bool + bool ShouldBuildMore(llarp_time_t now) const override; /// should we bundle RCs in builds? virtual bool ShouldBundleRC() const = 0; - virtual void + void ResetInternalState() override; /// return true if we hit our soft limit for building paths too fast @@ -78,7 +78,7 @@ namespace llarp return ePathRoleAny; } - virtual bool + bool Stop() override; bool @@ -90,7 +90,7 @@ namespace llarp llarp_time_t Now() const override; - virtual void + void Tick(llarp_time_t now) override; void @@ -113,13 +113,13 @@ namespace llarp virtual const SecretKey& GetTunnelEncryptionSecretKey() const; - virtual void + void HandlePathBuilt(Path_ptr p) override; - virtual void + void HandlePathBuildTimeout(Path_ptr p) override; - virtual void + void HandlePathBuildFailed(Path_ptr p) override; }; diff --git a/llarp/path/transit_hop.cpp b/llarp/path/transit_hop.cpp index f2a1d3bc3..b9a46c24c 100644 --- a/llarp/path/transit_hop.cpp +++ b/llarp/path/transit_hop.cpp @@ -31,9 +31,7 @@ namespace llarp return stream; } - TransitHop::TransitHop() - { - } + TransitHop::TransitHop() = default; bool TransitHop::Expired(llarp_time_t now) const diff --git a/llarp/pow.cpp b/llarp/pow.cpp index d8f20cd35..11673ff43 100644 --- a/llarp/pow.cpp +++ b/llarp/pow.cpp @@ -7,9 +7,7 @@ namespace llarp { - PoW::~PoW() - { - } + PoW::~PoW() = default; bool PoW::DecodeKey(ABSL_ATTRIBUTE_UNUSED const llarp_buffer_t& k, diff --git a/llarp/router/outbound_message_handler.hpp b/llarp/router/outbound_message_handler.hpp index e793968bc..d64a7c905 100644 --- a/llarp/router/outbound_message_handler.hpp +++ b/llarp/router/outbound_message_handler.hpp @@ -22,7 +22,7 @@ namespace llarp struct OutboundMessageHandler final : public IOutboundMessageHandler { public: - ~OutboundMessageHandler() = default; + ~OutboundMessageHandler() override = default; bool QueueMessage(const RouterID &remote, const ILinkMessage *msg, diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index 923cb8327..cff9e81de 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace llarp { @@ -22,8 +23,8 @@ namespace llarp size_t attemptCount = 0; - PendingSession(const RouterContact &_rc, LinkLayer_ptr _link) - : rc(_rc), link(_link) + PendingSession(RouterContact _rc, LinkLayer_ptr _link) + : rc(std::move(_rc)), link(std::move(_link)) { } }; diff --git a/llarp/router/outbound_session_maker.hpp b/llarp/router/outbound_session_maker.hpp index 022695442..aaa898ae5 100644 --- a/llarp/router/outbound_session_maker.hpp +++ b/llarp/router/outbound_session_maker.hpp @@ -26,7 +26,7 @@ namespace llarp using CallbacksQueue = std::list< RouterCallback >; public: - ~OutboundSessionMaker() = default; + ~OutboundSessionMaker() override = default; bool OnSessionEstablished(ILinkSession *session) override; diff --git a/llarp/router/rc_lookup_handler.hpp b/llarp/router/rc_lookup_handler.hpp index fc35f9a5a..a94a60a1c 100644 --- a/llarp/router/rc_lookup_handler.hpp +++ b/llarp/router/rc_lookup_handler.hpp @@ -28,7 +28,7 @@ namespace llarp public: using CallbacksQueue = std::list< RCRequestCallback >; - ~RCLookupHandler() = default; + ~RCLookupHandler() override = default; void AddValidRouter(const RouterID &router) override LOCKS_EXCLUDED(_mutex); diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 686e44d1a..804ca049b 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -81,9 +82,9 @@ namespace llarp Router::Router(std::shared_ptr< llarp::thread::ThreadPool > _tp, llarp_ev_loop_ptr __netloop, std::shared_ptr< Logic > l) : ready(false) - , _netloop(__netloop) - , cryptoworker(_tp) - , _logic(l) + , _netloop(std::move(__netloop)) + , cryptoworker(std::move(_tp)) + , _logic(std::move(l)) , paths(this) , _exitContext(this) , disk(std::make_shared< llarp::thread::ThreadPool >(1, 1000, @@ -288,7 +289,7 @@ namespace llarp { if(left) return; - Router *self = static_cast< Router * >(user); + auto *self = static_cast< Router * >(user); self->ticker_job_id = 0; self->Tick(); self->ScheduleTicker(orig); @@ -965,14 +966,14 @@ namespace llarp static void RouterAfterStopLinks(void *u, uint64_t, uint64_t) { - Router *self = static_cast< Router * >(u); + auto *self = static_cast< Router * >(u); self->Close(); } static void RouterAfterStopIssued(void *u, uint64_t, uint64_t) { - Router *self = static_cast< Router * >(u); + auto *self = static_cast< Router * >(u); self->StopLinks(); self->nodedb()->AsyncFlushToDisk(); self->_logic->call_later({200, self, &RouterAfterStopLinks}); diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 2b6b2df86..90f057970 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -297,7 +297,7 @@ namespace llarp Router(std::shared_ptr< llarp::thread::ThreadPool > worker, llarp_ev_loop_ptr __netloop, std::shared_ptr< Logic > logic); - ~Router(); + ~Router() override; bool HandleRecvLinkMessageBuffer(ILinkSession *from, diff --git a/llarp/routing/dht_message.hpp b/llarp/routing/dht_message.hpp index ae249401d..24534087b 100644 --- a/llarp/routing/dht_message.hpp +++ b/llarp/routing/dht_message.hpp @@ -15,7 +15,7 @@ namespace llarp std::vector< llarp::dht::IMessage::Ptr_t > M; uint64_t V = 0; - ~DHTMessage() = default; + ~DHTMessage() override = default; bool DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override; diff --git a/llarp/routing/message.hpp b/llarp/routing/message.hpp index e42909b5f..89cda76c7 100644 --- a/llarp/routing/message.hpp +++ b/llarp/routing/message.hpp @@ -15,16 +15,12 @@ namespace llarp struct IMessage { PathID_t from; - uint64_t S; + uint64_t S{0}; uint64_t version = LLARP_PROTO_VERSION; - IMessage() : S(0) - { - } + IMessage() = default; - virtual ~IMessage() - { - } + virtual ~IMessage() = default; virtual bool BEncode(llarp_buffer_t* buf) const = 0; diff --git a/llarp/routing/message_parser.cpp b/llarp/routing/message_parser.cpp index af90db319..b1173b29b 100644 --- a/llarp/routing/message_parser.cpp +++ b/llarp/routing/message_parser.cpp @@ -31,16 +31,11 @@ namespace llarp }; InboundMessageParser::InboundMessageParser() - : firstKey(false) - , ourKey('\0') - , msg(nullptr) - , m_Holder(std::make_unique< MessageHolder >()) + : m_Holder(std::make_unique< MessageHolder >()) { } - InboundMessageParser::~InboundMessageParser() - { - } + InboundMessageParser::~InboundMessageParser() = default; bool InboundMessageParser::operator()(llarp_buffer_t* buffer, diff --git a/llarp/routing/message_parser.hpp b/llarp/routing/message_parser.hpp index 5c0d7f78d..7353ce470 100644 --- a/llarp/routing/message_parser.hpp +++ b/llarp/routing/message_parser.hpp @@ -29,12 +29,12 @@ namespace llarp operator()(llarp_buffer_t* buffer, llarp_buffer_t* key); private: - bool firstKey; - char ourKey; + bool firstKey{false}; + char ourKey{'\0'}; struct MessageHolder; - IMessage* msg; + IMessage* msg{nullptr}; std::unique_ptr< MessageHolder > m_Holder; }; } // namespace routing diff --git a/llarp/routing/path_confirm_message.hpp b/llarp/routing/path_confirm_message.hpp index 7cfc008f6..58b3e5b80 100644 --- a/llarp/routing/path_confirm_message.hpp +++ b/llarp/routing/path_confirm_message.hpp @@ -14,7 +14,7 @@ namespace llarp PathConfirmMessage() = default; PathConfirmMessage(uint64_t lifetime); - ~PathConfirmMessage() = default; + ~PathConfirmMessage() override = default; bool BEncode(llarp_buffer_t* buf) const override; diff --git a/llarp/routing/path_latency_message.cpp b/llarp/routing/path_latency_message.cpp index 5d8d51a08..906f36497 100644 --- a/llarp/routing/path_latency_message.cpp +++ b/llarp/routing/path_latency_message.cpp @@ -7,9 +7,7 @@ namespace llarp { namespace routing { - PathLatencyMessage::PathLatencyMessage() - { - } + PathLatencyMessage::PathLatencyMessage() = default; bool PathLatencyMessage::DecodeKey(const llarp_buffer_t& key, diff --git a/llarp/routing/path_transfer_message.hpp b/llarp/routing/path_transfer_message.hpp index f0d9332f4..4dbcd56ef 100644 --- a/llarp/routing/path_transfer_message.hpp +++ b/llarp/routing/path_transfer_message.hpp @@ -22,7 +22,7 @@ namespace llarp { Y.Randomize(); } - ~PathTransferMessage() = default; + ~PathTransferMessage() override = default; bool DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override; diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index 8ae892ea1..8760aeece 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace llarp { @@ -22,15 +23,13 @@ namespace llarp { } - ~CallerHandler() - { - } + ~CallerHandler() override = default; virtual bool HandleJSONResult(const nlohmann::json& val) = 0; bool - HandleResponse(::abyss::http::RPC_Response response) + HandleResponse(::abyss::http::RPC_Response response) override { if(!response.is_object()) { @@ -50,7 +49,7 @@ namespace llarp } void - PopulateReqHeaders(abyss::http::Headers_t& hdr); + PopulateReqHeaders(abyss::http::Headers_t& hdr) override; }; struct GetServiceNodeListHandler final : public CallerHandler @@ -58,14 +57,12 @@ namespace llarp using PubkeyList_t = std::vector< RouterID >; using Callback_t = std::function< void(const PubkeyList_t&, bool) >; - ~GetServiceNodeListHandler() - { - } + ~GetServiceNodeListHandler() override = default; Callback_t handler; GetServiceNodeListHandler(::abyss::http::ConnImpl* impl, CallerImpl* parent, Callback_t h) - : CallerHandler(impl, parent), handler(h) + : CallerHandler(impl, parent), handler(std::move(h)) { } @@ -178,9 +175,7 @@ namespace llarp LogError("service node list not updated"); } - ~CallerImpl() - { - } + ~CallerImpl() = default; }; void @@ -197,9 +192,7 @@ namespace llarp { } - ~Handler() - { - } + ~Handler() override = default; Response DumpState() const @@ -269,7 +262,7 @@ namespace llarp absl::optional< Response > HandleJSONRPC(Method_t method, - __attribute__((unused)) const Params& params) + ABSL_ATTRIBUTE_UNUSED const Params& params) override { if(method == "llarp.admin.link.neighboors") { @@ -283,7 +276,7 @@ namespace llarp { return DumpState(); } - else if(method == "llarp.admin.status") + if(method == "llarp.admin.status") { return DumpStatus(); } @@ -299,7 +292,7 @@ namespace llarp } AbstractRouter* router; ::abyss::httpd::IRPCHandler* - CreateHandler(::abyss::httpd::ConnImpl* conn) + CreateHandler(::abyss::httpd::ConnImpl* conn) override { return new Handler(conn, router); } @@ -314,9 +307,7 @@ namespace llarp { } - ~ServerImpl() - { - } + ~ServerImpl() = default; void Stop() @@ -349,9 +340,7 @@ namespace llarp { } - Caller::~Caller() - { - } + Caller::~Caller() = default; void Caller::Stop() @@ -382,9 +371,7 @@ namespace llarp { } - Server::~Server() - { - } + Server::~Server() = default; void Server::Stop() diff --git a/llarp/service/async_key_exchange.cpp b/llarp/service/async_key_exchange.cpp index a788e24e3..660277c95 100644 --- a/llarp/service/async_key_exchange.cpp +++ b/llarp/service/async_key_exchange.cpp @@ -4,20 +4,18 @@ #include #include #include +#include namespace llarp { namespace service { - AsyncKeyExchange::AsyncKeyExchange(std::shared_ptr< Logic > l, - const ServiceInfo& r, - const Identity& localident, - const PQPubKey& introsetPubKey, - const Introduction& remote, - IDataHandler* h, const ConvoTag& t, - ProtocolType proto) - : logic(l) - , m_remote(r) + AsyncKeyExchange::AsyncKeyExchange( + std::shared_ptr< Logic > l, ServiceInfo r, const Identity& localident, + const PQPubKey& introsetPubKey, const Introduction& remote, + IDataHandler* h, const ConvoTag& t, ProtocolType proto) + : logic(std::move(l)) + , m_remote(std::move(r)) , m_LocalIdentity(localident) , introPubKey(introsetPubKey) , remoteIntro(remote) @@ -30,7 +28,7 @@ namespace llarp void AsyncKeyExchange::Result(void* user) { - AsyncKeyExchange* self = static_cast< AsyncKeyExchange* >(user); + auto* self = static_cast< AsyncKeyExchange* >(user); // put values self->handler->PutSenderFor(self->msg.tag, self->m_remote, false); self->handler->PutCachedSessionKeyFor(self->msg.tag, self->sharedKey); @@ -43,7 +41,7 @@ namespace llarp void AsyncKeyExchange::Encrypt(void* user) { - AsyncKeyExchange* self = static_cast< AsyncKeyExchange* >(user); + auto* self = static_cast< AsyncKeyExchange* >(user); // derive ntru session key component SharedSecret K; auto crypto = CryptoManager::instance(); diff --git a/llarp/service/async_key_exchange.hpp b/llarp/service/async_key_exchange.hpp index a555632f4..358481b23 100644 --- a/llarp/service/async_key_exchange.hpp +++ b/llarp/service/async_key_exchange.hpp @@ -26,7 +26,7 @@ namespace llarp IDataHandler* handler; ConvoTag tag; - AsyncKeyExchange(std::shared_ptr< Logic > l, const ServiceInfo& r, + AsyncKeyExchange(std::shared_ptr< Logic > l, ServiceInfo r, const Identity& localident, const PQPubKey& introsetPubKey, const Introduction& remote, IDataHandler* h, diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index ca1e3e420..6afaa75a5 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -49,9 +49,7 @@ namespace llarp { } - Context::~Context() - { - } + Context::~Context() = default; bool Context::StopAll() diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index f00fb9e9d..c8ff71eef 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace llarp { @@ -138,18 +139,17 @@ namespace llarp addr = itr->second.remote.Addr(); return true; } - else + + for(const auto& item : m_state->m_SNodeSessions) { - for(const auto& item : m_state->m_SNodeSessions) + if(item.second.second == tag) { - if(item.second.second == tag) - { - snode = true; - addr = item.first; - return true; - } + snode = true; + addr = item.first; + return true; } } + return false; } @@ -497,16 +497,15 @@ namespace llarp { IntroSet m_IntroSet; Endpoint* m_Endpoint; - PublishIntroSetJob(Endpoint* parent, uint64_t id, - const IntroSet& introset) + PublishIntroSetJob(Endpoint* parent, uint64_t id, IntroSet introset) : IServiceLookup(parent, id, "PublishIntroSet") - , m_IntroSet(introset) + , m_IntroSet(std::move(introset)) , m_Endpoint(parent) { } std::shared_ptr< routing::IMessage > - BuildRequestMessage() + BuildRequestMessage() override { auto msg = std::make_shared< routing::DHTMessage >(); msg->M.emplace_back( @@ -515,7 +514,7 @@ namespace llarp } bool - HandleResponse(const std::set< IntroSet >& response) + HandleResponse(const std::set< IntroSet >& response) override { if(response.size()) m_Endpoint->IntroSetPublished(); @@ -698,11 +697,11 @@ namespace llarp { if(msg->R.size()) { - llarp_async_verify_rc* job = new llarp_async_verify_rc; - job->nodedb = Router()->nodedb(); - job->cryptoworker = Router()->threadpool(); - job->diskworker = Router()->diskworker(); - job->logic = Router()->logic(); + auto* job = new llarp_async_verify_rc; + job->nodedb = Router()->nodedb(); + job->cryptoworker = Router()->threadpool(); + job->diskworker = Router()->diskworker(); + job->logic = Router()->logic(); job->hook = std::bind(&Endpoint::HandleVerifyGotRouter, this, msg, std::placeholders::_1); job->rc = msg->R[0]; diff --git a/llarp/service/endpoint.hpp b/llarp/service/endpoint.hpp index d895e900a..b40dfc345 100644 --- a/llarp/service/endpoint.hpp +++ b/llarp/service/endpoint.hpp @@ -71,7 +71,7 @@ namespace llarp static const size_t MAX_OUTBOUND_CONTEXT_COUNT = 4; Endpoint(const std::string& nickname, AbstractRouter* r, Context* parent); - ~Endpoint(); + ~Endpoint() override; /// return true if we are ready to recv packets from the void bool @@ -94,7 +94,7 @@ namespace llarp virtual bool SetOption(const std::string& k, const std::string& v); - virtual void + void Tick(llarp_time_t now) override; /// return true if we have a resolvable ip address @@ -111,7 +111,7 @@ namespace llarp return {0}; } - virtual void + void ResetInternalState() override; /// router's logic @@ -142,7 +142,7 @@ namespace llarp virtual bool Start(); - virtual std::string + std::string Name() const override; bool @@ -335,7 +335,7 @@ namespace llarp uint64_t GetSeqNoForConvo(const ConvoTag& tag); - virtual bool + bool SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev, RouterContact& cur, size_t hop, path::PathRole roles) override; diff --git a/llarp/service/hidden_service_address_lookup.cpp b/llarp/service/hidden_service_address_lookup.cpp index dd9340f7a..fda8cba45 100644 --- a/llarp/service/hidden_service_address_lookup.cpp +++ b/llarp/service/hidden_service_address_lookup.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace llarp { @@ -11,7 +12,7 @@ namespace llarp HandlerFunc h, const Address& addr, uint64_t tx) - : IServiceLookup(p, tx, "HSLookup"), remote(addr), handle(h) + : IServiceLookup(p, tx, "HSLookup"), remote(addr), handle(std::move(h)) { } diff --git a/llarp/service/hidden_service_address_lookup.hpp b/llarp/service/hidden_service_address_lookup.hpp index 9fdccd472..86aaeee64 100644 --- a/llarp/service/hidden_service_address_lookup.hpp +++ b/llarp/service/hidden_service_address_lookup.hpp @@ -20,15 +20,13 @@ namespace llarp HiddenServiceAddressLookup(Endpoint* p, HandlerFunc h, const Address& addr, uint64_t tx); - ~HiddenServiceAddressLookup() - { - } + ~HiddenServiceAddressLookup() override = default; bool - HandleResponse(const std::set< IntroSet >& results); + HandleResponse(const std::set< IntroSet >& results) override; std::shared_ptr< routing::IMessage > - BuildRequestMessage(); + BuildRequestMessage() override; }; } // namespace service } // namespace llarp diff --git a/llarp/service/lookup.cpp b/llarp/service/lookup.cpp index 51f9cfbbf..e231615f5 100644 --- a/llarp/service/lookup.cpp +++ b/llarp/service/lookup.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace llarp { @@ -11,9 +12,8 @@ namespace llarp namespace service { - IServiceLookup::IServiceLookup(ILookupHolder *p, uint64_t tx, - const std::string &n) - : m_parent(p), txid(tx), name(n) + IServiceLookup::IServiceLookup(ILookupHolder *p, uint64_t tx, std::string n) + : m_parent(p), txid(tx), name(std::move(n)) { m_created = time_now_ms(); p->PutLookup(this, tx); diff --git a/llarp/service/lookup.hpp b/llarp/service/lookup.hpp index 25c2dba68..03ffb09e4 100644 --- a/llarp/service/lookup.hpp +++ b/llarp/service/lookup.hpp @@ -23,10 +23,8 @@ namespace llarp struct IServiceLookup { - IServiceLookup() = delete; - virtual ~IServiceLookup() - { - } + IServiceLookup() = delete; + virtual ~IServiceLookup() = default; /// handle lookup result virtual bool @@ -71,8 +69,7 @@ namespace llarp } protected: - IServiceLookup(ILookupHolder* parent, uint64_t tx, - const std::string& name); + IServiceLookup(ILookupHolder* parent, uint64_t tx, std::string name); llarp_time_t m_created; }; diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 53f630a21..f975c486c 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -66,9 +66,7 @@ namespace llarp } } - OutboundContext::~OutboundContext() - { - } + OutboundContext::~OutboundContext() = default; /// actually swap intros void diff --git a/llarp/service/outbound_context.hpp b/llarp/service/outbound_context.hpp index 6cffa1296..1f591540b 100644 --- a/llarp/service/outbound_context.hpp +++ b/llarp/service/outbound_context.hpp @@ -21,7 +21,7 @@ namespace llarp public std::enable_shared_from_this< OutboundContext > { OutboundContext(const IntroSet& introSet, Endpoint* parent); - ~OutboundContext(); + ~OutboundContext() override; util::StatusObject ExtractStatus() const; diff --git a/llarp/service/protocol.cpp b/llarp/service/protocol.cpp index 5c821d9a2..09fb02d82 100644 --- a/llarp/service/protocol.cpp +++ b/llarp/service/protocol.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace llarp { @@ -19,9 +20,7 @@ namespace llarp { } - ProtocolMessage::~ProtocolMessage() - { - } + ProtocolMessage::~ProtocolMessage() = default; void ProtocolMessage::PutBuffer(const llarp_buffer_t& buf) @@ -92,9 +91,7 @@ namespace llarp return bencode_end(buf); } - ProtocolFrame::~ProtocolFrame() - { - } + ProtocolFrame::~ProtocolFrame() = default; bool ProtocolFrame::BEncode(llarp_buffer_t* buf) const @@ -255,11 +252,10 @@ namespace llarp const Introduction fromIntro; AsyncFrameDecrypt(std::shared_ptr< Logic > l, const Identity& localIdent, - IDataHandler* h, - const std::shared_ptr< ProtocolMessage >& m, + IDataHandler* h, std::shared_ptr< ProtocolMessage > m, const ProtocolFrame& f, const Introduction& recvIntro) - : logic(l) - , msg(m) + : logic(std::move(l)) + , msg(std::move(m)) , m_LocalIdentity(localIdent) , handler(h) , frame(f) @@ -270,8 +266,8 @@ namespace llarp static void Work(void* user) { - AsyncFrameDecrypt* self = static_cast< AsyncFrameDecrypt* >(user); - auto crypto = CryptoManager::instance(); + auto* self = static_cast< AsyncFrameDecrypt* >(user); + auto crypto = CryptoManager::instance(); SharedSecret K; SharedSecret sharedKey; // copy diff --git a/llarp/service/protocol.hpp b/llarp/service/protocol.hpp index 80e5ed8e2..c26963986 100644 --- a/llarp/service/protocol.hpp +++ b/llarp/service/protocol.hpp @@ -104,7 +104,7 @@ namespace llarp Clear(); } - ~ProtocolFrame(); + ~ProtocolFrame() override; bool operator==(const ProtocolFrame& other) const; diff --git a/llarp/service/router_lookup_job.cpp b/llarp/service/router_lookup_job.cpp index 1b60d2cd4..395a6c1e3 100644 --- a/llarp/service/router_lookup_job.cpp +++ b/llarp/service/router_lookup_job.cpp @@ -1,13 +1,14 @@ #include #include +#include namespace llarp { namespace service { RouterLookupJob::RouterLookupJob(Endpoint* p, RouterLookupHandler h) - : handler(h), txid(p->GenTXID()), started(p->Now()) + : handler(std::move(h)), txid(p->GenTXID()), started(p->Now()) { } diff --git a/llarp/service/sendcontext.cpp b/llarp/service/sendcontext.cpp index a7ba5a088..e25647978 100644 --- a/llarp/service/sendcontext.cpp +++ b/llarp/service/sendcontext.cpp @@ -4,15 +4,15 @@ #include #include #include +#include namespace llarp { namespace service { - SendContext::SendContext(const ServiceInfo& ident, - const Introduction& intro, path::PathSet* send, - Endpoint* ep) - : remoteIdent(ident) + SendContext::SendContext(ServiceInfo ident, const Introduction& intro, + path::PathSet* send, Endpoint* ep) + : remoteIdent(std::move(ident)) , remoteIntro(intro) , m_PathSet(send) , m_DataHandler(ep) diff --git a/llarp/service/sendcontext.hpp b/llarp/service/sendcontext.hpp index d289c5640..9ca0cb8c0 100644 --- a/llarp/service/sendcontext.hpp +++ b/llarp/service/sendcontext.hpp @@ -20,7 +20,7 @@ namespace llarp struct SendContext { - SendContext(const ServiceInfo& ident, const Introduction& intro, + SendContext(ServiceInfo ident, const Introduction& intro, path::PathSet* send, Endpoint* ep); void diff --git a/llarp/service/tag_lookup_job.hpp b/llarp/service/tag_lookup_job.hpp index f061df504..0221e4e6b 100644 --- a/llarp/service/tag_lookup_job.hpp +++ b/llarp/service/tag_lookup_job.hpp @@ -28,9 +28,7 @@ namespace llarp { } - ~CachedTagResult() - { - } + ~CachedTagResult() = default; void Expire(llarp_time_t now); @@ -54,9 +52,7 @@ namespace llarp { TagLookupJob(Endpoint* parent, CachedTagResult* result); - ~TagLookupJob() - { - } + ~TagLookupJob() override = default; std::shared_ptr< routing::IMessage > BuildRequestMessage() override diff --git a/llarp/util/bencode.cpp b/llarp/util/bencode.cpp index b8b32b3ee..25e46238f 100644 --- a/llarp/util/bencode.cpp +++ b/llarp/util/bencode.cpp @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include bool bencode_read_integer(struct llarp_buffer_t* buffer, uint64_t* result) diff --git a/llarp/util/bencode.h b/llarp/util/bencode.h index 04fe12c8a..46284126d 100644 --- a/llarp/util/bencode.h +++ b/llarp/util/bencode.h @@ -6,8 +6,8 @@ #include #include -#include -#include + +#include /** * bencode.h diff --git a/llarp/util/buffer.cpp b/llarp/util/buffer.cpp index 8a0f0d9bc..aca4fa1ae 100644 --- a/llarp/util/buffer.cpp +++ b/llarp/util/buffer.cpp @@ -1,8 +1,8 @@ #include #include -#include -#include +#include +#include size_t llarp_buffer_t::size_left() const diff --git a/llarp/util/buffer.hpp b/llarp/util/buffer.hpp index e95e66d93..e9a635378 100644 --- a/llarp/util/buffer.hpp +++ b/llarp/util/buffer.hpp @@ -7,10 +7,10 @@ #include #include -#include -#include -#include -#include + +#include +#include +#include #include #include @@ -64,20 +64,18 @@ struct ManagedBuffer; struct llarp_buffer_t { /// starting memory address - byte_t *base; + byte_t *base{nullptr}; /// memory address of stream position - byte_t *cur; + byte_t *cur{nullptr}; /// max size of buffer - size_t sz; + size_t sz{0}; byte_t operator[](size_t x) { return *(this->base + x); } - llarp_buffer_t() : base(nullptr), cur(nullptr), sz(0) - { - } + llarp_buffer_t() = default; llarp_buffer_t(byte_t *b, byte_t *c, size_t s) : base(b), cur(c), sz(s) { diff --git a/llarp/util/codel.hpp b/llarp/util/codel.hpp index 02486ea50..2d9e5d0bd 100644 --- a/llarp/util/codel.hpp +++ b/llarp/util/codel.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace llarp { @@ -31,8 +32,11 @@ namespace llarp llarp_time_t initialIntervalMs = 100, size_t MaxSize = 1024 > struct CoDelQueue { - CoDelQueue(const std::string& name, const PutTime& put, const GetNow& now) - : m_QueueIdx(0), m_name(name), _putTime(put), _getNow(now) + CoDelQueue(std::string name, PutTime put, GetNow now) + : m_QueueIdx(0) + , m_name(std::move(name)) + , _putTime(std::move(put)) + , _getNow(std::move(now)) { } diff --git a/llarp/util/common.hpp b/llarp/util/common.hpp index 3ef490f75..4223ebf52 100644 --- a/llarp/util/common.hpp +++ b/llarp/util/common.hpp @@ -5,7 +5,7 @@ #else #define INLINE inline #endif -#include -#include -#include + +#include +#include #endif diff --git a/llarp/util/encode.hpp b/llarp/util/encode.hpp index dee452a89..472007f61 100644 --- a/llarp/util/encode.hpp +++ b/llarp/util/encode.hpp @@ -1,6 +1,6 @@ #ifndef LLARP_ENCODE_HPP #define LLARP_ENCODE_HPP -#include +#include #include #include #include diff --git a/llarp/util/endian.hpp b/llarp/util/endian.hpp index 087517348..60d0a4659 100644 --- a/llarp/util/endian.hpp +++ b/llarp/util/endian.hpp @@ -3,8 +3,8 @@ // adapted from libi2pd -#include -#include +#include +#include #include #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) diff --git a/llarp/util/file_logger.cpp b/llarp/util/file_logger.cpp index 4c335e854..0b0bcbf4e 100644 --- a/llarp/util/file_logger.cpp +++ b/llarp/util/file_logger.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace llarp { @@ -16,7 +17,7 @@ namespace llarp FileLogStream::FileLogStream(std::shared_ptr< thread::ThreadPool > disk, FILE *f, llarp_time_t flushInterval, bool closeFile) - : m_Disk(disk) + : m_Disk(std::move(disk)) , m_File(f) , m_FlushInterval(flushInterval) , m_Close(closeFile) diff --git a/llarp/util/file_logger.hpp b/llarp/util/file_logger.hpp index 6143e775b..463b987bf 100644 --- a/llarp/util/file_logger.hpp +++ b/llarp/util/file_logger.hpp @@ -15,7 +15,7 @@ namespace llarp FileLogStream(std::shared_ptr< thread::ThreadPool > disk, FILE* f, llarp_time_t flushInterval, bool closefile = true); - ~FileLogStream(); + ~FileLogStream() override; void PreLog(std::stringstream& out, LogLevel lvl, const char* fname, int lineno, diff --git a/llarp/util/json.cpp b/llarp/util/json.cpp index dadf9d47f..9c9358ca2 100644 --- a/llarp/util/json.cpp +++ b/llarp/util/json.cpp @@ -21,7 +21,7 @@ namespace llarp size_t m_Offset; bool - FeedData(const char* buf, size_t sz) + FeedData(const char* buf, size_t sz) override { if(m_Offset + sz > m_Buf.size() - 1) return false; @@ -32,7 +32,7 @@ namespace llarp } Result - Parse(nlohmann::json& obj) const + Parse(nlohmann::json& obj) const override { if(m_Offset < m_Buf.size() - 1) return eNeedData; diff --git a/llarp/util/json.hpp b/llarp/util/json.hpp index 0fdd4a3dc..a9b8b8571 100644 --- a/llarp/util/json.hpp +++ b/llarp/util/json.hpp @@ -16,9 +16,7 @@ namespace llarp struct IParser { - virtual ~IParser() - { - } + virtual ~IParser() = default; /// result from feeding data to parser enum Result diff --git a/llarp/util/mem.cpp b/llarp/util/mem.cpp index cb082353a..210c9a8c8 100644 --- a/llarp/util/mem.cpp +++ b/llarp/util/mem.cpp @@ -9,7 +9,7 @@ namespace llarp void Zero(void *ptr, size_t sz) { - uint8_t *p = (uint8_t *)ptr; + auto *p = (uint8_t *)ptr; while(sz--) { *p = 0; @@ -30,9 +30,9 @@ llarp_mem_slab(ABSL_ATTRIBUTE_UNUSED struct llarp_alloc *mem, bool llarp_eq(const void *a, const void *b, size_t sz) { - bool result = true; - const uint8_t *a_ptr = (const uint8_t *)a; - const uint8_t *b_ptr = (const uint8_t *)b; + bool result = true; + const auto *a_ptr = (const uint8_t *)a; + const auto *b_ptr = (const uint8_t *)b; while(sz--) { result &= a_ptr[sz] == b_ptr[sz]; diff --git a/llarp/util/mem.h b/llarp/util/mem.h index acc98855c..313837038 100644 --- a/llarp/util/mem.h +++ b/llarp/util/mem.h @@ -1,8 +1,8 @@ #ifndef LLARP_MEM_H_ #define LLARP_MEM_H_ -#include -#include -#include + +#include +#include /** constant time memcmp */ bool diff --git a/llarp/util/metrics_core.cpp b/llarp/util/metrics_core.cpp index 294bbb32b..e58b63dbc 100644 --- a/llarp/util/metrics_core.cpp +++ b/llarp/util/metrics_core.cpp @@ -135,7 +135,7 @@ namespace llarp void Registry::setFormat(const Id &id, const Format &format) { - Description *description = const_cast< Description * >(id.description()); + auto *description = const_cast< Description * >(id.description()); absl::WriterMutexLock l(&m_mutex); @@ -197,7 +197,7 @@ namespace llarp const SampleGroup< int > &intGroup, const absl::Time &timeStamp) { - SampleCache::iterator it = cache.find(publisher); + auto it = cache.find(publisher); if(it == cache.end()) { Sample sample; @@ -227,7 +227,7 @@ namespace llarp manager.m_intRepo.collect(category)); // Get the time since last reset, and clear if needed. - Manager::ResetTimes::iterator it = manager.m_resetTimes.find(category); + auto it = manager.m_resetTimes.find(category); if(it == manager.m_resetTimes.end()) { if(clear) @@ -435,11 +435,10 @@ namespace llarp thread::Scheduler::Handle m_handle GUARDED_BY(m_mutex); std::set< const Category * > m_categories GUARDED_BY(m_mutex); - bool m_default GUARDED_BY(m_mutex); + bool m_default GUARDED_BY(m_mutex){false}; std::set< const Category * > m_nonDefaultCategories GUARDED_BY(m_mutex); - PublisherSchedulerData() - : m_handle(thread::Scheduler::INVALID_HANDLE), m_default(false) + PublisherSchedulerData() : m_handle(thread::Scheduler::INVALID_HANDLE) { } }; @@ -656,7 +655,7 @@ namespace llarp util::Lock lock(&data->m_mutex); data->m_default = true; - Categories::iterator cIt = m_categories.begin(); + auto cIt = m_categories.begin(); for(; cIt != m_categories.end(); ++cIt) { if(cIt->second != interval) @@ -679,7 +678,7 @@ namespace llarp { util::Lock l(&m_mutex); - Categories::iterator it = m_categories.find(category); + auto it = m_categories.find(category); if(it == m_categories.end()) { // This category has no specific schedule. diff --git a/llarp/util/metrics_core.hpp b/llarp/util/metrics_core.hpp index 42eea9466..512fa18ac 100644 --- a/llarp/util/metrics_core.hpp +++ b/llarp/util/metrics_core.hpp @@ -8,6 +8,7 @@ #include #include +#include #include namespace llarp @@ -279,7 +280,7 @@ namespace llarp std::set< std::string > m_stringmem GUARDED_BY(m_mutex); CategoryMap m_categories GUARDED_BY(m_mutex); MetricMap m_metrics GUARDED_BY(m_mutex); - bool m_defaultEnabled GUARDED_BY(m_mutex); + bool m_defaultEnabled GUARDED_BY(m_mutex){true}; mutable util::Mutex m_mutex; // protects m_stringmem, m_categories, // m_metrics, m_defaultEnabled @@ -292,9 +293,7 @@ namespace llarp EXCLUSIVE_LOCKS_REQUIRED(m_mutex); public: - Registry() : m_defaultEnabled(true) - { - } + Registry() = default; Id add(string_view category, string_view name) LOCKS_EXCLUDED(m_mutex); @@ -348,12 +347,10 @@ namespace llarp DoubleRecords doubleRecords; IntRecords intRecords; - Records() - { - } + Records() = default; - Records(const DoubleRecords &d, const IntRecords &i) - : doubleRecords(d), intRecords(i) + Records(DoubleRecords d, IntRecords i) + : doubleRecords(std::move(d)), intRecords(std::move(i)) { } }; @@ -917,7 +914,7 @@ namespace llarp { manager = DefaultManager::manager(manager); return manager ? (manager->*repoFunc)().defaultCollector(category, name) - : 0; + : nullptr; } static Collector * diff --git a/llarp/util/metrics_types.hpp b/llarp/util/metrics_types.hpp index a5af9e7a6..6a9d9dfe6 100644 --- a/llarp/util/metrics_types.hpp +++ b/llarp/util/metrics_types.hpp @@ -51,12 +51,12 @@ namespace llarp struct FormatSpec { - float m_scale; + float m_scale{1.0}; string_view m_format; static constexpr char DEFAULT_FORMAT[] = "%f"; - constexpr FormatSpec() : m_scale(1.0), m_format(DEFAULT_FORMAT) + constexpr FormatSpec() : m_format(DEFAULT_FORMAT) { } @@ -272,12 +272,10 @@ namespace llarp /// order to make things like static initialisation cleaner. class Id { - const Description *m_description; + const Description *m_description{nullptr}; public: - constexpr Id() : m_description(nullptr) - { - } + constexpr Id() = default; constexpr Id(const Description *description) : m_description(description) { @@ -395,7 +393,7 @@ namespace llarp template < typename Type > class Record { - size_t m_count; + size_t m_count{0}; Type m_total; Type m_min; Type m_max; @@ -406,8 +404,7 @@ namespace llarp static constexpr Type DEFAULT_MAX() { return RecordMax::max(); }; // clang-format on - Record() - : m_count(0), m_total(0.0), m_min(DEFAULT_MIN()), m_max(DEFAULT_MAX()) + Record() : m_total(0.0), m_min(DEFAULT_MIN()), m_max(DEFAULT_MAX()) { } @@ -603,12 +600,12 @@ namespace llarp absl::Time m_sampleTime; std::vector< absl::variant< SampleGroup< double >, SampleGroup< int > > > m_samples; - size_t m_recordCount; + size_t m_recordCount{0}; public: using const_iterator = typename decltype(m_samples)::const_iterator; - Sample() : m_sampleTime(), m_recordCount(0) + Sample() : m_sampleTime() { } diff --git a/llarp/util/ostream_logger.hpp b/llarp/util/ostream_logger.hpp index cbcb9d9ac..f423d8cc4 100644 --- a/llarp/util/ostream_logger.hpp +++ b/llarp/util/ostream_logger.hpp @@ -10,18 +10,16 @@ namespace llarp { OStreamLogStream(std::ostream& out); - ~OStreamLogStream() - { - } + ~OStreamLogStream() override = default; - virtual void + void PreLog(std::stringstream& s, LogLevel lvl, const char* fname, int lineno, const std::string& nodename) const override; void Print(LogLevel lvl, const char* tag, const std::string& msg) override; - virtual void + void PostLog(std::stringstream& ss) const override; void Tick(llarp_time_t) override diff --git a/llarp/util/queue_manager.cpp b/llarp/util/queue_manager.cpp index e799ba668..bdec4b55e 100644 --- a/llarp/util/queue_manager.cpp +++ b/llarp/util/queue_manager.cpp @@ -226,7 +226,7 @@ namespace llarp uint32_t elemGen = decodeGenerationFromElementState(compare); - int32_t difference = static_cast< int32_t >(currGen - elemGen); + auto difference = static_cast< int32_t >(currGen - elemGen); if(difference == 1 || (difference == -static_cast< int32_t >(m_maxGeneration))) @@ -326,7 +326,7 @@ namespace llarp uint32_t elemGen = decodeGenerationFromElementState(compare); ElementState state = decodeStateFromElementState(compare); - int32_t difference = static_cast< int32_t >(currGen - elemGen); + auto difference = static_cast< int32_t >(currGen - elemGen); if(difference == 1 || (difference == -static_cast< int32_t >(m_maxGeneration))) @@ -455,9 +455,9 @@ namespace llarp assert(0 < circularDifference(endCombinedIndex, loadedCombinedIndex, m_maxCombinedIndex + 1)); - uint32_t currIdx = + auto currIdx = static_cast< uint32_t >(loadedCombinedIndex % m_capacity); - uint32_t currGen = + auto currGen = static_cast< uint32_t >(loadedCombinedIndex / m_capacity); // Try to swap this cell from Full to Reading. diff --git a/llarp/util/scheduler.cpp b/llarp/util/scheduler.cpp index 3c45c1878..0b56f4efc 100644 --- a/llarp/util/scheduler.cpp +++ b/llarp/util/scheduler.cpp @@ -1,4 +1,5 @@ #include +#include namespace llarp { @@ -152,9 +153,9 @@ namespace llarp } } - Scheduler::Scheduler(const EventDispatcher& dispatcher, const Clock& clock) - : m_clock(clock) - , m_dispatcher(dispatcher) + Scheduler::Scheduler(EventDispatcher dispatcher, Clock clock) + : m_clock(std::move(clock)) + , m_dispatcher(std::move(dispatcher)) , m_running(false) , m_iterationCount(0) , m_eventIt() diff --git a/llarp/util/scheduler.hpp b/llarp/util/scheduler.hpp index 7bcb9854f..970ecfda1 100644 --- a/llarp/util/scheduler.hpp +++ b/llarp/util/scheduler.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace llarp @@ -40,8 +41,8 @@ namespace llarp std::atomic_bool m_isCancelled; Handle m_handle; - RepeatData(const Callback& callback, absl::Duration period) - : m_callback(callback) + RepeatData(Callback callback, absl::Duration period) + : m_callback(std::move(callback)) , m_period(period) , m_isCancelled(false) , m_handle(0) @@ -133,7 +134,7 @@ namespace llarp { } - Scheduler(const EventDispatcher& dispatcher, const Clock& clock); + Scheduler(EventDispatcher dispatcher, Clock clock); ~Scheduler(); diff --git a/llarp/util/stopwatch.hpp b/llarp/util/stopwatch.hpp index cfc992793..25a772c22 100644 --- a/llarp/util/stopwatch.hpp +++ b/llarp/util/stopwatch.hpp @@ -14,9 +14,7 @@ namespace llarp absl::optional< absl::Time > m_stop; public: - Stopwatch() - { - } + Stopwatch() = default; void start() diff --git a/llarp/util/threading.hpp b/llarp/util/threading.hpp index fb3608171..05113a2b3 100644 --- a/llarp/util/threading.hpp +++ b/llarp/util/threading.hpp @@ -32,6 +32,7 @@ namespace llarp ~NullLock() UNLOCK_FUNCTION() { + (void)this; // trick clang-tidy } }; diff --git a/llarp/util/threadpool.h b/llarp/util/threadpool.h index 3a513d44e..bd1103ea4 100644 --- a/llarp/util/threadpool.h +++ b/llarp/util/threadpool.h @@ -25,7 +25,7 @@ struct llarp_threadpool } llarp_threadpool() - : jobs(new llarp::thread::Queue< std::function< void(void) > >(128)) + : jobs(new llarp::thread::Queue< std::function< void() > >(128)) , callingPID(llarp::util::GetPid()) { jobs->enable(); @@ -59,23 +59,21 @@ llarp_init_same_process_threadpool(); void llarp_free_threadpool(struct llarp_threadpool **tp); -typedef void (*llarp_thread_work_func)(void *); +using llarp_thread_work_func = void (*)(void *); /** job to be done in worker thread */ struct llarp_thread_job { /** user data to pass to work function */ - void *user; + void *user{nullptr}; /** called in threadpool worker thread */ - llarp_thread_work_func work; + llarp_thread_work_func work{nullptr}; #ifdef __cplusplus llarp_thread_job(void *u, llarp_thread_work_func w) : user(u), work(w) { } - llarp_thread_job() : user(nullptr), work(nullptr) - { - } + llarp_thread_job() = default; #endif }; diff --git a/llarp/util/timer.cpp b/llarp/util/timer.cpp index 08d8ae522..c9278b5af 100644 --- a/llarp/util/timer.cpp +++ b/llarp/util/timer.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace llarp { @@ -28,15 +29,13 @@ namespace llarp , called_at(0) , started(now) , timeout(ms) - , func(_func) + , func(std::move(_func)) , done(false) , canceled(false) { } - ~timer() - { - } + ~timer() = default; void exec(); @@ -75,9 +74,7 @@ struct llarp_timer_context uint32_t currentId = 0; bool _run = true; - ~llarp_timer_context() - { - } + ~llarp_timer_context() = default; bool run() diff --git a/llarp/util/timerqueue.hpp b/llarp/util/timerqueue.hpp index eb2e0fd9c..5dd283748 100644 --- a/llarp/util/timerqueue.hpp +++ b/llarp/util/timerqueue.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace llarp { @@ -55,7 +56,7 @@ namespace llarp private: struct Node { - int m_index; + int m_index{0}; absl::Time m_time; Key m_key; Node* m_prev; @@ -63,8 +64,7 @@ namespace llarp object::Buffer< Value > m_value; Node() - : m_index(0) - , m_time() + : m_time() , m_key(nullptr) , m_prev(nullptr) , m_next(nullptr) @@ -73,8 +73,7 @@ namespace llarp } explicit Node(const absl::Time& time) - : m_index(0) - , m_time(time) + : m_time(time) , m_key(nullptr) , m_prev(nullptr) , m_next(nullptr) @@ -311,9 +310,12 @@ namespace llarp { } - TimerQueueItem(absl::Time time, const Value& value, Handle handle, + TimerQueueItem(absl::Time time, Value value, Handle handle, const Key& key) - : m_time(time), m_value(value), m_handle(handle), m_key(key) + : m_time(time) + , m_value(std::move(value)) + , m_handle(handle) + , m_key(key) { } diff --git a/llarp/utp/inbound_message.hpp b/llarp/utp/inbound_message.hpp index e8d492425..0bcf69757 100644 --- a/llarp/utp/inbound_message.hpp +++ b/llarp/utp/inbound_message.hpp @@ -45,7 +45,7 @@ namespace llarp struct InboundMessage { /// timestamp of last activity - llarp_time_t lastActive; + llarp_time_t lastActive{0}; /// the underlying message buffer MessageBuffer _msg; @@ -63,7 +63,7 @@ namespace llarp bool AppendData(const byte_t* ptr, uint16_t sz); - InboundMessage() : lastActive(0), _msg(), buffer(_msg) + InboundMessage() : _msg(), buffer(_msg) { } diff --git a/llarp/utp/linklayer.cpp b/llarp/utp/linklayer.cpp index 81cd1bfde..b0b589fc5 100644 --- a/llarp/utp/linklayer.cpp +++ b/llarp/utp/linklayer.cpp @@ -18,7 +18,7 @@ #endif #include -#include +#include namespace llarp { @@ -27,9 +27,9 @@ namespace llarp uint64 LinkLayer::OnConnect(utp_callback_arguments* arg) { - LinkLayer* l = + auto* l = static_cast< LinkLayer* >(utp_context_get_userdata(arg->context)); - Session* session = static_cast< Session* >(utp_get_userdata(arg->socket)); + auto* session = static_cast< Session* >(utp_get_userdata(arg->socket)); if(session && l) session->OutboundLinkEstablished(l); return 0; @@ -38,7 +38,7 @@ namespace llarp uint64 LinkLayer::SendTo(utp_callback_arguments* arg) { - LinkLayer* l = + auto* l = static_cast< LinkLayer* >(utp_context_get_userdata(arg->context)); if(l == nullptr) return 0; @@ -49,9 +49,9 @@ namespace llarp uint64 LinkLayer::OnError(utp_callback_arguments* arg) { - Session* session = static_cast< Session* >(utp_get_userdata(arg->socket)); + auto* session = static_cast< Session* >(utp_get_userdata(arg->socket)); - LinkLayer* link = + auto* link = static_cast< LinkLayer* >(utp_context_get_userdata(arg->context)); if(session && link) @@ -270,7 +270,7 @@ namespace llarp uint64 LinkLayer::OnRead(utp_callback_arguments* arg) { - Session* self = static_cast< Session* >(utp_get_userdata(arg->socket)); + auto* self = static_cast< Session* >(utp_get_userdata(arg->socket)); if(self) { @@ -297,7 +297,7 @@ namespace llarp uint64 LinkLayer::OnStateChange(utp_callback_arguments* arg) { - Session* session = static_cast< Session* >(utp_get_userdata(arg->socket)); + auto* session = static_cast< Session* >(utp_get_userdata(arg->socket)); if(session) { if(arg->state == UTP_STATE_WRITABLE) @@ -316,7 +316,7 @@ namespace llarp uint64 LinkLayer::OnAccept(utp_callback_arguments* arg) { - LinkLayer* self = + auto* self = static_cast< LinkLayer* >(utp_context_get_userdata(arg->context)); Addr remote(*arg->address); diff --git a/llarp/utp/linklayer.hpp b/llarp/utp/linklayer.hpp index 44c1d0f29..cb7f6929f 100644 --- a/llarp/utp/linklayer.hpp +++ b/llarp/utp/linklayer.hpp @@ -53,7 +53,7 @@ namespace llarp SessionClosedHandler closed, bool acceptInbound); /// destruct - ~LinkLayer(); + ~LinkLayer() override; /// get AI rank uint16_t diff --git a/llarp/utp/session.hpp b/llarp/utp/session.hpp index 0e5366457..20a07766d 100644 --- a/llarp/utp/session.hpp +++ b/llarp/utp/session.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -42,7 +43,7 @@ namespace llarp struct OutboundMessage { OutboundMessage(uint32_t id, CompletionHandler func) - : msgid{id}, completed{func} + : msgid{id}, completed{std::move(func)} { } @@ -110,7 +111,7 @@ namespace llarp util::StatusObject ExtractStatus() const override; - virtual ~Session() = 0; + ~Session() override = 0; /// base explicit Session(LinkLayer* p);