Merge pull request #1773 from necro-nemesis/fedora/34

merge upstream/stable & bump v0.9.7 fedora/34
This commit is contained in:
Jason Rhinelander 2021-10-27 21:33:47 -03:00 committed by GitHub
commit 5859a7f903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
113 changed files with 1235 additions and 495 deletions

View File

@ -41,6 +41,6 @@ local rpm_pipeline(image, buildarch='amd64', rpmarch='x86_64', jobs=6) = {
}; };
[ [
rpm_pipeline(distro_docker), rpm_pipeline(distro_docker),
rpm_pipeline("arm64v8/" + distro_docker, buildarch='arm64', rpmarch="aarch64", jobs=4) rpm_pipeline("arm64v8/" + distro_docker, buildarch='arm64', rpmarch="aarch64", jobs=4)
] ]

1
.gitattributes vendored
View File

@ -2,3 +2,4 @@ external/date/test export-ignore
external/nlohmann/doc export-ignore external/nlohmann/doc export-ignore
external/nlohmann/test export-ignore external/nlohmann/test export-ignore
external/nlohmann/benchmarks/data export-ignore external/nlohmann/benchmarks/data export-ignore
*.signed binary

View File

@ -22,7 +22,7 @@ endif()
project(lokinet project(lokinet
VERSION 0.9.6 VERSION 0.9.7
DESCRIPTION "lokinet - IP packet onion router" DESCRIPTION "lokinet - IP packet onion router"
LANGUAGES ${LANGS}) LANGUAGES ${LANGS})
@ -51,7 +51,7 @@ option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF)
option(BUILD_LIBLOKINET "build liblokinet.so" ON) option(BUILD_LIBLOKINET "build liblokinet.so" ON)
option(SHADOW "use shadow testing framework. linux only" OFF) option(SHADOW "use shadow testing framework. linux only" OFF)
option(XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF) option(XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF)
option(WITH_JEMALLOC "use jemalloc as allocator" OFF) option(USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON)
option(TESTNET "testnet build" OFF) option(TESTNET "testnet build" OFF)
option(WITH_COVERAGE "generate coverage data" OFF) option(WITH_COVERAGE "generate coverage data" OFF)
option(USE_SHELLHOOKS "enable shell hooks on compile time (dangerous)" OFF) option(USE_SHELLHOOKS "enable shell hooks on compile time (dangerous)" OFF)
@ -299,7 +299,6 @@ endif()
add_subdirectory(external) add_subdirectory(external)
include_directories(SYSTEM external/sqlite_orm/include) include_directories(SYSTEM external/sqlite_orm/include)
option(USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON)
if(USE_JEMALLOC AND NOT STATIC_LINK) if(USE_JEMALLOC AND NOT STATIC_LINK)
pkg_check_modules(JEMALLOC jemalloc IMPORTED_TARGET) pkg_check_modules(JEMALLOC jemalloc IMPORTED_TARGET)
if(JEMALLOC_FOUND) if(JEMALLOC_FOUND)

View File

@ -1,5 +1,5 @@
Name: lokinet Name: lokinet
Version: 0.9.6 Version: 0.9.7
Release: 1%{?dist} Release: 1%{?dist}
Summary: Lokinet anonymous, decentralized overlay network Summary: Lokinet anonymous, decentralized overlay network
@ -156,6 +156,9 @@ fi
%systemd_postun lokinet.service %systemd_postun lokinet.service
%changelog %changelog
* Wed Oct 20 2021 Technical Tumbleweed <necro_nemesis@hotmail.com> - 0.9.7-1
- bump version
* Thu Sep 09 2021 Jason Rhinelander <jason@imaginary.ca> - 0.9.6-1 * Thu Sep 09 2021 Jason Rhinelander <jason@imaginary.ca> - 0.9.6-1
- 0.9.6 release. - 0.9.6 release.
- bundle bootstrap.signed instead of downloading - bundle bootstrap.signed instead of downloading
@ -176,8 +179,8 @@ fi
- Updated for rpm.oxen.io packaging - Updated for rpm.oxen.io packaging
- Split into lokinet/lokinet-bin/lokinet-monitor packages - Split into lokinet/lokinet-bin/lokinet-monitor packages
* Thu Jul 22 2021 Technical Tumbleweed (necro_nemesis@hotmail.com) Lokinet 0.9.5 * Thu Jul 22 2021 Technical Tumbleweed <necro_nemesis@hotmail.com> Lokinet 0.9.5
- Build with systemd-resolved and binary lokinet-bootstrap - Build with systemd-resolved and binary lokinet-bootstrap
* Sun Mar 07 2021 Technical Tumbleweed (necro_nemesis@hotmail.com) Lokinet 0.8.2 * Sun Mar 07 2021 Technical Tumbleweed <necro_nemesis@hotmail.com> Lokinet 0.8.2
- First Lokinet RPM - First Lokinet RPM

View File

@ -388,6 +388,7 @@ foreach(curl_arch ${curl_arches})
--disable-progress-meter --without-brotli --with-zlib=${DEPS_DESTDIR} ${curl_ssl_opts} --disable-progress-meter --without-brotli --with-zlib=${DEPS_DESTDIR} ${curl_ssl_opts}
--without-libmetalink --without-librtmp --disable-versioned-symbols --enable-hidden-symbols --without-libmetalink --without-librtmp --disable-versioned-symbols --enable-hidden-symbols
--without-zsh-functions-dir --without-fish-functions-dir --without-zsh-functions-dir --without-fish-functions-dir
--without-nghttp3 --without-zstd
"CC=${deps_cc}" "CFLAGS=${deps_noarch_CFLAGS}${cflags_extra}" ${curl_extra} "CC=${deps_cc}" "CFLAGS=${deps_noarch_CFLAGS}${cflags_extra}" ${curl_extra}
BUILD_COMMAND true BUILD_COMMAND true
INSTALL_COMMAND ${_make} -C lib install && ${_make} -C include install INSTALL_COMMAND ${_make} -C lib install && ${_make} -C include install

View File

