diff --git a/android/build.gradle b/android/build.gradle index dcd2a6388..c53bd02c9 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -30,7 +30,7 @@ android { versionName '0.8.4' externalNativeBuild { cmake { - // targets "lokinet-android" + targets "lokinet-android" arguments "-DWITH_LTO=OFF", "-DCXXOPTS_BUILD_TESTS=OFF","-DWITH_TESTS=OFF", "-DCMAKE_CROSSCOMPILING=ON", "-DNATIVE_BUILD=OFF", "-DANDROID=ON", "-DANDROID_STL=c++_static", "-DBUILD_STATIC_DEPS=ON", "-DBUILD_SHARED_LIBS=OFF", "-DSTATIC_LINK=ON", "-DANDROID_ARM_MODE=arm", "-DFORCE_OXENMQ_SUBMODULE=ON" cppFlags "-std=c++17" abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 9bfeac730..c52188aa4 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -24,6 +24,11 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") endif() target_link_libraries(lokinet-bootstrap PUBLIC cpr::cpr) +if(NOT WIN32) + find_package(OpenSSL REQUIRED) + # because debian sid's curl doesn't link against openssl for some godawful cursed reason + target_link_libraries(lokinet-bootstrap PUBLIC OpenSSL::Crypto) +endif() foreach(exe lokinet lokinet-vpn lokinet-bootstrap) if(WIN32 AND NOT MSVC_VERSION) @@ -36,6 +41,7 @@ foreach(exe lokinet lokinet-vpn lokinet-bootstrap) if(WITH_JEMALLOC) target_link_libraries(${exe} PUBLIC jemalloc) endif() + target_include_directories(${exe} PRIVATE ${CMAKE_SOURCE_DIR}) target_compile_definitions(${exe} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) add_log_tag(${exe}) if(should_install) diff --git a/daemon/lokinet-bootstrap.cpp b/daemon/lokinet-bootstrap.cpp index 855dcc9f3..75209012c 100644 --- a/daemon/lokinet-bootstrap.cpp +++ b/daemon/lokinet-bootstrap.cpp @@ -1,11 +1,13 @@ #include #include #include -#include #include -#include +#include #include +#include + +#include #ifndef _WIN32 #include @@ -14,21 +16,41 @@ namespace { int - exit_with_message(std::string msg, int exitcode) + fail(std::string msg) { std::cout << msg << std::endl; - return exitcode; + return 1; } } // namespace int main(int argc, char* argv[]) { - std::string bootstrap_url{"https://seed.lokinet.org/lokinet.signed"}; + const std::unordered_map bootstrap_urls = { + {"mainnet", "https://seed.lokinet.org/lokinet.signed"}, + {"lokinet", "https://seed.lokinet.org/lokinet.signed"}, + {"testnet", "https://seed.lokinet.org/testnet.signed"}, + {"gamma", "https://seed.lokinet.org/testnet.signed"}}; + + std::string bootstrap_url = bootstrap_urls.at("lokinet"); + fs::path outputfile{llarp::GetDefaultBootstrap()}; + if (argc > 1) { - bootstrap_url = argv[1]; + if (auto itr = bootstrap_urls.find(argv[1]); itr != bootstrap_urls.end()) + { + bootstrap_url = itr->second; + } + else + { + bootstrap_url = argv[1]; + } } + if (argc > 2) + { + outputfile = fs::path{argv[2]}; + } + cpr::Response resp = #ifdef _WIN32 cpr::Get( @@ -41,24 +63,24 @@ main(int argc, char* argv[]) #endif if (resp.status_code != 200) { - return exit_with_message( - "failed to fetch '" + bootstrap_url + "' HTTP " + std::to_string(resp.status_code), 1); + return fail("failed to fetch '" + bootstrap_url + "' HTTP " + std::to_string(resp.status_code)); } - std::stringstream ss; ss << resp.text; - std::string data{ss.str()}; - llarp_buffer_t buf{&data[0], data.size()}; - - llarp::RouterContact rc; - if (not rc.BDecode(&buf)) - return exit_with_message("invalid bootstrap data was fetched", 1); - - const auto path = llarp::GetDefaultBootstrap(); - if (not rc.Write(path)) - return exit_with_message("failed to write bootstrap file to " + path.string(), 1); - - const llarp::RouterID router{rc.pubkey}; - return exit_with_message("fetched bootstrap file for " + router.ToString(), 0); + if (data[0] == 'l' or data[0] == 'd') + { + try + { + fs::ofstream ofs{outputfile, std::ios::binary}; + ofs.exceptions(fs::ofstream::failbit); + ofs << data; + return 0; + } + catch (std::exception& ex) + { + return fail(std::string{"failed to write bootstrap file: "} + ex.what()); + } + } + return fail("got invalid bootstrap file content"); } diff --git a/llarp/util/fs.hpp b/llarp/util/fs.hpp index d588292ea..be68057d6 100644 --- a/llarp/util/fs.hpp +++ b/llarp/util/fs.hpp @@ -13,7 +13,14 @@ namespace fs = ghc::filesystem; #else #include -namespace fs = std::filesystem; +namespace fs +{ + using namespace std::filesystem; + using ifstream = std::ifstream; + using ofstream = std::ofstream; + using fstream = std::fstream; +} // namespace fs + #endif #ifndef _MSC_VER