From 4d4b33607f39c2b9dfd27ffaed75696ed73fab92 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 12 Feb 2020 11:40:48 -0500 Subject: [PATCH] dont use optional --- llarp/service/endpoint.cpp | 14 ++++---------- llarp/service/endpoint_util.hpp | 6 ++---- llarp/service/outbound_context.cpp | 6 ++---- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index d2f548b0e..c34549606 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -462,13 +462,11 @@ namespace llarp { /// number of routers to publish to static constexpr size_t PublishRedundancy = 2; - const auto maybe = + const auto paths = GetManyPathsWithUniqueEndpoints(this, PublishRedundancy); - if(not maybe.has_value()) - return false; // do publishing for each path selected size_t published = 0; - for(const auto& path : maybe.value()) + for(const auto& path : paths) { if(PublishIntroSetVia(i, r, path)) { @@ -970,17 +968,13 @@ namespace llarp auto& lookups = m_state->m_PendingServiceLookups; - const auto maybe = + const auto paths = GetManyPathsWithUniqueEndpoints(this, NumParalellLookups); - if(not maybe.has_value()) - { - return false; - } using namespace std::placeholders; size_t lookedUp = 0; const dht::Key_t location = remote.ToKey(); - for(const auto& path : maybe.value()) + for(const auto& path : paths) { HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup( this, util::memFn(&Endpoint::OnLookup, this), location, diff --git a/llarp/service/endpoint_util.hpp b/llarp/service/endpoint_util.hpp index 33ce2b553..ab7dff06e 100644 --- a/llarp/service/endpoint_util.hpp +++ b/llarp/service/endpoint_util.hpp @@ -43,7 +43,7 @@ namespace llarp }; template < typename Endpoint_t > - static absl::optional< path::Path::UniqueEndpointSet_t > + static path::Path::UniqueEndpointSet_t GetManyPathsWithUniqueEndpoints(Endpoint_t* ep, size_t N, size_t tries = 10) { path::Path::UniqueEndpointSet_t paths; @@ -54,9 +54,7 @@ namespace llarp if(path) paths.emplace(path); } while(tries > 0 and paths.size() < N); - if(paths.size() == N) - return paths; - return {}; + return paths; } } // namespace service diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 8b6252ef0..3b4eca40c 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -228,10 +228,8 @@ namespace llarp return; const auto addr = currentIntroSet.A.Addr(); - const auto maybe = GetManyPathsWithUniqueEndpoints(this, 2); - if(not maybe.has_value()) - return; - for(const auto& path : maybe.value()) + const auto paths = GetManyPathsWithUniqueEndpoints(this, 2); + for(const auto& path : paths) { HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup( m_Endpoint,