@ -2,7 +2,6 @@ function(add_log_tag target)
get_target_property(TARGET_SRCS ${target} SOURCES) get_target_property(TARGET_SRCS ${target} SOURCES)
foreach(F ${TARGET_SRCS}) foreach(F ${TARGET_SRCS})
get_filename_component(fpath "${F}" ABSOLUTE) get_filename_component(fpath "${F}" ABSOLUTE)
string(REPLACE "${PROJECT_SOURCE_DIR}/" "" logtag "${fpath}") set_property(SOURCE ${F} APPEND PROPERTY COMPILE_DEFINITIONS SOURCE_ROOT=\"${PROJECT_SOURCE_DIR}\")
set_property(SOURCE ${F} APPEND PROPERTY COMPILE_DEFINITIONS LOG_TAG=\"${logtag}\")
endforeach() endforeach()
endfunction() endfunction()

View File

@ -1,49 +1,49 @@
function(check_working_cxx_atomics64 varname) function(check_working_cxx_atomics64 varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
if (EMBEDDED_CFG) if (EMBEDDED_CFG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -m32 -march=i486") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -m32 -march=i486")
elseif(MSVC OR MSVC_VERSION) elseif(MSVC OR MSVC_VERSION)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -arch:IA32 -std:c++14") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -arch:IA32 -std:c++14")
else() else()
# CMAKE_CXX_STANDARD does not propagate to cmake compile tests # CMAKE_CXX_STANDARD does not propagate to cmake compile tests
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++14") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++14")
endif() endif()
check_cxx_source_compiles(" check_cxx_source_compiles("
#include <atomic> #include <atomic>
#include <cstdint> #include <cstdint>
std::atomic<uint64_t> x (0); std::atomic<uint64_t> x (0);
int main() { int main() {
uint64_t i = x.load(std::memory_order_relaxed); uint64_t i = x.load(std::memory_order_relaxed);
return 0; return 0;
} }
" ${varname}) " ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction() endfunction()
function(link_libatomic) function(link_libatomic)
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
if(HAVE_CXX_ATOMICS64_WITHOUT_LIB) if(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
message(STATUS "Have working 64bit atomics") message(STATUS "Have working 64bit atomics")
return() return()
endif() endif()
if (NOT MSVC AND NOT MSVC_VERSION) if (NOT MSVC AND NOT MSVC_VERSION)
check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
if (HAVE_CXX_LIBATOMICS64) if (HAVE_CXX_LIBATOMICS64)
message(STATUS "Have 64bit atomics via library") message(STATUS "Have 64bit atomics via library")
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
if (HAVE_CXX_ATOMICS64_WITH_LIB) if (HAVE_CXX_ATOMICS64_WITH_LIB)
message(STATUS "Can link with libatomic") message(STATUS "Can link with libatomic")
link_libraries(-latomic) link_libraries(-latomic)
return() return()
endif() endif()
endif() endif()
endif() endif()
if (MSVC OR MSVC_VERSION) if (MSVC OR MSVC_VERSION)
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic! (What does MSVC do to inline atomics?)") message(FATAL_ERROR "Host compiler must support 64-bit std::atomic! (What does MSVC do to inline atomics?)")
else() else()
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!")
endif() endif()
endfunction() endfunction()

52
cmake/ngtcp2_lib.cmake Normal file
View File

@ -0,0 +1,52 @@
# ngtcp2's top-level CMakeLists.txt loads a bunch of crap we don't want (examples, a conflicting
# 'check' target, etc.); instead we directly include it's lib subdirectory to build just the
# library, but we have to set up a couple things to make that work:
function(add_ngtcp2_lib)
file(STRINGS ngtcp2/CMakeLists.txt ngtcp2_project_line REGEX "^project\\(ngtcp2 ")
if(NOT ngtcp2_project_line MATCHES "^project\\(ngtcp2 VERSION ([0-9]+)\\.([0-9]+)\\.([0-9]+)\\)$")
message(FATAL_ERROR "Unable to extract ngtcp2 version from ngtcp2/CMakeLists.txt (found '${ngtcp2_project_line}')")
endif()
set(PACKAGE_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
include(ngtcp2/cmake/Version.cmake)
HexVersion(PACKAGE_VERSION_NUM ${CMAKE_MATCH_1} ${CMAKE_MATCH_2} ${CMAKE_MATCH_3})
configure_file("ngtcp2/lib/includes/ngtcp2/version.h.in" "ngtcp2/lib/includes/ngtcp2/version.h" @ONLY)
set(BUILD_SHARED_LIBS OFF)
# Checks for header files.
include(CheckIncludeFile)
check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
check_include_file("stddef.h" HAVE_STDDEF_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("string.h" HAVE_STRING_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_file("endian.h" HAVE_ENDIAN_H)
check_include_file("byteswap.h" HAVE_BYTESWAP_H)
include(CheckTypeSize)
check_type_size("ssize_t" SIZEOF_SSIZE_T)
if(SIZEOF_SSIZE_T STREQUAL "")
set(ssize_t ptrdiff_t)
endif()
include(CheckSymbolExists)
if(HAVE_ENDIAN_H)
check_symbol_exists(be64toh "endian.h" HAVE_BE64TOH)
endif()
if(NOT HAVE_BE64TO AND HAVE_SYS_ENDIAN_H)
check_symbol_exists(be64toh "sys/endian.h" HAVE_BE64TOH)
endif()
check_symbol_exists(bswap_64 "byteswap.h" HAVE_BSWAP_64)
configure_file(ngtcp2/cmakeconfig.h.in ngtcp2/config.h)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/ngtcp2") # for config.h
add_subdirectory(ngtcp2/lib EXCLUDE_FROM_ALL)
target_compile_definitions(ngtcp2 PRIVATE -DHAVE_CONFIG_H -D_GNU_SOURCE)
endfunction()

View File

@ -7,15 +7,6 @@ endif()
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
include(CheckLibraryExists) include(CheckLibraryExists)
if(WITH_JEMALLOC)
find_package(Jemalloc REQUIRED)
if(NOT JEMALLOC_FOUND)
message(FATAL_ERROR "did not find jemalloc")
endif()
add_definitions(-DUSE_JEMALLOC)
message(STATUS "using jemalloc")
endif()
add_definitions(-DUNIX) add_definitions(-DUNIX)
add_definitions(-DPOSIX) add_definitions(-DPOSIX)

View File

@ -5,17 +5,12 @@ endif()
set(TUNTAP_URL "https://build.openvpn.net/downloads/releases/latest/tap-windows-latest-stable.exe") 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(TUNTAP_EXE "${CMAKE_BINARY_DIR}/tuntap-install.exe")
set(BOOTSTRAP_URL "https://seed.lokinet.org/lokinet.signed") set(BOOTSTRAP_FILE "${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed")
set(BOOTSTRAP_FILE "${CMAKE_BINARY_DIR}/bootstrap.signed")
file(DOWNLOAD file(DOWNLOAD
${TUNTAP_URL} ${TUNTAP_URL}
${TUNTAP_EXE}) ${TUNTAP_EXE})
file(DOWNLOAD
${BOOTSTRAP_URL}
${BOOTSTRAP_FILE})
file(DOWNLOAD file(DOWNLOAD
${GUI_ZIP_URL} ${GUI_ZIP_URL}
${CMAKE_BINARY_DIR}/lokinet-gui.zip ${CMAKE_BINARY_DIR}/lokinet-gui.zip
@ -26,7 +21,7 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${CMAKE_BINARY_DIR}/lokinet-g
install(DIRECTORY ${CMAKE_BINARY_DIR}/gui DESTINATION share COMPONENT gui) install(DIRECTORY ${CMAKE_BINARY_DIR}/gui DESTINATION share COMPONENT gui)
install(PROGRAMS ${TUNTAP_EXE} DESTINATION bin COMPONENT tuntap) install(PROGRAMS ${TUNTAP_EXE} DESTINATION bin COMPONENT tuntap)
install(FILES ${BOOTSTRAP_FILE} DESTINATION share COMPONENT lokinet) install(FILES ${BOOTSTRAP_FILE} DESTINATION share COMPONENT lokinet RENAME bootstrap.signed)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Lokinet") set(CPACK_PACKAGE_INSTALL_DIRECTORY "Lokinet")
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/win32-setup/lokinet.ico") set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/win32-setup/lokinet.ico")

Binary file not shown.

View File

@ -0,0 +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âw m)q2Øg¯±˜øš ï³À)˜TÑP•´ò³ö—Á1e

View File

@ -0,0 +1,6 @@
ARG ARCH=amd64
FROM ${ARCH}/debian:bullseye
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 -q autoremove -y

View File

@ -0,0 +1,6 @@
ARG ARCH=amd64
FROM ${ARCH}/debian:buster
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 -q autoremove -y

View File

@ -0,0 +1,6 @@
ARG ARCH=amd64
FROM ${ARCH}/debian:sid
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 -q autoremove -y

View File

@ -0,0 +1,6 @@
ARG ARCH=amd64
FROM ${ARCH}/debian:stable
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 -q autoremove -y

View File

@ -0,0 +1,6 @@
ARG ARCH=amd64
FROM ${ARCH}/debian:testing
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 -q autoremove -y

View File

@ -0,0 +1,39 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-bullseye-base/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev

View File

@ -0,0 +1,40 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-buster-base/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev \
xz-utils

View File

@ -0,0 +1,39 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-sid-base/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev

View File

@ -0,0 +1,39 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-stable-base/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev

View File

@ -0,0 +1,31 @@
ARG ARCH=amd64
FROM ${ARCH}/ubuntu:bionic
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 -q --no-install-recommends install -y \
autoconf \
automake \
ccache \
cmake \
eatmydata \
file \
g++-8 \
gdb \
git \
gperf \
libjemalloc-dev \
libpgm-dev \
libtool \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
ninja-build \
openssh-client \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev \
&& mkdir -p /usr/lib/x86_64-linux-gnu/pgm-5.2/include

View File

@ -0,0 +1,42 @@
ARG ARCH=amd64
FROM ${ARCH}/ubuntu:focal
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev

View File

@ -0,0 +1,42 @@
ARG ARCH=amd64
FROM ${ARCH}/ubuntu:impish
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev

View File

@ -0,0 +1,42 @@
ARG ARCH=amd64
FROM ${ARCH}/ubuntu:latest
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev

View File

@ -0,0 +1,42 @@
ARG ARCH=amd64
FROM ${ARCH}/ubuntu:rolling
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
automake \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
libboost-program-options-dev \
libboost-serialization-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libevent-dev \
libgtest-dev \
libhidapi-dev \
libjemalloc-dev \
libminiupnpc-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libsystemd-dev \
libtool \
libunbound-dev \
libunwind8-dev \
libusb-1.0.0-dev \
libuv1-dev \
libzmq3-dev \
lsb-release \
make \
nettle-dev \
ninja-build \
openssh-client \
patch \
pkg-config \
python3-dev \
qttools5-dev

View File

@ -0,0 +1,10 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-bullseye/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
ccache \
debhelper \
devscripts \
equivs \
git \
git-buildpackage \
python3-dev

View File

@ -0,0 +1,10 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-sid/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
ccache \
debhelper \
devscripts \
equivs \
git \
git-buildpackage \
python3-dev

View File

@ -0,0 +1,10 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-ubuntu-focal/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
ccache \
debhelper \
devscripts \
equivs \
git \
git-buildpackage \
python3-dev

View File

@ -0,0 +1,10 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-ubuntu-impish/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y \
ccache \
debhelper \
devscripts \
equivs \
git \
git-buildpackage \
python3-dev

View File

@ -0,0 +1,23 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-testing-base/${ARCH}
RUN /bin/bash -c 'sed -i "s/main/main contrib/g" /etc/apt/sources.list'
RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
android-sdk \
automake \
ccache \
cmake \
curl \
git \
google-android-ndk-installer \
libtool \
make \
openssh-client \
patch \
pkg-config \
wget \
xz-utils \
zip \
&& git clone https://github.com/Shadowstyler/android-sdk-licenses.git /tmp/android-sdk-licenses \
&& cp -a /tmp/android-sdk-licenses/*-license /usr/lib/android-sdk/licenses \
&& rm -rf /tmp/android-sdk-licenses

View File

@ -1,7 +0,0 @@
FROM debian:testing
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN /bin/bash -c 'sed -i "s/main/main contrib/g" /etc/apt/sources.list'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y android-sdk google-android-ndk-installer wget git pkg-config automake libtool cmake ccache curl zip'
RUN /bin/bash -c 'git clone https://github.com/Shadowstyler/android-sdk-licenses.git /tmp/android-sdk-licenses && cp -a /tmp/android-sdk-licenses/*-license /usr/lib/android-sdk/licenses && rm -rf /tmp/android-sdk-licenses'
RUN /bin/bash -c 'wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.2.2-stable.tar.xz -O /tmp/flutter.tar.xz && cd /opt && tar -xJvf /tmp/flutter.tar.xz && rm /tmp/flutter.tar.xz && ln -s /opt/flutter/bin/flutter /usr/local/bin/'
RUN /bin/bash -c 'flutter precache'

View File

@ -0,0 +1 @@
../00-debian-buster-base.dockerfile

View File

@ -0,0 +1 @@
../00-debian-stable-base.dockerfile

View File

@ -0,0 +1 @@
../10-debian-buster.dockerfile

View File

@ -0,0 +1 @@
../10-debian-stable.dockerfile

View File

@ -0,0 +1 @@
../00-debian-sid-base.dockerfile

View File

@ -0,0 +1 @@
../10-debian-sid.dockerfile

View File

@ -0,0 +1 @@
../40-debian-sid-debhelper.dockerfile

View File

@ -0,0 +1,7 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-debian-sid/${ARCH}
RUN apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
clang-13 \
libc++-13-dev \
libc++abi-13-dev \
lld-13

View File

@ -1,3 +0,0 @@
FROM debian:sid
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata gdb cmake git ninja-build pkg-config ccache clang-11 libsodium-dev libsystemd-dev python3-dev libuv1-dev libunbound-dev nettle-dev libssl-dev libevent-dev libsqlite3-dev libboost-thread-dev libboost-serialization-dev libboost-program-options-dev libgtest-dev libminiupnpc-dev libunwind8-dev libreadline-dev libhidapi-dev libusb-1.0.0-dev qttools5-dev libcurl4-openssl-dev'

View File

@ -1,3 +0,0 @@
FROM debian:stable
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata gdb cmake git ninja-build pkg-config ccache g++ libsodium-dev libsystemd-dev python3-dev libuv1-dev libunbound-dev nettle-dev libssl-dev libevent-dev libsqlite3-dev libboost-thread-dev libboost-serialization-dev libboost-program-options-dev libgtest-dev libminiupnpc-dev libunwind8-dev libreadline-dev libhidapi-dev libusb-1.0.0-dev qttools5-dev libcurl4-openssl-dev'

View File

@ -1,4 +1,24 @@
FROM debian:testing ARG ARCH=amd64
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections' FROM registry.oxen.rocks/lokinet-ci-debian-testing-base/${ARCH}
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata build-essential cmake git ninja-build pkg-config ccache g++-mingw-w64-x86-64-posix nsis zip automake libtool autoconf make qttools5-dev file gperf patch openssh-client' RUN apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
RUN /bin/bash -c 'update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix && update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix' autoconf \
automake \
build-essential \
ccache \
cmake \
eatmydata \
file \
g++-mingw-w64-x86-64-posix \
git \
gperf \
libtool \
make \
ninja-build \
nsis \
openssh-client \
patch \
pkg-config \
qttools5-dev \
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

View File

@ -0,0 +1,7 @@
ARG ARCH=amd64
FROM registry.oxen.rocks/lokinet-ci-android/${ARCH}
RUN cd /opt \
&& curl https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.2.2-stable.tar.xz \
| tar xJv \
&& ln -s /opt/flutter/bin/flutter /usr/local/bin/ \
&& flutter precache

View File

@ -0,0 +1 @@
../00-debian-stable-base.dockerfile

View File

@ -0,0 +1 @@
../10-debian-stable.dockerfile

View File

@ -1,3 +1,7 @@
FROM debian:sid ARG ARCH=amd64
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections' FROM registry.oxen.rocks/lokinet-ci-debian-sid-base/${ARCH}
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata git clang-format-11' RUN apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
clang-format-11 \
eatmydata \
git \
jsonnet

View File

@ -1,3 +1,17 @@
FROM node:14.16.1 FROM node:14.16.1
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections' RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y eatmydata gdb cmake git ninja-build pkg-config ccache g++ wine' RUN apt-get -o=Dpkg::Use-Pty=0 -q update \
&& apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y \
&& apt-get -o=Dpkg::Use-Pty=0 -q install --no-install-recommends -y \
ccache \
cmake \
eatmydata \
g++ \
gdb \
git \
make \
ninja-build \
openssh-client \
patch \
pkg-config \
wine

View File

@ -1,8 +1,13 @@
## drone-ci docker jizz ## drone-ci docker jizz
To rebuild all ci images and push them to a registry server do: To rebuild all ci images and push them to the oxen registry server do:
$ docker login your.registry.here $ docker login registry.oxen.rocks
$ ./rebuild-docker-images.sh your.registry.here *.dockerfile $ ./rebuild-docker-images.sh
The docker images will be `your.registry.here/lokinet-ci-*`for each *.dockerfile in this directory If you aren't part of the Oxen team, you'll likely need to set up your own registry and change
registry.oxen.rocks to your own domain name in order to do anything useful with this.
The docker images will be `registry.oxen.rocks/lokinet-ci-*`for each \*.dockerfile in this
directory, with the leading numeric `NN-` removed, if present (so that you can ensure proper
ordering using two-digit numeric prefixes).

View File

@ -1,13 +1,44 @@
#!/bin/bash #!/bin/bash
# the registry server to use set -o errexit
registry=$1
test "x$registry" != "x" || exit 1 trap 'echo -e "\n\n\n\e[31;1mAn error occurred!\e[1m\n\n"' ERR
for file in ${@:2} ; do registry=registry.oxen.rocks
name="$(echo $file | cut -d'.' -f1)"
echo "rebuild $name" if [[ $# -eq 0 ]]; then
docker build -f $file -t $registry/lokinet-ci-$name . files=(*.dockerfile i386/*.dockerfile arm64v8/*.dockerfile arm32v7/*.dockerfile)
docker push $registry/lokinet-ci-$name else
files=("$@")
fi
declare -A manifests
for file in "${files[@]}"; do
if [[ "$file" == */* ]]; then
arch="${file%%/*}"
name="${file#*/}"
else
arch="amd64"
name="$file"
fi
name="${name#[0-9][0-9]-}" # s/^\d\d-//
name="${name%.dockerfile}" # s/\.dockerfile$//
namearch=$registry/lokinet-ci-$name/$arch
latest=$registry/lokinet-ci-$name:latest
echo -e "\e[32;1mrebuilding \e[35;1m$namearch\e[0m"
docker build --pull -f $file -t $namearch --build-arg ARCH=$arch .
docker push $namearch
manifests[$latest]="${manifests[$latest]} $namearch"
done done
for latest in "${!manifests[@]}"; do
echo -e "\e[32;1mpushing new manifest for \e[33;1m$latest[\e[35;1m${manifests[$latest]} \e[33;1m]\e[0m"
docker manifest rm $latest 2>/dev/null || true
docker manifest create $latest ${manifests[$latest]}
docker manifest push $latest
done
echo -e "\n\n\n\e[32;1mAll done!\e[1m\n\n"

View File

@ -1,3 +0,0 @@
FROM ubuntu:bionic
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q --no-install-recommends install -y eatmydata gdb cmake git ninja-build pkg-config ccache g++-8 python3-dev automake libtool autoconf make qttools5-dev file gperf patch openssh-client'

View File

@ -1,3 +0,0 @@
FROM ubuntu:focal
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 --no-install-recommends -q install -y eatmydata gdb cmake git ninja-build pkg-config ccache g++ libsodium-dev libsystemd-dev python3-dev libuv1-dev libunbound-dev nettle-dev libssl-dev libevent-dev libsqlite3-dev libboost-thread-dev libboost-serialization-dev libboost-program-options-dev libgtest-dev libminiupnpc-dev libunwind8-dev libreadline-dev libhidapi-dev libusb-1.0.0-dev qttools5-dev libcurl4-openssl-dev'

View File

@ -2,4 +2,5 @@
test "x$IGNORE" != "x" && exit 0 test "x$IGNORE" != "x" && exit 0
repo=$(readlink -e $(dirname $0)/../../) repo=$(readlink -e $(dirname $0)/../../)
clang-format-11 -i $(find $repo/jni $repo/daemon $repo/llarp $repo/include $repo/pybind | grep -E '\.[hc](pp)?$') clang-format-11 -i $(find $repo/jni $repo/daemon $repo/llarp $repo/include $repo/pybind | grep -E '\.[hc](pp)?$')
jsonnetfmt -i $repo/.drone.jsonnet
git --no-pager diff --exit-code --color || (echo -ne '\n\n\e[31;1mLint check failed; please run ./contrib/format.sh\e[0m\n\n' ; exit 1) git --no-pager diff --exit-code --color || (echo -ne '\n\n\e[31;1mLint check failed; please run ./contrib/format.sh\e[0m\n\n' ; exit 1)

View File

@ -2,12 +2,12 @@
CLANG_FORMAT_DESIRED_VERSION=11 CLANG_FORMAT_DESIRED_VERSION=11
binary=$(which clang-format-$CLANG_FORMAT_DESIRED_VERSION 2>/dev/null) binary=$(command -v clang-format-$CLANG_FORMAT_DESIRED_VERSION 2>/dev/null)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
binary=$(which clang-format-mp-$CLANG_FORMAT_DESIRED_VERSION 2>/dev/null) binary=$(command -v clang-format-mp-$CLANG_FORMAT_DESIRED_VERSION 2>/dev/null)
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
binary=$(which clang-format 2>/dev/null) binary=$(command -v clang-format 2>/dev/null)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Please install clang-format version $CLANG_FORMAT_DESIRED_VERSION and re-run this script." echo "Please install clang-format version $CLANG_FORMAT_DESIRED_VERSION and re-run this script."
exit 1 exit 1
@ -22,18 +22,18 @@ fi
cd "$(dirname $0)/../" cd "$(dirname $0)/../"
if [ "$1" = "verify" ] ; then if [ "$1" = "verify" ] ; then
if [ $($binary --output-replacements-xml $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|mm?)$' | grep -v '\#') | grep '</replacement>' | wc -l) -ne 0 ] ; then if [ $($binary --output-replacements-xml $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|mm?)$' | grep -v '\#') | grep '</replacement>' | wc -l) -ne 0 ] ; then
exit 1 exit 2
fi fi
else else
$binary -i $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|mm)$' | grep -v '\#') &> /dev/null $binary -i $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|mm)$' | grep -v '\#') &> /dev/null
fi fi
swift_format=$(which swiftformat 2>/dev/null) swift_format=$(command -v swiftformat 2>/dev/null)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [ "$1" = "verify" ] ; then if [ "$1" = "verify" ] ; then
for f in $(find daemon | grep -E '\.swift$' | grep -v '\#') ; do for f in $(find daemon | grep -E '\.swift$' | grep -v '\#') ; do
if [ $($swift_format --quiet --dryrun < "$f" | diff "$f" - | wc -l) -ne 0 ] ; then if [ $($swift_format --quiet --dryrun < "$f" | diff "$f" - | wc -l) -ne 0 ] ; then
exit 1 exit 3
fi fi
done done
else else
@ -41,3 +41,14 @@ if [ $? -eq 0 ]; then
fi fi
fi fi
jsonnet_format=$(command -v jsonnetfmt 2>/dev/null)
if [ $? -eq 0 ]; then
if [ "$1" = "verify" ]; then
if ! $jsonnet_format --test .drone.jsonnet; then
exit 4
fi
else
$jsonnet_format --in-place .drone.jsonnet
fi
fi

View File

@ -333,7 +333,7 @@ mult96x8_float(__m256 h[192], const __m256 f[96], const __m256 g[96])
/* 96*(16*int8 stored in 32*int8) g inputs between -8 and 8 */ /* 96*(16*int8 stored in 32*int8) g inputs between -8 and 8 */
/* 192*16*int16 h outputs between -2400 and 2400 */ /* 192*16*int16 h outputs between -2400 and 2400 */
static void static void
mult96x16(__m256i h[192], const __m256i f[96], const __m256i g[96]) mult96x16(__m256i * h, const __m256i * f, const __m256i * g)
{ {
__m256 hfloat[192]; __m256 hfloat[192];
__m256 gfloat[96]; __m256 gfloat[96];

View File

@ -1,3 +1,8 @@
set(DEFAULT_WITH_BOOTSTRAP ON)
if(APPLE)
set(DEFAULT_WITH_BOOTSTRAP OFF)
endif()
option(WITH_BOOTSTRAP "build lokinet-bootstrap tool" ${DEFAULT_WITH_BOOTSTRAP})
add_executable(lokinet-vpn lokinet-vpn.cpp) add_executable(lokinet-vpn lokinet-vpn.cpp)
if(APPLE) if(APPLE)
@ -5,8 +10,12 @@ if(APPLE)
enable_lto(lokinet) enable_lto(lokinet)
else() else()
add_executable(lokinet lokinet.cpp) add_executable(lokinet lokinet.cpp)
add_executable(lokinet-bootstrap lokinet-bootstrap.cpp) enable_lto(lokinet lokinet-vpn)
enable_lto(lokinet lokinet-vpn lokinet-bootstrap)
if(WITH_BOOTSTRAP)
add_executable(lokinet-bootstrap lokinet-bootstrap.cpp)
enable_lto(lokinet-bootstrap)
endif()
endif() endif()
@ -30,7 +39,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
endif() endif()
endif() endif()
if(NOT APPLE) if(WITH_BOOTSTRAP)
target_link_libraries(lokinet-bootstrap PUBLIC cpr::cpr) target_link_libraries(lokinet-bootstrap PUBLIC cpr::cpr)
if(NOT WIN32) if(NOT WIN32)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
@ -40,7 +49,7 @@ if(NOT APPLE)
endif() endif()
set(exetargets lokinet lokinet-vpn) set(exetargets lokinet lokinet-vpn)
if(NOT APPLE) if(WITH_BOOTSTRAP)
list(APPEND exetargets lokinet-bootstrap) list(APPEND exetargets lokinet-bootstrap)
endif() endif()
@ -53,9 +62,6 @@ foreach(exe ${exetargets})
target_link_directories(${exe} PRIVATE /usr/local/lib) target_link_directories(${exe} PRIVATE /usr/local/lib)
endif() endif()
target_link_libraries(${exe} PUBLIC liblokinet) target_link_libraries(${exe} PUBLIC liblokinet)
if(WITH_JEMALLOC)
target_link_libraries(${exe} PUBLIC jemalloc)
endif()
target_include_directories(${exe} PUBLIC "${PROJECT_SOURCE_DIR}") target_include_directories(${exe} PUBLIC "${PROJECT_SOURCE_DIR}")
target_compile_definitions(${exe} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) target_compile_definitions(${exe} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL})
add_log_tag(${exe}) add_log_tag(${exe})
@ -79,10 +85,9 @@ if(APPLE)
DEPENDS ${PROJECT_SOURCE_DIR}/contrib/lokinet.svg ${PROJECT_SOURCE_DIR}/contrib/macos/mk-icns.sh) DEPENDS ${PROJECT_SOURCE_DIR}/contrib/lokinet.svg ${PROJECT_SOURCE_DIR}/contrib/macos/mk-icns.sh)
add_custom_target(icons DEPENDS ${mac_icon}) add_custom_target(icons DEPENDS ${mac_icon})
add_dependencies(lokinet icons lokinet-extension) add_dependencies(lokinet icons lokinet-extension)
file(DOWNLOAD "https://seed.lokinet.org/lokinet.signed" ${CMAKE_CURRENT_BINARY_DIR}/bootstrap.signed)
add_custom_command(TARGET lokinet add_custom_command(TARGET lokinet
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/bootstrap.signed COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed
$<TARGET_BUNDLE_DIR:lokinet-extension>/Contents/Resources/bootstrap.signed $<TARGET_BUNDLE_DIR:lokinet-extension>/Contents/Resources/bootstrap.signed
COMMAND mkdir -p $<TARGET_BUNDLE_DIR:lokinet>/Contents/PlugIns COMMAND mkdir -p $<TARGET_BUNDLE_DIR:lokinet>/Contents/PlugIns
COMMAND cp -a $<TARGET_BUNDLE_DIR:lokinet-extension> $<TARGET_BUNDLE_DIR:lokinet>/Contents/PlugIns/ COMMAND cp -a $<TARGET_BUNDLE_DIR:lokinet-extension> $<TARGET_BUNDLE_DIR:lokinet>/Contents/PlugIns/

View File

@ -18,32 +18,6 @@
#include <iostream> #include <iostream>
#include <future> #include <future>
#ifdef USE_JEMALLOC
#include <new>
#include <jemalloc/jemalloc.h>
void*
operator new(std::size_t sz)
{
void* ptr = malloc(sz);
if (ptr)
return ptr;
else
throw std::bad_alloc{};
}
void
operator delete(void* ptr) noexcept
{
free(ptr);
}
void
operator delete(void* ptr, size_t) noexcept
{
free(ptr);
}
#endif
int int
lokinet_main(int, char**); lokinet_main(int, char**);
@ -259,7 +233,7 @@ run_main_context(std::optional<fs::path> confFile, const llarp::RuntimeOptions o
try try
{ {
std::shared_ptr<llarp::Config> conf; std::shared_ptr<llarp::Config> conf;
if (confFile.has_value()) if (confFile)
{ {
llarp::LogInfo("Using config file: ", *confFile); llarp::LogInfo("Using config file: ", *confFile);
conf = std::make_shared<llarp::Config>(confFile->parent_path()); conf = std::make_shared<llarp::Config>(confFile->parent_path());
@ -268,8 +242,12 @@ run_main_context(std::optional<fs::path> confFile, const llarp::RuntimeOptions o
{ {
conf = std::make_shared<llarp::Config>(llarp::GetDefaultDataDir()); conf = std::make_shared<llarp::Config>(llarp::GetDefaultDataDir());
} }
if (!conf->Load(confFile, opts.isSNode)) if (not conf->Load(confFile, opts.isSNode))
throw std::runtime_error{"Config file parsing failed"}; {
llarp::LogError("failed to parse configuration");
exit_code.set_value(1);
return;
}
ctx = std::make_shared<llarp::Context>(); ctx = std::make_shared<llarp::Context>();
ctx->Configure(std::move(conf)); ctx->Configure(std::move(conf));
@ -281,7 +259,17 @@ run_main_context(std::optional<fs::path> confFile, const llarp::RuntimeOptions o
signal(SIGUSR1, handle_signal); signal(SIGUSR1, handle_signal);
#endif #endif
ctx->Setup(opts); try
{
ctx->Setup(opts);
}
catch (std::exception& ex)
{
llarp::LogError(
"failed to set up lokinet: ", ex.what(), ", is lokinet already running? 🤔");
exit_code.set_value(1);
return;
}
llarp::util::SetThreadName("llarp-mainloop"); llarp::util::SetThreadName("llarp-mainloop");
@ -522,7 +510,7 @@ lokinet_main(int argc, char* argv[])
} }
catch (std::exception& ex) catch (std::exception& ex)
{ {
LogError("cannot generate config at ", *configFile, ": ", ex.what()); llarp::LogError("cannot generate config at ", *configFile, ": ", ex.what());
return 1; return 1;
} }
} }
@ -538,7 +526,7 @@ lokinet_main(int argc, char* argv[])
} }
catch (std::exception& ex) catch (std::exception& ex)
{ {
LogError("cannot check if ", *configFile, " exists: ", ex.what()); llarp::LogError("cannot check if ", *configFile, " exists: ", ex.what());
return 1; return 1;
} }
} }
@ -600,7 +588,7 @@ lokinet_main(int argc, char* argv[])
"file a bug report now or be cursed with this " "file a bug report now or be cursed with this "
"annoying image in your syslog for all time."}) "annoying image in your syslog for all time."})
{ {
LogError(wtf); llarp::LogError{wtf};
llarp::LogContext::Instance().ImmediateFlush(); llarp::LogContext::Instance().ImmediateFlush();
} }
#ifdef _WIN32 #ifdef _WIN32

