Replace absl::optional with optional-lite

Step 1 of removing abseil from lokinet.

For the most part this is a drop-in replacement, but there are also a
few changes here to the JSONRPC layer that were needed to work around
current gcc 10 dev snapshot:

- JSONRPC returns a json now instead of an optional<json>.  It doesn't
  make any sense to have a json rpc call that just closes the connection
  with returning anything.  Invoked functions can return a null (default
  constructed) result now if they don't have anything to return (such a
  null value won't be added as "result").
pull/1110/head
Jason Rhinelander 4 years ago
parent ecdc389e1a
commit ac1486d0be

3
.gitmodules vendored

@ -16,3 +16,6 @@
[submodule "test/Catch2"] [submodule "test/Catch2"]
path = test/Catch2 path = test/Catch2
url = https://github.com/catchorg/Catch2 url = https://github.com/catchorg/Catch2
[submodule "external/optional-lite"]
path = external/optional-lite
url = https://github.com/martinmoene/optional-lite.git

@ -254,6 +254,7 @@ if(SUBMODULE_CHECK)
check_submodule(external/googletest) check_submodule(external/googletest)
check_submodule(external/cxxopts) check_submodule(external/cxxopts)
check_submodule(external/ghc-filesystem) check_submodule(external/ghc-filesystem)
check_submodule(external/optional-lite)
endif() endif()
endif() endif()
@ -266,6 +267,7 @@ set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(external/nlohmann EXCLUDE_FROM_ALL) add_subdirectory(external/nlohmann EXCLUDE_FROM_ALL)
add_subdirectory(external/cxxopts) add_subdirectory(external/cxxopts)
add_subdirectory(external/ghc-filesystem) add_subdirectory(external/ghc-filesystem)
add_subdirectory(external/optional-lite)
if(ANDROID) if(ANDROID)
list(APPEND LIBS log) list(APPEND LIBS log)

@ -0,0 +1 @@
Subproject commit 3b79f4ee539d8f4c709a76b95a13564b6d9ae9cb

@ -7,7 +7,9 @@
#include <util/thread/logic.hpp> #include <util/thread/logic.hpp>
#include <util/time.hpp> #include <util/time.hpp>
#include <absl/types/optional.h> #include <nlohmann/json.hpp>
#include <nonstd/optional.hpp>
#include <list> #include <list>
#include <memory> #include <memory>
#include <string> #include <string>
@ -27,7 +29,7 @@ namespace abyss
IRPCHandler(ConnImpl* impl); IRPCHandler(ConnImpl* impl);
virtual absl::optional< Response > virtual Response
HandleJSONRPC(Method_t method, const Params& params) = 0; HandleJSONRPC(Method_t method, const Params& params) = 0;
virtual ~IRPCHandler(); virtual ~IRPCHandler();

@ -13,12 +13,11 @@ struct DemoHandler : public abyss::httpd::IRPCHandler
{ {
} }
absl::optional< Response > nonstd::optional< Response >
HandleJSONRPC(Method_t method, HandleJSONRPC(Method_t method, const Params& /*params*/) override
ABSL_ATTRIBUTE_UNUSED const Params& params) override
{ {
llarp::LogInfo("method: ", method); llarp::LogInfo("method: ", method);
return Response::object(); return nonstd::make_optional(Response::object());
} }
}; };

@ -184,15 +184,15 @@ namespace abyss
{ {
nlohmann::json response; nlohmann::json response;
response["jsonrpc"] = "2.0"; response["jsonrpc"] = "2.0";
response["id"] = m_Request["id"]; response["id"] = m_Request["id"].get< std::string >();
auto value = handler->HandleJSONRPC( auto value = handler->HandleJSONRPC(
m_Request["method"].get< std::string >(), m_Request["method"].get< std::string >(),
m_Request["params"]); m_Request["params"]);
if(value)
{ if(!value.is_null())
response["result"] = value.value(); response["result"] = std::move(value);
return WriteResponseJSON(response);
} return WriteResponseJSON(response);
} }
return WriteResponseSimple(500, "internal error", "text/plain", return WriteResponseSimple(500, "internal error", "text/plain",
"nope"); "nope");

