From 1ecdfd73e7f4cc07fd1af55a30efe07a7d13bbe8 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 12 Nov 2020 08:15:46 -0400 Subject: [PATCH 01/12] Dev to stable (#1471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Install less stuff on windows CI mingw-w64 is a metapackage that pulls in 4 different compilers {i686,x86_64}×{-posix,-win32} but we only need x86_64-posix, so just install that package. * Update gui win32 package url (#1466) (#1468) Co-authored-by: Jeff * stop lokinet before uninstalling service (#1469) * stop lokinet before uninstalling service * kill gui in uninstaller * add helper script for building windows installers because i forgot how to most of the time. * Update win32 gui download with smaller svg icon Co-authored-by: Jeff --- .drone.jsonnet | 6 +++--- cmake/win32_installer_deps.cmake | 6 +++--- contrib/windows.sh | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100755 contrib/windows.sh diff --git a/.drone.jsonnet b/.drone.jsonnet index 80217a54c..0bfa9df7d 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -90,7 +90,7 @@ local windows_cross_pipeline(name, image, 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections', apt_get_quiet + ' update', apt_get_quiet + ' install -y eatmydata', - 'eatmydata ' + apt_get_quiet + ' install -y build-essential cmake git ninja-build pkg-config ccache mingw-w64 nsis zip', + 'eatmydata ' + apt_get_quiet + ' install -y build-essential cmake git ninja-build pkg-config ccache g++-mingw-w64-x86-64-posix nsis zip', 'update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix', 'update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix', 'git clone https://github.com/despair86/libuv.git win32-setup/libuv', @@ -215,8 +215,8 @@ local mac_builder(name, build_type='Release', werror=true, cmake_extra='', extra debian_pipeline("Debian sid (ARM64)", "debian:sid", arch="arm64"), debian_pipeline("Debian buster (armhf)", "arm32v7/debian:buster", arch="arm64", cmake_extra='-DDOWNLOAD_SODIUM=ON'), - // Windows builds (WOW64 and native) - windows_cross_pipeline("win32 (amd64)", "debian:testing", + // Windows builds (x64) + windows_cross_pipeline("Windows (amd64)", "debian:testing", toolchain='64', extra_cmds=[ '../contrib/ci/drone-static-upload.sh' ]), diff --git a/cmake/win32_installer_deps.cmake b/cmake/win32_installer_deps.cmake index fa0a0453b..17c737655 100644 --- a/cmake/win32_installer_deps.cmake +++ b/cmake/win32_installer_deps.cmake @@ -1,5 +1,5 @@ -set(GUI_ZIP_URL "https://builds.lokinet.dev/loki-project/loki-network-control-panel/master/lokinet-gui-windows-32bit-v0.3.2.zip") -set(GUI_ZIP_HASH SHA256=136595c287f0664e02a7c62a88fd69299510545b0f25c028dba0142f62b8e189) +set(GUI_ZIP_URL "https://builds.lokinet.dev/loki-project/loki-network-control-panel/master/lokinet-gui-windows-32bit-v0.3.3.zip") +set(GUI_ZIP_HASH SHA256=4a7be3e8d93b891959c896e050ff9e3beba2e82003419cb199fdacd53937a5cb) set(TUNTAP_URL "https://build.openvpn.net/downloads/releases/latest/tap-windows-latest-stable.exe") set(TUNTAP_EXE "${CMAKE_BINARY_DIR}/tuntap-install.exe") set(BOOTSTRAP_URL "https://seed.lokinet.org/lokinet.signed") @@ -29,7 +29,7 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "Lokinet") set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/win32-setup/lokinet.ico") set(CPACK_NSIS_DEFINES "RequestExecutionLevel admin") set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '$INSTDIR\\\\bin\\\\tuntap-install.exe /S'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe --install'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe -g C:\\\\ProgramData\\\\lokinet\\\\lokinet.ini'\\nCopyFiles '$INSTDIR\\\\share\\\\bootstrap.signed' C:\\\\ProgramData\\\\lokinet\\\\bootstrap.signed") -set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "ExecWait '$INSTDIR\\\\bin\\\\lokinet.exe --remove'\\nRMDir /r /REBOOTOK C:\\\\ProgramData\\\\lokinet") +set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "ExecWait 'net stop lokinet'\\nExecWait 'taskkill /f /t /im lokinet-gui.exe'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe --remove'\\nRMDir /r /REBOOTOK C:\\\\ProgramData\\\\lokinet") set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Lokinet.lnk' '$INSTDIR\\\\share\\\\gui\\\\lokinet-gui.exe'" ) diff --git a/contrib/windows.sh b/contrib/windows.sh new file mode 100755 index 000000000..5215e4420 --- /dev/null +++ b/contrib/windows.sh @@ -0,0 +1,5 @@ +#!/bin/bash +mkdir -p build-windows +cd build-windows +cmake -G Ninja -DCMAKE_CROSSCOMPILE=ON -DCMAKE_EXE_LINKER_FLAGS=-fstack-protector -DLIBUV_ROOT=$PWD/../external/libuv -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always -DCMAKE_TOOLCHAIN_FILE=../contrib/cross/mingw64.cmake -DBUILD_STATIC_DEPS=ON -DBUILD_PACKAGE=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DWITH_TESTS=OFF -DNATIVE_BUILD=OFF -DSTATIC_LINK=ON -DWITH_SYSTEMD=OFF -DFORCE_LOKIMQ_SUBMODULE=ON -DSUBMODULE_CHECK=OFF -DWITH_LTO=OFF .. +ninja package From 80a76c9386ebbbed9931d6c024e1c8cd4dd31778 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 11 Mar 2021 08:34:14 -0500 Subject: [PATCH 02/12] fix segfault --- llarp/service/protocol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/service/protocol.cpp b/llarp/service/protocol.cpp index 0f6fd0ee0..c3aa66001 100644 --- a/llarp/service/protocol.cpp +++ b/llarp/service/protocol.cpp @@ -457,7 +457,7 @@ namespace llarp RecvDataEvent ev; ev.fromPath = std::move(recvPath); ev.pathid = v->frame.F; - auto& handler = ev.msg->handler; + auto* handler = msg->handler; ev.msg = std::move(msg); handler->QueueRecvData(std::move(ev)); }); From aa0546563a39763def4228446f59f37148b05093 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 17 Mar 2021 07:53:11 -0400 Subject: [PATCH 03/12] lokimq -> oxenmq artifact * fix dep to lokimq in macos installer gui target when doing make package, change it to oxenmq --- cmake/macos_installer_deps.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/macos_installer_deps.cmake b/cmake/macos_installer_deps.cmake index 2333c7d41..a56995a73 100644 --- a/cmake/macos_installer_deps.cmake +++ b/cmake/macos_installer_deps.cmake @@ -37,13 +37,13 @@ endif() ExternalProject_Add(lokinet-gui - DEPENDS lokimq::lokimq + DEPENDS oxenmq::oxenmq GIT_REPOSITORY "${LOKINET_GUI_REPO}" GIT_TAG "${LOKINET_GUI_CHECKOUT}" CMAKE_ARGS -DMACOS_APP=ON -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DMACOS_SIGN=${MACOS_SIGN_APP} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DBUILD_SHARED_LIBS=OFF - "-DLOKIMQ_LIBRARIES=$$$$$" - "-DLOKIMQ_INCLUDE_DIRS=$" + "-DOXENMQ_LIBRARIES=$$$$$" + "-DOXENMQ_INCLUDE_DIRS=$" ) install(PROGRAMS ${CMAKE_SOURCE_DIR}/contrib/macos/lokinet_uninstall.sh From 3af465bb5f6671a1e87a57a59e1a10b9f2fe17d7 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 14 Apr 2021 12:53:53 -0400 Subject: [PATCH 04/12] rebrand and bump version --- CMakeLists.txt | 2 +- cmake/StaticBuild.cmake | 5 ++++- cmake/win32_installer_deps.cmake | 4 ++-- contrib/windows.sh | 2 +- win32-setup/lokinet.ico | Bin 4286 -> 1094 bytes 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47a6014bb..020172203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ if(CCACHE_PROGRAM) endif() project(lokinet - VERSION 0.8.4 + VERSION 0.8.5 DESCRIPTION "lokinet - IP packet onion router" LANGUAGES C CXX) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index ebac3a402..95909a140 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -278,7 +278,10 @@ add_static_target(sqlite3 sqlite3_external libsqlite3.a) if(ARCH_TRIPLET MATCHES mingw) - set(zmq_extra --with-poller=wepoll) + option(WITH_WEPOLL "use wepoll zmq poller (crashy)" OFF) + if(WITH_WEPOLL) + set(zmq_extra --with-poller=wepoll) + endif() endif() if(CMAKE_CROSSCOMPILING AND ARCH_TRIPLET MATCHES mingw) diff --git a/cmake/win32_installer_deps.cmake b/cmake/win32_installer_deps.cmake index 241c088e7..028d3445f 100644 --- a/cmake/win32_installer_deps.cmake +++ b/cmake/win32_installer_deps.cmake @@ -1,6 +1,6 @@ if(NOT GUI_ZIP_URL) - set(GUI_ZIP_URL "https://oxen.rocks/oxen-io/loki-network-control-panel/lokinet-gui-windows-32bit-v0.3.6.zip") - set(GUI_ZIP_HASH_OPTS EXPECTED_HASH SHA256=6feeb4df1983f00ee686b3de8b56e3e73c55d7d1a8a41b746a37234a426add31) + set(GUI_ZIP_URL "https://oxen.rocks/oxen-io/loki-network-control-panel/lokinet-gui-windows-32bit-v0.3.7.zip") + set(GUI_ZIP_HASH_OPTS EXPECTED_HASH SHA256=faafb5c7c8b9831f572ed78bb2cf8454bfa0d5f79897ce31e64e4a4331d55045) endif() set(TUNTAP_URL "https://build.openvpn.net/downloads/releases/latest/tap-windows-latest-stable.exe") diff --git a/contrib/windows.sh b/contrib/windows.sh index dddecd94a..cf8a94e7f 100755 --- a/contrib/windows.sh +++ b/contrib/windows.sh @@ -3,5 +3,5 @@ set -e set +x mkdir -p build-windows cd build-windows -cmake -G Ninja -DCMAKE_EXE_LINKER_FLAGS=-fstack-protector -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always -DCMAKE_TOOLCHAIN_FILE=../contrib/cross/mingw64.cmake -DBUILD_STATIC_DEPS=ON -DBUILD_PACKAGE=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DWITH_TESTS=OFF -DNATIVE_BUILD=OFF -DSTATIC_LINK=ON -DWITH_SYSTEMD=OFF -DFORCE_LOKIMQ_SUBMODULE=ON -DSUBMODULE_CHECK=OFF -DWITH_LTO=OFF -DCMAKE_BUILD_TYPE=Release .. +cmake -G Ninja -DCMAKE_EXE_LINKER_FLAGS=-fstack-protector -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always -DCMAKE_TOOLCHAIN_FILE=../contrib/cross/mingw64.cmake -DBUILD_STATIC_DEPS=ON -DBUILD_PACKAGE=ON -DBUILD_LIBLOKINET=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DWITH_TESTS=OFF -DNATIVE_BUILD=OFF -DSTATIC_LINK=ON -DWITH_SYSTEMD=OFF -DFORCE_OXENMQ_SUBMODULE=ON -DSUBMODULE_CHECK=OFF -DWITH_LTO=OFF -DCMAKE_BUILD_TYPE=Release $@ .. ninja package diff --git a/win32-setup/lokinet.ico b/win32-setup/lokinet.ico index 274d3b3a2618bad8931f59cc97d877e40393ba48..6efad98330dbd4c475032aabe89ba01d8aebcde7 100644 GIT binary patch literal 1094 zcmeHEF;2uV5FB5Sf)K(Kh-;8SNl8g{xhL@eBwONP7b>1W8;Ry53Vaoo$a$D`(((du zw3$qHvzeU*oUZM5Rq_4=xCU^i*easJ^1mIDH6<(xJ5#8@+|QWSGw%J2Lpx(^W`qm& zP$DXyfXXw_+lvI$27AQXAUV_qxrsGDwL@oh#qSNsE`^G_Z-Xy(N4}9C++}`}FOyF} z4Px;}&bSN! literal 4286 zcmeH~ZERCj7{@R2vPFh_ZE1V&ZOhipu`w3gZr#S(u689%6x<>V1czZv#Wf**kOTs; z7|o0y6cZyZK;}zeXo8?7)V0lTRM^_Nm@yg%2ClJHK9^Jl>o->m;c8O6ciL>DT?v| zYA^ntJCm!b4z%PH*Del$&2HDPi;9YJX2OTseQR{SLH{}X?v+eY<9zbtv{tLt+)E#p zeY~*@>`SQ3H_**$Ut2v6?q9+_{HW9E%=f|v_pwd~xWB~M#2@sJdcNrLs3j&J_`eH2 zjOg|H>P-6J`Re({!TUpCU-x|3wUjf!vw{D!;KQiFU})mw>9pRHFLr_ZkHG%k`RTL9 zL{03w1^kPG4}Z$C{8XY{GSAI}-2rf;0{h$gzV-Q}k)NMG4=lQWCseDYi24?y;Q5^3 zLj*o_(^#^_dt&S61olz;-nMMgDJ(3^Aui{X)Ghv@?)`QXjcGKR1?Ug)F|<+m@EnaL zQ@{=i>%QVX-kC-7p|64FnYcdgpnca$dLOU5j&80Z8@vzmF+Rd=j3wp}^(Rw&1OBkU zC;edMhK4F=Uf{ZD$7=#l{0dtdr+Tw~@0u3$2e}Q_&K`Mbc{mw1*(UOxeH)pnqU2w$ zi}p8JRlE)R*O!8OnfRX1yO_nbBpSED-q^OUK&bweSLK-PNlewJvX(K|M;*h?{!Ov7CLi<$eHDBf z=IcgGV)gH=7SosU^@&J*z;=k0i-bqqOZjI+^RD)lZchs}GalW`*jzOmFC5_Crp zPv_HK*Y`b5`R{zqtE;B$4Q$UN2I|Ph(Yy8m*qlY>`w*o5WD4%hR%lMX%Zd`u@%Fb` zbIZKdgMxoyDpK74z` zVw3gFRk>gf2u?s|#oq_Sc;q0uXG4ws9dafZchf)$ehB;l?n7}+`8PFhx5e(? z-R5R$9N!@P|Bp{JTJ3|G(!H-Uvpc}V5^*y&ZenaSm$9o^jGdaz*q%L%%|6AVbIh+q nvh&=Lyli(wk|ye`fIC8!Khqd&$d=~B=8^_!ktS&qLn!|N2GMF7 From e8178a032e659af1e36f8334662bd544deeea8cd Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 15 Apr 2021 13:39:45 -0400 Subject: [PATCH 05/12] lokinet-bootstrap native binary --- .drone.jsonnet | 2 +- .gitmodules | 3 + CMakeLists.txt | 38 +--------- cmake/StaticBuild.cmake | 118 +++++++++++++++++++++++++++++-- cmake/win32_installer_deps.cmake | 2 +- contrib/windows.sh | 19 ++++- daemon/CMakeLists.txt | 15 ++-- daemon/lokinet-bootstrap.cpp | 64 +++++++++++++++++ daemon/{main.cpp => lokinet.cpp} | 0 external/CMakeLists.txt | 76 ++++++++++++++++++++ external/cpr | 1 + llarp/CMakeLists.txt | 4 -- llarp/constants/files.hpp | 28 ++++---- readme.md | 3 +- 14 files changed, 302 insertions(+), 71 deletions(-) create mode 100644 daemon/lokinet-bootstrap.cpp rename daemon/{main.cpp => lokinet.cpp} (100%) create mode 100644 external/CMakeLists.txt create mode 160000 external/cpr diff --git a/.drone.jsonnet b/.drone.jsonnet index 06e479e5a..93a8b82e1 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -1,4 +1,4 @@ -local default_deps_base='libsystemd-dev python3-dev libuv1-dev libunbound-dev nettle-dev libssl-dev libevent-dev libsqlite3-dev'; +local default_deps_base='libsystemd-dev python3-dev libuv1-dev libunbound-dev nettle-dev libssl-dev libevent-dev libsqlite3-dev libcurl4-openssl-dev'; local default_deps_nocxx='libsodium-dev ' + default_deps_base; // libsodium-dev needs to be >= 1.0.18 local default_deps='g++ ' + default_deps_nocxx; // g++ sometimes needs replacement local default_windows_deps='mingw-w64 zip nsis'; diff --git a/.gitmodules b/.gitmodules index c1a7df151..b1b93f161 100644 --- a/.gitmodules +++ b/.gitmodules @@ -29,3 +29,6 @@ [submodule "external/uvw"] path = external/uvw url = https://github.com/jagerman/uvw.git +[submodule "external/cpr"] + path = external/cpr + url = https://github.com/whoshuu/cpr diff --git a/CMakeLists.txt b/CMakeLists.txt index 020172203..793b1c872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ if(BUILD_STATIC_DEPS AND NOT STATIC_LINK) message(FATAL_ERROR "Option BUILD_STATIC_DEPS requires STATIC_LINK to be enabled as well") endif() if(BUILD_STATIC_DEPS) + set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) include(StaticBuild) endif() @@ -293,42 +294,7 @@ if(WITH_SYSTEMD AND (NOT ANDROID)) target_compile_definitions(base_libs INTERFACE WITH_SYSTEMD) endif() -option(SUBMODULE_CHECK "Enables checking that vendored library submodules are up to date" ON) -if(SUBMODULE_CHECK) - find_package(Git) - if(GIT_FOUND) - function(check_submodule relative_path) - execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE localHead) - execute_process(COMMAND git rev-parse "HEAD:${relative_path}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE checkedHead) - string(COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate) - if (upToDate) - message(STATUS "Submodule '${relative_path}' is up-to-date") - else() - message(FATAL_ERROR "Submodule '${relative_path}' is not up-to-date. Please update with\ngit submodule update --init --recursive\nor run cmake with -DSUBMODULE_CHECK=OFF") - endif() - endfunction () - - message(STATUS "Checking submodules") - check_submodule(external/nlohmann) - check_submodule(external/cxxopts) - check_submodule(external/ghc-filesystem) - check_submodule(external/date) - check_submodule(external/pybind11) - check_submodule(external/sqlite_orm) - check_submodule(external/oxen-mq) - check_submodule(external/uvw) - endif() -endif() - -if(WITH_HIVE) - add_subdirectory(external/pybind11 EXCLUDE_FROM_ALL) -endif() - -set(JSON_BuildTests OFF CACHE INTERNAL "") -add_subdirectory(external/nlohmann EXCLUDE_FROM_ALL) -add_subdirectory(external/cxxopts EXCLUDE_FROM_ALL) -add_subdirectory(external/date EXCLUDE_FROM_ALL) - +add_subdirectory(external) include_directories(SYSTEM external/sqlite_orm/include) if(ANDROID) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 95909a140..256f58f9e 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -5,10 +5,10 @@ set(LOCAL_MIRROR "" CACHE STRING "local mirror path/URL for lib downloads") -set(OPENSSL_VERSION 1.1.1g CACHE STRING "openssl version") +set(OPENSSL_VERSION 1.1.1k CACHE STRING "openssl version") set(OPENSSL_MIRROR ${LOCAL_MIRROR} https://www.openssl.org/source CACHE STRING "openssl download mirror(s)") set(OPENSSL_SOURCE openssl-${OPENSSL_VERSION}.tar.gz) -set(OPENSSL_HASH SHA256=ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46 +set(OPENSSL_HASH SHA256=892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5 CACHE STRING "openssl source hash") set(EXPAT_VERSION 2.2.9 CACHE STRING "expat version") @@ -55,6 +55,20 @@ set(LIBUV_SOURCE libuv-v${LIBUV_VERSION}.tar.gz) set(LIBUV_HASH SHA256=61a90db95bac00adec1cc5ddc767ebbcaabc70242bd1134a7a6b1fb1d498a194 CACHE STRING "libuv source hash") +set(ZLIB_VERSION 1.2.11 CACHE STRING "zlib version") +set(ZLIB_MIRROR ${LOCAL_MIRROR} https://zlib.net + CACHE STRING "zlib mirror(s)") +set(ZLIB_SOURCE zlib-${ZLIB_VERSION}.tar.gz) +set(ZLIB_HASH SHA512=73fd3fff4adeccd4894084c15ddac89890cd10ef105dd5e1835e1e9bbb6a49ff229713bd197d203edfa17c2727700fce65a2a235f07568212d820dca88b528ae + CACHE STRING "zlib source hash") + +set(CURL_VERSION 7.74.0 CACHE STRING "curl version") +set(CURL_MIRROR ${LOCAL_MIRROR} https://curl.haxx.se/download https://curl.askapache.com + CACHE STRING "curl mirror(s)") +set(CURL_SOURCE curl-${CURL_VERSION}.tar.xz) +set(CURL_HASH SHA256=999d5f2c403cf6e25d58319fdd596611e455dd195208746bc6e6d197a77e878b + CACHE STRING "curl source hash") + include(ExternalProject) @@ -205,7 +219,13 @@ add_static_target(libuv libuv_external libuv.a) target_link_libraries(libuv INTERFACE ${CMAKE_DL_LIBS}) - +build_external(zlib + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS} -fPIC" ${cross_extra} ./configure --prefix=${DEPS_DESTDIR} --static + BUILD_BYPRODUCTS + ${DEPS_DESTDIR}/lib/libz.a + ${DEPS_DESTDIR}/include/zlib.h +) +add_static_target(zlib zlib_external libz.a) set(openssl_system_env "") @@ -239,9 +259,9 @@ if(WIN32) endif() set(OPENSSL_INCLUDE_DIR ${DEPS_DESTDIR}/include) +set(OPENSSL_CRYPTO_LIBRARY ${DEPS_DESTDIR}/lib/libcrypto.a ${DEPS_DESTDIR}/lib/libssl.a) set(OPENSSL_VERSION 1.1.1) - - +set(OPENSSL_ROOT_DIR ${DEPS_DESTDIR}) build_external(expat CONFIGURE_COMMAND ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --enable-static @@ -308,3 +328,91 @@ endif() set_target_properties(libzmq PROPERTIES INTERFACE_LINK_LIBRARIES "${libzmq_link_libs}" INTERFACE_COMPILE_DEFINITIONS "ZMQ_STATIC") + +set(curl_extra) +if(WIN32) + set(curl_ssl_opts --without-ssl --with-schannel) +elseif(APPLE) + set(curl_ssl_opts --without-ssl --with-secure-transport) + if(IOS) + # This CPP crap shouldn't be necessary but is because Apple's toolchain is trash + set(curl_extra "LDFLAGS=-L${DEPS_DESTDIR}/lib -isysroot ${CMAKE_OSX_SYSROOT}" CPP=cpp) + endif() +else() + set(curl_ssl_opts --with-ssl=${DEPS_DESTDIR}) + set(curl_extra "LIBS=-pthread") +endif() + +set(curl_arches default) +set(curl_lib_outputs) +if(IOS) + # On iOS things get a little messy: curl won't build a multi-arch library (with `clang -arch arch1 + # -arch arch2`) so we have to build them separately then glue them together if we're building + # multiple. + set(curl_arches ${CMAKE_OSX_ARCHITECTURES}) + list(GET curl_arches 0 curl_arch0) + list(LENGTH CMAKE_OSX_ARCHITECTURES num_arches) +endif() + +foreach(curl_arch ${curl_arches}) + set(curl_target_suffix "") + set(curl_prefix "${DEPS_DESTDIR}") + if(curl_arch STREQUAL "default") + set(curl_cflags_extra "") + elseif(IOS) + set(cflags_extra " -arch ${curl_arch}") + if(num_arches GREATER 1) + set(curl_target_suffix "-${curl_arch}") + set(curl_prefix "${DEPS_DESTDIR}/tmp/${curl_arch}") + endif() + else() + message(FATAL_ERROR "unexpected curl_arch=${curl_arch}") + endif() + + build_external(curl + TARGET_SUFFIX ${curl_target_suffix} + DEPENDS openssl_external zlib_external + CONFIGURE_COMMAND ./configure ${cross_host} ${cross_extra} --prefix=${curl_prefix} --disable-shared + --enable-static --disable-ares --disable-ftp --disable-ldap --disable-laps --disable-rtsp + --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb + --disable-smtp --disable-gopher --disable-manual --disable-libcurl-option --enable-http + --enable-ipv6 --disable-threaded-resolver --disable-pthreads --disable-verbose --disable-sspi + --enable-crypto-auth --disable-ntlm-wb --disable-tls-srp --disable-unix-sockets --disable-cookies + --enable-http-auth --enable-doh --disable-mime --enable-dateparse --disable-netrc --without-libidn2 + --disable-progress-meter --without-brotli --with-zlib=${DEPS_DESTDIR} ${curl_ssl_opts} + --without-libmetalink --without-librtmp --disable-versioned-symbols --enable-hidden-symbols + --without-zsh-functions-dir --without-fish-functions-dir + "CC=${deps_cc}" "CFLAGS=${deps_noarch_CFLAGS}${cflags_extra}" ${curl_extra} + BUILD_COMMAND true + INSTALL_COMMAND make -C lib install && make -C include install + BUILD_BYPRODUCTS + ${curl_prefix}/lib/libcurl.a + ${curl_prefix}/include/curl/curl.h + ) + list(APPEND curl_lib_targets curl${curl_target_suffix}_external) + list(APPEND curl_lib_outputs ${curl_prefix}/lib/libcurl.a) +endforeach() + +message(STATUS "TARGETS: ${curl_lib_targets}") + +if(IOS AND num_arches GREATER 1) + # We are building multiple architectures for different iOS devices, so we need to glue the + # separate libraries into one. (Normally multiple -arch values passed to clang does this for us, + # but curl refuses to build that way). + add_custom_target(curl_external + COMMAND lipo ${curl_lib_outputs} -create -output ${DEPS_DESTDIR}/libcurl.a + COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPS_DESTDIR}/tmp/${curl_arch0}/include/curl ${DEPS_DESTDIR}/include/curl + BYPRODUCTS ${DEPS_DESTDIR}/lib/libcurl.a ${DEPS_DESTDIR}/include/curl/curl.h + DEPENDS ${curl_lib_targets}) +endif() + +add_static_target(CURL::libcurl curl_external libcurl.a) +set(libcurl_link_libs zlib) +if(CMAKE_CROSSCOMPILING AND ARCH_TRIPLET MATCHES mingw) + list(APPEND libcurl_link_libs crypt32) +elseif(APPLE) + list(APPEND libcurl_link_libs "-framework Security") +endif() +set_target_properties(CURL::libcurl PROPERTIES + INTERFACE_LINK_LIBRARIES "${libcurl_link_libs}" + INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB") diff --git a/cmake/win32_installer_deps.cmake b/cmake/win32_installer_deps.cmake index 028d3445f..72945fbcf 100644 --- a/cmake/win32_installer_deps.cmake +++ b/cmake/win32_installer_deps.cmake @@ -32,7 +32,7 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "Lokinet") set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/win32-setup/lokinet.ico") set(CPACK_NSIS_DEFINES "RequestExecutionLevel admin") set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) -set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '$INSTDIR\\\\bin\\\\tuntap-install.exe /S'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe --install'\\nExecWait 'sc failure lokinet reset= 60 actions= restart/1000'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe -g C:\\\\ProgramData\\\\lokinet\\\\lokinet.ini'\\nCopyFiles '$INSTDIR\\\\share\\\\bootstrap.signed' C:\\\\ProgramData\\\\lokinet\\\\bootstrap.signed") +set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '$INSTDIR\\\\bin\\\\tuntap-install.exe /S'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe --install'\\nExecWait 'sc failure lokinet reset= 60 actions= restart/1000'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe -g C:\\\\ProgramData\\\\lokinet\\\\lokinet.ini'\\nCopyFiles '$INSTDIR\\\\share\\\\bootstrap.signed' C:\\\\ProgramData\\\\lokinet\\\\bootstrap.signed\\nExecWait '$INSTDIR\\\\bin\\\\lokinet-bootstrap.exe'") set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "ExecWait 'net stop lokinet'\\nExecWait 'taskkill /f /t /im lokinet-gui.exe'\\nExecWait '$INSTDIR\\\\bin\\\\lokinet.exe --remove'\\nRMDir /r /REBOOTOK C:\\\\ProgramData\\\\lokinet") set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Lokinet.lnk' '$INSTDIR\\\\share\\\\gui\\\\lokinet-gui.exe'" diff --git a/contrib/windows.sh b/contrib/windows.sh index cf8a94e7f..e89a67618 100755 --- a/contrib/windows.sh +++ b/contrib/windows.sh @@ -3,5 +3,22 @@ set -e set +x mkdir -p build-windows cd build-windows -cmake -G Ninja -DCMAKE_EXE_LINKER_FLAGS=-fstack-protector -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always -DCMAKE_TOOLCHAIN_FILE=../contrib/cross/mingw64.cmake -DBUILD_STATIC_DEPS=ON -DBUILD_PACKAGE=ON -DBUILD_LIBLOKINET=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DWITH_TESTS=OFF -DNATIVE_BUILD=OFF -DSTATIC_LINK=ON -DWITH_SYSTEMD=OFF -DFORCE_OXENMQ_SUBMODULE=ON -DSUBMODULE_CHECK=OFF -DWITH_LTO=OFF -DCMAKE_BUILD_TYPE=Release $@ .. +cmake \ + -G Ninja \ + -DCMAKE_EXE_LINKER_FLAGS=-fstack-protector \ + -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always\ + -DCMAKE_TOOLCHAIN_FILE=../contrib/cross/mingw64.cmake\ + -DBUILD_STATIC_DEPS=ON \ + -DBUILD_PACKAGE=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DWITH_TESTS=OFF \ + -DNATIVE_BUILD=OFF \ + -DSTATIC_LINK=ON \ + -DWITH_SYSTEMD=OFF \ + -DFORCE_OXENMQ_SUBMODULE=ON \ + -DSUBMODULE_CHECK=OFF \ + -DWITH_LTO=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + $@ .. ninja package diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index fe4a8aee6..9bfeac730 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -1,6 +1,7 @@ -add_executable(lokinet main.cpp) +add_executable(lokinet lokinet.cpp) add_executable(lokinet-vpn lokinet-vpn.cpp) -enable_lto(lokinet lokinet-vpn) +add_executable(lokinet-bootstrap lokinet-bootstrap.cpp) +enable_lto(lokinet lokinet-vpn lokinet-bootstrap) if(TRACY_ROOT) target_sources(lokinet PRIVATE ${TRACY_ROOT}/TracyClient.cpp) @@ -22,7 +23,9 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") endif() endif() -foreach(exe lokinet lokinet-vpn) +target_link_libraries(lokinet-bootstrap PUBLIC cpr::cpr) + +foreach(exe lokinet lokinet-vpn lokinet-bootstrap) if(WIN32 AND NOT MSVC_VERSION) target_sources(${exe} PRIVATE ../llarp/win32/version.rc) target_link_libraries(${exe} PRIVATE ws2_32 iphlpapi) @@ -43,9 +46,3 @@ endforeach() if(SETCAP) install(CODE "execute_process(COMMAND ${SETCAP} cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)") endif() - -if(NOT WIN32) - if(should_install) - install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin COMPONENT lokinet) - endif() -endif() diff --git a/daemon/lokinet-bootstrap.cpp b/daemon/lokinet-bootstrap.cpp new file mode 100644 index 000000000..855dcc9f3 --- /dev/null +++ b/daemon/lokinet-bootstrap.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include + +#include + +#ifndef _WIN32 +#include +#endif + +namespace +{ + int + exit_with_message(std::string msg, int exitcode) + { + std::cout << msg << std::endl; + return exitcode; + } +} // namespace + +int +main(int argc, char* argv[]) +{ + std::string bootstrap_url{"https://seed.lokinet.org/lokinet.signed"}; + if (argc > 1) + { + bootstrap_url = argv[1]; + } + cpr::Response resp = +#ifdef _WIN32 + cpr::Get( + cpr::Url{bootstrap_url}, cpr::Header{{"User-Agent", std::string{llarp::VERSION_FULL}}}); +#else + cpr::Get( + cpr::Url{bootstrap_url}, + cpr::Header{{"User-Agent", std::string{llarp::VERSION_FULL}}}, + cpr::Ssl(cpr::ssl::CaPath{X509_get_default_cert_dir()})); +#endif + if (resp.status_code != 200) + { + return exit_with_message( + "failed to fetch '" + bootstrap_url + "' HTTP " + std::to_string(resp.status_code), 1); + } + + 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); +} diff --git a/daemon/main.cpp b/daemon/lokinet.cpp similarity index 100% rename from daemon/main.cpp rename to daemon/lokinet.cpp diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 000000000..3ee93d913 --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,76 @@ + +option(SUBMODULE_CHECK "Enables checking that vendored library submodules are up to date" ON) +if(SUBMODULE_CHECK) + find_package(Git) + if(GIT_FOUND) + function(check_submodule relative_path) + execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE localHead) + execute_process(COMMAND git rev-parse "HEAD:external/${relative_path}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE checkedHead) + string(COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate) + if (upToDate) + message(STATUS "Submodule 'external/${relative_path}' is up-to-date") + else() + message(FATAL_ERROR "Submodule 'external/${relative_path}' is not up-to-date. Please update with\ngit submodule update --init --recursive\nor run cmake with -DSUBMODULE_CHECK=OFF") + endif() + endfunction () + + message(STATUS "Checking submodules") + check_submodule(nlohmann) + check_submodule(cxxopts) + check_submodule(ghc-filesystem) + check_submodule(date) + check_submodule(pybind11) + check_submodule(sqlite_orm) + check_submodule(oxen-mq) + check_submodule(uvw) + check_submodule(cpr) + endif() +endif() + +if(WITH_HIVE) + add_subdirectory(pybind11 EXCLUDE_FROM_ALL) +endif() + +set(JSON_BuildTests OFF CACHE INTERNAL "") +add_subdirectory(nlohmann EXCLUDE_FROM_ALL) +add_subdirectory(cxxopts EXCLUDE_FROM_ALL) +add_subdirectory(date EXCLUDE_FROM_ALL) + +add_library(sqlite_orm INTERFACE) +target_include_directories(sqlite_orm SYSTEM INTERFACE sqlite_orm/include) +if(NOT TARGET sqlite3) + add_library(sqlite3 INTERFACE) + pkg_check_modules(SQLITE3 REQUIRED IMPORTED_TARGET sqlite3) + target_link_libraries(sqlite3 INTERFACE PkgConfig::SQLITE3) +endif() +target_link_libraries(sqlite_orm INTERFACE sqlite3) + +add_library(uvw INTERFACE) +target_include_directories(uvw INTERFACE uvw/src) +target_link_libraries(uvw INTERFACE libuv) + +# cpr configuration. Ideally we'd just do this via add_subdirectory, but cpr's cmake requires +# 3.15+, and we target lower than that (and this is fairly simple to build). + +if(NOT BUILD_STATIC_DEPS) + find_package(CURL REQUIRED COMPONENTS HTTP HTTPS SSL) + + # CURL::libcurl wasn't added to FindCURL until cmake 3.12, so add it if necessary + if (CMAKE_VERSION VERSION_LESS 3.12 AND NOT TARGET CURL::libcurl) + add_library(libcurl UNKNOWN IMPORTED GLOBAL) + set_target_properties(libcurl PROPERTIES + IMPORTED_LOCATION ${CURL_LIBRARIES} + INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}") + add_library(CURL_libcurl INTERFACE) + target_link_libraries(CURL_libcurl INTERFACE libcurl) + add_library(CURL::libcurl ALIAS CURL_libcurl) + endif() +endif() + +file(GLOB cpr_sources ${conf_depends} cpr/cpr/*.cpp) + +add_library(cpr STATIC EXCLUDE_FROM_ALL ${cpr_sources}) +target_link_libraries(cpr PUBLIC CURL::libcurl) +target_include_directories(cpr PUBLIC cpr/include) +target_compile_definitions(cpr PUBLIC CPR_CURL_NOSIGNAL) +add_library(cpr::cpr ALIAS cpr) diff --git a/external/cpr b/external/cpr new file mode 160000 index 000000000..aac5058a1 --- /dev/null +++ b/external/cpr @@ -0,0 +1 @@ +Subproject commit aac5058a15e9ad5ad393973dc6fe44d7614a7f55 diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index b7e55c5ea..5cf43f66b 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -46,10 +46,6 @@ if(ANDROID) target_link_libraries(lokinet-util PUBLIC log) endif() -add_library(uvw INTERFACE) -target_include_directories(uvw INTERFACE ${PROJECT_SOURCE_DIR}/external/uvw/src) -target_link_libraries(uvw INTERFACE libuv) - add_library(lokinet-platform # for networking ev/ev.cpp diff --git a/llarp/constants/files.hpp b/llarp/constants/files.hpp index 8ea075b92..7d594444e 100644 --- a/llarp/constants/files.hpp +++ b/llarp/constants/files.hpp @@ -5,6 +5,7 @@ #include #ifndef _WIN32 +#include #include #endif @@ -21,23 +22,18 @@ namespace llarp GetDefaultDataDir() { #ifdef _WIN32 - const fs::path homedir = getenv("APPDATA"); - return homedir / "lokinet"; + return "C:/programdata/lokinet"; #else - fs::path homedir; + fs::path datadir{"/var/lib/lokinet"}; - auto pw = getpwuid(getuid()); - if ((pw and pw->pw_uid) and pw->pw_dir) + if (auto uid = ::geteuid()) { - homedir = pw->pw_dir; + if (auto* pw = getpwuid(uid)) + { + datadir = fs::path{pw->pw_dir} / ".lokinet"; + } } - else - { - // no home dir specified yea idk - homedir = "/var/lib/lokinet"; - return homedir; - } - return homedir / ".lokinet"; + return datadir; #endif } @@ -53,4 +49,10 @@ namespace llarp return GetDefaultDataDir() / GetDefaultConfigFilename(); } + inline fs::path + GetDefaultBootstrap() + { + return GetDefaultDataDir() / "bootstrap.signed"; + } + } // namespace llarp diff --git a/readme.md b/readme.md index 638c4fad8..81c776a33 100644 --- a/readme.md +++ b/readme.md @@ -21,6 +21,7 @@ Build requirements: * C++ 17 capable C++ compiler * libuv >= 1.27.0 * libsodium >= 1.0.18 +* libcurl (for lokinet-bootstrap) * libunbound * libzmq * sqlite3 @@ -39,7 +40,7 @@ You can install these using: if you want to build a dev build you can do the following: - $ sudo apt install build-essential cmake git libcap-dev curl libuv1-dev libsodium-dev pkg-config + $ sudo apt install build-essential cmake git libcap-dev libcurl4-openssl-dev libuv1-dev libsodium-dev pkg-config $ git clone --recursive https://github.com/loki-project/loki-network $ cd loki-network $ mkdir build From 27c80a2638b6c3ab51709b37ea542a8dbdf5288f Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 16 Apr 2021 05:51:34 -0400 Subject: [PATCH 06/12] add include directory for daemon directory so llarp/* includes work --- daemon/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 9bfeac730..8364006d1 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -36,6 +36,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) From 77de60af918909cdfc0e9f1b14a1c39371d4bdd4 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 16 Apr 2021 09:40:36 -0400 Subject: [PATCH 07/12] require openssl explicitly for lokinet-bootstrap --- daemon/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 8364006d1..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) From a80d8b95b3942467053c990ff0566b1e80d1598a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 16 Apr 2021 14:16:16 -0400 Subject: [PATCH 08/12] update lokinet-bootstrap * compat with old shell script curl wrapper's arguments * do lazy validation of fetched data --- daemon/lokinet-bootstrap.cpp | 58 ++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/daemon/lokinet-bootstrap.cpp b/daemon/lokinet-bootstrap.cpp index 855dcc9f3..c7a6dc944 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,16 @@ 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') + { + std::ofstream ofs{outputfile}; + ofs << data; + return 0; + } + return fail("got invalid bootstrap file content"); } From 6cde9062b532e898856f97d7e922729e73b6294c Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 16 Apr 2021 14:17:39 -0400 Subject: [PATCH 09/12] build lokinet-android target only on android --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' From a0d3ab125a2cabc047855fcc8229227a9c85367d Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 16 Apr 2021 14:47:17 -0400 Subject: [PATCH 10/12] throw on failed writing and port fs namespace changes from oxen-core --- daemon/lokinet-bootstrap.cpp | 3 ++- llarp/util/fs.hpp | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/daemon/lokinet-bootstrap.cpp b/daemon/lokinet-bootstrap.cpp index c7a6dc944..6bb17fabe 100644 --- a/daemon/lokinet-bootstrap.cpp +++ b/daemon/lokinet-bootstrap.cpp @@ -70,7 +70,8 @@ main(int argc, char* argv[]) std::string data{ss.str()}; if (data[0] == 'l' or data[0] == 'd') { - std::ofstream ofs{outputfile}; + fs::ofstream ofs{outputfile}; + ofs.exceptions(fs::ofstream::failbit); ofs << data; return 0; } diff --git a/llarp/util/fs.hpp b/llarp/util/fs.hpp index 96fe3bee8..cf4e9c787 100644 --- a/llarp/util/fs.hpp +++ b/llarp/util/fs.hpp @@ -14,7 +14,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 From 4daebc0141d2bdd5842bcd205737bb205a305de4 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 16 Apr 2021 15:01:00 -0400 Subject: [PATCH 11/12] catch exception and print out error --- daemon/lokinet-bootstrap.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/daemon/lokinet-bootstrap.cpp b/daemon/lokinet-bootstrap.cpp index 6bb17fabe..9b458b062 100644 --- a/daemon/lokinet-bootstrap.cpp +++ b/daemon/lokinet-bootstrap.cpp @@ -70,10 +70,17 @@ main(int argc, char* argv[]) std::string data{ss.str()}; if (data[0] == 'l' or data[0] == 'd') { - fs::ofstream ofs{outputfile}; - ofs.exceptions(fs::ofstream::failbit); - ofs << data; - return 0; + try + { + fs::ofstream ofs{outputfile}; + 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"); } From 68826f10bb4c8f52ff17da5980ed49a4a1fbc273 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 16 Apr 2021 17:51:09 -0400 Subject: [PATCH 12/12] use binary mode for writing files --- daemon/lokinet-bootstrap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/lokinet-bootstrap.cpp b/daemon/lokinet-bootstrap.cpp index 9b458b062..75209012c 100644 --- a/daemon/lokinet-bootstrap.cpp +++ b/daemon/lokinet-bootstrap.cpp @@ -72,7 +72,7 @@ main(int argc, char* argv[]) { try { - fs::ofstream ofs{outputfile}; + fs::ofstream ofs{outputfile, std::ios::binary}; ofs.exceptions(fs::ofstream::failbit); ofs << data; return 0;