View File

@ -10,7 +10,7 @@ to configure lokinet to be an exit add into `lokinet.ini`:
keyfile=/var/lib/lokinet/exit.private keyfile=/var/lib/lokinet/exit.private
reachable=1 reachable=1
ifaddr=10.0.0.1/16 ifaddr=10.0.0.1/16
hops=1 hops=2
paths=8 paths=8

View File

@ -50,15 +50,9 @@ add_library(uvw INTERFACE)
target_include_directories(uvw INTERFACE uvw/src) target_include_directories(uvw INTERFACE uvw/src)
target_link_libraries(uvw INTERFACE libuv) target_link_libraries(uvw INTERFACE libuv)
# ngtcp2 needs some massaging to build nicely:
include(ngtcp2_lib)
# We don't need any of these as we don't use the ssl crypto helper code at all: add_ngtcp2_lib()
set(ENABLE_GNUTLS OFF CACHE BOOL "Disable gnutls for ngtcp2")
set(ENABLE_OPENSSL OFF CACHE BOOL "Disable openssl for ngtcp2")
set(ENABLE_BORINGSSL OFF CACHE BOOL "Disable boringssl for ngtcp2")
add_definitions(-D_GNU_SOURCE)
add_subdirectory(ngtcp2 EXCLUDE_FROM_ALL)
# cpr configuration. Ideally we'd just do this via add_subdirectory, but cpr's cmake requires # 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). # 3.15+, and we target lower than that (and this is fairly simple to build).