@ -73,11 +73,12 @@ target_link_libraries(${UTIL_LIB} PUBLIC
absl::synchronization absl::flat_hash_map absl::container absl::synchronization absl::flat_hash_map absl::container
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
ghc_filesystem ghc_filesystem
optional-lite
) )
# cut back on fluff # cut back on fluff
if (NOT WIN32) if (NOT WIN32)
target_link_libraries(${UTIL_LIB} PUBLIC absl::optional absl::variant absl::strings) target_link_libraries(${UTIL_LIB} PUBLIC absl::variant absl::strings)
endif(NOT WIN32) endif(NOT WIN32)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

@ -35,7 +35,7 @@ namespace llarp
return std::atoi(str.c_str()); return std::atoi(str.c_str());
} }
absl::optional< bool > nonstd::optional< bool >
setOptBool(string_view val) setOptBool(string_view val)
{ {
if(IsTrueValue(val)) if(IsTrueValue(val))

@ -75,9 +75,9 @@ namespace llarp
} }
template <> template <>
inline absl::optional< bool > inline nonstd::optional< bool >
fromEnv< absl::optional< bool > >(const absl::optional< bool >& val, fromEnv< nonstd::optional< bool > >(const nonstd::optional< bool >& val,
string_view envNameSuffix) string_view envNameSuffix)
{ {
std::string envName = absl::StrCat("LOKINET_", envNameSuffix); std::string envName = absl::StrCat("LOKINET_", envNameSuffix);
const char* ptr = std::getenv(envName.c_str()); const char* ptr = std::getenv(envName.c_str());
@ -112,7 +112,7 @@ namespace llarp
// long term identity key // long term identity key
std::string m_identKeyfile = "identity.key"; std::string m_identKeyfile = "identity.key";
absl::optional< bool > m_blockBogons; nonstd::optional< bool > m_blockBogons;
bool m_publicOverride = false; bool m_publicOverride = false;
struct sockaddr_in m_ip4addr; struct sockaddr_in m_ip4addr;
@ -142,7 +142,7 @@ namespace llarp
int workerThreads() const { return fromEnv(m_workerThreads, "WORKER_THREADS"); } int workerThreads() const { return fromEnv(m_workerThreads, "WORKER_THREADS"); }
int numNetThreads() const { return fromEnv(m_numNetThreads, "NUM_NET_THREADS"); } int numNetThreads() const { return fromEnv(m_numNetThreads, "NUM_NET_THREADS"); }
std::string defaultLinkProto() const { return fromEnv(m_DefaultLinkProto, "LINK_PROTO"); } std::string defaultLinkProto() const { return fromEnv(m_DefaultLinkProto, "LINK_PROTO"); }
absl::optional< bool > blockBogons() const { return fromEnv(m_blockBogons, "BLOCK_BOGONS"); } nonstd::optional< bool > blockBogons() const { return fromEnv(m_blockBogons, "BLOCK_BOGONS"); }
// clang-format on // clang-format on
void void
@ -155,14 +155,14 @@ namespace llarp
using NetConfig = std::unordered_multimap< std::string, std::string >; using NetConfig = std::unordered_multimap< std::string, std::string >;
private: private:
absl::optional< bool > m_enableProfiling; nonstd::optional< bool > m_enableProfiling;
std::string m_routerProfilesFile = "profiles.dat"; std::string m_routerProfilesFile = "profiles.dat";
std::string m_strictConnect; std::string m_strictConnect;
NetConfig m_netConfig; NetConfig m_netConfig;
public: public:
// clang-format off // clang-format off
absl::optional< bool > enableProfiling() const { return fromEnv(m_enableProfiling, "ENABLE_PROFILING"); } nonstd::optional< bool > enableProfiling() const { return fromEnv(m_enableProfiling, "ENABLE_PROFILING"); }
std::string routerProfilesFile() const { return fromEnv(m_routerProfilesFile, "ROUTER_PROFILES_FILE"); } std::string routerProfilesFile() const { return fromEnv(m_routerProfilesFile, "ROUTER_PROFILES_FILE"); }
std::string strictConnect() const { return fromEnv(m_strictConnect, "STRICT_CONNECT"); } std::string strictConnect() const { return fromEnv(m_strictConnect, "STRICT_CONNECT"); }
const NetConfig& netConfig() const { return m_netConfig; } const NetConfig& netConfig() const { return m_netConfig; }

@ -134,7 +134,7 @@ namespace llarp
llarp_time_t exploreInterval) override; llarp_time_t exploreInterval) override;
/// get localally stored introset by service address /// get localally stored introset by service address
absl::optional< llarp::service::EncryptedIntroSet > nonstd::optional< llarp::service::EncryptedIntroSet >
GetIntroSetByLocation(const Key_t& location) const override; GetIntroSetByLocation(const Key_t& location) const override;
void void
@ -455,7 +455,7 @@ namespace llarp
} }
} }
absl::optional< llarp::service::EncryptedIntroSet > nonstd::optional< llarp::service::EncryptedIntroSet >
Context::GetIntroSetByLocation(const Key_t& key) const Context::GetIntroSetByLocation(const Key_t& key) const
{ {
auto itr = _services->nodes.find(key); auto itr = _services->nodes.find(key);

@ -101,7 +101,7 @@ namespace llarp
Init(const Key_t& us, AbstractRouter* router, Init(const Key_t& us, AbstractRouter* router,
llarp_time_t exploreInterval) = 0; llarp_time_t exploreInterval) = 0;
virtual absl::optional< llarp::service::EncryptedIntroSet > virtual nonstd::optional< llarp::service::EncryptedIntroSet >
GetIntroSetByLocation(const Key_t& location) const = 0; GetIntroSetByLocation(const Key_t& location) const = 0;
virtual llarp_time_t virtual llarp_time_t

@ -6,7 +6,7 @@
#include <util/copy_or_nullptr.hpp> #include <util/copy_or_nullptr.hpp>
#include <vector> #include <vector>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
namespace llarp namespace llarp
{ {
@ -20,7 +20,7 @@ namespace llarp
/// txid /// txid
uint64_t txid = 0; uint64_t txid = 0;
/// the key of a router closer in keyspace if iterative lookup /// the key of a router closer in keyspace if iterative lookup
absl::optional< Key_t > closer; nonstd::optional< Key_t > closer;
GotIntroMessage(const Key_t& from) : IMessage(from) GotIntroMessage(const Key_t& from) : IMessage(from)
{ {

@ -15,7 +15,7 @@
#include <util/thread/logic.hpp> #include <util/thread/logic.hpp>
#include <functional> #include <functional>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
namespace llarp namespace llarp
{ {
@ -187,7 +187,7 @@ namespace llarp
// the actual hop // the actual hop
std::shared_ptr< Hop > hop; std::shared_ptr< Hop > hop;
const absl::optional< llarp::Addr > fromAddr; const nonstd::optional< llarp::Addr > fromAddr;
LRCMFrameDecrypt(Context* ctx, Decrypter_ptr dec, LRCMFrameDecrypt(Context* ctx, Decrypter_ptr dec,
const LR_CommitMessage* commit) const LR_CommitMessage* commit)
@ -196,7 +196,7 @@ namespace llarp
, context(ctx) , context(ctx)
, hop(std::make_shared< Hop >()) , hop(std::make_shared< Hop >())
, fromAddr(commit->session->GetRemoteRC().IsPublicRouter() , fromAddr(commit->session->GetRemoteRC().IsPublicRouter()
? absl::optional< llarp::Addr >{} ? nonstd::optional< llarp::Addr >{}
: commit->session->GetRemoteEndpoint()) : commit->session->GetRemoteEndpoint())
{ {
hop->info.downstream = commit->session->GetPubKey(); hop->info.downstream = commit->session->GetPubKey();

@ -138,7 +138,7 @@ namespace llarp
uint64_t currentStatus = status; uint64_t currentStatus = status;
size_t index = 0; size_t index = 0;
absl::optional< RouterID > failedAt; nonstd::optional< RouterID > failedAt;
while(index < hops.size()) while(index < hops.size())
{ {
if(!frames[index].DoDecrypt(hops[index].shared)) if(!frames[index].DoDecrypt(hops[index].shared))

@ -165,7 +165,7 @@ namespace llarp
nickname.Zero(); nickname.Zero();
enckey.Zero(); enckey.Zero();
pubkey.Zero(); pubkey.Zero();
routerVersion = absl::optional< RouterVersion >{}; routerVersion = nonstd::optional< RouterVersion >{};
last_updated = 0; last_updated = 0;
} }

@ -105,7 +105,7 @@ namespace llarp
uint64_t last_updated = 0; uint64_t last_updated = 0;
uint64_t version = LLARP_PROTO_VERSION; uint64_t version = LLARP_PROTO_VERSION;
absl::optional< RouterVersion > routerVersion; nonstd::optional< RouterVersion > routerVersion;
util::StatusObject util::StatusObject
ExtractStatus() const; ExtractStatus() const;

@ -400,7 +400,7 @@ namespace llarp
return resp; return resp;
} }
absl::optional< Response > Response
HandleJSONRPC(Method_t method, HandleJSONRPC(Method_t method,
ABSL_ATTRIBUTE_UNUSED const Params& params) override ABSL_ATTRIBUTE_UNUSED const Params& params) override
{ {

@ -922,7 +922,7 @@ namespace llarp
bool bool
Endpoint::OnLookup(const Address& addr, Endpoint::OnLookup(const Address& addr,
absl::optional< const IntroSet > introset, nonstd::optional< IntroSet > introset,
const RouterID& endpoint) const RouterID& endpoint)
{ {
const auto now = Router()->Now(); const auto now = Router()->Now();

@ -411,7 +411,7 @@ namespace llarp
llarp_async_verify_rc* j); llarp_async_verify_rc* j);
bool bool
OnLookup(const service::Address& addr, absl::optional< const IntroSet > i, OnLookup(const service::Address& addr, nonstd::optional< IntroSet > i,
const RouterID& endpoint); /* */ const RouterID& endpoint); /* */
bool bool

@ -23,7 +23,7 @@ namespace llarp
HiddenServiceAddressLookup::HandleResponse( HiddenServiceAddressLookup::HandleResponse(
const std::set< EncryptedIntroSet >& results) const std::set< EncryptedIntroSet >& results)
{ {
absl::optional< IntroSet > found; nonstd::optional< IntroSet > found;
const Address remote(rootkey); const Address remote(rootkey);
LogInfo("found ", results.size(), " for ", remote.ToString()); LogInfo("found ", results.size(), " for ", remote.ToString());
if(results.size() > 0) if(results.size() > 0)

@ -16,7 +16,7 @@ namespace llarp
uint64_t relayOrder; uint64_t relayOrder;
const dht::Key_t location; const dht::Key_t location;
using HandlerFunc = std::function< bool( using HandlerFunc = std::function< bool(
const Address&, absl::optional< const IntroSet >, const RouterID&) >; const Address&, nonstd::optional< IntroSet >, const RouterID&) >;
HandlerFunc handle; HandlerFunc handle;
HiddenServiceAddressLookup(Endpoint* p, HandlerFunc h, HiddenServiceAddressLookup(Endpoint* p, HandlerFunc h,

@ -151,7 +151,7 @@ namespace llarp
return crypto->derive_subkey_private(derivedSignKey, signkey, 1); return crypto->derive_subkey_private(derivedSignKey, signkey, 1);
} }
absl::optional< EncryptedIntroSet > nonstd::optional< EncryptedIntroSet >
Identity::EncryptAndSignIntroSet(const IntroSet& other_i, Identity::EncryptAndSignIntroSet(const IntroSet& other_i,
llarp_time_t now) const llarp_time_t now) const
{ {

@ -47,7 +47,7 @@ namespace llarp
bool bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf); DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
absl::optional< EncryptedIntroSet > nonstd::optional< EncryptedIntroSet >
EncryptAndSignIntroSet(const IntroSet& i, llarp_time_t now) const; EncryptAndSignIntroSet(const IntroSet& i, llarp_time_t now) const;
bool bool

@ -6,7 +6,7 @@
#include <service/vanity.hpp> #include <service/vanity.hpp>
#include <util/bencode.hpp> #include <util/bencode.hpp>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
namespace llarp namespace llarp
{ {
@ -23,7 +23,7 @@ namespace llarp
VanityNonce vanity; VanityNonce vanity;
uint64_t version = LLARP_PROTO_VERSION; uint64_t version = LLARP_PROTO_VERSION;
using OptNonce = absl::optional< VanityNonce >; using OptNonce = nonstd::optional< VanityNonce >;
void void
RandomizeVanity() RandomizeVanity()

@ -84,7 +84,7 @@ namespace llarp
return out; return out;
} }
absl::optional< IntroSet > nonstd::optional< IntroSet >
EncryptedIntroSet::MaybeDecrypt(const PubKey& root) const EncryptedIntroSet::MaybeDecrypt(const PubKey& root) const
{ {
SharedSecret k(root); SharedSecret k(root);
@ -176,7 +176,7 @@ namespace llarp
if(key == "w") if(key == "w")
{ {
W = absl::make_optional< PoW >(); W.emplace();
return bencode_decode_dict(*W, buf); return bencode_decode_dict(*W, buf);
} }

@ -10,7 +10,7 @@
#include <util/time.hpp> #include <util/time.hpp>
#include <util/status.hpp> #include <util/status.hpp>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
@ -31,7 +31,7 @@ namespace llarp
PQPubKey K; PQPubKey K;
Tag topic; Tag topic;
llarp_time_t T = 0; llarp_time_t T = 0;
absl::optional< PoW > W; nonstd::optional< PoW > W;
Signature Z; Signature Z;
uint64_t version = LLARP_PROTO_VERSION; uint64_t version = LLARP_PROTO_VERSION;
@ -111,7 +111,7 @@ namespace llarp
llarp_time_t signedAt = 0; llarp_time_t signedAt = 0;
Payload_t introsetPayload; Payload_t introsetPayload;
TunnelNonce nounce; TunnelNonce nounce;
absl::optional< Tag > topic; nonstd::optional< Tag > topic;
Signature sig; Signature sig;
bool bool
@ -145,7 +145,7 @@ namespace llarp
util::StatusObject util::StatusObject
ExtractStatus() const; ExtractStatus() const;
absl::optional< IntroSet > nonstd::optional< IntroSet >
MaybeDecrypt(const PubKey& rootKey) const; MaybeDecrypt(const PubKey& rootKey) const;
}; };

@ -86,9 +86,9 @@ namespace llarp
} }
bool bool
OutboundContext::OnIntroSetUpdate( OutboundContext::OnIntroSetUpdate(const Address&,
const Address&, absl::optional< const IntroSet > foundIntro, nonstd::optional< IntroSet > foundIntro,
const RouterID& endpoint) const RouterID& endpoint)
{ {
if(markedBad) if(markedBad)
return true; return true;

@ -115,7 +115,7 @@ namespace llarp
OnGeneratedIntroFrame(AsyncKeyExchange* k, PathID_t p); OnGeneratedIntroFrame(AsyncKeyExchange* k, PathID_t p);
bool bool
OnIntroSetUpdate(const Address& addr, absl::optional< const IntroSet > i, OnIntroSetUpdate(const Address& addr, nonstd::optional< IntroSet > i,
const RouterID& endpoint); const RouterID& endpoint);
const dht::Key_t location; const dht::Key_t location;

@ -16,7 +16,7 @@ namespace fs = ghc::filesystem;
#include <dirent.h> #include <dirent.h>
#endif #endif
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
namespace llarp namespace llarp
{ {
@ -32,7 +32,7 @@ namespace llarp
/// open a stream to a file and ensure it exists before open /// open a stream to a file and ensure it exists before open
/// sets any permissions on creation /// sets any permissions on creation
template < typename T > template < typename T >
absl::optional< T > nonstd::optional< T >
OpenFileStream(fs::path pathname, std::ios::openmode mode) OpenFileStream(fs::path pathname, std::ios::openmode mode)
{ {
if(EnsurePrivateFile(pathname)) if(EnsurePrivateFile(pathname))

@ -45,7 +45,7 @@ namespace llarp
} }
} }
absl::optional< LogLevel > nonstd::optional< LogLevel >
LogLevelFromString(std::string level) LogLevelFromString(std::string level)
{ {
std::transform( std::transform(

@ -1,7 +1,7 @@
#ifndef LLARP_UTIL_LOG_LEVEL_HPP #ifndef LLARP_UTIL_LOG_LEVEL_HPP
#define LLARP_UTIL_LOG_LEVEL_HPP #define LLARP_UTIL_LOG_LEVEL_HPP
#include <string> #include <string>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
namespace llarp namespace llarp
{ {
@ -22,7 +22,7 @@ namespace llarp
std::string std::string
LogLevelToName(LogLevel lvl); LogLevelToName(LogLevel lvl);
absl::optional< LogLevel > nonstd::optional< LogLevel >
LogLevelFromString(std::string level); LogLevelFromString(std::string level);
} // namespace llarp } // namespace llarp

@ -3,7 +3,7 @@
#include <util/thread/threading.hpp> #include <util/thread/threading.hpp>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <vector> #include <vector>
namespace llarp namespace llarp
@ -330,7 +330,7 @@ namespace llarp
return true; return true;
} }
absl::optional< Value > nonstd::optional< Value >
find(int32_t handle) find(int32_t handle)
{ {
absl::ReaderMutexLock l(&m_mutex); absl::ReaderMutexLock l(&m_mutex);

@ -711,7 +711,7 @@ namespace llarp
m_categories.clear(); m_categories.clear();
} }
absl::optional< absl::Duration > nonstd::optional< absl::Duration >
PublisherScheduler::find(const Category *category) const PublisherScheduler::find(const Category *category) const
{ {
util::Lock l(&m_mutex); util::Lock l(&m_mutex);
@ -725,7 +725,7 @@ namespace llarp
return it->second; return it->second;
} }
absl::optional< absl::Duration > nonstd::optional< absl::Duration >
PublisherScheduler::getDefault() const PublisherScheduler::getDefault() const
{ {
util::Lock l(&m_mutex); util::Lock l(&m_mutex);

@ -1193,16 +1193,16 @@ namespace llarp
return m_manager; return m_manager;
} }
absl::optional< absl::Duration > nonstd::optional< absl::Duration >
find(string_view categoryName) const find(string_view categoryName) const
{ {
return find(m_manager->registry().get(categoryName)); return find(m_manager->registry().get(categoryName));
} }
absl::optional< absl::Duration > nonstd::optional< absl::Duration >
find(const Category *category) const; find(const Category *category) const;
absl::optional< absl::Duration > nonstd::optional< absl::Duration >
getDefault() const; getDefault() const;
std::vector< std::pair< const Category *, absl::Duration > > std::vector< std::pair< const Category *, absl::Duration > >

@ -32,7 +32,7 @@ namespace llarp
{ {
namespace namespace
{ {
absl::optional< std::string > nonstd::optional< std::string >
makeStr(double d) makeStr(double d)
{ {
if(std::isnan(d) || std::isinf(d)) if(std::isnan(d) || std::isinf(d))
@ -43,7 +43,7 @@ namespace llarp
return std::to_string(d); return std::to_string(d);
} }
absl::optional< std::string > nonstd::optional< std::string >
makeStr(int i) makeStr(int i)
{ {
if(i == std::numeric_limits< int >::min() if(i == std::numeric_limits< int >::min()
@ -56,7 +56,7 @@ namespace llarp
} }
template < typename Value > template < typename Value >
absl::optional< std::string > nonstd::optional< std::string >
formatValue(const Record< Value > &record, double elapsedTime, formatValue(const Record< Value > &record, double elapsedTime,
Publication::Type publicationType) Publication::Type publicationType)
{ {

@ -10,7 +10,7 @@
#include <absl/container/flat_hash_map.h> #include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h> #include <absl/container/flat_hash_set.h>
#include <absl/hash/hash.h> #include <absl/hash/hash.h>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <absl/types/span.h> #include <absl/types/span.h>
#include <absl/types/variant.h> #include <absl/types/variant.h>
#include <cstring> #include <cstring>
@ -78,7 +78,7 @@ namespace llarp
struct Format struct Format
{ {
using Spec = absl::optional< FormatSpec >; using Spec = nonstd::optional< FormatSpec >;
std::array< Spec, Publication::MaxSize > m_specs; std::array< Spec, Publication::MaxSize > m_specs;
@ -92,10 +92,11 @@ namespace llarp
m_specs[static_cast< size_t >(pub)].emplace(spec); m_specs[static_cast< size_t >(pub)].emplace(spec);
} }
constexpr void void
clear() clear()
{ {
m_specs = decltype(m_specs)(); for(auto &s : m_specs)
s.reset();
} }
constexpr const FormatSpec * constexpr const FormatSpec *

@ -1,7 +1,7 @@
#ifndef LLARP_STOPWATCH_HPP #ifndef LLARP_STOPWATCH_HPP
#define LLARP_STOPWATCH_HPP #define LLARP_STOPWATCH_HPP
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <absl/time/clock.h> #include <absl/time/clock.h>
namespace llarp namespace llarp
@ -10,8 +10,8 @@ namespace llarp
{ {
class Stopwatch class Stopwatch
{ {
absl::optional< absl::Time > m_start; nonstd::optional< absl::Time > m_start;
absl::optional< absl::Time > m_stop; nonstd::optional< absl::Time > m_stop;
public: public:
Stopwatch() = default; Stopwatch() = default;

@ -4,7 +4,7 @@
#include <ev/ev.hpp> #include <ev/ev.hpp>
#include <util/mem.h> #include <util/mem.h>
#include <util/thread/threadpool.h> #include <util/thread/threadpool.h>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
namespace llarp namespace llarp
{ {
@ -54,7 +54,7 @@ namespace llarp
using ID_t = std::thread::id; using ID_t = std::thread::id;
llarp_threadpool* const m_Thread; llarp_threadpool* const m_Thread;
llarp_ev_loop* m_Loop = nullptr; llarp_ev_loop* m_Loop = nullptr;
absl::optional< ID_t > m_ID; nonstd::optional< ID_t > m_ID;
util::ContentionKiller m_Killer; util::ContentionKiller m_Killer;
std::function< void(std::function< void(void) >) > m_Queue; std::function< void(std::function< void(void) >) > m_Queue;
}; };

@ -4,7 +4,7 @@
#include <util/thread/queue_manager.hpp> #include <util/thread/queue_manager.hpp>
#include <util/thread/threading.hpp> #include <util/thread/threading.hpp>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <atomic> #include <atomic>
#include <tuple> #include <tuple>
@ -73,7 +73,7 @@ namespace llarp
Type Type
popFront(); popFront();
absl::optional< Type > nonstd::optional< Type >
tryPopFront(); tryPopFront();
// Remove all elements from the queue. Note this is not atomic, and if // Remove all elements from the queue. Note this is not atomic, and if
@ -260,7 +260,7 @@ namespace llarp
} }
template < typename Type > template < typename Type >
absl::optional< Type > nonstd::optional< Type >
Queue< Type >::tryPopFront() Queue< Type >::tryPopFront()
{ {
uint32_t generation; uint32_t generation;
@ -285,7 +285,7 @@ namespace llarp
// - notify any waiting pushers // - notify any waiting pushers
QueuePopGuard< Type > popGuard(*this, generation, index); QueuePopGuard< Type > popGuard(*this, generation, index);
return absl::optional< Type >(std::move(m_data[index])); return nonstd::optional< Type >(std::move(m_data[index]));
} }
template < typename Type > template < typename Type >

@ -3,7 +3,7 @@
#include <absl/synchronization/barrier.h> #include <absl/synchronization/barrier.h>
#include <absl/synchronization/mutex.h> #include <absl/synchronization/mutex.h>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <absl/time/time.h> #include <absl/time/time.h>
#include <iostream> #include <iostream>
@ -45,7 +45,7 @@ namespace llarp
/// in debug mode, we implement lock() to enforce that any lock is only /// in debug mode, we implement lock() to enforce that any lock is only
/// used from a single thread. the point of this is to identify locks that /// used from a single thread. the point of this is to identify locks that
/// are actually needed by dying a painful death when used across threads /// are actually needed by dying a painful death when used across threads
mutable absl::optional< std::thread::id > m_id; mutable nonstd::optional< std::thread::id > m_id;
void void
lock() const lock() const
{ {

@ -6,7 +6,7 @@
#include <atomic> #include <atomic>
#include <absl/time/time.h> #include <absl/time/time.h>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <map> #include <map>
#include <utility> #include <utility>
@ -273,7 +273,7 @@ namespace llarp
return true; return true;
} }
absl::optional< absl::Time > nonstd::optional< absl::Time >
nextTime() const nextTime() const
{ {
absl::ReaderMutexLock lock(&m_mutex); absl::ReaderMutexLock lock(&m_mutex);

@ -69,7 +69,7 @@ namespace llarp
void(const dht::Key_t&, AbstractRouter*, llarp_time_t)); void(const dht::Key_t&, AbstractRouter*, llarp_time_t));
MOCK_CONST_METHOD1(GetIntroSetByLocation, MOCK_CONST_METHOD1(GetIntroSetByLocation,
absl::optional< llarp::service::EncryptedIntroSet >( nonstd::optional< llarp::service::EncryptedIntroSet >(
const llarp::dht::Key_t&)); const llarp::dht::Key_t&));
MOCK_CONST_METHOD0(ExtractStatus, util::StatusObject()); MOCK_CONST_METHOD0(ExtractStatus, util::StatusObject());

@ -107,7 +107,7 @@ struct ServerHandler : public abyss::httpd::IRPCHandler
{ {
} }
absl::optional< Response > Response
HandleJSONRPC(Method_t method, ABSL_ATTRIBUTE_UNUSED const Params& params) HandleJSONRPC(Method_t method, ABSL_ATTRIBUTE_UNUSED const Params& params)
{ {
test->AssertMethod(method); test->AssertMethod(method);

@ -50,7 +50,7 @@ TEST(Catalog, smoke)
ASSERT_EQ(handle1, handle2); ASSERT_EQ(handle1, handle2);
ASSERT_TRUE(catalog.find(handle1)); ASSERT_TRUE(catalog.find(handle1));
absl::optional< double > result = catalog.find(handle1); nonstd::optional< double > result = catalog.find(handle1);
ASSERT_TRUE(result); ASSERT_TRUE(result);
ASSERT_EQ(value2, result); ASSERT_EQ(value2, result);
catalog.remove(handle2); catalog.remove(handle2);
@ -80,7 +80,7 @@ TEST(Catalog, Iterator)
for(size_t j = 0; j < ITERATION_COUNT; ++j) for(size_t j = 0; j < ITERATION_COUNT; ++j)
{ {
int32_t handle = cat->add(id); int32_t handle = cat->add(id);
absl::optional< int32_t > res = cat->find(handle); nonstd::optional< int32_t > res = cat->find(handle);
ASSERT_TRUE(res); ASSERT_TRUE(res);
ASSERT_EQ(res.value(), id); ASSERT_EQ(res.value(), id);
ASSERT_TRUE(cat->replace(MAX - id, handle)); ASSERT_TRUE(cat->replace(MAX - id, handle));

@ -8,7 +8,7 @@ using TestString = std::string;
struct TestParseLog struct TestParseLog
{ {
TestString input; TestString input;
absl::optional< llarp::LogLevel > level; nonstd::optional< llarp::LogLevel > level;
}; };
struct LogLevelTest : public ::testing::TestWithParam< TestParseLog > struct LogLevelTest : public ::testing::TestWithParam< TestParseLog >

@ -585,7 +585,7 @@ TEST(TestQueue, moveIt)
ASSERT_EQ(5u, counter); ASSERT_EQ(5u, counter);
absl::optional< MoveTester > optPopped = queue.tryPopFront(); nonstd::optional< MoveTester > optPopped = queue.tryPopFront();
ASSERT_TRUE(optPopped.has_value()); ASSERT_TRUE(optPopped.has_value());

@ -1,6 +1,6 @@
#include <util/thread/queue_manager.hpp> #include <util/thread/queue_manager.hpp>
#include <absl/types/optional.h> #include <nonstd/optional.hpp>
#include <vector> #include <vector>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -75,7 +75,7 @@ class IntQueue
} }
} }
absl::optional< int > nonstd::optional< int >
tryPopFront() tryPopFront()
{ {
uint32_t gen = 0; uint32_t gen = 0;

Loading…
Cancel
Save