From ebd2142114a46d10ad002223fac4c491f008fce0 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Wed, 20 May 2020 16:46:08 -0300 Subject: [PATCH] Don't use std::optional::value() because f u macos This replaces all use of std::optional's `opt.value()` with `*opt` because macOS is great and the ghost of Steve Jobs says that actually supporting std::optional's value() method is not for chumps before macOS 10.14. So don't use it because Apple is great. Pretty much all of our use of it actually is done better with operator* anyway (since operator* doesn't do a check that the optional has a value). Also replaced *most* of the `has_value()` calls with direct bool context, except for one in the config section which looked really confusing at a glance without a has_value(). --- cmake/check_for_std_optional.cmake | 2 +- llarp/config/config.cpp | 21 +++++++++---------- llarp/config/definition.hpp | 14 ++++++------- llarp/context.cpp | 2 +- llarp/crypto/types.cpp | 4 ++-- llarp/dht/messages/findintro.cpp | 4 ++-- llarp/dht/messages/gotintro.cpp | 6 +++--- llarp/dht/taglookup.cpp | 4 ++-- llarp/link/server.cpp | 5 ++--- llarp/messages/relay_commit.cpp | 6 +++--- llarp/net/address_info.cpp | 6 +----- llarp/net/ip_address.cpp | 2 +- llarp/nodedb.cpp | 2 +- llarp/path/path.cpp | 8 +++---- llarp/path/transit_hop.cpp | 8 +++---- llarp/profiling.cpp | 2 +- llarp/router/router.cpp | 9 +++----- llarp/router_contact.cpp | 17 +++++++-------- llarp/service/endpoint.cpp | 12 +++++------ .../service/hidden_service_address_lookup.cpp | 4 ++-- llarp/service/identity.cpp | 4 ++-- llarp/service/info.cpp | 4 ++-- llarp/service/info.hpp | 4 +--- llarp/service/intro_set.cpp | 8 +++---- llarp/service/outbound_context.cpp | 6 +++--- llarp/service/sendcontext.cpp | 4 ++-- llarp/util/bencode.hpp | 9 +++----- llarp/util/logging/file_logger.cpp | 7 +++---- llarp/util/thread/logic.cpp | 6 +++--- llarp/util/thread/thread_pool.cpp | 6 +++--- llarp/util/thread/threading.hpp | 6 +++--- test/config/test_llarp_config_definition.cpp | 16 +++++++------- test/util/thread/test_llarp_util_queue.cpp | 2 +- .../thread/test_llarp_util_queue_manager.cpp | 4 ++-- 34 files changed, 104 insertions(+), 120 deletions(-) diff --git a/cmake/check_for_std_optional.cmake b/cmake/check_for_std_optional.cmake index 5bb712cee..7d9eda266 100644 --- a/cmake/check_for_std_optional.cmake +++ b/cmake/check_for_std_optional.cmake @@ -6,7 +6,7 @@ set(std_optional_code [[ int main() { std::optional maybe; maybe = 1; - return maybe.value() == 1; + return *maybe == 1; } ]]) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index a5b17d0b6..640d5f6c3 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -192,9 +192,9 @@ namespace llarp if (arg.empty()) { const auto maybe = llarp::FindFreeRange(); - if (not maybe.has_value()) + if (not maybe) throw std::invalid_argument("cannot determine free ip range"); - arg = maybe.value(); + arg = *maybe; } m_ifaddr = arg; }); @@ -203,9 +203,9 @@ namespace llarp if (arg.empty()) { const auto maybe = llarp::FindFreeTun(); - if (not maybe.has_value()) + if (not maybe) throw std::invalid_argument("cannot determine free interface name"); - arg = maybe.value(); + arg = *maybe; } m_ifname = arg; }); @@ -228,8 +228,7 @@ namespace llarp (void)params; auto parseDNSAddr = [](auto arg) { IpAddress addr{arg}; - const auto maybePort = addr.getPort(); - if (not maybePort.has_value()) + if (not addr.getPort()) addr.setPort(53); return addr; }; @@ -399,10 +398,10 @@ namespace llarp conf.defineOption( "logging", "level", false, DefaultLogLevel, [this](std::string arg) { std::optional level = LogLevelFromString(arg); - if (not level.has_value()) + if (not level) throw std::invalid_argument(stringify("invalid log level value: ", arg)); - m_logLevel = level.value(); + m_logLevel = *level; }); conf.defineOption( @@ -553,13 +552,13 @@ namespace llarp // open a filestream auto stream = llarp::util::OpenFileStream(confFile.c_str(), std::ios::binary); - if (not stream.has_value() or not stream.value().is_open()) + if (not stream or not stream->is_open()) throw std::runtime_error(stringify("Failed to open file ", confFile, " for writing")); llarp::LogInfo("confStr: ", confStr); - stream.value() << confStr; - stream.value().flush(); + *stream << confStr; + stream->flush(); llarp::LogInfo("Generated new config ", confFile); } diff --git a/llarp/config/definition.hpp b/llarp/config/definition.hpp index cb3214cef..f58f91d4d 100644 --- a/llarp/config/definition.hpp +++ b/llarp/config/definition.hpp @@ -156,8 +156,8 @@ namespace llarp defaultValueAsString() override { std::ostringstream oss; - if (defaultValue.has_value()) - oss << defaultValue.value(); + if (defaultValue) + oss << *defaultValue; return oss.str(); } @@ -192,8 +192,8 @@ namespace llarp std::ostringstream oss; if (parsedValues.size() > 0) oss << parsedValues[0]; - else if (useDefault and defaultValue.has_value()) - oss << defaultValue.value(); + else if (useDefault and defaultValue) + oss << *defaultValue; return oss.str(); } @@ -232,13 +232,13 @@ namespace llarp else { auto maybe = getValue(); - if (maybe.has_value()) + if (maybe) { - acceptor(maybe.value()); + acceptor(*maybe); } else { - assert(not defaultValue.has_value()); // maybe should have a value if defaultValue does + assert(not defaultValue); // maybe should have a value if defaultValue does } } } diff --git a/llarp/context.cpp b/llarp/context.cpp index 169639f4d..2e5e07108 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -29,7 +29,7 @@ namespace llarp bool Context::Configure(bool isRelay, std::optional dataDir) { - fs::path defaultDataDir = dataDir.has_value() ? dataDir.value() : GetDefaultDataDir(); + fs::path defaultDataDir = dataDir ? *dataDir : GetDefaultDataDir(); if (configfile.size()) { diff --git a/llarp/crypto/types.cpp b/llarp/crypto/types.cpp index 0f8a21336..df39e412a 100644 --- a/llarp/crypto/types.cpp +++ b/llarp/crypto/types.cpp @@ -101,7 +101,7 @@ namespace llarp auto optional_f = llarp::util::OpenFileStream(fpath, std::ios::binary); if (!optional_f) return false; - auto& f = optional_f.value(); + auto& f = *optional_f; if (!f.is_open()) return false; f.write((char*)buf.base, buf.cur - buf.base); @@ -115,7 +115,7 @@ namespace llarp auto optional = util::OpenFileStream(fpath, std::ios::binary | std::ios::in); if (!optional) return false; - auto& f = optional.value(); + auto& f = *optional; f.seekg(0, std::ios::end); const size_t sz = f.tellg(); f.seekg(0, std::ios::beg); diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index 9c26a11bf..571f18f67 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -122,9 +122,9 @@ namespace llarp { // we should have this value if introset was propagated properly const auto maybe = dht.GetIntroSetByLocation(location); - if (maybe.has_value()) + if (maybe) { - replies.emplace_back(new GotIntroMessage({maybe.value()}, txID)); + replies.emplace_back(new GotIntroMessage({*maybe}, txID)); } else { diff --git a/llarp/dht/messages/gotintro.cpp b/llarp/dht/messages/gotintro.cpp index 291a4b07d..b9fef9a2d 100644 --- a/llarp/dht/messages/gotintro.cpp +++ b/llarp/dht/messages/gotintro.cpp @@ -86,7 +86,7 @@ namespace llarp } if (key == "K") { - if (closer.has_value()) // duplicate key? + if (closer) // duplicate key? return false; dht::Key_t K; if (not K.BDecode(buf)) @@ -111,9 +111,9 @@ namespace llarp return false; if (!BEncodeWriteDictList("I", found, buf)) return false; - if (closer.has_value()) + if (closer) { - if (!BEncodeWriteDictEntry("K", closer.value(), buf)) + if (!BEncodeWriteDictEntry("K", *closer, buf)) return false; } if (!BEncodeWriteDictInt("T", txid, buf)) diff --git a/llarp/dht/taglookup.cpp b/llarp/dht/taglookup.cpp index e14574e29..650328fe4 100644 --- a/llarp/dht/taglookup.cpp +++ b/llarp/dht/taglookup.cpp @@ -15,9 +15,9 @@ namespace llarp llarp::LogWarn("got invalid introset from tag lookup"); return false; } - if (not introset.topic.has_value()) + if (not introset.topic) return false; - if (introset.topic.value() != target) + if (*introset.topic != target) { llarp::LogWarn("got introset with mismatched topic in tag lookup"); return false; diff --git a/llarp/link/server.cpp b/llarp/link/server.cpp index 56faece61..9c997aba7 100644 --- a/llarp/link/server.cpp +++ b/llarp/link/server.cpp @@ -125,10 +125,9 @@ namespace llarp } else { - const auto maybe = GetIFAddr(ifname, af); - if (maybe.has_value()) + if (const auto maybe = GetIFAddr(ifname, af)) { - m_ourAddr = maybe.value(); + m_ourAddr = *maybe; } else { diff --git a/llarp/messages/relay_commit.cpp b/llarp/messages/relay_commit.cpp index 6c38599c1..365b04389 100644 --- a/llarp/messages/relay_commit.cpp +++ b/llarp/messages/relay_commit.cpp @@ -261,14 +261,14 @@ namespace llarp return; } - if (self->fromAddr.has_value()) + if (self->fromAddr) { // only do ip limiting from non service nodes #ifndef LOKINET_HIVE - if (self->context->CheckPathLimitHitByIP(self->fromAddr.value())) + if (self->context->CheckPathLimitHitByIP(*self->fromAddr)) { // we hit a limit so tell it to slow tf down - llarp::LogError("client path build hit limit ", self->fromAddr.value()); + llarp::LogError("client path build hit limit ", *self->fromAddr); OnForwardLRCMResult( self->context->Router(), self->hop->info.rxID, diff --git a/llarp/net/address_info.cpp b/llarp/net/address_info.cpp index d49ae31d9..1c2ff66c9 100644 --- a/llarp/net/address_info.cpp +++ b/llarp/net/address_info.cpp @@ -164,11 +164,7 @@ namespace llarp const sockaddr_in6* addr6 = addr; memcpy(ip.s6_addr, addr6->sin6_addr.s6_addr, sizeof(ip.s6_addr)); - auto maybePort = address.getPort(); - if (maybePort) - port = maybePort.value(); - else - port = 0; + port = address.getPort().value_or(0); } std::ostream& diff --git a/llarp/net/ip_address.cpp b/llarp/net/ip_address.cpp index c30006c33..55513e0e9 100644 --- a/llarp/net/ip_address.cpp +++ b/llarp/net/ip_address.cpp @@ -94,7 +94,7 @@ namespace llarp { SockAddr addr(m_ipAddress); if (m_port) - addr.setPort(m_port.value()); + addr.setPort(*m_port); return addr; } diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 719ab0414..9cf8e1fbb 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -259,7 +259,7 @@ llarp_nodedb::SaveAll() filepath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); if (!optional_ofs) continue; - auto& ofs = optional_ofs.value(); + auto& ofs = *optional_ofs; ofs.write((char*)buf.base, buf.sz); ofs.flush(); ofs.close(); diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index e00bccdb9..c7510647f 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -192,12 +192,12 @@ namespace llarp } else { - if (failedAt.has_value()) + if (failedAt) { r->NotifyRouterEvent( - Endpoint(), RXID(), failedAt.value()); - LogWarn(Name(), " build failed at ", failedAt.value()); - r->routerProfiling().MarkHopFail(failedAt.value()); + Endpoint(), RXID(), *failedAt); + LogWarn(Name(), " build failed at ", *failedAt); + r->routerProfiling().MarkHopFail(*failedAt); } else r->routerProfiling().MarkPathFail(this); diff --git a/llarp/path/transit_hop.cpp b/llarp/path/transit_hop.cpp index 2ef55c574..89d5e19a9 100644 --- a/llarp/path/transit_hop.cpp +++ b/llarp/path/transit_hop.cpp @@ -125,9 +125,9 @@ namespace llarp do { auto maybe = self->m_DownstreamGather.tryPopFront(); - if (not maybe.has_value()) + if (not maybe) break; - msgs.emplace_back(maybe.value()); + msgs.emplace_back(*maybe); } while (true); self->HandleAllDownstream(std::move(msgs), r); }; @@ -167,9 +167,9 @@ namespace llarp do { auto maybe = self->m_UpstreamGather.tryPopFront(); - if (not maybe.has_value()) + if (not maybe) break; - msgs.emplace_back(maybe.value()); + msgs.emplace_back(*maybe); } while (true); self->HandleAllUpstream(std::move(msgs), r); }; diff --git a/llarp/profiling.cpp b/llarp/profiling.cpp index 18e9e425a..544101392 100644 --- a/llarp/profiling.cpp +++ b/llarp/profiling.cpp @@ -230,7 +230,7 @@ namespace llarp auto optional_f = util::OpenFileStream(fpath, std::ios::binary); if (!optional_f) return false; - auto& f = optional_f.value(); + auto& f = *optional_f; if (f.is_open()) { f.write((char*)buf.base, buf.sz); diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 6ada5c78b..1f5d623f0 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -548,13 +548,10 @@ namespace llarp } // Network config - if (conf->network.m_enableProfiling.has_value()) + if (conf->network.m_enableProfiling.has_value() and not *conf->network.m_enableProfiling) { - if (not conf->network.m_enableProfiling.value()) - { - routerProfiling().Disable(); - LogWarn("router profiling explicitly disabled"); - } + routerProfiling().Disable(); + LogWarn("router profiling explicitly disabled"); } if (!conf->network.m_routerProfilesFile.empty()) diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index dcc0139c1..d2a802065 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -125,9 +125,9 @@ namespace llarp if (!enckey.BEncode(buf)) return false; // write router version if present - if (routerVersion.has_value()) + if (routerVersion) { - if (not BEncodeWriteDictEntry("r", routerVersion.value(), buf)) + if (not BEncodeWriteDictEntry("r", *routerVersion, buf)) return false; } /* write last updated */ @@ -180,7 +180,7 @@ namespace llarp { obj["nickname"] = Nick(); } - if (routerVersion.has_value()) + if (routerVersion) { obj["routerVersion"] = routerVersion->ToString(); } @@ -246,7 +246,7 @@ namespace llarp bool RouterContact::IsPublicRouter() const { - if (not routerVersion.has_value()) + if (not routerVersion) return false; return !addrs.empty(); } @@ -390,17 +390,16 @@ namespace llarp buf.sz = buf.cur - buf.base; buf.cur = buf.base; const fs::path fpath = std::string(fname); /* */ - auto optional_f = llarp::util::OpenFileStream(fpath, std::ios::binary); - if (!optional_f) + auto f = llarp::util::OpenFileStream(fpath, std::ios::binary); + if (!f) { return false; } - auto& f = optional_f.value(); - if (!f.is_open()) + if (!f->is_open()) { return false; } - f.write((char*)buf.base, buf.sz); + f->write((char*)buf.base, buf.sz); return true; } diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index fab2d090b..d7fd827fb 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -106,12 +106,12 @@ namespace llarp return; } auto maybe = m_Identity.EncryptAndSignIntroSet(introSet(), now); - if (not maybe.has_value()) + if (not maybe) { LogWarn("failed to generate introset for endpoint ", Name()); return; } - if (PublishIntroSet(maybe.value(), Router())) + if (PublishIntroSet(*maybe, Router())) { LogInfo("(re)publishing introset for endpoint ", Name()); } @@ -798,9 +798,9 @@ namespace llarp do { auto maybe = m_RecvQueue.tryPopFront(); - if (not maybe.has_value()) + if (not maybe) return; - auto ev = std::move(maybe.value()); + auto ev = std::move(*maybe); ProtocolMessage::ProcessAsync(ev.fromPath, ev.pathid, ev.msg); } while (true); } @@ -928,7 +928,7 @@ namespace llarp const auto now = Router()->Now(); auto& fails = m_state->m_ServiceLookupFails; auto& lookups = m_state->m_PendingServiceLookups; - if (not introset.has_value() || introset->IsExpired(now)) + if (not introset or introset->IsExpired(now)) { LogError(Name(), " failed to lookup ", addr.ToString(), " from ", endpoint); fails[endpoint] = fails[endpoint] + 1; @@ -947,7 +947,7 @@ namespace llarp if (m_state->m_RemoteSessions.count(addr) > 0) return true; - PutNewOutboundContext(introset.value()); + PutNewOutboundContext(*introset); return true; } diff --git a/llarp/service/hidden_service_address_lookup.cpp b/llarp/service/hidden_service_address_lookup.cpp index 6923cdafb..4f35ad2fc 100644 --- a/llarp/service/hidden_service_address_lookup.cpp +++ b/llarp/service/hidden_service_address_lookup.cpp @@ -38,8 +38,8 @@ namespace llarp selected = introset; } const auto maybe = selected.MaybeDecrypt(rootkey); - if (maybe.has_value()) - found = maybe.value(); + if (maybe) + found = *maybe; } return handle(remote, found, endpoint); } diff --git a/llarp/service/identity.cpp b/llarp/service/identity.cpp index 2ba0fe332..108a92a32 100644 --- a/llarp/service/identity.cpp +++ b/llarp/service/identity.cpp @@ -118,7 +118,7 @@ namespace llarp auto optional_f = util::OpenFileStream(fname, std::ios::binary); if (!optional_f) return false; - auto& f = optional_f.value(); + auto& f = *optional_f; if (!f.is_open()) return false; f.write((char*)buf.cur, buf.sz); @@ -143,7 +143,7 @@ namespace llarp if (!bencode_decode_dict(*this, &buf)) return false; - ServiceInfo::OptNonce van; + std::optional van; if (!vanity.IsZero()) van = vanity; // update pubkeys diff --git a/llarp/service/info.cpp b/llarp/service/info.cpp index a37110613..d37124dc4 100644 --- a/llarp/service/info.cpp +++ b/llarp/service/info.cpp @@ -20,13 +20,13 @@ namespace llarp } bool - ServiceInfo::Update(const byte_t* sign, const byte_t* enc, const OptNonce& nonce) + ServiceInfo::Update(const byte_t* sign, const byte_t* enc, const std::optional& nonce) { signkey = sign; enckey = enc; if (nonce) { - vanity = nonce.value(); + vanity = *nonce; } return UpdateAddr(); } diff --git a/llarp/service/info.hpp b/llarp/service/info.hpp index e4ada7146..ce2a08fb5 100644 --- a/llarp/service/info.hpp +++ b/llarp/service/info.hpp @@ -23,8 +23,6 @@ namespace llarp VanityNonce vanity; uint64_t version = LLARP_PROTO_VERSION; - using OptNonce = std::optional; - void RandomizeVanity() { @@ -45,7 +43,7 @@ namespace llarp } bool - Update(const byte_t* sign, const byte_t* enc, const OptNonce& nonce = OptNonce()); + Update(const byte_t* sign, const byte_t* enc, const std::optional& nonce = {}); bool operator==(const ServiceInfo& other) const diff --git a/llarp/service/intro_set.cpp b/llarp/service/intro_set.cpp index 83f4cf558..0c209c485 100644 --- a/llarp/service/intro_set.cpp +++ b/llarp/service/intro_set.cpp @@ -279,13 +279,13 @@ namespace llarp { if (intro.expiresAt > now && intro.expiresAt - now > path::default_lifetime) { - if (W && intro.expiresAt - W->extendedLifetime > path::default_lifetime) + if (!W) { + LogWarn("intro has too high expire time"); return false; } - if (!W.has_value()) + if (intro.expiresAt - W->extendedLifetime > path::default_lifetime) { - LogWarn("intro has too high expire time"); return false; } } @@ -329,7 +329,7 @@ namespace llarp printer.printAttribute("T", T.count()); if (W) { - printer.printAttribute("W", W.value()); + printer.printAttribute("W", *W); } else { diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 759f7a5aa..dd17bc99c 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -90,11 +90,11 @@ namespace llarp if (markedBad) return true; updatingIntroSet = false; - if (foundIntro.has_value()) + if (foundIntro) { if (foundIntro->T == 0s) { - LogWarn(Name(), " got introset with zero timestamp: ", foundIntro.value()); + LogWarn(Name(), " got introset with zero timestamp: ", *foundIntro); return true; } if (currentIntroSet.T > foundIntro->T) @@ -109,7 +109,7 @@ namespace llarp LogError("got expired introset from lookup from ", endpoint); return true; } - currentIntroSet = foundIntro.value(); + currentIntroSet = *foundIntro; ShiftIntroduction(false); } else diff --git a/llarp/service/sendcontext.cpp b/llarp/service/sendcontext.cpp index dcf06b478..1415381c0 100644 --- a/llarp/service/sendcontext.cpp +++ b/llarp/service/sendcontext.cpp @@ -46,9 +46,9 @@ namespace llarp do { auto maybe = m_SendQueue.tryPopFront(); - if (not maybe.has_value()) + if (not maybe) break; - auto& item = maybe.value(); + auto& item = *maybe; if (item.second->SendRoutingMessage(*item.first, r)) { lastGoodSend = r->Now(); diff --git a/llarp/util/bencode.hpp b/llarp/util/bencode.hpp index 360570ce2..4fcfdb36d 100644 --- a/llarp/util/bencode.hpp +++ b/llarp/util/bencode.hpp @@ -357,13 +357,10 @@ namespace llarp buf.sz = buf.cur - buf.base; { const fs::path path = std::string(fpath); - auto optional_f = llarp::util::OpenFileStream(path, std::ios::binary); - if (!optional_f) + auto f = llarp::util::OpenFileStream(path, std::ios::binary); + if (not f or not f->is_open()) return false; - auto& f = optional_f.value(); - if (!f.is_open()) - return false; - f.write((char*)buf.base, buf.sz); + f->write((char*)buf.base, buf.sz); } return true; } diff --git a/llarp/util/logging/file_logger.cpp b/llarp/util/logging/file_logger.cpp index 3e8485eb7..61d69f9f5 100644 --- a/llarp/util/logging/file_logger.cpp +++ b/llarp/util/logging/file_logger.cpp @@ -14,10 +14,9 @@ namespace llarp do { auto maybe_line = lines->tryPopFront(); - if (not maybe_line.has_value()) + if (not maybe_line) break; - const auto& line = maybe_line.value(); - if (fprintf(f, "%s\n", line.c_str()) >= 0) + if (fprintf(f, "%s\n", maybe_line->c_str()) >= 0) wrote_stuff = true; } while (true); @@ -43,7 +42,7 @@ namespace llarp do { auto line = m_Lines.tryPopFront(); - if (not line.has_value()) + if (not line) break; } while (true); fflush(m_File); diff --git a/llarp/util/thread/logic.cpp b/llarp/util/thread/logic.cpp index 2d61e1541..3d8389363 100644 --- a/llarp/util/thread/logic.cpp +++ b/llarp/util/thread/logic.cpp @@ -13,8 +13,8 @@ namespace llarp std::promise result; // queue setting id and try to get the result back llarp_threadpool_queue_job(m_Thread, [&]() { - m_ID.emplace(std::this_thread::get_id()); - result.set_value(m_ID.value()); + m_ID = std::this_thread::get_id(); + result.set_value(*m_ID); }); // get the result back ID_t spawned = result.get_future().get(); @@ -129,7 +129,7 @@ namespace llarp bool Logic::can_flush() const { - return m_ID.value() == std::this_thread::get_id(); + return *m_ID == std::this_thread::get_id(); } void diff --git a/llarp/util/thread/thread_pool.cpp b/llarp/util/thread/thread_pool.cpp index 86411a799..a313b1e8c 100644 --- a/llarp/util/thread/thread_pool.cpp +++ b/llarp/util/thread/thread_pool.cpp @@ -27,9 +27,9 @@ namespace llarp { auto functor = m_queue.tryPopFront(); - if (functor.has_value()) + if (functor) { - functor.value()(); + (*functor)(); } else { @@ -57,7 +57,7 @@ namespace llarp return; } - functor.value()(); + (*functor)(); } } diff --git a/llarp/util/thread/threading.hpp b/llarp/util/thread/threading.hpp index 9f3a41a81..7914a3891 100644 --- a/llarp/util/thread/threading.hpp +++ b/llarp/util/thread/threading.hpp @@ -51,13 +51,13 @@ namespace llarp { if (!m_id) { - m_id.emplace(std::this_thread::get_id()); + m_id = std::this_thread::get_id(); } - else if (m_id.value() != std::this_thread::get_id()) + else if (*m_id != std::this_thread::get_id()) { std::cerr << "NullMutex " << this << " was used across threads: locked by " << std::this_thread::get_id() << " and was previously locked by " - << m_id.value() << "\n"; + << *m_id << "\n"; // if you're encountering this abort() call, you may have discovered a // case where a NullMutex should be reverted to a "real mutex" std::abort(); diff --git a/test/config/test_llarp_config_definition.cpp b/test/config/test_llarp_config_definition.cpp index 951b88e1a..bc72a49f9 100644 --- a/test/config/test_llarp_config_definition.cpp +++ b/test/config/test_llarp_config_definition.cpp @@ -392,14 +392,14 @@ TEST_CASE("ConfigDefinition truthy/falsy bool values", "[config]") // defaults to false auto maybe = def.getValue(); - CHECK(maybe.has_value()); - CHECK(maybe.value() == false); + REQUIRE(maybe); + CHECK(*maybe == false); // val should result in true CHECK_NOTHROW(def.parseValue(val)); maybe = def.getValue(); - CHECK(maybe.has_value()); - CHECK(maybe.value() == true); + REQUIRE(maybe); + CHECK(*maybe); } // falsy values @@ -409,14 +409,14 @@ TEST_CASE("ConfigDefinition truthy/falsy bool values", "[config]") // defaults to true auto maybe = def.getValue(); - CHECK(maybe.has_value()); - CHECK(maybe.value() == true); + REQUIRE(maybe); + CHECK(maybe == true); // val should result in false CHECK_NOTHROW(def.parseValue(val)); maybe = def.getValue(); - CHECK(maybe.has_value()); - CHECK(maybe.value() == false); + REQUIRE(maybe); + CHECK(maybe == false); } // illegal values diff --git a/test/util/thread/test_llarp_util_queue.cpp b/test/util/thread/test_llarp_util_queue.cpp index f891c6b7e..022e67ea1 100644 --- a/test/util/thread/test_llarp_util_queue.cpp +++ b/test/util/thread/test_llarp_util_queue.cpp @@ -577,7 +577,7 @@ TEST(TestQueue, moveIt) std::optional< MoveTester > optPopped = queue.tryPopFront(); - ASSERT_TRUE(optPopped.has_value()); + ASSERT_TRUE(optPopped); // Moved twice here to construct the optional. ASSERT_EQ(6u, counter); diff --git a/test/util/thread/test_llarp_util_queue_manager.cpp b/test/util/thread/test_llarp_util_queue_manager.cpp index d548bb25e..7776130e2 100644 --- a/test/util/thread/test_llarp_util_queue_manager.cpp +++ b/test/util/thread/test_llarp_util_queue_manager.cpp @@ -258,8 +258,8 @@ TEST(TestQueueManager, SimpleUsage) auto result = queue.tryPopFront(); - ASSERT_TRUE(result.has_value()); - ASSERT_EQ(1, result.value()); + ASSERT_TRUE(result); + ASSERT_EQ(1, *result); } class BasicFunctionality : public ::testing::TestWithParam< uint32_t >