Remove redundant else blocks

pull/690/head
Michael 5 years ago
parent 0cd9b4c380
commit 488695047f
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -0,0 +1,2 @@
HeaderFilterRegex: 'llarp/.*'
Checks: 'readability-else-after-return,clang-analyzer-core-*'

@ -367,8 +367,8 @@ namespace llarp
if(c.VisitSection(name.c_str(), visitor))
return ret;
else
return {};
return {};
}
bool

@ -302,8 +302,8 @@ __ ___ ____ _ _ ___ _ _ ____
f << std::to_string(getpid());
return f.good();
}
else
return true;
return true;
}
void

@ -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;
}
};

@ -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

@ -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));

@ -45,10 +45,8 @@ namespace llarp
{
return nodes->FindCloseExcluding(k, next, exclude);
}
else
{
return false;
}
return false;
}
void

@ -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,

@ -99,8 +99,8 @@ namespace llarp
ip = llarp::ipaddr_ipv4_bits(a, b, c, d);
return true;
}
else
return false;
return false;
}
} // namespace dns

@ -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

@ -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);

@ -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;
}

@ -256,7 +256,7 @@ namespace llarp
::shutdown(fd, SHUT_RDWR);
return false;
}
else if(tcp.tick)
if(tcp.tick)
tcp.tick(&tcp);
return true;
}

@ -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

@ -1,5 +1,7 @@
#include <ev/ev_win32.hpp>
#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

@ -1,5 +1,6 @@
#ifndef EV_WIN32_H
#define EV_WIN32_H
#ifdef _WIN32
#include <ev/ev.hpp>
#include <net/net.h>
#include <net/net.hpp>
@ -151,3 +152,4 @@ struct llarp_win32_loop : public llarp_ev_loop
};
#endif
#endif

@ -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

@ -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

@ -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;

@ -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);
}

@ -38,10 +38,8 @@ namespace llarp
{
return {};
}
else
{
return std::to_string(d);
}
return std::to_string(d);
}
absl::optional< std::string >

@ -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;
}

@ -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

@ -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;
}

@ -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");

@ -327,8 +327,8 @@ namespace llarp
{
return established[randint() % sz];
}
else
return nullptr;
return nullptr;
}
} // namespace path

@ -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);

@ -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

@ -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);
}

@ -108,10 +108,8 @@ namespace llarp
firstKey = false;
return msg != nullptr;
}
else
{
return msg->DecodeKey(*key, buffer);
}
return msg->DecodeKey(*key, buffer);
}
bool

@ -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();
}

@ -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

@ -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;
}

@ -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;

@ -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;

@ -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

@ -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

@ -132,11 +132,9 @@ namespace llarp
nextTickAt = start + nextTickInterval;
return;
}
else
{
nextTickInterval = initialIntervalMs;
dropNum = 0;
}
nextTickInterval = initialIntervalMs;
dropNum = 0;
}
visitor(*item);
item->~T();

@ -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
#endif

@ -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 > >

@ -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

@ -335,10 +335,8 @@ namespace llarp
return m_description->toString();
;
}
else
{
return "INVALID_METRIC";
}
return "INVALID_METRIC";
}
std::ostream &

@ -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

@ -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

@ -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

@ -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;
}
};

Loading…
Cancel
Save