2
external/ngtcp2 vendored

@ -1 +1 @@
Subproject commit 51e95c8d8972abd69515d9790e8fbb774262d9ea Subproject commit 15ba6021ca352e2e60f9b43f4b96d2e97a42f60b

View File

@ -1,6 +1,7 @@
include(Version) include(Version)
add_library(lokinet-util add_library(lokinet-util
STATIC
${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp ${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp
util/bencode.cpp util/bencode.cpp
util/buffer.cpp util/buffer.cpp
@ -9,7 +10,6 @@ add_library(lokinet-util
util/logging/android_logger.cpp util/logging/android_logger.cpp
util/logging/buffer.cpp util/logging/buffer.cpp
util/logging/file_logger.cpp util/logging/file_logger.cpp
util/logging/json_logger.cpp
util/logging/logger.cpp util/logging/logger.cpp
util/logging/logger_internal.cpp util/logging/logger_internal.cpp
util/logging/loglevel.cpp util/logging/loglevel.cpp

View File

@ -6,7 +6,7 @@ namespace llarp::apple
NSLogStream::PreLog( NSLogStream::PreLog(
std::stringstream& ss, std::stringstream& ss,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view fname,
int lineno, int lineno,
const std::string& nodename) const const std::string& nodename) const
{ {
@ -17,7 +17,7 @@ namespace llarp::apple
} }
void void
NSLogStream::Print(LogLevel, const char*, const std::string& msg) NSLogStream::Print(LogLevel, std::string_view, const std::string& msg)
{ {
ns_logger(msg.c_str()); ns_logger(msg.c_str());
} }

View File

@ -16,15 +16,15 @@ namespace llarp::apple
PreLog( PreLog(
std::stringstream& s, std::stringstream& s,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view fname,
int lineno, int lineno,
const std::string& nodename) const override; const std::string& nodename) const override;
void void
Print(LogLevel lvl, const char* tag, const std::string& msg) override; Print(LogLevel lvl, std::string_view tag, const std::string& msg) override;
void void
PostLog(std::stringstream& ss) const override PostLog(std::stringstream&) const override
{} {}
void void

View File

@ -105,7 +105,7 @@ llarp_apple_init(llarp_apple_config* appleconf)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
LogError("Failed to initialize lokinet from config: ", e.what()); llarp::LogError("Failed to initialize lokinet from config: ", e.what());
} }
return nullptr; return nullptr;
} }
@ -149,7 +149,7 @@ llarp_apple_start(void* lokinet, void* callback_context)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
LogError("Failed to initialize lokinet: ", e.what()); llarp::LogError("Failed to initialize lokinet: ", e.what());
return -1; return -1;
} }
@ -178,7 +178,7 @@ llarp_apple_incoming(void* lokinet, const void* bytes, size_t size)
if (iface->OfferReadPacket(buf)) if (iface->OfferReadPacket(buf))
return 0; return 0;
LogError("invalid IP packet: ", llarp::buffer_printer(buf)); llarp::LogError("invalid IP packet: ", llarp::buffer_printer(buf));
return -1; return -1;
} }

View File

@ -569,7 +569,13 @@ namespace llarp
IP6RangeDefault, IP6RangeDefault,
[this](std::string arg) { [this](std::string arg) {
if (arg.empty()) if (arg.empty())
{
LogError(
"!!! Disabling ipv6 tunneling when you have ipv6 routes WILL lead to "
"de-anonymization as lokinet will no longer carry your ipv6 traffic !!!");
m_baseV6Address = std::nullopt;
return; return;
}
m_baseV6Address = huint128_t{}; m_baseV6Address = huint128_t{};
if (not m_baseV6Address->FromString(arg)) if (not m_baseV6Address->FromString(arg))
throw std::invalid_argument( throw std::invalid_argument(
@ -1048,7 +1054,6 @@ namespace llarp
Comment{ Comment{
"Log type (format). Valid options are:", "Log type (format). Valid options are:",
" file - plaintext formatting", " file - plaintext formatting",
" json - json-formatted log statements",
" syslog - logs directed to syslog", " syslog - logs directed to syslog",
}); });

View File

@ -117,16 +117,16 @@ namespace llarp
{ {
if (!qd.Decode(buf)) if (!qd.Decode(buf))
{ {
llarp::LogError("failed to decode question"); LogError("failed to decode question");
return false; return false;
} }
llarp::LogDebug(qd); LogDebug("dns question: ", qd);
} }
for (auto& an : answers) for (auto& an : answers)
{ {
if (not an.Decode(buf)) if (not an.Decode(buf))
{ {
llarp::LogDebug("failed to decode answer"); LogDebug("failed to decode answer");
return false; return false;
} }
} }

View File

@ -748,11 +748,14 @@ namespace llarp
LogError("short XMIT from ", m_RemoteAddr); LogError("short XMIT from ", m_RemoteAddr);
return; return;
} }
uint16_t sz = bufbe16toh(data.data() + CommandOverhead + PacketOverhead); auto* pos = data.data() + CommandOverhead + PacketOverhead;
uint64_t rxid = bufbe64toh(data.data() + CommandOverhead + sizeof(uint16_t) + PacketOverhead); uint16_t sz = bufbe16toh(pos);
ShortHash h{ pos += sizeof(sz);
data.data() + CommandOverhead + sizeof(uint16_t) + sizeof(uint64_t) + PacketOverhead}; uint64_t rxid = bufbe64toh(pos);
LogTrace("rxid=", rxid, " sz=", sz, " h=", h.ToHex(), " from ", m_RemoteAddr); pos += sizeof(rxid);
auto p2 = pos + ShortHash::SIZE;
assert(p2 == data.data() + XMITOverhead);
LogTrace("rxid=", rxid, " sz=", sz, " h=", oxenmq::to_hex(pos, p2), " from ", m_RemoteAddr);
m_LastRX = m_Parent->Now(); m_LastRX = m_Parent->Now();
{ {
// check for replay // check for replay
@ -769,8 +772,8 @@ namespace llarp
auto itr = m_RXMsgs.find(rxid); auto itr = m_RXMsgs.find(rxid);
if (itr == m_RXMsgs.end()) if (itr == m_RXMsgs.end())
{ {
itr = itr = m_RXMsgs.emplace(rxid, InboundMessage{rxid, sz, ShortHash{pos}, m_Parent->Now()})
m_RXMsgs.emplace(rxid, InboundMessage{rxid, sz, std::move(h), m_Parent->Now()}).first; .first;
sz = std::min(sz, uint16_t{FragmentSize}); sz = std::min(sz, uint16_t{FragmentSize});
if ((data.size() - XMITOverhead) == sz) if ((data.size() - XMITOverhead) == sz)
{ {

View File

@ -110,7 +110,7 @@ namespace llarp
llarp_time_t llarp_time_t
Now() const override; Now() const override;
void virtual void
Tick(llarp_time_t now) override; Tick(llarp_time_t now) override;
void void

View File

@ -21,7 +21,7 @@ namespace llarp::quic
class Address class Address
{ {
sockaddr_in6 saddr{}; sockaddr_in6 saddr{};
ngtcp2_addr a{sizeof(saddr), reinterpret_cast<sockaddr*>(&saddr), nullptr}; ngtcp2_addr a{sizeof(saddr), reinterpret_cast<sockaddr*>(&saddr)};
public: public:
Address() = default; Address() = default;
@ -102,8 +102,7 @@ namespace llarp::quic
Address local_, remote_; Address local_, remote_;
public: public:
ngtcp2_path path{ ngtcp2_path path{{local_.sockaddr_size(), local_}, {remote_.sockaddr_size(), remote_}, nullptr};
{local_.sockaddr_size(), local_, nullptr}, {remote_.sockaddr_size(), remote_, nullptr}};
// Public accessors are const: // Public accessors are const:
const Address& local = local_; const Address& local = local_;

View File

@ -244,6 +244,7 @@ namespace llarp::quic
int int
stream_close_cb( stream_close_cb(
ngtcp2_conn* conn, ngtcp2_conn* conn,
uint32_t flags,
int64_t stream_id, int64_t stream_id,
uint64_t app_error_code, uint64_t app_error_code,
void* user_data, void* user_data,
@ -275,17 +276,13 @@ namespace llarp::quic
return 0; return 0;
} }
int void
rand( rand(uint8_t* dest, size_t destlen, const ngtcp2_rand_ctx* rand_ctx)
uint8_t* dest,
size_t destlen,
const ngtcp2_rand_ctx* rand_ctx,
[[maybe_unused]] ngtcp2_rand_usage usage)
{ {
LogTrace("######################", __func__); LogTrace("######################", __func__);
randombytes_buf(dest, destlen); randombytes_buf(dest, destlen);
return 0;
} }
int int
get_new_connection_id( get_new_connection_id(
ngtcp2_conn* conn_, ngtcp2_cid* cid_, uint8_t* token, size_t cidlen, void* user_data) ngtcp2_conn* conn_, ngtcp2_cid* cid_, uint8_t* token, size_t cidlen, void* user_data)
@ -340,7 +337,7 @@ namespace llarp::quic
va_start(ap, fmt); va_start(ap, fmt);
if (char* msg; vasprintf(&msg, fmt, ap) >= 0) if (char* msg; vasprintf(&msg, fmt, ap) >= 0)
{ {
LogTraceExplicit("external/ngtcp2/*.c", 0, msg); LogTrace{msg};
std::free(msg); std::free(msg);
} }
va_end(ap); va_end(ap);
@ -406,7 +403,7 @@ namespace llarp::quic
settings.initial_ts = get_timestamp(); settings.initial_ts = get_timestamp();
// FIXME: IPv6 // FIXME: IPv6
settings.max_udp_payload_size = NGTCP2_MAX_PKTLEN_IPV4; settings.max_udp_payload_size = Endpoint::max_pkt_size_v4;
settings.cc_algo = NGTCP2_CC_ALGO_CUBIC; settings.cc_algo = NGTCP2_CC_ALGO_CUBIC;
// settings.initial_rtt = ???; # NGTCP2's default is 333ms // settings.initial_rtt = ???; # NGTCP2's default is 333ms
@ -1185,8 +1182,7 @@ namespace llarp::quic
ngtcp2_conn_get_local_transport_params(*this, &tparams); ngtcp2_conn_get_local_transport_params(*this, &tparams);
assert(conn_buffer.empty()); assert(conn_buffer.empty());
static_assert(NGTCP2_MAX_PKTLEN_IPV4 > NGTCP2_MAX_PKTLEN_IPV6); conn_buffer.resize(Endpoint::max_pkt_size_v4);
conn_buffer.resize(NGTCP2_MAX_PKTLEN_IPV4);
auto* buf = u8data(conn_buffer); auto* buf = u8data(conn_buffer);
auto* bufend = buf + conn_buffer.size(); auto* bufend = buf + conn_buffer.size();

View File

@ -123,7 +123,7 @@ namespace llarp::quic
}; };
// Packet data storage for a packet we are currently sending // Packet data storage for a packet we are currently sending
std::array<std::byte, NGTCP2_MAX_PKTLEN_IPV4> send_buffer{}; std::array<std::byte, NGTCP2_MAX_UDP_PAYLOAD_SIZE> send_buffer{};
size_t send_buffer_size = 0; size_t send_buffer_size = 0;
ngtcp2_pkt_info send_pkt_info{}; ngtcp2_pkt_info send_pkt_info{};

View File

@ -199,7 +199,7 @@ namespace llarp::quic
void void
Endpoint::send_version_negotiation(const version_info& vi, const Address& source) Endpoint::send_version_negotiation(const version_info& vi, const Address& source)
{ {
std::array<std::byte, NGTCP2_MAX_PKTLEN_IPV4> buf; std::array<std::byte, Endpoint::max_pkt_size_v4> buf;
std::array<uint32_t, NGTCP2_PROTO_VER_MAX - NGTCP2_PROTO_VER_MIN + 2> versions; std::array<uint32_t, NGTCP2_PROTO_VER_MAX - NGTCP2_PROTO_VER_MIN + 2> versions;
std::iota(versions.begin() + 1, versions.end(), NGTCP2_PROTO_VER_MIN); std::iota(versions.begin() + 1, versions.end(), NGTCP2_PROTO_VER_MIN);
// we're supposed to send some 0x?a?a?a?a version to trigger version negotiation // we're supposed to send some 0x?a?a?a?a version to trigger version negotiation
@ -234,11 +234,13 @@ namespace llarp::quic
Path path; Path path;
ngtcp2_pkt_info pi; ngtcp2_pkt_info pi;
auto write_close_func = auto write_close_func = application ? ngtcp2_conn_write_application_close_versioned
application ? ngtcp2_conn_write_application_close : ngtcp2_conn_write_connection_close; : ngtcp2_conn_write_connection_close_versioned;
auto written = write_close_func( auto written = write_close_func(
conn, conn,
path, path,
NGTCP2_PKT_INFO_VERSION,
&pi, &pi,
u8data(conn.conn_buffer), u8data(conn.conn_buffer),
conn.conn_buffer.size(), conn.conn_buffer.size(),

View File

@ -64,8 +64,8 @@ namespace llarp::quic
// Max theoretical size of a UDP packet is 2^16-1 minus IP/UDP header overhead // Max theoretical size of a UDP packet is 2^16-1 minus IP/UDP header overhead
static constexpr size_t max_buf_size = 64 * 1024; static constexpr size_t max_buf_size = 64 * 1024;
// Max size of a UDP packet that we'll send // Max size of a UDP packet that we'll send
static constexpr size_t max_pkt_size_v4 = NGTCP2_MAX_PKTLEN_IPV4; static constexpr size_t max_pkt_size_v4 = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
static constexpr size_t max_pkt_size_v6 = NGTCP2_MAX_PKTLEN_IPV6; static constexpr size_t max_pkt_size_v6 = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
using primary_conn_ptr = std::shared_ptr<Connection>; using primary_conn_ptr = std::shared_ptr<Connection>;
using alias_conn_ptr = std::weak_ptr<Connection>; using alias_conn_ptr = std::weak_ptr<Connection>;

View File

@ -324,6 +324,9 @@ namespace llarp
virtual util::StatusObject virtual util::StatusObject
ExtractStatus() const = 0; ExtractStatus() const = 0;
virtual util::StatusObject
ExtractSummaryStatus() const = 0;
/// gossip an rc if required /// gossip an rc if required
virtual void virtual void
GossipRCIfNeeded(const RouterContact rc) = 0; GossipRCIfNeeded(const RouterContact rc) = 0;

View File

@ -15,7 +15,6 @@
#include <stdexcept> #include <stdexcept>
#include <llarp/util/buffer.hpp> #include <llarp/util/buffer.hpp>
#include <llarp/util/logging/file_logger.hpp> #include <llarp/util/logging/file_logger.hpp>
#include <llarp/util/logging/json_logger.hpp>
#include <llarp/util/logging/logger_syslog.hpp> #include <llarp/util/logging/logger_syslog.hpp>
#include <llarp/util/logging/logger.hpp> #include <llarp/util/logging/logger.hpp>
#include <llarp/util/meta/memfn.hpp> #include <llarp/util/meta/memfn.hpp>
@ -97,6 +96,77 @@ namespace llarp
} }
} }
util::StatusObject
Router::ExtractSummaryStatus() const
{
if (!_running)
return util::StatusObject{{"running", false}};
auto services = _hiddenServiceContext.ExtractStatus();
auto link_types = _linkManager.ExtractStatus();
uint64_t tx_rate = 0;
uint64_t rx_rate = 0;
uint64_t peers = 0;
for (const auto& links : link_types)
{
for (const auto& link : links)
{
if (link.empty())
continue;
for (const auto& peer : link["sessions"]["established"])
{
tx_rate += peer["tx"].get<uint64_t>();
rx_rate += peer["rx"].get<uint64_t>();
peers++;
}
}
}
// Compute all stats on all path builders on the default endpoint
// Merge snodeSessions, remoteSessions and default into a single array
std::vector<nlohmann::json> builders;
auto snode_sessions = services["default"]["snodeSessions"];
for (const auto& session : snode_sessions)
builders.push_back(session["buildStats"]);
auto remote_sessions = services["default"]["remoteSessions"];
for (const auto& session : remote_sessions)
builders.push_back(session["buildStats"]);
builders.push_back(services["default"]["buildStats"]);
// Iterate over all items on this array to build the global pathStats
uint64_t paths = 0;
uint64_t success = 0;
uint64_t attempts = 0;
for (const auto& builder : builders)
{
if (builder.is_null())
continue;
if (builder["length"].is_number())
paths += builder["length"].get<uint64_t>();
if (builder["success"].is_number())
success += builder["success"].get<uint64_t>();
if (builder["attempts"].is_number())
attempts += builder["attempts"].get<uint64_t>();
}
double ratio = static_cast<double>(success) / (attempts + 1);
return util::StatusObject{
{"running", true},
{"authCodes", services["default"]["authCodes"]},
{"exitMap", services["default"]["exitMap"]},
{"lokiAddress", services["default"]["identity"]},
{"numPathsBuilt", paths},
{"numPeersConnected", peers},
{"numRoutersKnown", _nodedb->NumLoaded()},
{"ratio", ratio},
{"txRate", tx_rate},
{"rxRate", rx_rate},
};
}
bool bool
Router::HandleRecvLinkMessageBuffer(ILinkSession* session, const llarp_buffer_t& buf) Router::HandleRecvLinkMessageBuffer(ILinkSession* session, const llarp_buffer_t& buf)
{ {

View File

@ -103,6 +103,9 @@ namespace llarp
util::StatusObject util::StatusObject
ExtractStatus() const override; ExtractStatus() const override;
util::StatusObject
ExtractSummaryStatus() const override;
const std::shared_ptr<NodeDB>& const std::shared_ptr<NodeDB>&
nodedb() const override nodedb() const override
{ {

View File

@ -87,46 +87,84 @@ namespace llarp
{ {
// This passing address by bytes and using two separate calls for ipv4/ipv6 is gross, but the // This passing address by bytes and using two separate calls for ipv4/ipv6 is gross, but the
// alternative is to build up a bunch of crap with va_args, which is slightly more gross. // alternative is to build up a bunch of crap with va_args, which is slightly more gross.
const bool isStandardDNSPort = dns.getPort() == 53;
if (dns.isIPv6()) if (dns.isIPv6())
{ {
auto ipv6 = dns.getIPv6(); auto ipv6 = dns.getIPv6();
static_assert(sizeof(ipv6) == 16); static_assert(sizeof(ipv6) == 16);
auto* a = reinterpret_cast<const uint8_t*>(&ipv6); auto* a = reinterpret_cast<const uint8_t*>(&ipv6);
resolved_call( if (isStandardDNSPort)
bus, {
"SetLinkDNSEx", resolved_call(
"ia(iayqs)", bus,
(int32_t)if_ndx, "SetLinkDNS",
(int)1, // number of "iayqs"s we are passing "ia(iay)",
(int32_t)AF_INET6, // network address type (int32_t)if_ndx,
(int)16, // network addr byte size (int)1, // number of "iayqs"s we are passing
// clang-format off (int32_t)AF_INET6, // network address type
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], (int)16, // network addr byte size
a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], // yuck // clang-format off
// clang-format on a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
(uint16_t)dns.getPort(), a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15] // yuck
nullptr // dns server name (for TLS SNI which we don't care about) // clang-format on
); );
}
else
{
resolved_call(
bus,
"SetLinkDNSEx",
"ia(iayqs)",
(int32_t)if_ndx,
(int)1, // number of "iayqs"s we are passing
(int32_t)AF_INET6, // network address type
(int)16, // network addr byte size
// clang-format off
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], // yuck
// clang-format on
(uint16_t)dns.getPort(),
nullptr // dns server name (for TLS SNI which we don't care about)
);
}
} }
else else
{ {
auto ipv4 = dns.getIPv4(); auto ipv4 = dns.getIPv4();
static_assert(sizeof(ipv4) == 4); static_assert(sizeof(ipv4) == 4);
auto* a = reinterpret_cast<const uint8_t*>(&ipv4); auto* a = reinterpret_cast<const uint8_t*>(&ipv4);
resolved_call( if (isStandardDNSPort)
bus, {
"SetLinkDNSEx", resolved_call(
"ia(iayqs)", bus,
(int32_t)if_ndx, "SetLinkDNS",
(int)1, // number of "iayqs"s we are passing "ia(iay)",
(int32_t)AF_INET, // network address type (int32_t)if_ndx,
(int)4, // network addr byte size (int)1, // number of "iayqs"s we are passing
// clang-format off (int32_t)AF_INET, // network address type
a[0], a[1], a[2], a[3], // yuck (int)4, // network addr byte size
// clang-format on // clang-format off
(uint16_t)dns.getPort(), a[0], a[1], a[2], a[3] // yuck
nullptr // dns server name (for TLS SNI which we don't care about) // clang-format on
); );
}
else
{
resolved_call(
bus,
"SetLinkDNSEx",
"ia(iayqs)",
(int32_t)if_ndx,
(int)1, // number of "iayqs"s we are passing
(int32_t)AF_INET, // network address type
(int)4, // network addr byte size
// clang-format off
a[0], a[1], a[2], a[3], // yuck
// clang-format on
(uint16_t)dns.getPort(),
nullptr // dns server name (for TLS SNI which we don't care about)
);
}
} }
if (global) if (global)

View File

@ -35,7 +35,9 @@ namespace llarp
explicit NetID(const byte_t* val); explicit NetID(const byte_t* val);
explicit NetID(const NetID& other) = default; NetID(const NetID& other) = default;
NetID&
operator=(const NetID& other) = default;
bool bool
operator==(const NetID& other) const; operator==(const NetID& other) const;

View File

@ -133,6 +133,13 @@ namespace llarp::rpc
defer.reply(data); defer.reply(data);
}); });
}) })
.add_request_command(
"get_status",
[&](oxenmq::Message& msg) {
m_Router->loop()->call([defer = msg.send_later(), r = m_Router]() {
defer.reply(CreateJSONResponse(r->ExtractSummaryStatus()));
});
})
.add_request_command( .add_request_command(
"quic_connect", "quic_connect",
[&](oxenmq::Message& msg) { [&](oxenmq::Message& msg) {

View File

@ -470,6 +470,7 @@ namespace llarp
if (itr == Sessions().end()) if (itr == Sessions().end())
return false; return false;
si = itr->second.remote; si = itr->second.remote;
si.UpdateAddr();
return true; return true;
} }
@ -1100,13 +1101,14 @@ namespace llarp
bool bool
Endpoint::HandleDataMessage( Endpoint::HandleDataMessage(
path::Path_ptr, const PathID_t from, std::shared_ptr<ProtocolMessage> msg) path::Path_ptr p, const PathID_t from, std::shared_ptr<ProtocolMessage> msg)
{ {
PutSenderFor(msg->tag, msg->sender, true); PutSenderFor(msg->tag, msg->sender, true);
Introduction intro = msg->introReply; Introduction intro = msg->introReply;
if (HasInboundConvo(msg->sender.Addr())) if (HasInboundConvo(msg->sender.Addr()))
{ {
intro.pathID = from; intro.pathID = from;
intro.router = p->Endpoint();
} }
PutReplyIntroFor(msg->tag, intro); PutReplyIntroFor(msg->tag, intro);
ConvoTagRX(msg->tag); ConvoTagRX(msg->tag);

View File

@ -13,7 +13,7 @@ namespace llarp
{ {
struct Introduction struct Introduction
{ {
PubKey router; RouterID router;
PathID_t pathID; PathID_t pathID;
llarp_time_t latency = 0s; llarp_time_t latency = 0s;
llarp_time_t expiresAt = 0s; llarp_time_t expiresAt = 0s;

View File

@ -54,7 +54,7 @@ namespace llarp
return true; return true;
} }
constexpr auto OutboundContextNumPaths = 2; constexpr auto OutboundContextNumPaths = 4;
OutboundContext::OutboundContext(const IntroSet& introset, Endpoint* parent) OutboundContext::OutboundContext(const IntroSet& introset, Endpoint* parent)
: path::Builder{parent->Router(), OutboundContextNumPaths, parent->numHops} : path::Builder{parent->Router(), OutboundContextNumPaths, parent->numHops}
@ -64,12 +64,17 @@ namespace llarp
, currentIntroSet{introset} , currentIntroSet{introset}
{ {
assert(not introset.intros.empty());
updatingIntroSet = false; updatingIntroSet = false;
for (const auto& intro : introset.intros)
// pick random first intro
auto it = introset.intros.begin();
if (introset.intros.size() > 1)
{ {
if (m_NextIntro.latency == 0s or m_NextIntro.latency > intro.latency) CSRNG rng{};
m_NextIntro = intro; it += std::uniform_int_distribution<size_t>{0, introset.intros.size() - 1}(rng);
} }
m_NextIntro = *it;
currentConvoTag.Randomize(); currentConvoTag.Randomize();
lastShift = Now(); lastShift = Now();
// add send and connect timeouts to the parent endpoints path alignment timeout // add send and connect timeouts to the parent endpoints path alignment timeout
@ -333,6 +338,7 @@ namespace llarp
Encrypted<64> tmp; Encrypted<64> tmp;
tmp.Randomize(); tmp.Randomize();
SendPacketToRemote(tmp, ProtocolType::Control); SendPacketToRemote(tmp, ProtocolType::Control);
m_LastKeepAliveAt = Now();
} }
bool bool
@ -348,7 +354,10 @@ namespace llarp
// expunge // expunge
SharedSecret discardme; SharedSecret discardme;
if (not m_DataHandler->GetCachedSessionKeyFor(currentConvoTag, discardme)) if (not m_DataHandler->GetCachedSessionKeyFor(currentConvoTag, discardme))
{
LogError(Name(), " no cached key after sending intro, we are in a fugged state, oh no");
return true; return true;
}
} }
if (m_GotInboundTraffic and m_LastInboundTraffic + sendTimeout <= now) if (m_GotInboundTraffic and m_LastInboundTraffic + sendTimeout <= now)
@ -404,21 +413,33 @@ namespace llarp
m_ReadyHooks.clear(); m_ReadyHooks.clear();
} }
if (m_LastInboundTraffic > 0s and lastGoodSend > 0s
and now >= sendTimeout + m_LastInboundTraffic)
return true;
const auto timeout = std::max(lastGoodSend, m_LastInboundTraffic); const auto timeout = std::max(lastGoodSend, m_LastInboundTraffic);
if (lastGoodSend > 0s and now >= timeout + (sendTimeout / 2)) if (lastGoodSend > 0s and now >= timeout + (sendTimeout / 2))
{ {
// send a keep alive to keep this session alive // send a keep alive to keep this session alive
KeepAlive(); KeepAlive();
if (markedBad) if (markedBad)
{
LogWarn(Name(), " keepalive timeout hit");
return true; return true;
}
}
// check for half open state where we can send but we get nothing back
if (m_LastInboundTraffic == 0s and now - createdAt > connectTimeout)
{
LogWarn(Name(), " half open state, we can send but we got nothing back");
return true;
} }
// if we are dead return true so we are removed // if we are dead return true so we are removed
return timeout > 0s ? (now >= timeout && now - timeout > sendTimeout) const bool removeIt = timeout > 0s ? (now >= timeout && now - timeout > sendTimeout)
: (now >= createdAt && now - createdAt > connectTimeout); : (now >= createdAt && now - createdAt > connectTimeout);
if (removeIt)
{
LogInfo(Name(), " session is stale");
return true;
}
return false;
} }
void void
@ -584,6 +605,25 @@ namespace llarp
} }
} }
bool
OutboundContext::ShouldKeepAlive(llarp_time_t now) const
{
const auto SendKeepAliveInterval = sendTimeout / 2;
if (not m_GotInboundTraffic)
return false;
if (m_LastInboundTraffic == 0s)
return false;
return (now - m_LastKeepAliveAt) >= SendKeepAliveInterval;
}
void
OutboundContext::Tick(llarp_time_t now)
{
path::Builder::Tick(now);
if (ShouldKeepAlive(now))
KeepAlive();
}
bool bool
OutboundContext::HandleHiddenServiceFrame(path::Path_ptr p, const ProtocolFrame& frame) OutboundContext::HandleHiddenServiceFrame(path::Path_ptr p, const ProtocolFrame& frame)
{ {

View File

@ -23,6 +23,9 @@ namespace llarp
~OutboundContext() override; ~OutboundContext() override;
void
Tick(llarp_time_t now) override;
util::StatusObject util::StatusObject
ExtractStatus() const; ExtractStatus() const;
@ -129,6 +132,9 @@ namespace llarp
void void
KeepAlive(); KeepAlive();
bool
ShouldKeepAlive(llarp_time_t now) const;
const IntroSet& const IntroSet&
GetCurrentIntroSet() const GetCurrentIntroSet() const
{ {
@ -170,6 +176,7 @@ namespace llarp
bool sentIntro = false; bool sentIntro = false;
std::vector<std::function<void(OutboundContext*)>> m_ReadyHooks; std::vector<std::function<void(OutboundContext*)>> m_ReadyHooks;
llarp_time_t m_LastIntrosetUpdateAt = 0s; llarp_time_t m_LastIntrosetUpdateAt = 0s;
llarp_time_t m_LastKeepAliveAt = 0s;
}; };
} // namespace service } // namespace service

View File

@ -45,7 +45,7 @@ namespace llarp
llarp_time_t lastGoodSend = 0s; llarp_time_t lastGoodSend = 0s;
const llarp_time_t createdAt; const llarp_time_t createdAt;
llarp_time_t sendTimeout = path::build_timeout; llarp_time_t sendTimeout = path::build_timeout;
llarp_time_t connectTimeout = path::build_timeout; llarp_time_t connectTimeout = path::build_timeout * 2;
llarp_time_t shiftTimeout = (path::build_timeout * 5) / 2; llarp_time_t shiftTimeout = (path::build_timeout * 5) / 2;
llarp_time_t estimatedRTT = 0s; llarp_time_t estimatedRTT = 0s;
bool markedBad = false; bool markedBad = false;

View File

@ -75,7 +75,7 @@ namespace llarp
{ {
if (!item.BDecode(buf)) if (!item.BDecode(buf))
{ {
llarp::LogWarnTag("llarp/bencode.hpp", "failed to decode key ", k, " for entry in dict"); llarp::LogWarn("failed to decode key ", k, " for entry in dict");
return false; return false;
} }
@ -94,7 +94,7 @@ namespace llarp
uint64_t read_i; uint64_t read_i;
if (!bencode_read_integer(buf, &read_i)) if (!bencode_read_integer(buf, &read_i))
{ {
llarp::LogWarnTag("llarp/BEncode.hpp", "failed to decode key ", k, " for integer in dict"); llarp::LogWarn("failed to decode key ", k, " for integer in dict");
return false; return false;
} }
@ -210,8 +210,7 @@ namespace llarp
return true; return true;
if (sink.DecodeKey(*key, buffer)) if (sink.DecodeKey(*key, buffer))
return true; return true;
llarp::LogWarnTag( llarp::LogWarn("undefined key '", *key->cur, "' for entry in dict");
"llarp/bencode.hpp", "undefined key '", *key->cur, "' for entry in dict");
return false; return false;
}, },

View File

@ -1,12 +1,7 @@
#pragma once #pragma once
#include <functional> #include <functional>
#include <set>
#if defined(WIN32) || defined(_WIN32)
#define PATH_SEP "\\"
#else
#define PATH_SEP "/"
#endif
#ifdef USE_GHC_FILESYSTEM #ifdef USE_GHC_FILESYSTEM
#include <ghc/filesystem.hpp> #include <ghc/filesystem.hpp>
@ -61,36 +56,31 @@ namespace llarp
return std::make_optional<T>(pathname, mode); return std::make_optional<T>(pathname, mode);
} }
using PathVisitor = std::function<bool(const fs::path&)>; template <typename PathVisitor>
using PathIter = std::function<void(const fs::path&, PathVisitor)>; static void
IterDir(const fs::path& path, PathVisitor visit)
static PathIter IterDir = [](const fs::path& path, PathVisitor visit) { {
#ifdef _MSC_VER
for (auto& p : fs::directory_iterator(path))
{
if (!visit(p.path()))
{
break;
}
}
#else
DIR* d = opendir(path.string().c_str()); DIR* d = opendir(path.string().c_str());
if (d == nullptr) if (d == nullptr)
return; return;
struct dirent* ent = nullptr; struct dirent* ent = nullptr;
std::set<fs::path> entries;
do do
{ {
ent = readdir(d); ent = readdir(d);
if (!ent) if (not ent)
break; break;
if (ent->d_name[0] == '.') if (ent->d_name[0] == '.')
continue; continue;
fs::path p = path / fs::path(ent->d_name); entries.emplace(path / fs::path{ent->d_name});
if (!visit(p))
break;
} while (ent); } while (ent);
closedir(d); closedir(d);
#endif
for (const auto& p : entries)
{
if (not visit(p))
return;
}
}; };
} // namespace util } // namespace util
} // namespace llarp } // namespace llarp

