mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-02 03:40:12 +00:00
Cmake restructuring
This commit is contained in:
parent
b597ae5a94
commit
12a89328fe
@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "macOS deployment target (Apple clang only)")
|
||||
|
||||
option(BUILD_DAEMON "build lokinet daemon and associated utils" ON)
|
||||
|
||||
option(GRAPH_DEPENDENCIES "Produce graphviz representation of cmake dependencies" OFF)
|
||||
|
||||
set(LANGS C CXX)
|
||||
if(APPLE AND BUILD_DAEMON)
|
||||
@ -257,23 +257,26 @@ pkg_check_modules(SD libsystemd IMPORTED_TARGET)
|
||||
# Default WITH_SYSTEMD to true if we found it
|
||||
option(WITH_SYSTEMD "enable systemd integration for sd_notify" ${SD_FOUND})
|
||||
|
||||
# Base interface target where we set up global link libraries, definitions, includes, etc.
|
||||
add_library(base_libs INTERFACE)
|
||||
add_subdirectory(external)
|
||||
|
||||
# interface library for setting common includes, linkage and flags
|
||||
add_library(lokinet-base INTERFACE)
|
||||
target_include_directories(lokinet-base INTERFACE . include)
|
||||
target_link_libraries(lokinet-base INTERFACE quic)
|
||||
|
||||
if(WITH_SYSTEMD AND (NOT ANDROID))
|
||||
if(NOT SD_FOUND)
|
||||
message(FATAL_ERROR "libsystemd not found")
|
||||
endif()
|
||||
target_link_libraries(base_libs INTERFACE PkgConfig::SD)
|
||||
target_compile_definitions(base_libs INTERFACE WITH_SYSTEMD)
|
||||
target_link_libraries(lokinet-base INTERFACE PkgConfig::SD)
|
||||
target_compile_definitions(lokinet-base INTERFACE WITH_SYSTEMD)
|
||||
endif()
|
||||
|
||||
add_subdirectory(external)
|
||||
|
||||
if(USE_JEMALLOC AND NOT STATIC_LINK)
|
||||
pkg_check_modules(JEMALLOC jemalloc IMPORTED_TARGET)
|
||||
if(JEMALLOC_FOUND)
|
||||
target_link_libraries(base_libs INTERFACE PkgConfig::JEMALLOC)
|
||||
target_link_libraries(lokinet-base INTERFACE PkgConfig::JEMALLOC)
|
||||
else()
|
||||
message(STATUS "jemalloc not found, not linking to jemalloc")
|
||||
endif()
|
||||
@ -283,8 +286,8 @@ endif()
|
||||
|
||||
|
||||
if(ANDROID)
|
||||
target_link_libraries(base_libs INTERFACE log)
|
||||
target_compile_definitions(base_libs INTERFACE ANDROID)
|
||||
target_link_libraries(lokinet-base INTERFACE log)
|
||||
target_compile_definitions(lokinet-base INTERFACE ANDROID)
|
||||
set(ANDROID_PLATFORM_SRC android/ifaddrs.c)
|
||||
endif()
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
set(GRAPHVIZ_MODULE_LIBS OFF CACHE BOOL "")
|
||||
set(GRAPHVIZ_EXTERNAL_LIBS OFF CACHE BOOL "")
|
||||
set(GRAPHVIZ_GENERATE_PER_TARGET OFF CACHE BOOL "")
|
||||
set(GRAPHVIZ_GENERATE_DEPENDERS OFF CACHE BOOL "")
|
||||
set(GRAPHVIZ_GRAPH_NAME "graph.dot" CACHE STRING "")
|
||||
# set(GRAPHVIZ_MODULE_LIBS OFF CACHE BOOL "")
|
||||
# set(GRAPHVIZ_EXTERNAL_LIBS OFF CACHE BOOL "")
|
||||
set(GRAPHVIZ_GENERATE_PER_TARGET FALSE CACHE BOOL "")
|
||||
set(GRAPHVIZ_GENERATE_DEPENDERS FALSE CACHE BOOL "")
|
||||
set(GRAPHVIZ_OBJECT_LIBS OFF CACHE BOOL "")
|
||||
|
@ -59,7 +59,8 @@ foreach(exe ${exetargets})
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
target_link_directories(${exe} PRIVATE /usr/local/lib)
|
||||
endif()
|
||||
target_link_libraries(${exe} PUBLIC lokinet-amalgum hax_and_shims_for_cmake)
|
||||
# target_link_libraries(${exe} PUBLIC lokinet-amalgum hax_and_shims_for_cmake)
|
||||
target_link_libraries(${exe} PUBLIC lokinet-core hax_and_shims_for_cmake)
|
||||
if(STRIP_SYMBOLS)
|
||||
add_custom_command(TARGET ${exe}
|
||||
POST_BUILD
|
||||
@ -79,6 +80,9 @@ foreach(exe ${exetargets})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
target_link_libraries(lokinet PRIVATE CLI11)
|
||||
target_link_libraries(lokinet-vpn PRIVATE CLI11)
|
||||
|
||||
if(SETCAP)
|
||||
install(CODE "execute_process(COMMAND ${SETCAP} cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)")
|
||||
endif()
|
||||
|
@ -371,9 +371,6 @@ namespace
|
||||
int
|
||||
lokinet_main(int argc, char** argv)
|
||||
{
|
||||
// if (auto result = Lokinet_INIT())
|
||||
// return result;
|
||||
|
||||
llarp::RuntimeOptions opts;
|
||||
opts.showBanner = false;
|
||||
|
||||
|
2
external/CMakeLists.txt
vendored
2
external/CMakeLists.txt
vendored
@ -147,7 +147,7 @@ option(WITH_LIBCRYPT "enable fast password hash with libcrypt" ${default_libcryp
|
||||
add_library(lokinet-libcrypt INTERFACE)
|
||||
if(WITH_LIBCRYPT)
|
||||
pkg_check_modules(LIBCRYPT libcrypt IMPORTED_TARGET REQUIRED)
|
||||
add_definitions(-DHAVE_CRYPT)
|
||||
target_compile_definitions(lokinet-libcrypt INTERFACE -DHAVE_CRYPT)
|
||||
target_link_libraries(lokinet-libcrypt INTERFACE PkgConfig::LIBCRYPT)
|
||||
message(STATUS "using libcrypt ${LIBCRYPT_VERSION}")
|
||||
else()
|
||||
|
@ -1,44 +1,49 @@
|
||||
include(Version)
|
||||
|
||||
add_library(lokinet-cryptography
|
||||
STATIC
|
||||
|
||||
# Add an internal lokinet static library target, enables LTO (if enabled) on the target,
|
||||
# and links it to the common lokinet-base interface.
|
||||
# Invoke with the target/library name (e.g. "lokinet-foo") and list of source files, e.g.
|
||||
# lokinet_add_library(lokinet-foo foo/source1.cpp foo/source2.cpp)
|
||||
function(lokinet_add_library libname)
|
||||
add_library(${libname} STATIC ${ARGN})
|
||||
target_link_libraries(${libname} PUBLIC lokinet-base)
|
||||
enable_lto(${libname})
|
||||
endfunction()
|
||||
|
||||
|
||||
lokinet_add_library(lokinet-cryptography
|
||||
crypto/crypto.cpp
|
||||
crypto/encrypted_frame.cpp
|
||||
crypto/types.cpp
|
||||
)
|
||||
|
||||
# files only included by lokinet-core
|
||||
add_library(lokinet-core-internal
|
||||
STATIC
|
||||
router/rc_gossiper.cpp
|
||||
service/info.cpp
|
||||
service/lns_tracker.cpp
|
||||
service/session.cpp
|
||||
)
|
||||
|
||||
# Functional objects use by lokinet-core and other libraries
|
||||
# needed by vpn/ router/ rpc/ handlers/ net/ link/
|
||||
add_library(lokinet-core-utils
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-core-utils
|
||||
endpoint_base.cpp
|
||||
exit/context.cpp
|
||||
exit/endpoint.cpp # handlers/exit.hpp
|
||||
exit/policy.cpp # net/
|
||||
handlers/exit.cpp # link/ exit/
|
||||
handlers/tun.cpp
|
||||
router/rc_gossiper.cpp
|
||||
service/auth.cpp # config/
|
||||
service/context.cpp
|
||||
service/identity.cpp
|
||||
service/info.cpp
|
||||
service/intro.cpp # path
|
||||
service/lns_tracker.cpp
|
||||
service/name.cpp
|
||||
service/session.cpp
|
||||
service/tag.cpp
|
||||
vpn/egres_packet_router.cpp
|
||||
)
|
||||
|
||||
add_library(lokinet-core
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-core
|
||||
context.cpp
|
||||
consensus/reachability_testing.cpp
|
||||
exit/session.cpp
|
||||
handlers/exit.cpp # link/ exit/
|
||||
handlers/tun.cpp
|
||||
link/link_manager.cpp
|
||||
router/router.cpp
|
||||
router/route_poker.cpp
|
||||
@ -49,16 +54,9 @@ add_library(lokinet-core
|
||||
service/name.cpp
|
||||
service/outbound_context.cpp
|
||||
service/protocol.cpp
|
||||
vpn/egres_packet_router.cpp
|
||||
)
|
||||
|
||||
# Files only included by lokinet-rpc
|
||||
# add_library(lokinet-rpc-internal
|
||||
# STATIC
|
||||
# )
|
||||
|
||||
add_library(lokinet-rpc
|
||||
STATIC
|
||||
|
||||
lokinet_add_library(lokinet-rpc
|
||||
rpc/json_binary_proxy.cpp
|
||||
rpc/json_conversions.cpp
|
||||
rpc/lokid_rpc_client.cpp
|
||||
@ -66,28 +64,16 @@ add_library(lokinet-core
|
||||
rpc/rpc_server.cpp
|
||||
rpc/endpoint_rpc.cpp
|
||||
)
|
||||
|
||||
# Files only included by lokinet-wire
|
||||
add_library(lokinet-wire-internal
|
||||
STATIC
|
||||
|
||||
lokinet_add_library(lokinet-wire
|
||||
link/connection.cpp
|
||||
)
|
||||
|
||||
add_library(lokinet-wire
|
||||
STATIC
|
||||
link/contacts.cpp
|
||||
link/link_manager.cpp
|
||||
# link/tunnel.cpp
|
||||
)
|
||||
|
||||
add_library(lokinet-utils-internal
|
||||
STATIC
|
||||
util/thread/queue_manager.cpp
|
||||
)
|
||||
|
||||
# config, crypto, timeplace, nodedb, bootstrap.cpp, net, router
|
||||
add_library(lokinet-utils
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-utils
|
||||
${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp
|
||||
util/bencode.cpp
|
||||
util/buffer.cpp
|
||||
@ -95,16 +81,16 @@ add_library(lokinet-utils
|
||||
util/mem.cpp
|
||||
util/str.cpp
|
||||
util/thread/threading.cpp
|
||||
util/thread/queue_manager.cpp
|
||||
util/time.cpp
|
||||
util/logging/buffer.cpp
|
||||
)
|
||||
|
||||
|
||||
add_dependencies(lokinet-utils genversion)
|
||||
|
||||
# Addressing and event loop files used by lokinet-core and other libraries
|
||||
# needed by rpc/ link/ service/ config/ path/ dht/
|
||||
add_library(lokinet-time-place
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-time-place
|
||||
pow.cpp # only intro_set
|
||||
router_contact.cpp
|
||||
router_id.cpp
|
||||
@ -124,8 +110,7 @@ add_library(lokinet-time-place
|
||||
)
|
||||
|
||||
# lokinet-platform holds all platform specific code
|
||||
add_library(lokinet-platform
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-platform
|
||||
router/rc_lookup_handler.cpp
|
||||
net/interface_info.cpp
|
||||
vpn/packet_router.cpp
|
||||
@ -171,7 +156,6 @@ endif()
|
||||
# should have no concept of dns caching, this is left as an implementation
|
||||
# detail of dns resolvers (LATER: make separate lib for dns resolvers)
|
||||
add_library(lokinet-dns-internal
|
||||
STATIC
|
||||
dns/name.cpp # srv_data, question, rr
|
||||
dns/platform.cpp
|
||||
dns/question.cpp # message
|
||||
@ -179,8 +163,7 @@ add_library(lokinet-dns-internal
|
||||
dns/serialize.cpp
|
||||
)
|
||||
|
||||
add_library(lokinet-dns
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-dns
|
||||
dns/message.cpp # dns/server
|
||||
dns/server.cpp # handlers/exit+tun and service/endpoint
|
||||
dns/srv_data.cpp
|
||||
@ -195,8 +178,7 @@ endif()
|
||||
|
||||
# lokinet-nodedb holds all types and logic for storing parsing and constructing
|
||||
# nodedb data published to the network and versions of it stored locally
|
||||
add_library(lokinet-nodedb
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-nodedb
|
||||
bootstrap.cpp # config, router.hpp
|
||||
nodedb.cpp
|
||||
profiling.cpp # path, router, service::endpoint
|
||||
@ -223,8 +205,7 @@ configure_file("bootstrap-fallbacks.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/bootstr
|
||||
target_sources(lokinet-nodedb PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/bootstrap-fallbacks.cpp")
|
||||
|
||||
# lokinet-config is for all configuration types and parsers
|
||||
add_library(lokinet-config
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-config
|
||||
config/config.cpp
|
||||
config/definition.cpp
|
||||
config/ini.cpp
|
||||
@ -232,8 +213,7 @@ add_library(lokinet-config
|
||||
)
|
||||
|
||||
# All path objects; link directly to lokinet-core
|
||||
add_library(lokinet-path
|
||||
STATIC
|
||||
lokinet_add_library(lokinet-path
|
||||
path/abstracthophandler.cpp
|
||||
path/path_context.cpp
|
||||
path/path.cpp
|
||||
@ -243,23 +223,11 @@ add_library(lokinet-path
|
||||
messages/relay.cpp
|
||||
)
|
||||
|
||||
add_library(lokinet-amalgum INTERFACE)
|
||||
|
||||
# interface library for setting common includes, linkage and flags.
|
||||
add_library(lokinet-base INTERFACE)
|
||||
target_include_directories(lokinet-base
|
||||
INTERFACE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
target_link_libraries(lokinet-base INTERFACE quic)
|
||||
|
||||
# Link libraries to their internals
|
||||
target_link_libraries(lokinet-core-internal PUBLIC lokinet-utils lokinet-core-utils)
|
||||
target_link_libraries(lokinet-core PRIVATE lokinet-core-internal)
|
||||
# target_link_libraries(lokinet-rpc PRIVATE lokinet-rpc-internal)
|
||||
target_link_libraries(lokinet-wire PRIVATE lokinet-wire-internal)
|
||||
# target_link_libraries(lokinet-time-place PRIVATE lokinet-time-place-internal)
|
||||
target_link_libraries(lokinet-core-utils PUBLIC lokinet-dns)
|
||||
target_link_libraries(lokinet-core PUBLIC lokinet-core-utils)
|
||||
|
||||
target_link_libraries(lokinet-dns PRIVATE lokinet-dns-internal)
|
||||
target_link_libraries(lokinet-utils PRIVATE lokinet-utils-internal)
|
||||
|
||||
# Link lokinet-dns to alternate libraries
|
||||
target_link_libraries(lokinet-dns PUBLIC lokinet-dns-platform)
|
||||
@ -267,36 +235,9 @@ if (TARGET lokinet-dns-systemd)
|
||||
target_link_libraries(lokinet-dns PUBLIC lokinet-dns-systemd)
|
||||
endif()
|
||||
|
||||
# Link relevant to lokinet-base
|
||||
target_link_libraries(lokinet-core PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-rpc PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-nodedb PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-wire PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-time-place PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-dns PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-platform PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-utils PUBLIC lokinet-base)
|
||||
target_link_libraries(lokinet-libntrup PUBLIC lokinet-base)
|
||||
|
||||
# Link relevant to amalgum
|
||||
target_link_libraries(lokinet-amalgum
|
||||
INTERFACE
|
||||
lokinet-core
|
||||
lokinet-rpc
|
||||
lokinet-nodedb
|
||||
lokinet-wire
|
||||
lokinet-time-place
|
||||
lokinet-dns
|
||||
lokinet-platform
|
||||
lokinet-utils
|
||||
lokinet-cryptography
|
||||
lokinet-path
|
||||
)
|
||||
#or just do this??
|
||||
# target_link_libraries(lokinet-amalgum INTERFACE lokinet-base)
|
||||
target_link_libraries(lokinet-wire-internal PUBLIC lokinet-time-place)
|
||||
target_link_libraries(lokinet-dns-internal PUBLIC lokinet-utils lokinet-config)
|
||||
target_link_libraries(lokinet-dns PUBLIC lokinet-cryptography)
|
||||
target_link_libraries(lokinet-wire PUBLIC lokinet-time-place)
|
||||
target_link_libraries(lokinet-dns-internal PUBLIC lokinet-utils)
|
||||
target_link_libraries(lokinet-dns PUBLIC lokinet-cryptography lokinet-config)
|
||||
target_link_libraries(lokinet-nodedb PUBLIC lokinet-cryptography)
|
||||
target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography)
|
||||
target_link_libraries(lokinet-rpc PUBLIC lokinet-wire)
|
||||
@ -304,6 +245,11 @@ target_link_libraries(lokinet-time-place PUBLIC lokinet-utils lokinet-cryptograp
|
||||
target_link_libraries(lokinet-wire PUBLIC lokinet-cryptography)
|
||||
target_link_libraries(lokinet-config PUBLIC lokinet-cryptography)
|
||||
|
||||
target_link_libraries(lokinet-dns
|
||||
PUBLIC
|
||||
lokinet-time-place
|
||||
)
|
||||
|
||||
target_link_libraries(lokinet-path
|
||||
PUBLIC
|
||||
lokinet-time-place
|
||||
@ -311,10 +257,10 @@ target_link_libraries(lokinet-path
|
||||
|
||||
target_link_libraries(lokinet-core-utils
|
||||
PUBLIC
|
||||
lokinet-core
|
||||
lokinet-wire
|
||||
lokinet-rpc
|
||||
lokinet-config
|
||||
lokinet-platform
|
||||
lokinet-rpc
|
||||
lokinet-wire
|
||||
)
|
||||
|
||||
target_link_libraries(lokinet-cryptography
|
||||
@ -333,50 +279,42 @@ target_link_libraries(lokinet-core
|
||||
PUBLIC
|
||||
lokinet-rpc
|
||||
lokinet-wire
|
||||
lokinet-nodedb
|
||||
lokinet-config
|
||||
lokinet-nodedb
|
||||
lokinet-path
|
||||
lokinet-cryptography
|
||||
)
|
||||
|
||||
target_link_libraries(lokinet-base INTERFACE oxenc::oxenc oxen::logging)
|
||||
|
||||
# per component external deps
|
||||
# target_link_libraries(oxenmq::oxenmq
|
||||
# PUBLIC
|
||||
# lokinet-time-place
|
||||
# lokinet-core
|
||||
# lokinet-config
|
||||
# lokinet-platform
|
||||
# lokinet-dns
|
||||
# lokinet-rpc
|
||||
# )
|
||||
|
||||
target_link_libraries(lokinet-rpc PUBLIC oxenmq::oxenmq oxenc::oxenc)
|
||||
target_link_libraries(lokinet-core PUBLIC oxenmq::oxenmq CLI11 uvw)
|
||||
target_link_libraries(lokinet-rpc PUBLIC oxenmq::oxenmq)
|
||||
target_link_libraries(lokinet-core PUBLIC oxenmq::oxenmq)
|
||||
target_link_libraries(lokinet-config PUBLIC oxenmq::oxenmq)
|
||||
target_link_libraries(lokinet-nodedb PUBLIC oxenmq::oxenmq uvw)
|
||||
target_link_libraries(lokinet-nodedb PUBLIC oxenmq::oxenmq)
|
||||
target_link_libraries(lokinet-path PUBLIC oxenmq::oxenmq)
|
||||
target_link_libraries(lokinet-time-place PUBLIC uvw oxenc::oxenc)
|
||||
target_link_libraries(lokinet-platform PUBLIC oxenmq::oxenmq Threads::Threads base_libs uvw)
|
||||
target_link_libraries(lokinet-cryptography PUBLIC oxenc::oxenc sodium)
|
||||
target_link_libraries(lokinet-dns PUBLIC libunbound uvw)
|
||||
target_link_libraries(lokinet-utils PUBLIC nlohmann_json::nlohmann_json oxenc::oxenc)
|
||||
target_link_libraries(lokinet-wire PUBLIC oxenmq::oxenmq quic uvw)
|
||||
target_link_libraries(lokinet-time-place PUBLIC uvw)
|
||||
# target_link_libraries(lokinet-platform PUBLIC oxenmq::oxenmq Threads::Threads base_libs uvw)
|
||||
target_link_libraries(lokinet-platform PUBLIC oxenmq::oxenmq Threads::Threads uvw)
|
||||
target_link_libraries(lokinet-cryptography PUBLIC sodium)
|
||||
target_link_libraries(lokinet-dns PUBLIC libunbound)
|
||||
target_link_libraries(lokinet-utils PUBLIC nlohmann_json::nlohmann_json)
|
||||
target_link_libraries(lokinet-wire PUBLIC oxenmq::oxenmq quic)
|
||||
|
||||
# if(WITH_EMBEDDED_LOKINET)
|
||||
# include(GNUInstallDirs)
|
||||
# add_library(lokinet-shared SHARED lokinet_shared.cpp)
|
||||
# target_link_libraries(lokinet-shared PUBLIC lokinet-amalgum)
|
||||
# if(WIN32)
|
||||
# set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "")
|
||||
# endif()
|
||||
# set_target_properties(lokinet-shared PROPERTIES OUTPUT_NAME lokinet)
|
||||
# if(WIN32)
|
||||
# target_link_libraries(lokinet-shared PUBLIC ws2_32 iphlpapi -fstack-protector)
|
||||
# install(TARGETS lokinet-shared DESTINATION bin COMPONENT liblokinet)
|
||||
# elseif(NOT APPLE)
|
||||
# install(TARGETS lokinet-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT liblokinet)
|
||||
# endif()
|
||||
# endif()
|
||||
if(WITH_EMBEDDED_LOKINET)
|
||||
include(GNUInstallDirs)
|
||||
add_library(lokinet-shared SHARED lokinet_shared.cpp)
|
||||
# target_link_libraries(lokinet-shared PUBLIC lokinet-amalgum)
|
||||
target_link_libraries(lokinet-shared PUBLIC lokinet-core)
|
||||
if(WIN32)
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "")
|
||||
endif()
|
||||
set_target_properties(lokinet-shared PROPERTIES OUTPUT_NAME lokinet)
|
||||
if(WIN32)
|
||||
target_link_libraries(lokinet-shared PUBLIC ws2_32 iphlpapi -fstack-protector)
|
||||
install(TARGETS lokinet-shared DESTINATION bin COMPONENT liblokinet)
|
||||
elseif(NOT APPLE)
|
||||
install(TARGETS lokinet-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT liblokinet)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# file(GLOB_RECURSE docs_SRC */*.hpp *.hpp)
|
||||
# set(DOCS_SRC ${docs_SRC} PARENT_SCOPE)
|
||||
file(GLOB_RECURSE docs_SRC */*.hpp *.hpp)
|
||||
set(DOCS_SRC ${docs_SRC} PARENT_SCOPE)
|
||||
|
@ -1,421 +0,0 @@
|
||||
include(Version)
|
||||
|
||||
add_library(lokinet-cryptography
|
||||
STATIC
|
||||
crypto/crypto.cpp
|
||||
crypto/encrypted_frame.cpp
|
||||
crypto/types.cpp
|
||||
)
|
||||
|
||||
add_library(lokinet-util
|
||||
STATIC
|
||||
${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp
|
||||
util/bencode.cpp
|
||||
util/buffer.cpp
|
||||
util/file.cpp
|
||||
util/json.cpp
|
||||
util/logging/buffer.cpp
|
||||
util/easter_eggs.cpp
|
||||
util/mem.cpp
|
||||
util/str.cpp
|
||||
util/thread/queue_manager.cpp
|
||||
util/thread/threading.cpp
|
||||
util/time.cpp)
|
||||
|
||||
add_dependencies(lokinet-util genversion)
|
||||
|
||||
# lokinet-platform holds all platform specific code
|
||||
add_library(lokinet-platform
|
||||
STATIC
|
||||
# for networking
|
||||
ev/ev.cpp
|
||||
ev/libuv.cpp
|
||||
net/interface_info.cpp
|
||||
net/ip.cpp
|
||||
net/ip_address.cpp
|
||||
net/ip_packet.cpp
|
||||
net/ip_range.cpp
|
||||
net/net_int.cpp
|
||||
net/sock_addr.cpp
|
||||
vpn/packet_router.cpp
|
||||
vpn/egres_packet_router.cpp
|
||||
vpn/platform.cpp
|
||||
)
|
||||
|
||||
if (ANDROID)
|
||||
target_sources(lokinet-platform PRIVATE android/ifaddrs.c util/nop_service_manager.cpp)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
target_sources(lokinet-platform PRIVATE linux/dbus.cpp)
|
||||
if(WITH_SYSTEMD)
|
||||
target_sources(lokinet-platform PRIVATE linux/sd_service_manager.cpp)
|
||||
else()
|
||||
target_sources(lokinet-platform PRIVATE util/nop_service_manager.cpp)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
target_sources(lokinet-platform PRIVATE
|
||||
net/win32.cpp
|
||||
vpn/win32.cpp
|
||||
win32/service_manager.cpp
|
||||
win32/exec.cpp
|
||||
win32/dll.cpp
|
||||
win32/exception.cpp
|
||||
win32/wintun.cpp
|
||||
win32/windivert.cpp)
|
||||
target_include_directories(lokinet-platform PRIVATE ${CMAKE_BINARY_DIR}/wintun/include/ ${CMAKE_BINARY_DIR}/WinDivert-${WINDIVERT_VERSION}/include/)
|
||||
else()
|
||||
target_sources(lokinet-platform PRIVATE
|
||||
net/posix.cpp)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
add_subdirectory(apple)
|
||||
target_sources(lokinet-platform PRIVATE util/nop_service_manager.cpp)
|
||||
endif()
|
||||
|
||||
# lokinet-dns is the dns parsing and hooking library that we use to
|
||||
# parse modify and reconstitute dns wire proto, dns queries and RR
|
||||
# should have no concept of dns caching, this is left as an implementation
|
||||
# detail of dns resolvers (LATER: make separate lib for dns resolvers)
|
||||
add_library(lokinet-dns
|
||||
STATIC
|
||||
dns/message.cpp
|
||||
dns/name.cpp
|
||||
dns/platform.cpp
|
||||
dns/question.cpp
|
||||
dns/rr.cpp
|
||||
dns/serialize.cpp
|
||||
dns/server.cpp
|
||||
dns/srv_data.cpp)
|
||||
|
||||
# platform specific bits and bobs for setting dns
|
||||
add_library(lokinet-dns-platform INTERFACE)
|
||||
if(WITH_SYSTEMD)
|
||||
add_library(lokinet-dns-systemd STATIC dns/nm_platform.cpp dns/sd_platform.cpp)
|
||||
target_link_libraries(lokinet-dns-platform INTERFACE lokinet-dns-systemd)
|
||||
endif()
|
||||
|
||||
# lokinet-nodedb holds all types and logic for storing parsing and constructing
|
||||
# nodedb data published to the network and versions of it stored locally
|
||||
add_library(lokinet-nodedb
|
||||
STATIC
|
||||
bootstrap.cpp
|
||||
net/exit_info.cpp
|
||||
net/traffic_policy.cpp
|
||||
nodedb.cpp
|
||||
pow.cpp
|
||||
profiling.cpp
|
||||
router_contact.cpp
|
||||
router_id.cpp
|
||||
router_version.cpp
|
||||
)
|
||||
|
||||
set(BOOTSTRAP_FALLBACKS)
|
||||
foreach(bs IN ITEMS MAINNET TESTNET)
|
||||
if(BOOTSTRAP_FALLBACK_${bs})
|
||||
message(STATUS "Building with ${bs} fallback boostrap path \"${BOOTSTRAP_FALLBACK_${bs}}\"")
|
||||
file(READ "${BOOTSTRAP_FALLBACK_${bs}}" bs_data HEX)
|
||||
if(bs STREQUAL TESTNET)
|
||||
set(network "gamma")
|
||||
elseif(bs STREQUAL MAINNET)
|
||||
set(network "lokinet")
|
||||
else()
|
||||
string(TOLOWER "${bs}" network)
|
||||
endif()
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "\\\\x\\1" bs_data "${bs_data}")
|
||||
set(BOOTSTRAP_FALLBACKS "${BOOTSTRAP_FALLBACKS}{\"${network}\"s, \"${bs_data}\"sv},\n")
|
||||
endif()
|
||||
endforeach()
|
||||
configure_file("bootstrap-fallbacks.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/bootstrap-fallbacks.cpp" @ONLY)
|
||||
target_sources(lokinet-nodedb PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/bootstrap-fallbacks.cpp")
|
||||
|
||||
# lokinet-config is for all configuration types and parsers
|
||||
add_library(lokinet-config
|
||||
STATIC
|
||||
config/config.cpp
|
||||
config/definition.cpp
|
||||
config/ini.cpp
|
||||
config/key_manager.cpp
|
||||
)
|
||||
|
||||
# lokinet-consensus is for deriving and tracking network consensus state for both service nodes and clients
|
||||
add_library(lokinet-consensus
|
||||
STATIC
|
||||
consensus/reachability_testing.cpp
|
||||
)
|
||||
|
||||
# lokinet-layer-onion is the "dumb" onion routing layer with builds manages and does i/o
|
||||
# with onion paths. onion paths anonymize routing layer pdu.
|
||||
add_library(lokinet-layer-onion
|
||||
STATIC
|
||||
path/abstracthophandler.cpp
|
||||
path/path_context.cpp
|
||||
path/path.cpp
|
||||
path/pathbuilder.cpp
|
||||
path/pathset.cpp
|
||||
path/transit_hop.cpp
|
||||
messages/relay.cpp
|
||||
)
|
||||
|
||||
# lokinet-layer-link is for our layer 2 analog which splits up layer 2 frames into
|
||||
# a series of layer 1 symbols which are then transmitted between lokinet instances
|
||||
add_library(lokinet-layer-link
|
||||
STATIC
|
||||
link/connection.cpp
|
||||
link/contacts.cpp
|
||||
link/link_manager.cpp
|
||||
# link/tunnel.cpp
|
||||
)
|
||||
|
||||
# lokinet-context holds the contextualized god objects for a lokinet instance
|
||||
# it is what any main function would link to in practice but it is hidden behind an interface library (lokinet-amalgum)
|
||||
add_library(lokinet-context
|
||||
STATIC
|
||||
context.cpp
|
||||
link/link_manager.cpp
|
||||
router/rc_lookup_handler.cpp
|
||||
router/rc_gossiper.cpp
|
||||
router/router.cpp
|
||||
router/route_poker.cpp
|
||||
)
|
||||
|
||||
# lokinet-rpc holds all rpc related compilation units
|
||||
add_library(lokinet-rpc
|
||||
STATIC
|
||||
rpc/json_binary_proxy.cpp
|
||||
rpc/json_conversions.cpp
|
||||
rpc/lokid_rpc_client.cpp
|
||||
rpc/rpc_request_parser.cpp
|
||||
rpc/rpc_server.cpp
|
||||
rpc/endpoint_rpc.cpp
|
||||
)
|
||||
|
||||
# optional peer stats library
|
||||
add_library(lokinet-peerstats
|
||||
STATIC
|
||||
peerstats/peer_db.cpp
|
||||
peerstats/types.cpp
|
||||
)
|
||||
|
||||
# kitchen sink to be removed after refactor
|
||||
add_library(lokinet-service-deprecated-kitchensink
|
||||
STATIC
|
||||
endpoint_base.cpp
|
||||
exit/context.cpp
|
||||
exit/endpoint.cpp
|
||||
exit/policy.cpp
|
||||
exit/session.cpp
|
||||
handlers/exit.cpp
|
||||
handlers/tun.cpp
|
||||
service/name.cpp
|
||||
service/address.cpp
|
||||
service/async_key_exchange.cpp
|
||||
service/auth.cpp
|
||||
service/convotag.cpp
|
||||
service/context.cpp
|
||||
service/endpoint_state.cpp
|
||||
service/endpoint_util.cpp
|
||||
service/endpoint.cpp
|
||||
service/identity.cpp
|
||||
service/info.cpp
|
||||
service/intro_set.cpp
|
||||
service/intro.cpp
|
||||
service/lns_tracker.cpp
|
||||
service/name.cpp
|
||||
service/outbound_context.cpp
|
||||
service/protocol.cpp
|
||||
service/session.cpp
|
||||
service/tag.cpp
|
||||
)
|
||||
|
||||
# interface library for setting commone includes, linkage and flags.
|
||||
add_library(lokinet-base INTERFACE)
|
||||
target_include_directories(lokinet-base
|
||||
INTERFACE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
target_link_libraries(lokinet-base INTERFACE quic)
|
||||
|
||||
if(WITH_PEERSTATS)
|
||||
target_compile_definitions(lokinet-base INTERFACE -DLOKINET_PEERSTATS_BACKEND)
|
||||
target_link_libraries(lokinet-base INTERFACE sqlite_orm)
|
||||
endif()
|
||||
|
||||
# interface libraries for internal linkage
|
||||
add_library(lokinet-layers INTERFACE)
|
||||
add_library(lokinet-amalgum INTERFACE)
|
||||
|
||||
# helper function to link a library to lokinet-base, enable lto, add to lokinet-amalgum and then link to other libs
|
||||
function(lokinet_link_lib libname)
|
||||
# Absolutely fuck this line, it doesn't "create" the target, as the target already exists
|
||||
# message(DEBUG "created target: ${libname}")
|
||||
enable_lto(${libname})
|
||||
target_link_libraries(${libname} PUBLIC lokinet-base ${ARGN})
|
||||
target_link_libraries(lokinet-amalgum INTERFACE ${libname})
|
||||
endfunction()
|
||||
|
||||
# internal public linkages of components
|
||||
lokinet_link_lib(lokinet-util lokinet-libntrup)
|
||||
lokinet_link_lib(lokinet-cryptography lokinet-libcrypt lokinet-util)
|
||||
lokinet_link_lib(lokinet-peerstats lokinet-context)
|
||||
lokinet_link_lib(lokinet-consensus lokinet-context)
|
||||
lokinet_link_lib(lokinet-layer-link lokinet-cryptography lokinet-peerstats)
|
||||
|
||||
if(TARGET lokinet-dns-systemd)
|
||||
lokinet_link_lib(lokinet-dns-systemd
|
||||
lokinet-dns
|
||||
lokinet-platform
|
||||
)
|
||||
endif()
|
||||
|
||||
lokinet_link_lib(lokinet-platform lokinet-util)
|
||||
|
||||
lokinet_link_lib(lokinet-config
|
||||
lokinet-util
|
||||
lokinet-nodedb
|
||||
lokinet-dns
|
||||
lokinet-platform
|
||||
)
|
||||
|
||||
lokinet_link_lib(lokinet-context
|
||||
lokinet-config
|
||||
lokinet-platform
|
||||
lokinet-peerstats
|
||||
lokinet-layers
|
||||
lokinet-consensus
|
||||
lokinet-rpc
|
||||
)
|
||||
|
||||
lokinet_link_lib(
|
||||
lokinet-platform
|
||||
lokinet-config
|
||||
)
|
||||
|
||||
lokinet_link_lib(lokinet-dns
|
||||
lokinet-platform
|
||||
lokinet-dns-platform
|
||||
lokinet-config
|
||||
)
|
||||
|
||||
lokinet_link_lib(lokinet-nodedb
|
||||
lokinet-util
|
||||
lokinet-platform
|
||||
)
|
||||
|
||||
lokinet_link_lib(lokinet-util
|
||||
lokinet-nodedb
|
||||
lokinet-platform
|
||||
)
|
||||
|
||||
lokinet_link_lib(lokinet-rpc
|
||||
lokinet-context
|
||||
lokinet-peerstats
|
||||
lokinet-util
|
||||
)
|
||||
|
||||
# inter lokinet-layer public/private linkage.
|
||||
# when linking each layer, we consider the layer directly below private linkage and the layer above public linkage.
|
||||
# this lets us hide functionality of layers below us when depended on by another component.
|
||||
#
|
||||
# from highest to lowest layer, the above layers are stacked as follows:
|
||||
#
|
||||
# platform (what lokinet snapps interact with, be it l3 os interaction or embedded lokinet)
|
||||
# flow (how we want to route and stripe over our onion routing)
|
||||
# routing (what we are onion routing)
|
||||
# onion (how the onion routing happens)
|
||||
# link (what we want to send over the wire and to where)
|
||||
# wire (what is actually sent over the wire)
|
||||
#
|
||||
function(link_lokinet_layers)
|
||||
set(lib ${ARGV0})
|
||||
if(${ARGC} GREATER 1)
|
||||
lokinet_link_lib(${ARGV1} ${lib})
|
||||
list(REMOVE_AT ARGV 1)
|
||||
target_link_libraries(${lib} PRIVATE ${ARGV1})
|
||||
# recursion :D
|
||||
link_lokinet_layers(${ARGV})
|
||||
else()
|
||||
lokinet_link_lib(${lib})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
link_lokinet_layers(
|
||||
lokinet-layer-onion
|
||||
lokinet-layer-link
|
||||
)
|
||||
|
||||
# set me to OFF to disable old codepath
|
||||
set(use_old_impl ON)
|
||||
if(use_old_impl)
|
||||
# flow layer deprecated-kitchensink (remove me after refactor)
|
||||
lokinet_link_lib(lokinet-service-deprecated-kitchensink
|
||||
lokinet-dns
|
||||
lokinet-nodedb
|
||||
lokinet-context
|
||||
lokinet-layer-onion
|
||||
lokinet-platform
|
||||
lokinet-rpc
|
||||
)
|
||||
target_link_libraries(lokinet-layers INTERFACE lokinet-service-deprecated-kitchensink)
|
||||
endif()
|
||||
|
||||
target_link_libraries(lokinet-layers INTERFACE
|
||||
lokinet-layer-onion
|
||||
lokinet-layer-link
|
||||
)
|
||||
|
||||
|
||||
# per component external deps
|
||||
|
||||
target_link_libraries(lokinet-config PUBLIC oxenmq::oxenmq)
|
||||
target_link_libraries(lokinet-platform PUBLIC oxenmq::oxenmq)
|
||||
target_link_libraries(lokinet-dns PUBLIC libunbound)
|
||||
|
||||
target_link_libraries(lokinet-cryptography PUBLIC
|
||||
oxenc::oxenc
|
||||
sodium
|
||||
)
|
||||
|
||||
target_link_libraries(lokinet-context PUBLIC
|
||||
CLI11
|
||||
oxenmq::oxenmq
|
||||
uvw
|
||||
)
|
||||
|
||||
target_link_libraries(lokinet-platform PUBLIC
|
||||
Threads::Threads
|
||||
base_libs
|
||||
uvw
|
||||
)
|
||||
|
||||
target_link_libraries(lokinet-util PUBLIC
|
||||
nlohmann_json::nlohmann_json
|
||||
# filesystem
|
||||
oxenc::oxenc
|
||||
)
|
||||
|
||||
target_link_libraries(lokinet-layer-link PUBLIC
|
||||
quic
|
||||
uvw
|
||||
)
|
||||
|
||||
if(WITH_EMBEDDED_LOKINET)
|
||||
include(GNUInstallDirs)
|
||||
add_library(lokinet-shared SHARED lokinet_shared.cpp)
|
||||
target_link_libraries(lokinet-shared PUBLIC lokinet-amalgum)
|
||||
if(WIN32)
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "")
|
||||
endif()
|
||||
set_target_properties(lokinet-shared PROPERTIES OUTPUT_NAME lokinet)
|
||||
if(WIN32)
|
||||
target_link_libraries(lokinet-shared PUBLIC ws2_32 iphlpapi -fstack-protector)
|
||||
install(TARGETS lokinet-shared DESTINATION bin COMPONENT liblokinet)
|
||||
elseif(NOT APPLE)
|
||||
install(TARGETS lokinet-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT liblokinet)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE docs_SRC */*.hpp *.hpp)
|
||||
set(DOCS_SRC ${docs_SRC} PARENT_SCOPE)
|
@ -184,6 +184,7 @@ namespace llarp
|
||||
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
||||
};
|
||||
|
||||
// TODO: remove oxenmq from this header
|
||||
struct ApiConfig
|
||||
{
|
||||
bool m_enableRPCServer = false;
|
||||
|
@ -100,9 +100,7 @@ namespace llarp
|
||||
}
|
||||
|
||||
// load encryption key
|
||||
auto encryptionKeygen = [](llarp::SecretKey& key) {
|
||||
llarp::crypto::encryption_keygen(key);
|
||||
};
|
||||
auto encryptionKeygen = [](llarp::SecretKey& key) { llarp::crypto::encryption_keygen(key); };
|
||||
if (not loadOrCreateKey(m_encKeyPath, encryptionKey, encryptionKeygen))
|
||||
return false;
|
||||
|
||||
|
@ -109,7 +109,7 @@ namespace llarp
|
||||
}
|
||||
|
||||
std::optional<AlignedBuffer<32>>
|
||||
crypto::maybe_decrypt_name(std::string_view ciphertext, SymmNonce nounce, std::string_view name)
|
||||
crypto::maybe_decrypt_name(std::string_view ciphertext, SymmNonce nonce, std::string_view name)
|
||||
{
|
||||
const auto payloadsize = ciphertext.size() - crypto_aead_xchacha20poly1305_ietf_ABYTES;
|
||||
if (payloadsize != 32)
|
||||
@ -132,7 +132,7 @@ namespace llarp
|
||||
ciphertext.size(),
|
||||
nullptr,
|
||||
0,
|
||||
nounce.data(),
|
||||
nonce.data(),
|
||||
derivedKey.data())
|
||||
== -1)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ namespace llarp
|
||||
{
|
||||
/// decrypt cipherText given the key generated from name
|
||||
std::optional<AlignedBuffer<32>>
|
||||
maybe_decrypt_name(std::string_view ciphertext, SymmNonce nounce, std::string_view name);
|
||||
maybe_decrypt_name(std::string_view ciphertext, SymmNonce nonce, std::string_view name);
|
||||
|
||||
/// xchacha symmetric cipher
|
||||
bool
|
||||
@ -117,7 +117,7 @@ namespace llarp
|
||||
|
||||
bool
|
||||
check_passwd_hash(std::string pwhash, std::string challenge);
|
||||
};
|
||||
}; // namespace crypto
|
||||
|
||||
/// return random 64bit unsigned interger
|
||||
uint64_t
|
||||
|
@ -16,8 +16,8 @@ namespace llarp
|
||||
|
||||
if (noDH)
|
||||
{
|
||||
crypto::randbytes(nonce_ptr, TUNNONCESIZE);
|
||||
crypto::randbytes(pubkey_ptr, PUBKEYSIZE);
|
||||
crypto::randbytes(nonce_ptr, TUNNONCESIZE);
|
||||
crypto::randbytes(pubkey_ptr, PUBKEYSIZE);
|
||||
}
|
||||
|
||||
TunnelNonce nonce(nonce_ptr);
|
||||
|
@ -4,9 +4,6 @@
|
||||
#include <llarp/util/file.hpp>
|
||||
#include <oxenc/hex.h>
|
||||
|
||||
// #include <sodium/crypto_hash_sha512.h>
|
||||
// #include <sodium/crypto_scalarmult_ed25519.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
bool
|
||||
|
@ -220,15 +220,14 @@ namespace llarp
|
||||
using PQKeyPair = AlignedBuffer<PQ_KEYPAIRSIZE>;
|
||||
|
||||
/// PKE(result, publickey, secretkey, nonce)
|
||||
using path_dh_func =
|
||||
bool(*)(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&);
|
||||
using path_dh_func = bool (*)(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&);
|
||||
|
||||
/// TKE(result, publickey, secretkey, nonce)
|
||||
using transport_dh_func =
|
||||
bool(*)(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&);
|
||||
bool (*)(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&);
|
||||
|
||||
/// SH(result, body)
|
||||
using shorthash_func = bool(*)(ShortHash&, const llarp_buffer_t&);
|
||||
using shorthash_func = bool (*)(ShortHash&, const llarp_buffer_t&);
|
||||
} // namespace llarp
|
||||
|
||||
namespace std
|
||||
|
@ -10,10 +10,8 @@
|
||||
|
||||
namespace llarp::handlers
|
||||
{
|
||||
ExitEndpoint::ExitEndpoint(std::string name, Router* r)
|
||||
: router(r)
|
||||
, name(std::move(name))
|
||||
// , tunnel_manager{std::make_shared<link::TunnelManager>(*this)}
|
||||
ExitEndpoint::ExitEndpoint(std::string name, Router* r) : router(r), name(std::move(name))
|
||||
// , tunnel_manager{std::make_shared<link::TunnelManager>(*this)}
|
||||
{
|
||||
should_init_tun = true;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <uvw/tcp.h>
|
||||
// #include <uvw/tcp.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
@ -157,12 +157,12 @@ namespace llarp::link
|
||||
// Callback to invoke on quic connection established (true argument) or failed (false arg)
|
||||
OpenCallback open_cb;
|
||||
// TCP listening socket
|
||||
std::shared_ptr<uvw::TCPHandle> tcp;
|
||||
// Accepted TCP connections
|
||||
std::unordered_set<std::shared_ptr<uvw::TCPHandle>> conns;
|
||||
// Queue of incoming connections that are waiting for a stream to become available (either
|
||||
// because we are still handshaking, or we reached the stream limit).
|
||||
std::queue<std::weak_ptr<uvw::TCPHandle>> pending_incoming;
|
||||
// std::shared_ptr<uvw::TCPHandle> tcp;
|
||||
// // Accepted TCP connections
|
||||
// std::unordered_set<std::shared_ptr<uvw::TCPHandle>> conns;
|
||||
// // Queue of incoming connections that are waiting for a stream to become available (either
|
||||
// // because we are still handshaking, or we reached the stream limit).
|
||||
// std::queue<std::weak_ptr<uvw::TCPHandle>> pending_incoming;
|
||||
|
||||
~ClientTunnel()
|
||||
{
|
||||
@ -225,8 +225,8 @@ namespace llarp::link
|
||||
std::map<int, ListenHandler> incoming_handlers_;
|
||||
int next_handler_id_ = 1;
|
||||
|
||||
std::shared_ptr<uvw::Loop>
|
||||
get_loop();
|
||||
// std::shared_ptr<uvw::Loop>
|
||||
// get_loop();
|
||||
|
||||
// Cleanup member
|
||||
std::shared_ptr<int> timer_keepalive_ = std::make_shared<int>(0);
|
||||
|
@ -27,8 +27,7 @@ namespace llarp
|
||||
btdp.append("E", flag);
|
||||
btdp.append("T", tx_id);
|
||||
|
||||
if (not crypto::sign(
|
||||
reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
if (not crypto::sign(reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
throw std::runtime_error{
|
||||
"Error: ObtainExitMessage failed to sign and serialize contents!"};
|
||||
}
|
||||
@ -51,8 +50,7 @@ namespace llarp
|
||||
btdp.append("T", tx_id);
|
||||
btdp.append("Y", nonce);
|
||||
|
||||
if (crypto::sign(
|
||||
reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
if (crypto::sign(reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
throw std::runtime_error{
|
||||
"Error: ObtainExitMessage response failed to sign and serialize contents!"};
|
||||
}
|
||||
@ -80,8 +78,7 @@ namespace llarp
|
||||
btdp.append("P", path_id);
|
||||
btdp.append("T", tx_id);
|
||||
|
||||
if (not crypto::sign(
|
||||
reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
if (not crypto::sign(reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
throw std::runtime_error{
|
||||
"Error: UpdateExitMessage failed to sign and serialize contents!"};
|
||||
}
|
||||
@ -104,8 +101,7 @@ namespace llarp
|
||||
btdp.append("T", tx_id);
|
||||
btdp.append("Y", nonce);
|
||||
|
||||
if (crypto::sign(
|
||||
reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
if (crypto::sign(reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
throw std::runtime_error{
|
||||
"Error: UpdateExitMessage response failed to sign and serialize contents!"};
|
||||
}
|
||||
@ -134,8 +130,7 @@ namespace llarp
|
||||
btdp.append("T", tx_id);
|
||||
btdp.append("Y", nonce);
|
||||
|
||||
if (not crypto::sign(
|
||||
reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
if (not crypto::sign(reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
throw std::runtime_error{
|
||||
"Error: CloseExitMessage failed to sign and serialize contents!"};
|
||||
}
|
||||
@ -158,8 +153,7 @@ namespace llarp
|
||||
btdp.append("T", tx_id);
|
||||
btdp.append("Y", nonce);
|
||||
|
||||
if (crypto::sign(
|
||||
reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
if (crypto::sign(reinterpret_cast<uint8_t*>(sig.data()), sk, to_usv(btdp.view())))
|
||||
throw std::runtime_error{
|
||||
"Error: CloseExitMessage response failed to sign and serialize contents!"};
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace llarp
|
||||
setup_hop_keys(path::PathHopConfig& hop, const RouterID& nextHop)
|
||||
{
|
||||
// generate key
|
||||
crypto::encryption_keygen(hop.commkey);
|
||||
crypto::encryption_keygen(hop.commkey);
|
||||
|
||||
hop.nonce.Randomize();
|
||||
// do key exchange
|
||||
|
@ -25,9 +25,7 @@ namespace llarp::path
|
||||
|
||||
bool
|
||||
TransitHop::send_path_control_message(
|
||||
std::string,
|
||||
std::string,
|
||||
std::function<void(oxen::quic::message m)>)
|
||||
std::string, std::string, std::function<void(oxen::quic::message m)>)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -31,8 +31,7 @@ namespace llarp
|
||||
auto buf = bt_encode();
|
||||
|
||||
// hash
|
||||
if (!crypto::shorthash(
|
||||
digest, reinterpret_cast<uint8_t*>(buf.data()), buf.size()))
|
||||
if (!crypto::shorthash(digest, reinterpret_cast<uint8_t*>(buf.data()), buf.size()))
|
||||
return false;
|
||||
// check bytes required
|
||||
uint32_t required = std::floor(std::log(extendedLifetime.count()));
|
||||
|
@ -409,8 +409,7 @@ namespace llarp
|
||||
copy.signature.Zero();
|
||||
|
||||
auto bte = copy.bt_encode();
|
||||
return crypto::verify(
|
||||
pubkey, reinterpret_cast<uint8_t*>(bte.data()), bte.size(), signature);
|
||||
return crypto::verify(pubkey, reinterpret_cast<uint8_t*>(bte.data()), bte.size(), signature);
|
||||
}
|
||||
|
||||
static constexpr std::array obsolete_bootstraps = {
|
||||
|
@ -50,7 +50,8 @@ namespace llarp::service
|
||||
// compute post handshake session key
|
||||
// PKE (A, B, N)
|
||||
SharedSecret sharedSecret;
|
||||
if (!self->m_LocalIdentity.KeyExchange(crypto::dh_client, sharedSecret, self->m_remote, frame->nonce))
|
||||
if (!self->m_LocalIdentity.KeyExchange(
|
||||
crypto::dh_client, sharedSecret, self->m_remote, frame->nonce))
|
||||
{
|
||||
LogError("failed to derive x25519 shared key component");
|
||||
}
|
||||
|
@ -124,8 +124,7 @@ namespace llarp::service
|
||||
case AuthFileType::eAuthFilePlain:
|
||||
return hash == challenge;
|
||||
case AuthFileType::eAuthFileHashes:
|
||||
return crypto::check_passwd_hash(
|
||||
std::move(hash), std::move(challenge));
|
||||
return crypto::check_passwd_hash(std::move(hash), std::move(challenge));
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -6,214 +6,211 @@
|
||||
|
||||
#include "endpoint.hpp"
|
||||
|
||||
namespace llarp
|
||||
namespace llarp::service
|
||||
{
|
||||
namespace service
|
||||
static auto logcat = log::Cat("service");
|
||||
namespace
|
||||
{
|
||||
static auto logcat = log::Cat("service");
|
||||
namespace
|
||||
using EndpointConstructor = std::function<service::Endpoint_ptr(Router*, service::Context*)>;
|
||||
using EndpointConstructors = std::map<std::string, EndpointConstructor>;
|
||||
|
||||
static EndpointConstructors endpointConstructors = {
|
||||
{"tun",
|
||||
[](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::TunEndpoint>(r, c);
|
||||
}},
|
||||
{"android",
|
||||
[](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::TunEndpoint>(r, c);
|
||||
}},
|
||||
{"ios",
|
||||
[](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::TunEndpoint>(r, c);
|
||||
}},
|
||||
{"null", [](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::NullEndpoint>(r, c);
|
||||
}}};
|
||||
|
||||
} // namespace
|
||||
Context::Context(Router* r) : m_Router(r)
|
||||
{}
|
||||
|
||||
Context::~Context() = default;
|
||||
|
||||
bool
|
||||
Context::StopAll()
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
{
|
||||
using EndpointConstructor = std::function<service::Endpoint_ptr(Router*, service::Context*)>;
|
||||
using EndpointConstructors = std::map<std::string, EndpointConstructor>;
|
||||
|
||||
static EndpointConstructors endpointConstructors = {
|
||||
{"tun",
|
||||
[](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::TunEndpoint>(r, c);
|
||||
}},
|
||||
{"android",
|
||||
[](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::TunEndpoint>(r, c);
|
||||
}},
|
||||
{"ios",
|
||||
[](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::TunEndpoint>(r, c);
|
||||
}},
|
||||
{"null", [](Router* r, service::Context* c) {
|
||||
return std::make_shared<handlers::NullEndpoint>(r, c);
|
||||
}}};
|
||||
|
||||
} // namespace
|
||||
Context::Context(Router* r) : m_Router(r)
|
||||
{}
|
||||
|
||||
Context::~Context() = default;
|
||||
|
||||
bool
|
||||
Context::StopAll()
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
{
|
||||
log::debug(logcat, "Stopping endpoint {}.", itr->first);
|
||||
itr->second->Stop();
|
||||
log::debug(logcat, "Endpoint {} stopped.", itr->first);
|
||||
m_Stopped.emplace_back(std::move(itr->second));
|
||||
itr = m_Endpoints.erase(itr);
|
||||
}
|
||||
return true;
|
||||
log::debug(logcat, "Stopping endpoint {}.", itr->first);
|
||||
itr->second->Stop();
|
||||
log::debug(logcat, "Endpoint {} stopped.", itr->first);
|
||||
m_Stopped.emplace_back(std::move(itr->second));
|
||||
itr = m_Endpoints.erase(itr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
util::StatusObject
|
||||
Context::ExtractStatus() const
|
||||
util::StatusObject
|
||||
Context::ExtractStatus() const
|
||||
{
|
||||
util::StatusObject obj{};
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
{
|
||||
util::StatusObject obj{};
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
{
|
||||
obj[itr->first] = itr->second->ExtractStatus();
|
||||
obj[itr->first] = itr->second->ExtractStatus();
|
||||
++itr;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
void
|
||||
Context::ForEachService(
|
||||
std::function<bool(const std::string&, const std::shared_ptr<Endpoint>&)> visit) const
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
{
|
||||
if (visit(itr->first, itr->second))
|
||||
++itr;
|
||||
}
|
||||
return obj;
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Context::ForEachService(
|
||||
std::function<bool(const std::string&, const std::shared_ptr<Endpoint>&)> visit) const
|
||||
void
|
||||
Context::Pump()
|
||||
{
|
||||
auto now = time_now_ms();
|
||||
for (auto& [name, endpoint] : m_Endpoints)
|
||||
endpoint->Pump(now);
|
||||
}
|
||||
|
||||
bool
|
||||
Context::RemoveEndpoint(const std::string& name)
|
||||
{
|
||||
auto itr = m_Endpoints.find(name);
|
||||
if (itr == m_Endpoints.end())
|
||||
return false;
|
||||
std::shared_ptr<Endpoint> ep = std::move(itr->second);
|
||||
m_Endpoints.erase(itr);
|
||||
ep->Stop();
|
||||
m_Stopped.emplace_back(std::move(ep));
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Context::Tick(llarp_time_t now)
|
||||
{
|
||||
// erase stopped endpoints that are done
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
auto itr = m_Stopped.begin();
|
||||
while (itr != m_Stopped.end())
|
||||
{
|
||||
if (visit(itr->first, itr->second))
|
||||
++itr;
|
||||
if ((*itr)->ShouldRemove())
|
||||
itr = m_Stopped.erase(itr);
|
||||
else
|
||||
return;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Context::Pump()
|
||||
// tick active endpoints
|
||||
for (const auto& item : m_Endpoints)
|
||||
{
|
||||
auto now = time_now_ms();
|
||||
for (auto& [name, endpoint] : m_Endpoints)
|
||||
endpoint->Pump(now);
|
||||
item.second->Tick(now);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Context::RemoveEndpoint(const std::string& name)
|
||||
{
|
||||
auto itr = m_Endpoints.find(name);
|
||||
if (itr == m_Endpoints.end())
|
||||
return false;
|
||||
std::shared_ptr<Endpoint> ep = std::move(itr->second);
|
||||
m_Endpoints.erase(itr);
|
||||
ep->Stop();
|
||||
m_Stopped.emplace_back(std::move(ep));
|
||||
return true;
|
||||
}
|
||||
bool
|
||||
Context::hasEndpoints()
|
||||
{
|
||||
return m_Endpoints.size() ? true : false;
|
||||
}
|
||||
|
||||
void
|
||||
Context::Tick(llarp_time_t now)
|
||||
{
|
||||
// erase stopped endpoints that are done
|
||||
{
|
||||
auto itr = m_Stopped.begin();
|
||||
while (itr != m_Stopped.end())
|
||||
{
|
||||
if ((*itr)->ShouldRemove())
|
||||
itr = m_Stopped.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
// tick active endpoints
|
||||
for (const auto& item : m_Endpoints)
|
||||
{
|
||||
item.second->Tick(now);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Context::hasEndpoints()
|
||||
{
|
||||
return m_Endpoints.size() ? true : false;
|
||||
}
|
||||
|
||||
static const char*
|
||||
DefaultEndpointType()
|
||||
{
|
||||
static const char*
|
||||
DefaultEndpointType()
|
||||
{
|
||||
#ifdef ANDROID
|
||||
return "android";
|
||||
return "android";
|
||||
#else
|
||||
#ifdef IOS
|
||||
return "ios";
|
||||
return "ios";
|
||||
#else
|
||||
return "tun";
|
||||
return "tun";
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Context::StartAll()
|
||||
bool
|
||||
Context::StartAll()
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while (itr != m_Endpoints.end())
|
||||
if (!itr->second->Start())
|
||||
{
|
||||
if (!itr->second->Start())
|
||||
{
|
||||
LogError(itr->first, " failed to start");
|
||||
return false;
|
||||
}
|
||||
LogInfo(itr->first, " started");
|
||||
++itr;
|
||||
LogError(itr->first, " failed to start");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
LogInfo(itr->first, " started");
|
||||
++itr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Endpoint_ptr
|
||||
Context::GetEndpointByName(const std::string& name) const
|
||||
Endpoint_ptr
|
||||
Context::GetEndpointByName(const std::string& name) const
|
||||
{
|
||||
auto itr = m_Endpoints.find(name);
|
||||
if (itr != m_Endpoints.end())
|
||||
return itr->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
Context::InjectEndpoint(std::string name, std::shared_ptr<Endpoint> ep)
|
||||
{
|
||||
ep->LoadKeyFile();
|
||||
if (ep->Start())
|
||||
{
|
||||
auto itr = m_Endpoints.find(name);
|
||||
if (itr != m_Endpoints.end())
|
||||
return itr->second;
|
||||
return nullptr;
|
||||
m_Endpoints.emplace(std::move(name), std::move(ep));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Context::InjectEndpoint(std::string name, std::shared_ptr<Endpoint> ep)
|
||||
void
|
||||
Context::AddEndpoint(const Config& conf, bool autostart)
|
||||
{
|
||||
constexpr auto endpointName = "default";
|
||||
|
||||
if (m_Endpoints.find(endpointName) != m_Endpoints.end())
|
||||
throw std::invalid_argument("service::Context only supports one endpoint now");
|
||||
|
||||
const auto& endpointType = conf.network.m_endpointType;
|
||||
// use factory to create endpoint
|
||||
const auto itr = endpointConstructors.find(endpointType);
|
||||
if (itr == endpointConstructors.end())
|
||||
throw std::invalid_argument{fmt::format("Endpoint type {} does not exist", endpointType)};
|
||||
|
||||
auto service = itr->second(m_Router, this);
|
||||
if (not service)
|
||||
throw std::runtime_error{
|
||||
fmt::format("Failed to construct endpoint of type {}", endpointType)};
|
||||
|
||||
// pass conf to service
|
||||
service->Configure(conf.network, conf.dns);
|
||||
|
||||
if (not service->LoadKeyFile())
|
||||
throw std::runtime_error("Endpoint's keyfile could not be loaded");
|
||||
|
||||
// autostart if requested
|
||||
if (autostart)
|
||||
{
|
||||
ep->LoadKeyFile();
|
||||
if (ep->Start())
|
||||
{
|
||||
m_Endpoints.emplace(std::move(name), std::move(ep));
|
||||
}
|
||||
if (service->Start())
|
||||
LogInfo("autostarting hidden service endpoint ", service->Name());
|
||||
else
|
||||
throw std::runtime_error("failed to start hidden service endpoint");
|
||||
}
|
||||
|
||||
void
|
||||
Context::AddEndpoint(const Config& conf, bool autostart)
|
||||
{
|
||||
constexpr auto endpointName = "default";
|
||||
|
||||
if (m_Endpoints.find(endpointName) != m_Endpoints.end())
|
||||
throw std::invalid_argument("service::Context only supports one endpoint now");
|
||||
|
||||
const auto& endpointType = conf.network.m_endpointType;
|
||||
// use factory to create endpoint
|
||||
const auto itr = endpointConstructors.find(endpointType);
|
||||
if (itr == endpointConstructors.end())
|
||||
throw std::invalid_argument{fmt::format("Endpoint type {} does not exist", endpointType)};
|
||||
|
||||
auto service = itr->second(m_Router, this);
|
||||
if (not service)
|
||||
throw std::runtime_error{
|
||||
fmt::format("Failed to construct endpoint of type {}", endpointType)};
|
||||
|
||||
// pass conf to service
|
||||
service->Configure(conf.network, conf.dns);
|
||||
|
||||
if (not service->LoadKeyFile())
|
||||
throw std::runtime_error("Endpoint's keyfile could not be loaded");
|
||||
|
||||
// autostart if requested
|
||||
if (autostart)
|
||||
{
|
||||
if (service->Start())
|
||||
LogInfo("autostarting hidden service endpoint ", service->Name());
|
||||
else
|
||||
throw std::runtime_error("failed to start hidden service endpoint");
|
||||
}
|
||||
|
||||
m_Endpoints.emplace(endpointName, service);
|
||||
}
|
||||
} // namespace service
|
||||
} // namespace llarp
|
||||
m_Endpoints.emplace(endpointName, service);
|
||||
}
|
||||
} // namespace llarp::service
|
||||
|
@ -168,8 +168,7 @@ namespace llarp::service
|
||||
auto bte = i.bt_encode();
|
||||
|
||||
const SharedSecret k{i.address_keys.Addr()};
|
||||
crypto::xchacha20(
|
||||
reinterpret_cast<uint8_t*>(bte.data()), bte.size(), k, encrypted.nounce);
|
||||
crypto::xchacha20(reinterpret_cast<uint8_t*>(bte.data()), bte.size(), k, encrypted.nounce);
|
||||
|
||||
std::memcpy(encrypted.introsetPayload.data(), bte.data(), bte.size());
|
||||
|
||||
|
@ -123,8 +123,7 @@ namespace llarp::service
|
||||
std::string payload{
|
||||
reinterpret_cast<const char*>(introsetPayload.data()), introsetPayload.size()};
|
||||
|
||||
crypto::xchacha20(
|
||||
reinterpret_cast<uint8_t*>(payload.data()), payload.size(), k, nounce);
|
||||
crypto::xchacha20(reinterpret_cast<uint8_t*>(payload.data()), payload.size(), k, nounce);
|
||||
|
||||
return IntroSet{payload};
|
||||
}
|
||||
@ -144,8 +143,7 @@ namespace llarp::service
|
||||
sig.Zero();
|
||||
auto bte = bt_encode();
|
||||
|
||||
if (not crypto::sign(
|
||||
sig, k, reinterpret_cast<uint8_t*>(bte.data()), bte.size()))
|
||||
if (not crypto::sign(sig, k, reinterpret_cast<uint8_t*>(bte.data()), bte.size()))
|
||||
return false;
|
||||
LogDebug("signed encrypted introset: ", *this);
|
||||
return true;
|
||||
|
@ -207,8 +207,7 @@ namespace llarp::service
|
||||
// encode message
|
||||
auto bte1 = msg.bt_encode();
|
||||
// encrypt
|
||||
crypto::xchacha20(
|
||||
reinterpret_cast<uint8_t*>(bte1.data()), bte1.size(), sessionKey, nonce);
|
||||
crypto::xchacha20(reinterpret_cast<uint8_t*>(bte1.data()), bte1.size(), sessionKey, nonce);
|
||||
// put encrypted buffer
|
||||
std::memcpy(enc.data(), bte1.data(), bte1.size());
|
||||
// zero out signature
|
||||
|
Loading…
Reference in New Issue
Block a user