From 488695047fc3ce9244e3516a6b344878323ae317 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 6 Jul 2019 18:03:40 +0100 Subject: [PATCH] Remove redundant else blocks --- .clang-tidy | 2 + llarp/config/config.cpp | 4 +- llarp/context.cpp | 4 +- llarp/dht/message.cpp | 8 +- llarp/dht/messages/findintro.cpp | 139 ++++++++++++------------- llarp/dht/messages/findrouter.cpp | 4 +- llarp/dht/serviceaddresslookup.cpp | 6 +- llarp/dht/txholder.hpp | 6 +- llarp/dns/name.cpp | 4 +- llarp/dns/question.cpp | 4 +- llarp/dnsc.cpp | 2 +- llarp/dnsd.cpp | 6 +- llarp/ev/ev.cpp | 2 +- llarp/ev/ev.hpp | 6 +- llarp/ev/ev_win32.cpp | 4 + llarp/ev/ev_win32.hpp | 2 + llarp/exit/endpoint.cpp | 6 +- llarp/exit/session.cpp | 8 +- llarp/handlers/exit.cpp | 6 +- llarp/messages/link_intro.cpp | 4 +- llarp/metrics/metrictank_publisher.cpp | 6 +- llarp/net/net.cpp | 9 +- llarp/net/net_addr.cpp | 26 ++--- llarp/net/net_inaddr.cpp | 8 +- llarp/path/path.cpp | 18 ++-- llarp/path/pathset.cpp | 4 +- llarp/path/transit_hop.cpp | 22 ++-- llarp/router/router.cpp | 18 ++-- llarp/routing/dht_message.cpp | 4 +- llarp/routing/message_parser.cpp | 6 +- llarp/rpc/rpc.cpp | 12 +-- llarp/service/context.cpp | 10 +- llarp/service/endpoint.cpp | 23 ++-- llarp/service/identity.cpp | 4 +- llarp/service/intro_set.cpp | 2 +- llarp/service/outbound_context.cpp | 22 ++-- llarp/util/buffer.cpp | 8 +- llarp/util/codel.hpp | 8 +- llarp/util/compare_ptr.hpp | 6 +- llarp/util/metrics_core.cpp | 24 ++--- llarp/util/metrics_types.cpp | 8 +- llarp/util/metrics_types.hpp | 6 +- llarp/util/queue_manager.cpp | 8 +- llarp/util/str.cpp | 32 +++--- llarp/util/thread_pool.hpp | 6 +- llarp/util/threadpool.h | 4 +- 46 files changed, 243 insertions(+), 288 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..5d635f09e --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,2 @@ +HeaderFilterRegex: 'llarp/.*' +Checks: 'readability-else-after-return,clang-analyzer-core-*' diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index b57521cec..b71e67af3 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -367,8 +367,8 @@ namespace llarp if(c.VisitSection(name.c_str(), visitor)) return ret; - else - return {}; + + return {}; } bool diff --git a/llarp/context.cpp b/llarp/context.cpp index cce9a0d02..d906df66c 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -302,8 +302,8 @@ __ ___ ____ _ _ ___ _ _ ____ f << std::to_string(getpid()); return f.good(); } - else - return true; + + return true; } void diff --git a/llarp/dht/message.cpp b/llarp/dht/message.cpp index f33f580b8..7ca88c76e 100644 --- a/llarp/dht/message.cpp +++ b/llarp/dht/message.cpp @@ -79,8 +79,8 @@ namespace llarp firstKey = false; return msg != nullptr; } - else - return msg->DecodeKey(*key, buffer); + + return msg->DecodeKey(*key, buffer); } }; @@ -117,8 +117,8 @@ namespace llarp l.emplace_back(std::move(msg)); return true; } - else - return false; + + return false; } }; diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index 86a498b36..8240385d6 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -98,105 +98,98 @@ namespace llarp replies.emplace_back(new GotIntroMessage({i}, T)); return true; } - else + + if(R == 0) { - if(R == 0) - { - // we don't have it - Key_t target = S.ToKey(); - Key_t closer; - // find closer peer - if(!dht.Nodes()->FindClosest(target, closer)) - return false; - if(relayed) - dht.LookupIntroSetForPath(S, T, pathID, closer); - else - replies.emplace_back(new GotIntroMessage(From, closer, T)); - return true; - } + // we don't have it + Key_t target = S.ToKey(); + Key_t closer; + // find closer peer + if(!dht.Nodes()->FindClosest(target, closer)) + return false; + if(relayed) + dht.LookupIntroSetForPath(S, T, pathID, closer); + else + replies.emplace_back(new GotIntroMessage(From, closer, T)); + return true; + } + + Key_t us = dht.OurKey(); + Key_t target = S.ToKey(); + // we are recursive + if(dht.Nodes()->FindCloseExcluding(target, peer, exclude)) + { + if(relayed) + dht.LookupIntroSetForPath(S, T, pathID, peer); else { - Key_t us = dht.OurKey(); - Key_t target = S.ToKey(); - // we are recursive - if(dht.Nodes()->FindCloseExcluding(target, peer, exclude)) - { - if(relayed) - dht.LookupIntroSetForPath(S, T, pathID, peer); - else - { - if((us ^ target) < (peer ^ target)) - { - // we are not closer than our peer to the target so don't - // recurse farther - replies.emplace_back(new GotIntroMessage({}, T)); - return true; - } - else if(R > 0) - dht.LookupIntroSetRecursive(S, From, T, peer, R - 1); - else - dht.LookupIntroSetIterative(S, From, T, peer); - } - return true; - } - else + if((us ^ target) < (peer ^ target)) { - // no more closer peers + // we are not closer than our peer to the target so don't + // recurse farther replies.emplace_back(new GotIntroMessage({}, T)); return true; } + if(R > 0) + dht.LookupIntroSetRecursive(S, From, T, peer, R - 1); + else + dht.LookupIntroSetIterative(S, From, T, peer); } + return true; + } + + // no more closer peers + replies.emplace_back(new GotIntroMessage({}, T)); + return true; + } + + if(relayed) + { + // tag lookup + if(dht.Nodes()->GetRandomNodeExcluding(peer, exclude)) + { + dht.LookupTagForPath(N, T, pathID, peer); + } + else + { + // no more closer peers + replies.emplace_back(new GotIntroMessage({}, T)); + return true; } } else { - if(relayed) + if(R == 0) + { + // base case + auto introsets = dht.FindRandomIntroSetsWithTagExcluding(N, 2, {}); + std::vector< service::IntroSet > reply; + for(const auto& introset : introsets) + { + reply.push_back(introset); + } + replies.emplace_back(new GotIntroMessage(reply, T)); + return true; + } + if(R < 5) { // tag lookup if(dht.Nodes()->GetRandomNodeExcluding(peer, exclude)) { - dht.LookupTagForPath(N, T, pathID, peer); + dht.LookupTagRecursive(N, From, T, peer, R - 1); } else { - // no more closer peers replies.emplace_back(new GotIntroMessage({}, T)); - return true; } } else { - if(R == 0) - { - // base case - auto introsets = dht.FindRandomIntroSetsWithTagExcluding(N, 2, {}); - std::vector< service::IntroSet > reply; - for(const auto& introset : introsets) - { - reply.push_back(introset); - } - replies.emplace_back(new GotIntroMessage(reply, T)); - return true; - } - else if(R < 5) - { - // tag lookup - if(dht.Nodes()->GetRandomNodeExcluding(peer, exclude)) - { - dht.LookupTagRecursive(N, From, T, peer, R - 1); - } - else - { - replies.emplace_back(new GotIntroMessage({}, T)); - } - } - else - { - // too big R value - replies.emplace_back(new GotIntroMessage({}, T)); - } + // too big R value + replies.emplace_back(new GotIntroMessage({}, T)); } } + return true; } } // namespace dht diff --git a/llarp/dht/messages/findrouter.cpp b/llarp/dht/messages/findrouter.cpp index b2774b359..2c2c31fde 100644 --- a/llarp/dht/messages/findrouter.cpp +++ b/llarp/dht/messages/findrouter.cpp @@ -172,13 +172,13 @@ namespace llarp Key_t k{K}; if(exploritory) return dht.HandleExploritoryRouterLookup(From, txid, K, replies); - else if(!dht.GetRouter()->ConnectionToRouterAllowed(K)) + if(!dht.GetRouter()->ConnectionToRouterAllowed(K)) { // explicitly disallowed by network replies.emplace_back(new GotRouterMessage(k, txid, {}, false)); return true; } - else if(dht.Nodes()->HasNode(k)) + if(dht.Nodes()->HasNode(k)) { found = dht.Nodes()->nodes[k].rc; replies.emplace_back(new GotRouterMessage(k, txid, {found}, false)); diff --git a/llarp/dht/serviceaddresslookup.cpp b/llarp/dht/serviceaddresslookup.cpp index e83f0d811..99f358a1d 100644 --- a/llarp/dht/serviceaddresslookup.cpp +++ b/llarp/dht/serviceaddresslookup.cpp @@ -45,10 +45,8 @@ namespace llarp { return nodes->FindCloseExcluding(k, next, exclude); } - else - { - return false; - } + + return false; } void diff --git a/llarp/dht/txholder.hpp b/llarp/dht/txholder.hpp index 8226d958a..3f57f465d 100644 --- a/llarp/dht/txholder.hpp +++ b/llarp/dht/txholder.hpp @@ -105,10 +105,8 @@ namespace llarp { return nullptr; } - else - { - return itr->second.get(); - } + + return itr->second.get(); } template < typename K, typename V, typename K_Hash, diff --git a/llarp/dns/name.cpp b/llarp/dns/name.cpp index 424eb7009..7b7ad4c5b 100644 --- a/llarp/dns/name.cpp +++ b/llarp/dns/name.cpp @@ -99,8 +99,8 @@ namespace llarp ip = llarp::ipaddr_ipv4_bits(a, b, c, d); return true; } - else - return false; + + return false; } } // namespace dns diff --git a/llarp/dns/question.cpp b/llarp/dns/question.cpp index 7dafe723f..e4db7a303 100644 --- a/llarp/dns/question.cpp +++ b/llarp/dns/question.cpp @@ -55,8 +55,8 @@ namespace llarp // does other have a . at the end? if(other.find_last_of('.') == (other.size() - 1)) return other == qname; - else // no, add it and retry - return IsName(other + "."); + // no, add it and retry + return IsName(other + "."); } std::string diff --git a/llarp/dnsc.cpp b/llarp/dnsc.cpp index 43f33ecb4..3e1034849 100644 --- a/llarp/dnsc.cpp +++ b/llarp/dnsc.cpp @@ -400,7 +400,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, request->resolved(request); return; } - else if(rcode == 3) + if(rcode == 3) { llarp::LogWarn("nameserver ", upstreamAddr, " returned NXDOMAIN for: ", request->question.name); diff --git a/llarp/dnsd.cpp b/llarp/dnsd.cpp index 691b28951..813c98cde 100644 --- a/llarp/dnsd.cpp +++ b/llarp/dnsd.cpp @@ -608,8 +608,6 @@ llarp_dnsd_init(struct dnsd_context *const dnsd, llarp::Logic *const logic, (const sockaddr *)dnsd_sockaddr) != -1; } - else - { - return true; - } + + return true; } diff --git a/llarp/ev/ev.cpp b/llarp/ev/ev.cpp index 0a09180af..bf70e6e5f 100644 --- a/llarp/ev/ev.cpp +++ b/llarp/ev/ev.cpp @@ -256,7 +256,7 @@ namespace llarp ::shutdown(fd, SHUT_RDWR); return false; } - else if(tcp.tick) + if(tcp.tick) tcp.tick(&tcp); return true; } diff --git a/llarp/ev/ev.hpp b/llarp/ev/ev.hpp index d5e22d8fa..a6492c610 100644 --- a/llarp/ev/ev.hpp +++ b/llarp/ev/ev.hpp @@ -407,13 +407,13 @@ namespace llarp m_LossyWriteQueue->Emplace(buf, sz); return true; } - else if(m_BlockingWriteQueue) + if(m_BlockingWriteQueue) { m_BlockingWriteQueue->emplace_back(buf, sz); return true; } - else - return false; + + return false; } virtual void diff --git a/llarp/ev/ev_win32.cpp b/llarp/ev/ev_win32.cpp index 2b406170e..1b1567297 100644 --- a/llarp/ev/ev_win32.cpp +++ b/llarp/ev/ev_win32.cpp @@ -1,5 +1,7 @@ #include +#ifdef _WIN32 + // a single event queue for the TUN interface static HANDLE tun_event_queue = INVALID_HANDLE_VALUE; @@ -683,3 +685,5 @@ llarp_win32_loop::stop() upollfd = nullptr; llarp::LogDebug("destroy upoll"); } + +#endif diff --git a/llarp/ev/ev_win32.hpp b/llarp/ev/ev_win32.hpp index df4dcc915..d09712b7b 100644 --- a/llarp/ev/ev_win32.hpp +++ b/llarp/ev/ev_win32.hpp @@ -1,5 +1,6 @@ #ifndef EV_WIN32_H #define EV_WIN32_H +#ifdef _WIN32 #include #include #include @@ -151,3 +152,4 @@ struct llarp_win32_loop : public llarp_ev_loop }; #endif +#endif diff --git a/llarp/exit/endpoint.cpp b/llarp/exit/endpoint.cpp index 4ac7b40ba..7c1db573c 100644 --- a/llarp/exit/endpoint.cpp +++ b/llarp/exit/endpoint.cpp @@ -98,7 +98,7 @@ namespace llarp auto lastPing = path->LastRemoteActivityAt(); if(lastPing == 0 || (now > lastPing && now - lastPing > timeout)) return now > m_LastActive && now - m_LastActive > timeout; - else if(lastPing) + if(lastPing) return now > lastPing && now - lastPing > timeout; return lastPing > 0; } @@ -155,8 +155,8 @@ namespace llarp queue.emplace_back(); return queue.back().PutBuffer(pktbuf, m_Counter++); } - else - return msg.PutBuffer(pktbuf, m_Counter++); + + return msg.PutBuffer(pktbuf, m_Counter++); } bool diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index e6825d63e..57ef30c6c 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -85,8 +85,8 @@ namespace llarp router->LookupRouter(m_ExitRouter, nullptr); return false; } - else - return path::Builder::SelectHop(db, exclude, cur, hop, roles); + + return path::Builder::SelectHop(db, exclude, cur, hop, roles); } bool @@ -242,8 +242,8 @@ namespace llarp queue.emplace_back(); return queue.back().PutBuffer(buf, m_Counter++); } - else - return back.PutBuffer(buf, m_Counter++); + + return back.PutBuffer(buf, m_Counter++); } bool diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index ad688d940..f37fe8227 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -71,9 +71,9 @@ namespace llarp return false; return m_OurRange.Contains(ip); } - else if(msg.questions[0].qtype == dns::qTypeA - || msg.questions[0].qtype == dns::qTypeCNAME - || msg.questions[0].qtype == dns::qTypeAAAA) + if(msg.questions[0].qtype == dns::qTypeA + || msg.questions[0].qtype == dns::qTypeCNAME + || msg.questions[0].qtype == dns::qTypeAAAA) { if(msg.questions[0].IsName("localhost.loki")) return true; diff --git a/llarp/messages/link_intro.cpp b/llarp/messages/link_intro.cpp index dbf091120..b414d95d4 100644 --- a/llarp/messages/link_intro.cpp +++ b/llarp/messages/link_intro.cpp @@ -20,14 +20,14 @@ namespace llarp return false; return *strbuf.cur == 'i'; } - else if(key == "n") + if(key == "n") { if(N.BDecode(buf)) return true; llarp::LogWarn("failed to decode nonce in LIM"); return false; } - else if(key == "p") + if(key == "p") { return bencode_read_integer(buf, &P); } diff --git a/llarp/metrics/metrictank_publisher.cpp b/llarp/metrics/metrictank_publisher.cpp index 23a0c6bcb..1f76c770b 100644 --- a/llarp/metrics/metrictank_publisher.cpp +++ b/llarp/metrics/metrictank_publisher.cpp @@ -38,10 +38,8 @@ namespace llarp { return {}; } - else - { - return std::to_string(d); - } + + return std::to_string(d); } absl::optional< std::string > diff --git a/llarp/net/net.cpp b/llarp/net/net.cpp index fd8792f3c..6e50a52e6 100644 --- a/llarp/net/net.cpp +++ b/llarp/net/net.cpp @@ -973,7 +973,7 @@ namespace llarp result = addr; return true; } - else if(af == AF_INET6) + if(af == AF_INET6) { sockaddr_in6 addr6; addr6.sin6_family = AF_INET6; @@ -982,10 +982,9 @@ namespace llarp result = addr6; return true; } - else - { - // TODO: implement sockaddr_ll - } + + // TODO: implement sockaddr_ll + return false; } diff --git a/llarp/net/net_addr.cpp b/llarp/net/net_addr.cpp index ac33a7f33..ab6f48801 100644 --- a/llarp/net/net_addr.cpp +++ b/llarp/net/net_addr.cpp @@ -123,7 +123,7 @@ namespace llarp LogError("IPv6 address not supported yet", str); return false; } - else if(res->ai_family != AF_INET) + if(res->ai_family != AF_INET) { LogError("Address family not supported yet", str); return false; @@ -359,16 +359,16 @@ namespace llarp { if(af() == AF_INET) return (const sockaddr*)&_addr4; - else - return (const sockaddr*)&_addr; + + return (const sockaddr*)&_addr; } Addr::operator sockaddr*() const { if(af() == AF_INET) return (sockaddr*)&_addr4; - else - return (sockaddr*)&_addr; + + return (sockaddr*)&_addr; } bool @@ -376,9 +376,9 @@ namespace llarp { if(af() == AF_INET && other.af() == AF_INET) return port() < other.port() || addr4()->s_addr < other.addr4()->s_addr; - else - return port() < other.port() || *addr6() < *other.addr6() - || af() < other.af(); + + return port() < other.port() || *addr6() < *other.addr6() + || af() < other.af(); } bool @@ -386,9 +386,9 @@ namespace llarp { if(af() == AF_INET && other.af() == AF_INET) return port() == other.port() && addr4()->s_addr == other.addr4()->s_addr; - else - return af() == other.af() && memcmp(addr6(), other.addr6(), 16) == 0 - && port() == other.port(); + + return af() == other.af() && memcmp(addr6(), other.addr6(), 16) == 0 + && port() == other.port(); } Addr& @@ -471,8 +471,8 @@ namespace llarp { if(af() == AF_INET) return sizeof(sockaddr_in); - else - return sizeof(sockaddr_in6); + + return sizeof(sockaddr_in6); } bool diff --git a/llarp/net/net_inaddr.cpp b/llarp/net/net_inaddr.cpp index 3149de7cc..45af70628 100644 --- a/llarp/net/net_inaddr.cpp +++ b/llarp/net/net_inaddr.cpp @@ -84,11 +84,9 @@ namespace llarp llarp::LogWarn("Not in presentation format"); return false; } - else - { - llarp::LogWarn("inet_pton failure"); - return false; - } + + llarp::LogWarn("inet_pton failure"); + return false; } return true; } diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 4f93c6577..4d01e9a1d 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -272,10 +272,10 @@ namespace llarp { if(_status == ePathEstablished || _status == ePathTimeout) return now >= ExpireTime(); - else if(_status == ePathBuilding) + if(_status == ePathBuilding) return false; - else - return true; + + return true; } std::string @@ -435,11 +435,9 @@ namespace llarp LogDebug("path latency is now ", intro.latency, " for ", Name()); return true; } - else - { - LogWarn("unwarranted path latency message via ", Upstream()); - return false; - } + + LogWarn("unwarranted path latency message via ", Upstream()); + return false; } bool @@ -467,8 +465,8 @@ namespace llarp _role &= ~ePathRoleExit; return true; } - else - LogError(Name(), " CXM from exit with bad signature"); + + LogError(Name(), " CXM from exit with bad signature"); } else LogError(Name(), " unwarranted CXM"); diff --git a/llarp/path/pathset.cpp b/llarp/path/pathset.cpp index 62fbbb1a7..b7ab5fa2f 100644 --- a/llarp/path/pathset.cpp +++ b/llarp/path/pathset.cpp @@ -327,8 +327,8 @@ namespace llarp { return established[randint() % sz]; } - else - return nullptr; + + return nullptr; } } // namespace path diff --git a/llarp/path/transit_hop.cpp b/llarp/path/transit_hop.cpp index 8a8a82ff3..419a0ea0d 100644 --- a/llarp/path/transit_hop.cpp +++ b/llarp/path/transit_hop.cpp @@ -109,17 +109,15 @@ namespace llarp m_LastActivity = r->Now(); return r->ParseRoutingMessageBuffer(buf, this, info.rxID); } - else - { - RelayUpstreamMessage msg; - msg.pathid = info.txID; - msg.Y = Y ^ nonceXOR; - msg.X = buf; - llarp::LogDebug("relay ", msg.X.size(), " bytes upstream from ", - info.downstream, " to ", info.upstream); - return r->SendToOrQueue(info.upstream, &msg); - } + RelayUpstreamMessage msg; + msg.pathid = info.txID; + msg.Y = Y ^ nonceXOR; + + msg.X = buf; + llarp::LogDebug("relay ", msg.X.size(), " bytes upstream from ", + info.downstream, " to ", info.upstream); + return r->SendToOrQueue(info.upstream, &msg); } bool @@ -283,8 +281,8 @@ namespace llarp } return sent; } - else - llarp::LogError("No exit endpoint on ", info); + + llarp::LogError("No exit endpoint on ", info); // discarded llarp::routing::DataDiscardMessage discard(info.rxID, msg.S); return SendRoutingMessage(discard, r); diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 1a45e4861..c1405fe05 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -192,10 +192,8 @@ namespace llarp _logic->queue_func(std::bind(&on_try_connecting, job)); return true; } - else - { - itr.first->second->Attempt(); - } + + itr.first->second->Attempt(); } return false; } @@ -442,8 +440,8 @@ namespace llarp return false; if(usingSNSeed) return llarp_loadServiceNodeIdentityKey(ident_keyfile, _identity); - else - return llarp_findOrCreateIdentity(ident_keyfile, _identity); + + return llarp_findOrCreateIdentity(ident_keyfile, _identity); } bool @@ -601,10 +599,10 @@ namespace llarp { if(strictConnectPubkeys.size() && strictConnectPubkeys.count(router) == 0) return false; - else if(IsServiceNode() && whitelistRouters) + if(IsServiceNode() && whitelistRouters) return lokinetRouters.find(router) != lokinetRouters.end(); - else - return true; + + return true; } void @@ -1679,7 +1677,7 @@ namespace llarp LogInfo("Disabling default hidden service"); return false; } - else if(enabledOption == "auto") + if(enabledOption == "auto") { // auto detect if we have any pre-defined endpoints // no if we have a endpoints diff --git a/llarp/routing/dht_message.cpp b/llarp/routing/dht_message.cpp index 2c2543219..2d9a65acb 100644 --- a/llarp/routing/dht_message.cpp +++ b/llarp/routing/dht_message.cpp @@ -16,11 +16,11 @@ namespace llarp { return llarp::dht::DecodeMesssageList(from, val, M, true); } - else if(key == "S") + if(key == "S") { return bencode_read_integer(val, &S); } - else if(key == "V") + if(key == "V") { return bencode_read_integer(val, &V); } diff --git a/llarp/routing/message_parser.cpp b/llarp/routing/message_parser.cpp index 8825f14c5..af90db319 100644 --- a/llarp/routing/message_parser.cpp +++ b/llarp/routing/message_parser.cpp @@ -108,10 +108,8 @@ namespace llarp firstKey = false; return msg != nullptr; } - else - { - return msg->DecodeKey(*key, buffer); - } + + return msg->DecodeKey(*key, buffer); } bool diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index 47d6b1a6b..8ae892ea1 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -41,14 +41,12 @@ namespace llarp { return HandleJSONResult({}); } - else if(itr.value().is_object()) + if(itr.value().is_object()) { return HandleJSONResult(itr.value()); } - else - { - return false; - } + + return false; } void @@ -277,11 +275,11 @@ namespace llarp { return ListNeighboors(); } - else if(method == "llarp.admin.exit.list") + if(method == "llarp.admin.exit.list") { return ListExitLevels(); } - else if(method == "llarp.admin.dumpstate") + if(method == "llarp.admin.dumpstate") { return DumpState(); } diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index 3c0d00a66..276caacab 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -287,12 +287,10 @@ namespace llarp LogError("failed to start hidden service endpoint ", conf.first); return false; } - else - { - LogInfo("added hidden service endpoint ", service->Name()); - m_Endpoints.emplace(conf.first, service); - return true; - } + + LogInfo("added hidden service endpoint ", service->Name()); + m_Endpoints.emplace(conf.first, service); + return true; } } // namespace service } // namespace llarp diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 80d66f25c..f04afdfbb 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -114,8 +114,8 @@ namespace llarp { if(m_IsolatedNetLoop) return m_IsolatedNetLoop; - else - return m_Router->netloop(); + + return m_Router->netloop(); } bool @@ -280,8 +280,7 @@ namespace llarp continue; std::array< byte_t, 128 > tmp = {0}; llarp_buffer_t buf(tmp); - if(SendToServiceOrQueue(introset.A.Addr(), buf, - eProtocolControl)) + if(SendToServiceOrQueue(introset.A.Addr(), buf, eProtocolControl)) LogInfo(Name(), " send message to ", introset.A.Addr(), " for tag ", tag.ToString()); else @@ -371,10 +370,8 @@ namespace llarp IntroSetPublished(); return true; } - else - { - remote.insert(introset); - } + + remote.insert(introset); } auto itr = m_PendingLookups.find(msg->T); if(itr == m_PendingLookups.end()) @@ -793,8 +790,8 @@ namespace llarp m_PendingRouters.emplace(router, RouterLookupJob(this, handler)); return true; } - else - LogError("failed to send request for router lookup"); + + LogError("failed to send request for router lookup"); } return false; } @@ -862,7 +859,7 @@ namespace llarp m_InboundTrafficQueue.emplace(msg); return true; } - else if(msg->proto == eProtocolControl) + if(msg->proto == eProtocolControl) { // TODO: implement me (?) // right now it's just random noise @@ -948,8 +945,8 @@ namespace llarp } return false; } - else - PutNewOutboundContext(*introset); + + PutNewOutboundContext(*introset); return true; } diff --git a/llarp/service/identity.cpp b/llarp/service/identity.cpp index 87ff269d1..73301d491 100644 --- a/llarp/service/identity.cpp +++ b/llarp/service/identity.cpp @@ -41,8 +41,8 @@ namespace llarp pq = str.base; return true; } - else - return false; + + return false; } if(!BEncodeMaybeReadDictEntry("s", signkey, read, key, buf)) return false; diff --git a/llarp/service/intro_set.cpp b/llarp/service/intro_set.cpp index bf19d75fe..5f9ae1fd7 100644 --- a/llarp/service/intro_set.cpp +++ b/llarp/service/intro_set.cpp @@ -150,7 +150,7 @@ namespace llarp { return false; } - else if(!W.has_value()) + if(!W.has_value()) { LogWarn("intro has too high expire time"); return false; diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index ee2f9184c..35d68f368 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -339,20 +339,18 @@ namespace llarp BuildOneAlignedTo(m_NextIntro.router); return true; } - else + + // we didn't shift check if we should update introset + if(now - lastShift >= MIN_SHIFT_INTERVAL + || currentIntroSet.HasExpiredIntros(now) + || currentIntroSet.IsExpired(now)) { - // we didn't shift check if we should update introset - if(now - lastShift >= MIN_SHIFT_INTERVAL - || currentIntroSet.HasExpiredIntros(now) - || currentIntroSet.IsExpired(now)) - { - // update introset - LogInfo(Name(), " updating introset"); - UpdateIntroSet(true); - return true; - } - return false; + // update introset + LogInfo(Name(), " updating introset"); + UpdateIntroSet(true); + return true; } + return false; } bool diff --git a/llarp/util/buffer.cpp b/llarp/util/buffer.cpp index a51986741..8a0f0d9bc 100644 --- a/llarp/util/buffer.cpp +++ b/llarp/util/buffer.cpp @@ -12,8 +12,8 @@ llarp_buffer_t::size_left() const { return 0; } - else - return sz - diff; + + return sz - diff; } bool @@ -110,8 +110,8 @@ llarp_buffer_t::read_until(char delim, byte_t* result, size_t resultsize) if(size_left()) return read; - else - return 0; + + return 0; } bool diff --git a/llarp/util/codel.hpp b/llarp/util/codel.hpp index 022c9b64e..02486ea50 100644 --- a/llarp/util/codel.hpp +++ b/llarp/util/codel.hpp @@ -132,11 +132,9 @@ namespace llarp nextTickAt = start + nextTickInterval; return; } - else - { - nextTickInterval = initialIntervalMs; - dropNum = 0; - } + + nextTickInterval = initialIntervalMs; + dropNum = 0; } visitor(*item); item->~T(); diff --git a/llarp/util/compare_ptr.hpp b/llarp/util/compare_ptr.hpp index b658cc7b6..7078291fc 100644 --- a/llarp/util/compare_ptr.hpp +++ b/llarp/util/compare_ptr.hpp @@ -13,10 +13,10 @@ namespace llarp { if(left && right) return Compare()(*left, *right); - else - return Compare()(left, right); + + return Compare()(left, right); } }; } // namespace llarp -#endif \ No newline at end of file +#endif diff --git a/llarp/util/metrics_core.cpp b/llarp/util/metrics_core.cpp index 395be656e..c758ecab6 100644 --- a/llarp/util/metrics_core.cpp +++ b/llarp/util/metrics_core.cpp @@ -236,15 +236,13 @@ namespace llarp } return {result, now - manager.m_createTime}; } - else + + auto tmp = now - it->second; + if(clear) { - auto tmp = now - it->second; - if(clear) - { - it->second = now; - } - return {result, tmp}; + it->second = now; } + return {result, tmp}; } template < typename Type > @@ -723,10 +721,8 @@ namespace llarp { return {}; } - else - { - return it->second; - } + + return it->second; } absl::optional< absl::Duration > @@ -738,10 +734,8 @@ namespace llarp { return {}; } - else - { - return m_defaultInterval; - } + + return m_defaultInterval; } std::vector< std::pair< const Category *, absl::Duration > > diff --git a/llarp/util/metrics_types.cpp b/llarp/util/metrics_types.cpp index 4092e3fa4..a918440a5 100644 --- a/llarp/util/metrics_types.cpp +++ b/llarp/util/metrics_types.cpp @@ -39,11 +39,9 @@ namespace llarp stream << "Bad format " << format.m_format << " applied to " << data; return stream; } - else - { - stream << vec.data(); - return stream; - } + + stream << vec.data(); + return stream; } string_view diff --git a/llarp/util/metrics_types.hpp b/llarp/util/metrics_types.hpp index 802d1544f..c4cb5262c 100644 --- a/llarp/util/metrics_types.hpp +++ b/llarp/util/metrics_types.hpp @@ -335,10 +335,8 @@ namespace llarp return m_description->toString(); ; } - else - { - return "INVALID_METRIC"; - } + + return "INVALID_METRIC"; } std::ostream & diff --git a/llarp/util/queue_manager.cpp b/llarp/util/queue_manager.cpp index cd2104e2b..e799ba668 100644 --- a/llarp/util/queue_manager.cpp +++ b/llarp/util/queue_manager.cpp @@ -136,14 +136,12 @@ namespace llarp { return difference - modulo; } - else if(difference < -static_cast< int32_t >(modulo / 2)) + if(difference < -static_cast< int32_t >(modulo / 2)) { return difference + modulo; } - else - { - return difference; - } + + return difference; } uint32_t diff --git a/llarp/util/str.cpp b/llarp/util/str.cpp index 6469f8003..cfab843ce 100644 --- a/llarp/util/str.cpp +++ b/llarp/util/str.cpp @@ -14,28 +14,26 @@ namespace llarp { return true; } - else if(lhs.size() > rhs.size()) + if(lhs.size() > rhs.size()) { return false; } - else + + for(size_t i = 0; i < lhs.size(); ++i) { - for(size_t i = 0; i < lhs.size(); ++i) - { - auto l = std::tolower(lhs[i]); - auto r = std::tolower(rhs[i]); + auto l = std::tolower(lhs[i]); + auto r = std::tolower(rhs[i]); - if(l < r) - { - return true; - } - else if(l > r) - { - return false; - } + if(l < r) + { + return true; + } + if(l > r) + { + return false; } - return false; } + return false; } bool @@ -65,7 +63,7 @@ namespace llarp { return strncmp(s1, s2, sz1) == 0; } - else - return false; + + return false; } } // namespace llarp diff --git a/llarp/util/thread_pool.hpp b/llarp/util/thread_pool.hpp index 594789603..c53ec9050 100644 --- a/llarp/util/thread_pool.hpp +++ b/llarp/util/thread_pool.hpp @@ -182,10 +182,8 @@ namespace llarp { return m_threads.size() - m_idleThreads.load(std::memory_order_relaxed); } - else - { - return 0; - } + + return 0; } inline size_t diff --git a/llarp/util/threadpool.h b/llarp/util/threadpool.h index 2ebc13db0..438e4ce7b 100644 --- a/llarp/util/threadpool.h +++ b/llarp/util/threadpool.h @@ -43,8 +43,8 @@ struct llarp_threadpool { if(impl) return impl->tryAddJob(f); - else - return jobs->tryPushBack(f) == llarp::thread::QueueReturn::Success; + + return jobs->tryPushBack(f) == llarp::thread::QueueReturn::Success; } };