View File

@ -8,7 +8,8 @@ namespace llarp
{ {
void void
AndroidLogStream::PreLog( AndroidLogStream::PreLog(
std::stringstream& ss, LogLevel lvl, const char* fname, int lineno, const std::string&) const std::stringstream& ss, LogLevel lvl, std::string_view fname, int lineno, const std::string&)
const
{ {
switch (lvl) switch (lvl)
{ {
@ -43,7 +44,7 @@ namespace llarp
{} {}
void void
AndroidLogStream::Print(LogLevel lvl, const char* tag, const std::string& msg) AndroidLogStream::Print(LogLevel lvl, std::string_view tag, const std::string& msg)
{ {
std::string str("lokinet|"); std::string str("lokinet|");
str += tag; str += tag;
@ -62,6 +63,8 @@ namespace llarp
case eLogError: case eLogError:
__android_log_write(ANDROID_LOG_ERROR, str.c_str(), msg.c_str()); __android_log_write(ANDROID_LOG_ERROR, str.c_str(), msg.c_str());
return; return;
default:
return;
} }
} // namespace llarp } // namespace llarp

View File

@ -12,12 +12,12 @@ namespace llarp
PreLog( PreLog(
std::stringstream& s, std::stringstream& s,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename) const override; const std::string& nodename) const override;
void void
Print(LogLevel lvl, const char* filename, const std::string& msg) override; Print(LogLevel lvl, std::string_view filename, const std::string& msg) override;
void void
PostLog(std::stringstream&) const override; PostLog(std::stringstream&) const override;

View File

@ -65,18 +65,18 @@ namespace llarp
FileLogStream::PreLog( FileLogStream::PreLog(
std::stringstream& ss, std::stringstream& ss,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename) const const std::string& nodename) const
{ {
ss << "[" << LogLevelToString(lvl) << "] "; ss << "[" << LogLevelToString(lvl) << "] ";
ss << "[" << nodename << "]" ss << "[" << nodename << "]"
<< "(" << thread_id_string() << ") " << log_timestamp() << " " << fname << ":" << lineno << "(" << thread_id_string() << ") " << log_timestamp() << " " << filename << ":" << lineno
<< "\t"; << "\t";
} }
void void
FileLogStream::Print(LogLevel, const char*, const std::string& msg) FileLogStream::Print(LogLevel, std::string_view, const std::string& msg)
{ {
m_Lines.pushBack(msg); m_Lines.pushBack(msg);
} }
@ -84,12 +84,12 @@ namespace llarp
void void
FileLogStream::AppendLog( FileLogStream::AppendLog(
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename, const std::string& nodename,
const std::string msg) const std::string msg)
{ {
ILogStream::AppendLog(lvl, fname, lineno, nodename, msg); ILogStream::AppendLog(lvl, filename, lineno, nodename, msg);
Tick(llarp::time_now_ms()); Tick(llarp::time_now_ms());
} }

View File

@ -23,12 +23,12 @@ namespace llarp
PreLog( PreLog(
std::stringstream& out, std::stringstream& out,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename) const override; const std::string& nodename) const override;
void void
Print(LogLevel, const char*, const std::string& msg) override; Print(LogLevel, std::string_view filename, const std::string& msg) override;
void void
Tick(llarp_time_t now) override; Tick(llarp_time_t now) override;
@ -39,7 +39,7 @@ namespace llarp
void void
AppendLog( AppendLog(
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename, const std::string& nodename,
const std::string msg) override; const std::string msg) override;

View File

@ -1,24 +0,0 @@
#include "json_logger.hpp"
#include <llarp/util/json.hpp>
namespace llarp
{
void
JSONLogStream::AppendLog(
LogLevel lvl,
const char* fname,
int lineno,
const std::string& nodename,
const std::string msg)
{
json::Object obj;
obj["time"] = to_json(llarp::time_now_ms());
obj["nickname"] = nodename;
obj["file"] = std::string(fname);
obj["line"] = lineno;
obj["level"] = LogLevelToString(lvl);
obj["message"] = msg;
m_Lines.pushBack(obj.dump());
}
} // namespace llarp

View File

@ -1,28 +0,0 @@
#ifndef LLARP_UTIL_JSON_LOGGER
#define LLARP_UTIL_JSON_LOGGER
#include "file_logger.hpp"
namespace llarp
{
struct JSONLogStream : public FileLogStream
{
JSONLogStream(
std::function<void(FileLogStream::Work_t)> disk,
FILE* f,
llarp_time_t flushInterval,
bool closeFile)
: FileLogStream(std::move(disk), f, flushInterval, closeFile)
{}
void
AppendLog(
LogLevel lvl,
const char* fname,
int lineno,
const std::string& nodename,
const std::string msg) override;
};
} // namespace llarp
#endif

View File

@ -2,7 +2,6 @@
#include "ostream_logger.hpp" #include "ostream_logger.hpp"
#include "logger_syslog.hpp" #include "logger_syslog.hpp"
#include "file_logger.hpp" #include "file_logger.hpp"
#include "json_logger.hpp"
#if defined(_WIN32) #if defined(_WIN32)
#include "win32_logger.hpp" #include "win32_logger.hpp"
#endif #endif
@ -36,8 +35,6 @@ namespace llarp
return LogType::Unknown; return LogType::Unknown;
else if (str == "file") else if (str == "file")
return LogType::File; return LogType::File;
else if (str == "json")
return LogType::Json;
else if (str == "syslog") else if (str == "syslog")
return LogType::Syslog; return LogType::Syslog;
@ -111,7 +108,7 @@ namespace llarp
{ {
logfile = stdout; logfile = stdout;
} }
else else if (type != LogType::Syslog)
{ {
logfile = ::fopen(file.c_str(), "a"); logfile = ::fopen(file.c_str(), "a");
if (not logfile) if (not logfile)
@ -141,26 +138,10 @@ namespace llarp
} }
break; break;
case LogType::Json:
LogInfo("Switching logger to JSON with file: ", file);
std::cout << std::flush;
LogContext::Instance().logStream =
std::make_unique<JSONLogStream>(io, logfile, 100ms, logfile != stdout);
break;
case LogType::Syslog: case LogType::Syslog:
if (logfile)
{
// TODO: this logic should be handled in Config
// TODO: this won't even work because of default value for 'file' (== "stdout")
::fclose(logfile);
throw std::invalid_argument("Cannot mix log type=syslog and file=*");
}
#if defined(_WIN32) #if defined(_WIN32)
throw std::runtime_error("syslog not supported on win32"); throw std::runtime_error("syslog not supported on win32");
#else #else
LogInfo("Switching logger to syslog");
std::cout << std::flush;
LogContext::Instance().logStream = std::make_unique<SysLogStream>(); LogContext::Instance().logStream = std::make_unique<SysLogStream>();
#endif #endif
break; break;

View File

@ -1,9 +1,11 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <llarp/util/str.hpp>
#include <llarp/util/time.hpp> #include <llarp/util/time.hpp>
#include "logstream.hpp" #include "logstream.hpp"
#include "logger_internal.hpp" #include "logger_internal.hpp"
#include "source_location.hpp"
namespace llarp namespace llarp
{ {
@ -11,7 +13,6 @@ namespace llarp
{ {
Unknown = 0, Unknown = 0,
File, File,
Json,
Syslog, Syslog,
}; };
LogType LogType
@ -77,52 +78,91 @@ namespace llarp
LogLevel LogLevel
GetLogLevel(); GetLogLevel();
/** internal */ namespace
template <typename... TArgs>
inline static void
_log(LogLevel lvl, const char* fname, int lineno, TArgs&&... args) noexcept
{ {
auto& log = LogContext::Instance(); /** internal */
if (log.curLevel > lvl || log.logStream == nullptr) template <typename... TArgs>
return; inline static void
std::ostringstream ss; _log(LogLevel lvl, const slns::source_location& location, TArgs&&... args) noexcept
if constexpr (sizeof...(args) > 0) {
LogAppend(ss, std::forward<TArgs>(args)...); auto& log = LogContext::Instance();
log.logStream->AppendLog(lvl, fname, lineno, log.nodeName, ss.str()); if (log.curLevel > lvl || log.logStream == nullptr)
} return;
std::ostringstream ss;
if constexpr (sizeof...(args) > 0)
LogAppend(ss, std::forward<TArgs>(args)...);
log.logStream->AppendLog(
lvl,
strip_prefix(location.file_name(), SOURCE_ROOT),
location.line(),
log.nodeName,
ss.str());
}
} // namespace
inline void template <typename... T>
_log_noop() noexcept struct LogTrace
{} {
LogTrace(T... args, const slns::source_location& location = slns::source_location::current())
{
#ifdef NDEBUG
((void)args, ...);
(void)location;
#else
_log(eLogTrace, location, std::forward<T>(args)...);
#endif
}
};
template <typename... T>
LogTrace(T&&...) -> LogTrace<T...>;
template <typename... T>
struct LogDebug
{
LogDebug(T... args, const slns::source_location& location = slns::source_location::current())
{
_log(eLogDebug, location, std::forward<T>(args)...);
}
};
template <typename... T>
LogDebug(T&&...) -> LogDebug<T...>;
template <typename... T>
struct LogInfo
{
LogInfo(T... args, const slns::source_location& location = slns::source_location::current())
{
_log(eLogInfo, location, std::forward<T>(args)...);
}
};
template <typename... T>
LogInfo(T&&...) -> LogInfo<T...>;
template <typename... T>
struct LogWarn
{
LogWarn(T... args, const slns::source_location& location = slns::source_location::current())
{
_log(eLogWarn, location, std::forward<T>(args)...);
}
};
template <typename... T>
LogWarn(T&&...) -> LogWarn<T...>;
template <typename... T>
struct LogError
{
LogError(T... args, const slns::source_location& location = slns::source_location::current())
{
_log(eLogError, location, std::forward<T>(args)...);
}
};
template <typename... T>
LogError(T&&...) -> LogError<T...>;
} // namespace llarp } // namespace llarp
#define LogDebug(...) _log(llarp::eLogDebug, LOG_TAG, __LINE__, __VA_ARGS__)
#define LogInfo(...) _log(llarp::eLogInfo, LOG_TAG, __LINE__, __VA_ARGS__)
#define LogWarn(...) _log(llarp::eLogWarn, LOG_TAG, __LINE__, __VA_ARGS__)
#define LogError(...) _log(llarp::eLogError, LOG_TAG, __LINE__, __VA_ARGS__)
#define LogDebugTag(tag, ...) _log(llarp::eLogDebug, tag, __LINE__, __VA_ARGS__)
#define LogInfoTag(tag, ...) _log(llarp::eLogInfo, tag, __LINE__, __VA_ARGS__)
#define LogWarnTag(tag, ...) _log(llarp::eLogWarn, tag, __LINE__, __VA_ARGS__)
#define LogErrorTag(tag, ...) _log(llarp::eLogError, tag, __LINE__, __VA_ARGS__)
#define LogDebugExplicit(tag, line, ...) _log(llarp::eLogDebug, tag, line, __VA_ARGS__)
#define LogInfoExplicit(tag, line, ...) _log(llarp::eLogInfo, tag, line __VA_ARGS__)
#define LogWarnExplicit(tag, line, ...) _log(llarp::eLogWarn, tag, line, __VA_ARGS__)
#define LogErrorExplicit(tag, line, ...) _log(llarp::eLogError, tag, line, __VA_ARGS__)
// null-op Trace logging if this is a release build
#ifdef NDEBUG
#define LogTrace(...) _log_noop()
#define LogTraceTag(tag, ...) _log_noop()
#define LogTraceExplicit(tag, line, ...) _log_noop()
#else
#define LogTrace(...) _log(llarp::eLogTrace, LOG_TAG, __LINE__, __VA_ARGS__)
#define LogTraceTag(tag, ...) _log(llarp::eLogTrace, tag, __LINE__, __VA_ARGS__)
#define LogTraceExplicit(tag, line, ...) _log(llarp::eLogTrace, tag, line, __VA_ARGS__)
#endif
#ifndef LOG_TAG
#define LOG_TAG "default"
#endif

View File

@ -11,12 +11,12 @@ namespace llarp
PreLog( PreLog(
std::stringstream& s, std::stringstream& s,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename) const override; const std::string& nodename) const override;
void void
Print(LogLevel lvl, const char* tag, const std::string& msg) override; Print(LogLevel lvl, std::string_view tag, const std::string& msg) override;
void void
PostLog(std::stringstream& ss) const override; PostLog(std::stringstream& ss) const override;

View File

@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <string_view>
namespace llarp namespace llarp
{ {
@ -18,12 +19,12 @@ namespace llarp
PreLog( PreLog(
std::stringstream& out, std::stringstream& out,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename) const = 0; const std::string& nodename) const = 0;
virtual void virtual void
Print(LogLevel lvl, const char* filename, const std::string& msg) = 0; Print(LogLevel lvl, std::string_view filename, const std::string& msg) = 0;
virtual void virtual void
PostLog(std::stringstream& out) const = 0; PostLog(std::stringstream& out) const = 0;
@ -31,16 +32,16 @@ namespace llarp
virtual void virtual void
AppendLog( AppendLog(
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename, const std::string& nodename,
const std::string msg) const std::string msg)
{ {
std::stringstream ss; std::stringstream ss;
PreLog(ss, lvl, fname, lineno, nodename); PreLog(ss, lvl, filename, lineno, nodename);
ss << msg; ss << msg;
PostLog(ss); PostLog(ss);
Print(lvl, fname, ss.str()); Print(lvl, filename, ss.str());
} }
/// A blocking call to flush to disk. Should only be called in rare circumstances. /// A blocking call to flush to disk. Should only be called in rare circumstances.

View File

@ -11,7 +11,7 @@ namespace llarp
OStreamLogStream::PreLog( OStreamLogStream::PreLog(
std::stringstream& ss, std::stringstream& ss,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename) const const std::string& nodename) const
{ {
@ -38,7 +38,7 @@ namespace llarp
} }
ss << "[" << LogLevelToString(lvl) << "] "; ss << "[" << LogLevelToString(lvl) << "] ";
ss << "[" << nodename << "]" ss << "[" << nodename << "]"
<< "(" << thread_id_string() << ") " << log_timestamp() << " " << fname << ":" << lineno << "(" << thread_id_string() << ") " << log_timestamp() << " " << filename << ":" << lineno
<< "\t"; << "\t";
} }
@ -51,7 +51,7 @@ namespace llarp
} }
void void
OStreamLogStream::Print(LogLevel, const char*, const std::string& msg) OStreamLogStream::Print(LogLevel, std::string_view, const std::string& msg)
{ {
m_Out << msg << std::flush; m_Out << msg << std::flush;
} }

View File

@ -15,12 +15,12 @@ namespace llarp
PreLog( PreLog(
std::stringstream& s, std::stringstream& s,
LogLevel lvl, LogLevel lvl,
const char* fname, std::string_view filename,
int lineno, int lineno,
const std::string& nodename) const override; const std::string& nodename) const override;
virtual void virtual void
Print(LogLevel lvl, const char* tag, const std::string& msg) override; Print(LogLevel lvl, std::string_view tag, const std::string& msg) override;
void void
PostLog(std::stringstream& ss) const override; PostLog(std::stringstream& ss) const override;

View File

@ -0,0 +1,53 @@
#pragma once
#ifdef __cpp_lib_source_location
#include <source_location>
namespace slns = std;
#else
namespace slns
{
struct source_location
{
public:
static constexpr source_location
current(
const char* fileName = __builtin_FILE(),
const char* functionName = __builtin_FUNCTION(),
const uint_least32_t lineNumber = __builtin_LINE()) noexcept
{
return source_location{fileName, functionName, lineNumber};
}
source_location(const source_location&) = default;
source_location(source_location&&) = default;
constexpr const char*
file_name() const noexcept
{
return fileName;
}
constexpr const char*
function_name() const noexcept
{
return functionName;
}
constexpr uint_least32_t
line() const noexcept
{
return lineNumber;
}
private:
constexpr explicit source_location(
const char* fileName, const char* functionName, const uint_least32_t lineNumber) noexcept
: fileName(fileName), functionName(functionName), lineNumber(lineNumber)
{}
const char* const fileName;
const char* const functionName;
const uint_least32_t lineNumber;
};
} // namespace slns
#endif

Some files were not shown because too many files have changed in this diff Show More