mirror of https://github.com/oxen-io/lokinet
bake in bootstrap fallbacks at build time
also change the defailt/fallback bootstrap file for testnet to be a list of RCs (albeit of size 1) rather than just an RC dict.
This commit is contained in:
parent
82c95a2486
commit
82e2e6fb10
|
@ -39,7 +39,6 @@ set(RELEASE_MOTTO "Our Lord And Savior" CACHE STRING "Release motto")
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||||
|
|
||||||
set(BOOTSTRAP_SYSTEM_PATH "" CACHE PATH "Fallback bootstrap path")
|
|
||||||
set(DEFAULT_WITH_BOOTSTRAP ON)
|
set(DEFAULT_WITH_BOOTSTRAP ON)
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(DEFAULT_WITH_BOOTSTRAP OFF)
|
set(DEFAULT_WITH_BOOTSTRAP OFF)
|
||||||
|
@ -64,6 +63,8 @@ option(WITH_BOOTSTRAP "build lokinet-bootstrap tool" ${DEFAULT_WITH_BOOTSTRAP})
|
||||||
option(WITH_PEERSTATS "build with experimental peerstats db support" OFF)
|
option(WITH_PEERSTATS "build with experimental peerstats db support" OFF)
|
||||||
option(STRIP_SYMBOLS "strip off all debug symbols into an external archive for all executables built" OFF)
|
option(STRIP_SYMBOLS "strip off all debug symbols into an external archive for all executables built" OFF)
|
||||||
|
|
||||||
|
set(BOOTSTRAP_FALLBACK_MAINNET "${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed" CACHE PATH "Fallback bootstrap path (mainnet)")
|
||||||
|
set(BOOTSTRAP_FALLBACK_TESTNET "${PROJECT_SOURCE_DIR}/contrib/bootstrap/testnet.signed" CACHE PATH "Fallback bootstrap path (testnet)")
|
||||||
|
|
||||||
include(cmake/enable_lto.cmake)
|
include(cmake/enable_lto.cmake)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
d1:ald1:ci2e1:d3:iwp1:e32:9ãxÚsX«l%ìû€ê<,sØ›”•©÷ïå_1:i21:::ffff:144.76.164.2021:pi1666e1:vi0eee1:i5:gamma1:k32:ÞÊðòm=o›„ZÐ1ÿßmcŒ%»¸ÿû¾™SĹ1:p32:!EÏâéz˜ý:Š‹úý…/0¡Ú„Ãݪ„µNçB1:rli0ei0ei8ei3ee1:ui1614788310454e1:vi0e1:xle1:z64:Œ¤u G¿”D“=Œxµ¢{ïÌ51þ`í߀ùEâwm)q2Øg¯±˜øš ï³À)˜TÑP•´ò³ö—Á1e
|
ld1:ald1:ci2e1:d3:iwp1:e32:9ãxÚsX«l%ìû€ê<,sØ›”•©÷ïå_1:i21:::ffff:144.76.164.2021:pi1666e1:vi0eee1:i5:gamma1:k32:ÞÊðòm=o›„ZÐ1ÿßmcŒ%»¸ÿû¾™SĹ1:p32:!EÏâéz˜ý:Š‹úý…/0¡Ú„Ãݪ„µNçB1:rli0ei0ei8ei3ee1:ui1614788310454e1:vi0e1:xle1:z64:Œ¤u G¿”D“=Œxµ¢{ïÌ51þ`í߀ùEâwm)q2Øg¯±˜øš ï³À)˜TÑP•´ò³ö—Á1ee
|
||||||
|
|
|
@ -235,10 +235,24 @@ add_library(lokinet-amalgum
|
||||||
service/tag.cpp
|
service/tag.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(BOOTSTRAP_SYSTEM_PATH)
|
set(BOOTSTRAP_FALLBACKS)
|
||||||
message(STATUS "Building with fallback boostrap path \"${BOOTSTRAP_SYSTEM_PATH}\"")
|
foreach(bs IN ITEMS MAINNET TESTNET)
|
||||||
target_compile_definitions(lokinet-amalgum PRIVATE "BOOTSTRAP_FALLBACK=\"${BOOTSTRAP_SYSTEM_PATH}\"")
|
if(BOOTSTRAP_FALLBACK_${bs})
|
||||||
endif()
|
message(STATUS "Building with ${bs} fallback boostrap path \"${BOOTSTRAP_FALLBACK_${bs}}\"")
|
||||||
|
file(READ "${BOOTSTRAP_FALLBACK_${bs}}" bs_data HEX)
|
||||||
|
if(bs STREQUAL TESTNET)
|
||||||
|
set(network "gamma")
|
||||||
|
elseif(bs STREQUAL MAINNET)
|
||||||
|
set(network "lokinet")
|
||||||
|
else()
|
||||||
|
string(TOLOWER "${bs}" network)
|
||||||
|
endif()
|
||||||
|
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "\\\\x\\1" bs_data "${bs_data}")
|
||||||
|
set(BOOTSTRAP_FALLBACKS "${BOOTSTRAP_FALLBACKS}{\"${network}\"s, \"${bs_data}\"sv},\n")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
configure_file("bootstrap-fallbacks.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/bootstrap-fallbacks.cpp" @ONLY)
|
||||||
|
target_sources(lokinet-amalgum PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/bootstrap-fallbacks.cpp")
|
||||||
|
|
||||||
if(WITH_PEERSTATS_BACKEND)
|
if(WITH_PEERSTATS_BACKEND)
|
||||||
target_compile_definitions(lokinet-amalgum PRIVATE -DLOKINET_PEERSTATS_BACKEND)
|
target_compile_definitions(lokinet-amalgum PRIVATE -DLOKINET_PEERSTATS_BACKEND)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <initializer_list>
|
||||||
|
#include "llarp/bootstrap.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, BootstrapList>
|
||||||
|
load_bootstrap_fallbacks()
|
||||||
|
{
|
||||||
|
std::unordered_map<std::string, BootstrapList> fallbacks;
|
||||||
|
using init_list = std::initializer_list<std::pair<std::string, std::string_view>>;
|
||||||
|
// clang-format off
|
||||||
|
for (const auto& [network, bootstrap] : init_list{
|
||||||
|
@BOOTSTRAP_FALLBACKS@
|
||||||
|
})
|
||||||
|
// clang-format on
|
||||||
|
{
|
||||||
|
llarp_buffer_t buf{bootstrap.data(), bootstrap.size()};
|
||||||
|
auto& bsl = fallbacks[network];
|
||||||
|
bsl.BDecode(&buf);
|
||||||
|
}
|
||||||
|
return fallbacks;
|
||||||
|
}
|
||||||
|
} // namespace llarp
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "router_contact.hpp"
|
#include "router_contact.hpp"
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <unordered_map>
|
||||||
#include "llarp/util/fs.hpp"
|
#include "llarp/util/fs.hpp"
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp
|
||||||
|
@ -20,4 +21,8 @@ namespace llarp
|
||||||
void
|
void
|
||||||
Clear();
|
Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::unordered_map<std::string, BootstrapList>
|
||||||
|
load_bootstrap_fallbacks();
|
||||||
|
|
||||||
} // namespace llarp
|
} // namespace llarp
|
||||||
|
|
|
@ -665,21 +665,14 @@ namespace llarp
|
||||||
|
|
||||||
// if our conf had no bootstrap files specified, try the default location of
|
// if our conf had no bootstrap files specified, try the default location of
|
||||||
// <DATA_DIR>/bootstrap.signed. If this isn't present, leave a useful error message
|
// <DATA_DIR>/bootstrap.signed. If this isn't present, leave a useful error message
|
||||||
|
// TODO: use constant
|
||||||
|
fs::path defaultBootstrapFile = conf.router.m_dataDir / "bootstrap.signed";
|
||||||
if (configRouters.empty() and conf.bootstrap.routers.empty())
|
if (configRouters.empty() and conf.bootstrap.routers.empty())
|
||||||
{
|
{
|
||||||
// TODO: use constant
|
|
||||||
fs::path defaultBootstrapFile = conf.router.m_dataDir / "bootstrap.signed";
|
|
||||||
if (fs::exists(defaultBootstrapFile))
|
if (fs::exists(defaultBootstrapFile))
|
||||||
{
|
{
|
||||||
configRouters.push_back(defaultBootstrapFile);
|
configRouters.push_back(defaultBootstrapFile);
|
||||||
}
|
}
|
||||||
else if (not conf.bootstrap.seednode)
|
|
||||||
{
|
|
||||||
LogError("No bootstrap files specified in config file, and the default");
|
|
||||||
LogError("bootstrap file ", defaultBootstrapFile, " does not exist.");
|
|
||||||
LogError("Please provide a bootstrap file (e.g. run 'lokinet-bootstrap)'");
|
|
||||||
throw std::runtime_error("No bootstrap files available.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BootstrapList b_list;
|
BootstrapList b_list;
|
||||||
|
@ -708,7 +701,7 @@ namespace llarp
|
||||||
{
|
{
|
||||||
if (rc.IsObsoleteBootstrap())
|
if (rc.IsObsoleteBootstrap())
|
||||||
{
|
{
|
||||||
LogWarn("ignoring obsolete boostrap RC: ", RouterID(rc.pubkey));
|
log::warning(logcat, "ignoring obsolete boostrap RC: {}", RouterID(rc.pubkey));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (not rc.Verify(Now()))
|
if (not rc.Verify(Now()))
|
||||||
|
@ -722,29 +715,29 @@ namespace llarp
|
||||||
|
|
||||||
verifyRCs();
|
verifyRCs();
|
||||||
|
|
||||||
#ifdef BOOTSTRAP_FALLBACK
|
|
||||||
constexpr std::string_view bootstrap_fallback = BOOTSTRAP_FALLBACK;
|
|
||||||
#else
|
|
||||||
constexpr std::string_view bootstrap_fallback{};
|
|
||||||
#endif // BOOTSTRAP_FALLBACK
|
|
||||||
|
|
||||||
if (bootstrapRCList.empty() and not conf.bootstrap.seednode)
|
if (bootstrapRCList.empty() and not conf.bootstrap.seednode)
|
||||||
{
|
{
|
||||||
if (not bootstrap_fallback.empty())
|
auto fallbacks = llarp::load_bootstrap_fallbacks();
|
||||||
|
if (auto itr = fallbacks.find(_rc.netID.ToString()); itr != fallbacks.end())
|
||||||
{
|
{
|
||||||
b_list.clear();
|
b_list = itr->second;
|
||||||
b_list.AddFromFile(bootstrap_fallback);
|
|
||||||
|
|
||||||
verifyRCs();
|
verifyRCs();
|
||||||
}
|
}
|
||||||
if (bootstrapRCList.empty()) // empty after trying fallback, if set
|
if (bootstrapRCList.empty()
|
||||||
throw std::runtime_error{"we have no bootstrap nodes"};
|
and not conf.bootstrap.seednode) // empty after trying fallback, if set
|
||||||
|
{
|
||||||
|
log::error(
|
||||||
|
logcat,
|
||||||
|
"No bootstrap routers were loaded. The default bootstrap file {} does not exist, and "
|
||||||
|
"loading fallback bootstrap RCs failed.",
|
||||||
|
defaultBootstrapFile);
|
||||||
|
throw std::runtime_error("No bootstrap nodes available.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf.bootstrap.seednode)
|
if (conf.bootstrap.seednode)
|
||||||
{
|
|
||||||
LogInfo("we are a seed node");
|
LogInfo("we are a seed node");
|
||||||
}
|
|
||||||
else
|
else
|
||||||
LogInfo("Loaded ", bootstrapRCList.size(), " bootstrap routers");
|
LogInfo("Loaded ", bootstrapRCList.size(), " bootstrap routers");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue