mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
Merge remote-tracking branch 'origin/master' into memlink
This commit is contained in:
commit
3c3338e801
203 changed files with 2305 additions and 1902 deletions
|
@ -1,2 +1,2 @@
|
|||
HeaderFilterRegex: 'llarp/.*'
|
||||
Checks: 'readability-else-after-return,clang-analyzer-core-*'
|
||||
Checks: 'readability-else-after-return,clang-analyzer-core-*,modernize-*'
|
||||
|
|
114
.travis.yml
114
.travis.yml
|
@ -5,58 +5,82 @@ cache: ccache
|
|||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- os: linux
|
||||
- name: "lint check"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env: MAKE_TARGET=format-verify PATH="/usr/lib/llvm-8/bin:$PATH"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- llvm-toolchain-xenial-8
|
||||
packages:
|
||||
- clang-format-8
|
||||
- name: "make debug (linux/gcc)"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env: BUILD_TYPE=Debug IS_NOTIFICATION=1
|
||||
- os: linux
|
||||
- name: "make release (linux/gcc)"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env: BUILD_TYPE=Release
|
||||
- name: "make debug (linux/clang)"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env: BUILD_TYPE=Debug
|
||||
- name: "make release (linux/clang)"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env: BUILD_TYPE=Release
|
||||
- name: "make debug (macOS/clang)"
|
||||
os: osx
|
||||
osx_image: xcode10.2
|
||||
env: BUILD_TYPE=Debug PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- name: "make release (macOS/clang)"
|
||||
os: osx
|
||||
osx_image: xcode10.2
|
||||
env: BUILD_TYPE=Release PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- name: "make windows (macOS)"
|
||||
os: osx
|
||||
osx_image: xcode10.2
|
||||
env: MAKE_TARGET=windows PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- name: "make windows-release (macOS)"
|
||||
os: osx
|
||||
osx_image: xcode10.2
|
||||
env: MAKE_TARGET=windows-release PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- name: "make release (macOS beta/clang)"
|
||||
os: osx
|
||||
osx_image: xcode11
|
||||
env: BUILD_TYPE=Release PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- name: "address sanitizer"
|
||||
os: osx
|
||||
osx_image: xcode10.2
|
||||
env: BUILD_TYPE=Debug ASAN=ON PATH="/usr/local/opt/ccache/libexec:$PATH" CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++
|
||||
- name: "native windows debug"
|
||||
os: windows
|
||||
env: BUILD_TYPE=Debug
|
||||
- name: "native windows release"
|
||||
os: windows
|
||||
env: BUILD_TYPE=Release
|
||||
- name: "router docker image"
|
||||
os: linux
|
||||
dist: xenial
|
||||
env: DOCKER_FILE=docker/router.Dockerfile
|
||||
services: docker
|
||||
- os: linux
|
||||
- name: "make windows docker image"
|
||||
os: linux
|
||||
dist: xenial
|
||||
env: DOCKER_FILE=docker/alpine-windows.Dockerfile
|
||||
services: docker
|
||||
- os: linux
|
||||
- name: "gcc trunk"
|
||||
os: linux
|
||||
dist: xenial
|
||||
env: DOCKER_FILE=docker/gcc-trunk.Dockerfile
|
||||
services: docker
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env: BUILD_TYPE=Release
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env: BUILD_TYPE=Debug
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env: BUILD_TYPE=Release
|
||||
- os: osx
|
||||
osx_image: xcode10.2
|
||||
compiler: gcc
|
||||
env: BUILD_TYPE=Debug
|
||||
- os: osx
|
||||
osx_image: xcode10.2
|
||||
compiler: gcc
|
||||
env: BUILD_TYPE=Release
|
||||
- os: osx
|
||||
osx_image: xcode10.2
|
||||
env: BUILD_TYPE=Debug PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- os: osx
|
||||
osx_image: xcode10.2
|
||||
env: BUILD_TYPE=Release PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- os: osx
|
||||
osx_image: xcode11
|
||||
env: BUILD_TYPE=Release PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- os: osx
|
||||
osx_image: xcode10.2
|
||||
env: BUILD_TYPE=Debug ASAN=ON PATH="/usr/local/opt/ccache/libexec:$PATH" CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++
|
||||
- os: windows
|
||||
env: BUILD_TYPE=Debug
|
||||
- os: windows
|
||||
env: BUILD_TYPE=Release
|
||||
allow_failures:
|
||||
- os: linux
|
||||
dist: xenial
|
||||
|
@ -66,6 +90,12 @@ matrix:
|
|||
dist: xenial
|
||||
env: DOCKER_FILE=docker/gcc-trunk.Dockerfile
|
||||
services: docker
|
||||
- os: osx
|
||||
osx_image: xcode10.2
|
||||
env: MAKE_TARGET=windows PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
- os: osx
|
||||
osx_image: xcode10.2
|
||||
env: MAKE_TARGET=windows-release PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
|
||||
env:
|
||||
global:
|
||||
|
@ -77,6 +107,7 @@ addons:
|
|||
packages:
|
||||
- binutils-gold
|
||||
- build-essential
|
||||
- clang-format
|
||||
- cmake
|
||||
- curl
|
||||
- docker-ce
|
||||
|
@ -94,8 +125,9 @@ addons:
|
|||
- cmake
|
||||
- libuv
|
||||
- llvm
|
||||
- ninja
|
||||
- make
|
||||
- mingw-w64
|
||||
- ninja
|
||||
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "windows" ]; then
|
||||
|
|
|
@ -164,36 +164,7 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
|||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# not supported on Solaris - system libraries are not available as archives
|
||||
# LTO is supported only for native builds
|
||||
if(STATIC_LINK_RUNTIME)
|
||||
if (NOT SOLARIS)
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
add_compile_options(-static -flto)
|
||||
else()
|
||||
add_compile_options(-static)
|
||||
endif()
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
link_libraries( -static -static-libstdc++ -pthread -flto )
|
||||
else()
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
# this is messing with release builds
|
||||
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0)
|
||||
set(CMAKE_AR "gcc-ar")
|
||||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_C_ARCHIVE_FINISH "true")
|
||||
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_CXX_ARCHIVE_FINISH "true")
|
||||
link_libraries( -flto -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive )
|
||||
else()
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive" )
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
link_libraries( -static-libstdc++ -static-libgcc )
|
||||
endif()
|
||||
endif(STATIC_LINK_RUNTIME)
|
||||
include(cmake/static_link.cmake)
|
||||
|
||||
if(USE_NETNS)
|
||||
add_definitions(-DNETNS=1)
|
||||
|
@ -286,15 +257,20 @@ if(SHADOW)
|
|||
else()
|
||||
if(NOT WIN32)
|
||||
add_executable(${EXE} ${EXE_SRC})
|
||||
add_executable(lokinet-rcutil daemon/rcutil.cpp)
|
||||
elseif(NOT MSVC_VERSION)
|
||||
add_executable(${EXE} ${EXE_SRC} llarp/win32/version.rc)
|
||||
add_executable(lokinet-rcutil daemon/rcutil.cpp llarp/win32/version.rc)
|
||||
else()
|
||||
add_executable(${EXE} ${EXE_SRC})
|
||||
add_executable(lokinet-rcutil daemon/rcutil.cpp)
|
||||
endif(NOT WIN32)
|
||||
|
||||
add_log_tag(${EXE})
|
||||
add_log_tag(lokinet-rcutil)
|
||||
|
||||
install(TARGETS ${EXE} RUNTIME DESTINATION bin)
|
||||
install(TARGETS lokinet-rcutil RUNTIME DESTINATION bin)
|
||||
if(WIN32)
|
||||
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin)
|
||||
else()
|
||||
|
@ -306,8 +282,10 @@ else()
|
|||
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
target_link_directories(${EXE} PRIVATE /usr/local/lib)
|
||||
target_link_directories(lokinet-rcutil PRIVATE /usr/local/lib)
|
||||
endif()
|
||||
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS})
|
||||
target_link_libraries(lokinet-rcutil PUBLIC ${EXE_LIBS} ${LIBS})
|
||||
|
||||
if(ANDROID)
|
||||
add_library(${ANDROID_LIB} SHARED jni/lokinet_android.cpp)
|
||||
|
|
5
Makefile
5
Makefile
|
@ -243,6 +243,11 @@ abyss: debug
|
|||
format:
|
||||
clang-format -i $$(find jni daemon llarp include libabyss | grep -E '\.[h,c](pp)?$$')
|
||||
|
||||
format-verify: format
|
||||
(type clang-format)
|
||||
clang-format --version
|
||||
git diff --quiet || (echo 'Please run make format!!' && git --no-pager diff ; exit 1)
|
||||
|
||||
analyze-config: clean
|
||||
mkdir -p '$(BUILD_ROOT)'
|
||||
$(ANALYZE_CONFIG_CMD)
|
||||
|
|
|
@ -4,8 +4,10 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|||
add_compile_options(-Wno-unused-command-line-argument -Wno-c++11-narrowing)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-bad-function-cast>)
|
||||
if (NO_LIBGCC)
|
||||
set(CMAKE_CXX_STANDARD_LIBRARIES "-lunwind -lpsapi ${CMAKE_CXX_STANDARD_LIBRARIES}")
|
||||
set(CMAKE_C_STANDARD_LIBRARIES "-lunwind -lpsapi ${CMAKE_C_STANDARD_LIBRARIES}")
|
||||
find_library(UNWIND_LIB unwind)
|
||||
link_libraries(${UNWIND_LIB})
|
||||
find_library(PSAPI_LIB psapi)
|
||||
link_libraries(${PSAPI_LIB})
|
||||
endif(NO_LIBGCC)
|
||||
else()
|
||||
# found it. this is GNU only
|
||||
|
|
40
cmake/static_link.cmake
Normal file
40
cmake/static_link.cmake
Normal file
|
@ -0,0 +1,40 @@
|
|||
if(NOT STATIC_LINK_RUNTIME)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# not supported on Solaris - system libraries are not available as archives
|
||||
# LTO is supported only for native builds
|
||||
if(SOLARIS)
|
||||
link_libraries( -static-libstdc++ -static-libgcc )
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
add_compile_options(-static -flto)
|
||||
else()
|
||||
add_compile_options(-static)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
if(APPLE)
|
||||
link_libraries( -flto)
|
||||
else()
|
||||
link_libraries( -static -static-libstdc++ -pthread -flto )
|
||||
endif()
|
||||
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
# this is messing with release builds
|
||||
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0)
|
||||
set(CMAKE_AR "gcc-ar")
|
||||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_C_ARCHIVE_FINISH "true")
|
||||
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_CXX_ARCHIVE_FINISH "true")
|
||||
link_libraries( -flto -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive )
|
||||
else()
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive" )
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
endif()
|
|
@ -2,6 +2,9 @@ if(NOT UNIX)
|
|||
return()
|
||||
endif()
|
||||
|
||||
include(CheckCXXSourceCompiles)
|
||||
include(CheckLibraryExists)
|
||||
|
||||
add_definitions(-DUNIX)
|
||||
add_definitions(-DPOSIX)
|
||||
|
||||
|
@ -21,9 +24,49 @@ endif()
|
|||
|
||||
include_directories(${LIBUV_INCLUDE_DIRS})
|
||||
|
||||
function(check_working_cxx_atomics64 varname)
|
||||
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++14")
|
||||
check_cxx_source_compiles("
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
std::atomic<uint64_t> x (0);
|
||||
int main() {
|
||||
uint64_t i = x.load(std::memory_order_relaxed);
|
||||
return 0;
|
||||
}
|
||||
" ${varname})
|
||||
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
|
||||
endfunction()
|
||||
|
||||
function(link_libatomic)
|
||||
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
|
||||
|
||||
if(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
|
||||
message(STATUS "Have working 64bit atomics")
|
||||
return()
|
||||
endif()
|
||||
|
||||
check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
|
||||
if (HAVE_CXX_LIBATOMICS64)
|
||||
message(STATUS "Have 64bit atomics via library")
|
||||
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
|
||||
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
|
||||
if (HAVE_CXX_ATOMICS64_WITH_LIB)
|
||||
message(STATUS "Can link with libatomic")
|
||||
link_libraries(-latomic)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!")
|
||||
endfunction()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(FS_LIB stdc++fs)
|
||||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
||||
|
||||
link_libatomic()
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
find_library(FS_LIB NAMES c++fs c++experimental stdc++fs)
|
||||
if(FS_LIB STREQUAL FS_LIB-NOTFOUND)
|
||||
|
|
|
@ -8,6 +8,10 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|||
if (MSVC OR MSVC_VERSION)
|
||||
add_compile_options(/EHca /arch:AVX2 /MD)
|
||||
add_definitions(-D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING)
|
||||
|
||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
|
||||
add_compile_options(-Wno-nonportable-system-include-path)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT MSVC_VERSION)
|
||||
|
@ -17,7 +21,9 @@ if(NOT MSVC_VERSION)
|
|||
# GNU ld sees fit to merge *all* the .ident sections in object files
|
||||
# to .r[o]data section one after the other!
|
||||
add_compile_options(-fno-ident -Wa,-mbig-obj)
|
||||
link_libraries( -lshlwapi -ldbghelp )
|
||||
find_library(shlwapi_lib shlwapi)
|
||||
find_library(dbghelp_lib dbghelp)
|
||||
link_libraries( ${shlwapi_lib} ${dbghelp_lib} )
|
||||
add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500)
|
||||
# Wait a minute, if we're not Microsoft C++, nor a Clang paired with Microsoft C++,
|
||||
# then the only possible option has to be GNU or a GNU-linked Clang!
|
||||
|
@ -29,7 +35,10 @@ endif()
|
|||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-windows.c ABSOLUTE)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_win32.cpp" ABSOLUTE)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN -DWIN32 -DWINVER=0x0500)
|
||||
set(EXE_LIBS ${STATIC_LIB} ${FS_LIB} ws2_32 iphlpapi)
|
||||
|
||||
find_library(ws2_32_lib ws2_32)
|
||||
find_library(iphlpapi_lib iphlpapi)
|
||||
set(EXE_LIBS ${STATIC_LIB} ${FS_LIB} ${ws2_32_lib} ${iphlpapi_lib})
|
||||
|
||||
if(RELEASE_MOTTO)
|
||||
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
|
||||
|
|
|
@ -1,28 +1,16 @@
|
|||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
|
||||
set(TOOLCHAIN_SUFFIX "")
|
||||
|
||||
add_definitions("-DWINNT_CROSS_COMPILE")
|
||||
|
||||
# target environment on the build host system
|
||||
# second one is for non-root installs
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX} /usr/local/opt/mingw-w64/toolchain-x86_64/ /opt/mingw64 /home/$ENV{USER}/mingw32 /home/$ENV{USER}/mingw64 /home/$ENV{USER}/mingw64/${TOOLCHAIN_PREFIX} /home/$ENV{USER}/mingw32/${TOOLCHAIN_PREFIX})
|
||||
|
||||
# modify default behavior of FIND_XXX() commands
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
# cross compilers to use
|
||||
if($ENV{COMPILER} MATCHES "clang")
|
||||
set(USING_CLANG ON)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-clang)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-clang++)
|
||||
else()
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc${TOOLCHAIN_SUFFIX})
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++${TOOLCHAIN_SUFFIX})
|
||||
add_compile_options("-Wa,-mbig-obj")
|
||||
endif()
|
||||
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
||||
set(WIN64_CROSS_COMPILE ON)
|
||||
|
||||
set(TOOLCHAIN_PATHS
|
||||
/usr/${TOOLCHAIN_PREFIX}
|
||||
/usr/local/opt/mingw-w64/toolchain-x86_64
|
||||
/usr/local/opt/mingw-w64/toolchain-x86_64/x86_64-w64-mingw32
|
||||
/opt/mingw64
|
||||
/home/$ENV{USER}/mingw32
|
||||
/home/$ENV{USER}/mingw64
|
||||
/home/$ENV{USER}/mingw64/${TOOLCHAIN_PREFIX}
|
||||
/home/$ENV{USER}/mingw32/${TOOLCHAIN_PREFIX})
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/mingw_core.cmake")
|
||||
|
|
|
@ -1,26 +1,15 @@
|
|||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(TOOLCHAIN_PREFIX i686-w64-mingw32)
|
||||
|
||||
add_definitions("-DWINNT_CROSS_COMPILE")
|
||||
|
||||
# target environment on the build host system
|
||||
# second one is for non-root installs
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX} /opt/mingw32 /home/$ENV{USER}/mingw32 /home/$ENV{USER}/mingw32/${TOOLCHAIN_PREFIX})
|
||||
|
||||
# modify default behavior of FIND_XXX() commands
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
# cross compilers to use
|
||||
if($ENV{COMPILER} MATCHES "clang")
|
||||
set(USING_CLANG ON)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-clang)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-clang++)
|
||||
else()
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||
endif()
|
||||
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
||||
set(TOOLCHAIN_SUFFIX "")
|
||||
set(WOW64_CROSS_COMPILE ON)
|
||||
|
||||
set(TOOLCHAIN_PATHS
|
||||
/usr/${TOOLCHAIN_PREFIX}
|
||||
/usr/local/opt/mingw-w64/toolchain-i686
|
||||
/usr/local/opt/mingw-w64/toolchain-i686/i686-w64-mingw32
|
||||
/opt/mingw32
|
||||
/home/$ENV{USER}/mingw32
|
||||
/home/$ENV{USER}/mingw32/${TOOLCHAIN_PREFIX}
|
||||
)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/mingw_core.cmake")
|
||||
|
|
24
contrib/cross/mingw_core.cmake
Normal file
24
contrib/cross/mingw_core.cmake
Normal file
|
@ -0,0 +1,24 @@
|
|||
# target environment on the build host system
|
||||
# second one is for non-root installs
|
||||
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PATHS})
|
||||
|
||||
add_definitions("-DWINNT_CROSS_COMPILE")
|
||||
|
||||
# modify default behavior of FIND_XXX() commands
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
# cross compilers to use
|
||||
if($ENV{COMPILER} MATCHES "clang")
|
||||
set(USING_CLANG ON)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-clang)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-clang++)
|
||||
else()
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc${TOOLCHAIN_SUFFIX})
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++${TOOLCHAIN_SUFFIX})
|
||||
add_compile_options("-Wa,-mbig-obj")
|
||||
endif()
|
||||
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
1
contrib/py/admin/.gitignore
vendored
Normal file
1
contrib/py/admin/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
v/
|
266
contrib/py/admin/lokinetmon
Executable file
266
contrib/py/admin/lokinetmon
Executable file
|
@ -0,0 +1,266 @@
|
|||
#!/usr/bin/env python3
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
import curses
|
||||
import math
|
||||
import traceback
|
||||
|
||||
|
||||
class Monitor:
|
||||
|
||||
_speedSamples = 8
|
||||
_globalspeed = []
|
||||
|
||||
def __init__(self, url):
|
||||
self.data = dict()
|
||||
self.win = curses.initscr()
|
||||
self._url = url
|
||||
while len(self._globalspeed) < self._speedSamples:
|
||||
self._globalspeed.append((0, 0))
|
||||
|
||||
def __del__(self):
|
||||
curses.endwin()
|
||||
|
||||
def on_timer(self, event):
|
||||
"""called on timer event"""
|
||||
self.update_data()
|
||||
|
||||
def jsonrpc(self, meth, params):
|
||||
r = requests.post(
|
||||
self._url,
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": "0",
|
||||
"method": "{}".format(meth),
|
||||
"params": params,
|
||||
},
|
||||
)
|
||||
return r.json()
|
||||
|
||||
def update_data(self):
|
||||
"""update data from lokinet"""
|
||||
try:
|
||||
j = self.jsonrpc("llarp.admin.dumpstate", {})
|
||||
self.data = j["result"]
|
||||
except Exception as ex:
|
||||
self.data = None
|
||||
|
||||
def _render_path(self, y, path, name):
|
||||
"""render a path at current position"""
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("({}) ".format(name))
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
y += 1
|
||||
self.win.addstr("me -> ")
|
||||
for hop in path["hops"]:
|
||||
self.win.addstr(" {} ->".format(hop["router"][:4]))
|
||||
self.win.addstr(" [{} ms latency]".format(path["intro"]["latency"]))
|
||||
self.win.addstr(" [{} until expire]".format(self.timeTo(path["expiresAt"])))
|
||||
if path["expiresSoon"]:
|
||||
self.win.addstr("(expiring)")
|
||||
elif path["expired"]:
|
||||
self.win.addstr("(expired)")
|
||||
return y
|
||||
|
||||
def timeTo(self, ts):
|
||||
""" return time until timestamp in seconds formatted"""
|
||||
now = time.time() * 1000
|
||||
return "{} seconds".format(int((ts - now) / 1000))
|
||||
|
||||
def speedOf(self, rate):
|
||||
"""turn int speed into string formatted"""
|
||||
units = ["B", "KB", "MB", "GB"]
|
||||
idx = 0
|
||||
while rate > 1000 and idx < len(units):
|
||||
rate /= 1000.0
|
||||
idx += 1
|
||||
return "{} {}ps".format("%.2f" % rate, units[idx])
|
||||
|
||||
def display_service(self, y, name, status):
|
||||
"""display a service at current position"""
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("service [{}]".format(name))
|
||||
build = status["buildStats"]
|
||||
ratio = build["success"] / (build["attempts"] or 1)
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("build success: {} %".format(int(100 * ratio)))
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
paths = status["paths"]
|
||||
self.win.addstr("paths: {}".format(len(paths)))
|
||||
for path in paths:
|
||||
y = self._render_path(y, path, "inbound")
|
||||
for session in status["remoteSessions"]:
|
||||
for path in session["paths"]:
|
||||
y = self._render_path(
|
||||
y, path, "[active] {}".format(session["currentConvoTag"])
|
||||
)
|
||||
for session in status["snodeSessions"]:
|
||||
for path in session["paths"]:
|
||||
y = self._render_path(y, path, "[snode]")
|
||||
return y
|
||||
|
||||
# for k in status:
|
||||
# self.win.move(y + 1, 1)
|
||||
# y += 1
|
||||
# self.win.addstr('{}: {}'.format(k, json.dumps(status[k])))
|
||||
|
||||
def display_links(self, y, data):
|
||||
self.txrate = 0
|
||||
self.rxrate = 0
|
||||
for link in data["outbound"]:
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("outbound sessions:")
|
||||
y = self.display_link(y, link)
|
||||
for link in data["inbound"]:
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("inbound sessions:")
|
||||
y = self.display_link(y, link)
|
||||
y += 2
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr(
|
||||
"global speed:\t\t[{}\ttx]\t[{}\trx]".format(
|
||||
self.speedOf(self.txrate), self.speedOf(self.rxrate)
|
||||
)
|
||||
)
|
||||
|
||||
self._globalspeed.append((self.txrate, self.rxrate))
|
||||
while len(self._globalspeed) > self._speedSamples:
|
||||
self._globalspeed.pop(0)
|
||||
return self.display_speedgraph(y + 2, self._globalspeed)
|
||||
|
||||
def display_speedgraph(self, y, samps, maxsz=20):
|
||||
""" display global speed graph """
|
||||
|
||||
def scale(x, n):
|
||||
while n > 0:
|
||||
x /= 2
|
||||
n -= 1
|
||||
return int(x)
|
||||
|
||||
txmax, rxmax = 1000, 1000
|
||||
for tx, rx in samps:
|
||||
if tx > txmax:
|
||||
txmax = tx
|
||||
if rx > rxmax:
|
||||
rxmax = rx
|
||||
|
||||
rxscale = 0
|
||||
while rxmax > maxsz:
|
||||
rxscale += 1
|
||||
rxmax /= 2
|
||||
|
||||
txscale = 0
|
||||
while txmax > maxsz:
|
||||
txscale += 1
|
||||
txmax /= 2
|
||||
|
||||
def makebar(samp, max):
|
||||
bar = "#" * samp
|
||||
pad = " " * (max - samp)
|
||||
return pad, bar
|
||||
|
||||
txlabelpad = int(txmax / 2) - 1
|
||||
rxlabelpad = int(rxmax / 2) - 1
|
||||
if txlabelpad <= 0:
|
||||
txlabelpad = 1
|
||||
if rxlabelpad <= 0:
|
||||
rxlabelpad = 1
|
||||
txlabelpad = " " * txlabelpad
|
||||
rxlabelpad = " " * rxlabelpad
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr(
|
||||
"{}tx{}{}rx{}".format(txlabelpad, txlabelpad, rxlabelpad, rxlabelpad)
|
||||
)
|
||||
for tx, rx in samps:
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
txpad, txbar = makebar(scale(tx, txscale), int(txmax))
|
||||
rxpad, rxbar = makebar(scale(rx, rxscale), int(rxmax))
|
||||
self.win.addstr("{}{}|{}{}".format(txpad, txbar, rxbar, rxpad))
|
||||
return y + 2
|
||||
|
||||
def display_link(self, y, link):
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
sessions = link["sessions"]["established"]
|
||||
for s in sessions:
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.txrate += s["tx"]
|
||||
self.rxrate += s["rx"]
|
||||
self.win.addstr(
|
||||
"{}\t[{}\ttx]\t[{}\trx]".format(
|
||||
s["remoteAddr"], self.speedOf(s["tx"]), self.speedOf(s["rx"])
|
||||
)
|
||||
)
|
||||
if s["sendBacklog"] > 0:
|
||||
self.win.addstr("[backlog {}]".format(s["sendBacklog"]))
|
||||
return y
|
||||
|
||||
def display_dht(self, y, data):
|
||||
y += 2
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("DHT:")
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("introset lookups")
|
||||
y = self.display_bucket(y, data["pendingIntrosetLookups"])
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("router lookups")
|
||||
return self.display_bucket(y, data["pendingRouterLookups"])
|
||||
|
||||
def display_bucket(self, y, data):
|
||||
txs = data["tx"]
|
||||
self.win.addstr(" ({} lookups)".format(len(txs)))
|
||||
for tx in txs:
|
||||
y += 1
|
||||
self.win.move(y, 1)
|
||||
self.win.addstr("search for {}".format(tx["tx"]["target"]))
|
||||
return y
|
||||
|
||||
def display_data(self):
|
||||
"""draw main window"""
|
||||
if self.data is not None:
|
||||
self.win.addstr(1, 1, "lokinet online")
|
||||
# print(self.data)
|
||||
services = self.data["services"] or {}
|
||||
y = 3
|
||||
try:
|
||||
y = self.display_links(y, self.data["links"])
|
||||
for k in services:
|
||||
y = self.display_service(y, k, services[k])
|
||||
y = self.display_dht(y, self.data["dht"])
|
||||
except Exception as exc:
|
||||
pass
|
||||
else:
|
||||
self.win.move(1, 1)
|
||||
self.win.addstr("lokinet offline")
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.win.clear()
|
||||
self.win.box()
|
||||
self.update_data()
|
||||
self.display_data()
|
||||
self.win.refresh()
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
mon = Monitor(
|
||||
"http://{}/jsonrpc".format(
|
||||
len(sys.argv) > 1 and sys.argv[1] or "127.0.0.1:1190"
|
||||
)
|
||||
)
|
||||
mon.run()
|
1
contrib/py/admin/requirements.txt
Normal file
1
contrib/py/admin/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
requests
|
|
@ -1,598 +1,99 @@
|
|||
#include <buffer.hpp>
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <fs.hpp>
|
||||
#include <llarp.h>
|
||||
#include <logger.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <net.hpp>
|
||||
#include <nodedb.hpp>
|
||||
#include <router.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <time.hpp>
|
||||
#include <util/logger.hpp>
|
||||
#include <util/ostream_logger.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <absl/synchronization/mutex.h>
|
||||
#include <cxxopts.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct llarp_main *ctx = 0;
|
||||
|
||||
void
|
||||
handle_signal(int sig)
|
||||
bool
|
||||
dumpRc(const std::vector< std::string >& files, bool json)
|
||||
{
|
||||
if(ctx)
|
||||
llarp_main_signal(ctx, sig);
|
||||
}
|
||||
|
||||
#ifndef TESTNET
|
||||
#define TESTNET 0
|
||||
#endif
|
||||
|
||||
void
|
||||
displayRC(const llarp::RouterContact &rc)
|
||||
{
|
||||
std::cout << rc.pubkey << std::endl;
|
||||
for(const auto &addr : rc.addrs)
|
||||
nlohmann::json result;
|
||||
for(const auto& file : files)
|
||||
{
|
||||
std::cout << "AddressInfo: " << addr << std::endl;
|
||||
}
|
||||
}
|
||||
llarp::RouterContact rc;
|
||||
const bool ret = rc.Read(file.c_str());
|
||||
|
||||
// fwd declr
|
||||
struct check_online_request;
|
||||
|
||||
void
|
||||
HandleDHTLocate(llarp_router_lookup_job *job)
|
||||
{
|
||||
llarp::LogInfo("DHT result: ", job->found ? "found" : "not found");
|
||||
if(job->found)
|
||||
{
|
||||
// save to nodedb?
|
||||
displayRC(job->result);
|
||||
}
|
||||
// shutdown router
|
||||
|
||||
// well because we're in the gotroutermessage, we can't sigint because we'll
|
||||
// deadlock because we're session locked
|
||||
// llarp_main_signal(ctx, SIGINT);
|
||||
|
||||
// llarp_timer_run(logic->timer, logic->thread);
|
||||
// we'll we don't want logic thread
|
||||
// but we want to switch back to the main thread
|
||||
// llarp_logic_stop();
|
||||
// still need to exit this logic thread...
|
||||
llarp_main_abort(ctx);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
// take -c to set location of daemon.ini
|
||||
// take -o to set log level
|
||||
// --generate-blank /path/to/file.signed
|
||||
// --update-ifs /path/to/file.signed
|
||||
// --key /path/to/long_term_identity.key
|
||||
// --import
|
||||
// --export
|
||||
|
||||
// --generate /path/to/file.signed
|
||||
// --update /path/to/file.signed
|
||||
// --verify /path/to/file.signed
|
||||
// printf("has [%d]options\n", argc);
|
||||
if(argc < 2)
|
||||
{
|
||||
printf(
|
||||
"please specify: \n"
|
||||
"--generate with a path to a router contact file\n"
|
||||
"--update with a path to a router contact file\n"
|
||||
"--list path to nodedb skiplist\n"
|
||||
"--import with a path to a router contact file\n"
|
||||
"--export a hex formatted public key\n"
|
||||
"--locate a hex formatted public key\n"
|
||||
"--find a base32 formatted service address\n"
|
||||
"--b32 a hex formatted public key\n"
|
||||
"--hex a base32 formatted public key\n"
|
||||
"--localInfo \n"
|
||||
"--read with a path to a router contact file\n"
|
||||
"--verify with a path to a router contact file\n"
|
||||
"\n");
|
||||
return 0;
|
||||
}
|
||||
bool haveRequiredOptions = false;
|
||||
bool genMode = false;
|
||||
bool updMode = false;
|
||||
bool listMode = false;
|
||||
bool importMode = false;
|
||||
bool exportMode = false;
|
||||
bool locateMode = false;
|
||||
bool findMode = false;
|
||||
bool localMode = false;
|
||||
bool verifyMode = false;
|
||||
bool readMode = false;
|
||||
bool toHexMode = false;
|
||||
bool toB32Mode = false;
|
||||
int c;
|
||||
char *conffname;
|
||||
char defaultConfName[] = "daemon.ini";
|
||||
conffname = defaultConfName;
|
||||
char *rcfname = nullptr;
|
||||
char *nodesdir = nullptr;
|
||||
|
||||
llarp::RouterContact rc;
|
||||
while(1)
|
||||
{
|
||||
static struct option long_options[] = {
|
||||
{"file", required_argument, 0, 'f'},
|
||||
{"config", required_argument, 0, 'c'},
|
||||
{"logLevel", required_argument, 0, 'o'},
|
||||
{"generate", required_argument, 0, 'g'},
|
||||
{"update", required_argument, 0, 'u'},
|
||||
{"list", required_argument, 0, 'l'},
|
||||
{"import", required_argument, 0, 'i'},
|
||||
{"export", required_argument, 0, 'e'},
|
||||
{"locate", required_argument, 0, 'q'},
|
||||
{"find", required_argument, 0, 'F'},
|
||||
{"localInfo", no_argument, 0, 'n'},
|
||||
{"read", required_argument, 0, 'r'},
|
||||
{"b32", required_argument, 0, 'b'},
|
||||
{"hex", required_argument, 0, 'h'},
|
||||
{"verify", required_argument, 0, 'V'},
|
||||
{0, 0, 0, 0}};
|
||||
int option_index = 0;
|
||||
c = getopt_long(argc, argv, "c:f:o:g:lu:i:e:q:F:nr:b:h:V:", long_options,
|
||||
&option_index);
|
||||
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
|
||||
if(c == -1)
|
||||
break;
|
||||
switch(c)
|
||||
if(ret)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 'c':
|
||||
conffname = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
if(strncmp(optarg, "debug",
|
||||
MIN(strlen(optarg), static_cast< unsigned long >(5)))
|
||||
== 0)
|
||||
{
|
||||
llarp::SetLogLevel(llarp::eLogDebug);
|
||||
}
|
||||
else if(strncmp(optarg, "info",
|
||||
MIN(strlen(optarg), static_cast< unsigned long >(4)))
|
||||
== 0)
|
||||
{
|
||||
llarp::SetLogLevel(llarp::eLogInfo);
|
||||
}
|
||||
else if(strncmp(optarg, "warn",
|
||||
MIN(strlen(optarg), static_cast< unsigned long >(4)))
|
||||
== 0)
|
||||
{
|
||||
llarp::SetLogLevel(llarp::eLogWarn);
|
||||
}
|
||||
else if(strncmp(optarg, "error",
|
||||
MIN(strlen(optarg), static_cast< unsigned long >(5)))
|
||||
== 0)
|
||||
{
|
||||
llarp::SetLogLevel(llarp::eLogError);
|
||||
}
|
||||
break;
|
||||
case 'V':
|
||||
rcfname = optarg;
|
||||
haveRequiredOptions = true;
|
||||
verifyMode = true;
|
||||
break;
|
||||
case 'f':
|
||||
rcfname = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
nodesdir = optarg;
|
||||
listMode = true;
|
||||
break;
|
||||
case 'i':
|
||||
// printf ("option -g with value `%s'\n", optarg);
|
||||
nodesdir = optarg;
|
||||
importMode = true;
|
||||
break;
|
||||
case 'e':
|
||||
// printf ("option -g with value `%s'\n", optarg);
|
||||
rcfname = optarg;
|
||||
exportMode = true;
|
||||
break;
|
||||
case 'q':
|
||||
// printf ("option -g with value `%s'\n", optarg);
|
||||
rcfname = optarg;
|
||||
locateMode = true;
|
||||
break;
|
||||
case 'F':
|
||||
rcfname = optarg;
|
||||
haveRequiredOptions = true;
|
||||
findMode = true;
|
||||
break;
|
||||
case 'g':
|
||||
// printf ("option -g with value `%s'\n", optarg);
|
||||
rcfname = optarg;
|
||||
genMode = true;
|
||||
break;
|
||||
case 'u':
|
||||
// printf ("option -u with value `%s'\n", optarg);
|
||||
rcfname = optarg;
|
||||
updMode = true;
|
||||
break;
|
||||
case 'n':
|
||||
localMode = true;
|
||||
break;
|
||||
case 'r':
|
||||
rcfname = optarg;
|
||||
readMode = true;
|
||||
break;
|
||||
case 'b':
|
||||
rcfname = optarg;
|
||||
haveRequiredOptions = true;
|
||||
toB32Mode = true;
|
||||
break;
|
||||
case 'h':
|
||||
rcfname = optarg;
|
||||
haveRequiredOptions = true;
|
||||
toHexMode = true;
|
||||
break;
|
||||
default:
|
||||
printf("Bad option: %c\n", c);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#undef MIN
|
||||
if(!haveRequiredOptions)
|
||||
{
|
||||
llarp::LogError("Parameters dont all have their required parameters.\n");
|
||||
return 0;
|
||||
}
|
||||
// printf("parsed options\n");
|
||||
|
||||
if(!genMode && !updMode && !listMode && !importMode && !exportMode
|
||||
&& !locateMode && !localMode && !readMode && !findMode && !toB32Mode
|
||||
&& !toHexMode && !verifyMode)
|
||||
{
|
||||
llarp::LogError(
|
||||
"I don't know what to do, no generate or update parameter\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef LOKINET_DEBUG
|
||||
absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kAbort);
|
||||
#endif
|
||||
|
||||
llarp::RouterContact tmp;
|
||||
|
||||
if(verifyMode)
|
||||
{
|
||||
llarp::Crypto crypto(llarp::Crypto::sodium{});
|
||||
if(!rc.Read(rcfname))
|
||||
{
|
||||
std::cout << "failed to read " << rcfname << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(!rc.Verify(&crypto))
|
||||
{
|
||||
std::cout << rcfname << " is invalid" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(!rc.IsPublicRouter())
|
||||
{
|
||||
std::cout << rcfname << " is not a public router";
|
||||
if(rc.addrs.size() == 0)
|
||||
if(json)
|
||||
{
|
||||
std::cout << " because it has no public addresses";
|
||||
result[file] = rc.ToJson();
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "router identity and dht routing key: " << rc.pubkey
|
||||
<< std::endl;
|
||||
|
||||
std::cout << "router encryption key: " << rc.enckey << std::endl;
|
||||
|
||||
if(rc.HasNick())
|
||||
std::cout << "router nickname: " << rc.Nick() << std::endl;
|
||||
|
||||
std::cout << "advertised addresses: " << std::endl;
|
||||
for(const auto &addr : rc.addrs)
|
||||
{
|
||||
std::cout << addr << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "advertised exits: ";
|
||||
if(rc.exits.size())
|
||||
{
|
||||
for(const auto &exit : rc.exits)
|
||||
else
|
||||
{
|
||||
std::cout << exit << std::endl;
|
||||
std::cout << "file = " << file << "\n";
|
||||
std::cout << rc << "\n\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "none";
|
||||
std::cerr << "file = " << file << " was not a valid rc file\n";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx = llarp_main_init(conffname, !TESTNET);
|
||||
if(!ctx)
|
||||
if(json)
|
||||
std::cout << result << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef LOKINET_DEBUG
|
||||
absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kAbort);
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
cxxopts::Options options(
|
||||
"lokinet-rcutil",
|
||||
"LokiNET is a free, open source, private, decentralized, \"market based sybil resistant\" and IP based onion routing network"
|
||||
);
|
||||
|
||||
options.add_options()
|
||||
("v,verbose", "Verbose", cxxopts::value<bool>())
|
||||
("h,help", "help", cxxopts::value<bool>())
|
||||
("j,json", "output in json", cxxopts::value<bool>())
|
||||
("dump", "dump rc file", cxxopts::value<std::vector<std::string> >(), "FILE");
|
||||
// clang-format on
|
||||
|
||||
try
|
||||
{
|
||||
llarp::LogError("Cant set up context");
|
||||
const auto result = options.parse(argc, argv);
|
||||
|
||||
const bool json = result["json"].as< bool >();
|
||||
|
||||
if(result.count("verbose") > 0)
|
||||
{
|
||||
SetLogLevel(llarp::eLogDebug);
|
||||
llarp::LogContext::Instance().logStream =
|
||||
std::make_unique< llarp::OStreamLogStream >(std::cerr);
|
||||
llarp::LogDebug("debug logging activated");
|
||||
}
|
||||
|
||||
if(result.count("help") > 0)
|
||||
{
|
||||
std::cout << options.help() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(result.count("dump") > 0)
|
||||
{
|
||||
if(!dumpRc(result["dump"].as< std::vector< std::string > >(), json))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const cxxopts::OptionParseException& ex)
|
||||
{
|
||||
std::cerr << ex.what() << std::endl;
|
||||
std::cout << options.help() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
signal(SIGINT, handle_signal);
|
||||
|
||||
// is this Neuro or Jeff's?
|
||||
// this is the only one...
|
||||
if(listMode)
|
||||
{
|
||||
llarp::Crypto crypto(llarp::Crypto::sodium{});
|
||||
auto nodedb = llarp_nodedb_new(&crypto);
|
||||
llarp_nodedb_iter itr;
|
||||
itr.visit = [](llarp_nodedb_iter *i) -> bool {
|
||||
std::cout << i->rc->pubkey << std::endl;
|
||||
return true;
|
||||
};
|
||||
if(llarp_nodedb_load_dir(nodedb, nodesdir) > 0)
|
||||
llarp_nodedb_iterate_all(nodedb, itr);
|
||||
llarp_nodedb_free(&nodedb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(importMode)
|
||||
{
|
||||
if(rcfname == nullptr)
|
||||
{
|
||||
std::cout << "no file to import" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
llarp::Crypto crypto(llarp::Crypto::sodium{});
|
||||
auto nodedb = llarp_nodedb_new(&crypto);
|
||||
if(!llarp_nodedb_ensure_dir(nodesdir))
|
||||
{
|
||||
std::cout << "failed to ensure " << nodesdir << strerror(errno)
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
llarp_nodedb_set_dir(nodedb, nodesdir);
|
||||
if(!rc.Read(rcfname))
|
||||
{
|
||||
std::cout << "failed to read " << rcfname << " " << strerror(errno)
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!rc.Verify(&crypto))
|
||||
{
|
||||
std::cout << rcfname << " is invalid" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!llarp_nodedb_put_rc(nodedb, rc))
|
||||
{
|
||||
std::cout << "failed to store " << strerror(errno) << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "imported " << rc.pubkey << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(genMode)
|
||||
{
|
||||
printf("Creating [%s]\n", rcfname);
|
||||
// if we zero it out then
|
||||
// set updated timestamp
|
||||
rc.last_updated = llarp::time_now_ms();
|
||||
// load longterm identity
|
||||
llarp::Crypto crypt(llarp::Crypto::sodium{});
|
||||
|
||||
// which is in daemon.ini config: router.encryption-privkey (defaults
|
||||
// "encryption.key")
|
||||
fs::path encryption_keyfile = "encryption.key";
|
||||
llarp::SecretKey encryption;
|
||||
|
||||
llarp_findOrCreateEncryption(&crypt, encryption_keyfile, encryption);
|
||||
|
||||
rc.enckey = llarp::seckey_topublic(encryption);
|
||||
|
||||
// get identity public sig key
|
||||
fs::path ident_keyfile = "identity.key";
|
||||
llarp::SecretKey identity;
|
||||
llarp_findOrCreateIdentity(&crypt, ident_keyfile, identity);
|
||||
|
||||
rc.pubkey = llarp::seckey_topublic(identity);
|
||||
|
||||
// this causes a segfault
|
||||
if(!rc.Sign(&crypt, identity))
|
||||
{
|
||||
std::cout << "failed to sign" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
// set filename
|
||||
fs::path our_rc_file = rcfname;
|
||||
// write file
|
||||
rc.Write(our_rc_file.string().c_str());
|
||||
|
||||
// llarp_rc_write(&tmp, our_rc_file.string().c_str());
|
||||
|
||||
// release memory for tmp lists
|
||||
// llarp_rc_free(&tmp);
|
||||
}
|
||||
if(updMode)
|
||||
{
|
||||
printf("rcutil.cpp - Loading [%s]\n", rcfname);
|
||||
llarp::RouterContact tmp;
|
||||
// llarp_rc_clear(&rc);
|
||||
rc.Clear();
|
||||
// FIXME: new rc api
|
||||
// llarp_rc_read(rcfname, &rc);
|
||||
|
||||
// set updated timestamp
|
||||
rc.last_updated = llarp::time_now_ms();
|
||||
// load longterm identity
|
||||
llarp::Crypto crypt(llarp::Crypto::sodium{});
|
||||
|
||||
// no longer used?
|
||||
// llarp_crypto_libsodium_init(&crypt);
|
||||
llarp::SecretKey identityKey; // FIXME: Jeff requests we use this
|
||||
fs::path ident_keyfile = "identity.key";
|
||||
llarp::SecretKey identity;
|
||||
llarp_findOrCreateIdentity(&crypt, ident_keyfile, identity);
|
||||
|
||||
// FIXME: update RC API
|
||||
// get identity public key
|
||||
// const uint8_t *pubkey = llarp::seckey_topublic(identity);
|
||||
|
||||
// FIXME: update RC API
|
||||
// llarp_rc_set_pubsigkey(&rc, pubkey);
|
||||
// // FIXME: update RC API
|
||||
// llarp_rc_sign(&crypt, identity, &rc);
|
||||
|
||||
// set filename
|
||||
fs::path our_rc_file_out = "update_debug.rc";
|
||||
// write file
|
||||
// FIXME: update RC API
|
||||
// rc.Write(our_rc_file.string().c_str());
|
||||
// llarp_rc_write(&tmp, our_rc_file_out.string().c_str());
|
||||
}
|
||||
|
||||
if(listMode)
|
||||
{
|
||||
llarp::Crypto crypto(llarp::Crypto::sodium{});
|
||||
auto nodedb = llarp_nodedb_new(&crypto);
|
||||
llarp_nodedb_iter itr;
|
||||
itr.visit = [](llarp_nodedb_iter *i) -> bool {
|
||||
std::cout << llarp::PubKey(i->rc->pubkey) << std::endl;
|
||||
return true;
|
||||
};
|
||||
if(llarp_nodedb_load_dir(nodedb, nodesdir) > 0)
|
||||
llarp_nodedb_iterate_all(nodedb, itr);
|
||||
llarp_nodedb_free(&nodedb);
|
||||
return 0;
|
||||
}
|
||||
if(exportMode)
|
||||
{
|
||||
llarp_main_loadDatabase(ctx);
|
||||
// llarp::LogInfo("Looking for string: ", rcfname);
|
||||
|
||||
llarp::PubKey binaryPK;
|
||||
llarp::HexDecode(rcfname, binaryPK.data(), binaryPK.size());
|
||||
|
||||
llarp::LogInfo("Looking for binary: ", binaryPK);
|
||||
llarp::RouterContact *rc = llarp_main_getDatabase(ctx, binaryPK.data());
|
||||
if(!rc)
|
||||
{
|
||||
llarp::LogError("Can't load RC from database");
|
||||
}
|
||||
std::string filename(rcfname);
|
||||
filename.append(".signed");
|
||||
llarp::LogInfo("Writing out: ", filename);
|
||||
// FIXME: update RC API
|
||||
// rc.Write(our_rc_file.string().c_str());
|
||||
// llarp_rc_write(rc, filename.c_str());
|
||||
}
|
||||
if(locateMode)
|
||||
{
|
||||
llarp::LogInfo("Going online");
|
||||
llarp_main_setup(ctx);
|
||||
|
||||
llarp::PubKey binaryPK;
|
||||
llarp::HexDecode(rcfname, binaryPK.data(), binaryPK.size());
|
||||
|
||||
llarp::LogInfo("Queueing job");
|
||||
llarp_router_lookup_job *job = new llarp_router_lookup_job;
|
||||
job->iterative = true;
|
||||
job->found = false;
|
||||
job->hook = &HandleDHTLocate;
|
||||
// llarp_rc_new(&job->result);
|
||||
job->target = binaryPK; // set job's target
|
||||
|
||||
// create query DHT request
|
||||
check_online_request *request = new check_online_request;
|
||||
request->ptr = ctx;
|
||||
request->job = job;
|
||||
request->online = false;
|
||||
request->nodes = 0;
|
||||
request->first = false;
|
||||
llarp_main_queryDHT(request);
|
||||
|
||||
llarp::LogInfo("Processing");
|
||||
// run system and wait
|
||||
llarp_main_run(ctx);
|
||||
}
|
||||
if(findMode)
|
||||
{
|
||||
llarp::LogInfo("Going online");
|
||||
llarp_main_setup(ctx);
|
||||
|
||||
llarp::LogInfo("Please find ", rcfname);
|
||||
std::string str(rcfname);
|
||||
|
||||
llarp::service::Tag tag(rcfname);
|
||||
llarp::LogInfo("Tag ", tag);
|
||||
|
||||
llarp::service::Address addr;
|
||||
str = str.append(".loki");
|
||||
llarp::LogInfo("Prestring ", str);
|
||||
bool res = addr.FromString(str.c_str());
|
||||
llarp::LogInfo(res ? "Success" : "not a base32 string");
|
||||
|
||||
// Base32Decode(rcfname, addr);
|
||||
llarp::LogInfo("Addr ", addr);
|
||||
|
||||
// uint64_t txid, const llarp::service::Address& addr
|
||||
// FIXME: new API?
|
||||
// msg->M.push_back(new llarp::dht::FindIntroMessage(tag, 1));
|
||||
|
||||
// I guess we may need a router to get any replies
|
||||
llarp::LogInfo("Processing");
|
||||
// run system and wait
|
||||
llarp_main_run(ctx);
|
||||
}
|
||||
if(localMode)
|
||||
{
|
||||
// FIXME: update llarp_main_getLocalRC
|
||||
// llarp::RouterContact *rc = llarp_main_getLocalRC(ctx);
|
||||
// displayRC(rc);
|
||||
// delete it
|
||||
}
|
||||
{
|
||||
if(rc.Read(rcfname))
|
||||
displayRC(rc);
|
||||
}
|
||||
|
||||
if(toB32Mode)
|
||||
{
|
||||
llarp::LogInfo("Converting hex string ", rcfname);
|
||||
std::string str(rcfname);
|
||||
|
||||
llarp::PubKey binaryPK;
|
||||
// llarp::service::Address::FromString
|
||||
llarp::HexDecode(rcfname, binaryPK.data(), binaryPK.size());
|
||||
char tmp[(1 + 32) * 2] = {0};
|
||||
std::string b32 = llarp::Base32Encode(binaryPK, tmp);
|
||||
llarp::LogInfo("to base32 ", b32);
|
||||
}
|
||||
if(toHexMode)
|
||||
{
|
||||
llarp::service::Address addr;
|
||||
llarp::Base32Decode(rcfname, addr);
|
||||
llarp::LogInfo("Converting base32 string ", addr);
|
||||
|
||||
// llarp::service::Address::ToString
|
||||
char ftmp[68] = {0};
|
||||
const char *hexname =
|
||||
llarp::HexEncode< llarp::service::Address, decltype(ftmp) >(addr, ftmp);
|
||||
|
||||
llarp::LogInfo("to hex ", hexname);
|
||||
}
|
||||
// it's a unique_ptr, should clean up itself
|
||||
// llarp_main_free(ctx);
|
||||
return 0; // success
|
||||
return 0;
|
||||
}
|
||||
|
|
6
docker/compose/bootstrap.Dockerfile
Normal file
6
docker/compose/bootstrap.Dockerfile
Normal file
|
@ -0,0 +1,6 @@
|
|||
FROM compose-base:latest
|
||||
|
||||
COPY ./docker/compose/bootstrap.ini /root/.lokinet/lokinet.ini
|
||||
|
||||
CMD ["/lokinet"]
|
||||
EXPOSE 1090/udp 1190/tcp
|
76
docker/compose/bootstrap.ini
Normal file
76
docker/compose/bootstrap.ini
Normal file
|
@ -0,0 +1,76 @@
|
|||
# this configuration was auto generated with 'sane' defaults
|
||||
# change these values as desired
|
||||
|
||||
|
||||
[router]
|
||||
# number of crypto worker threads
|
||||
threads=4
|
||||
# path to store signed RC
|
||||
contact-file=/root/.lokinet/self.signed
|
||||
# path to store transport private key
|
||||
transport-privkey=/root/.lokinet/transport.private
|
||||
# path to store identity signing key
|
||||
ident-privkey=/root/.lokinet/identity.private
|
||||
# encryption key for onion routing
|
||||
encryption-privkey=/root/.lokinet/encryption.private
|
||||
|
||||
# uncomment following line to set router nickname to 'lokinet'
|
||||
#nickname=lokinet
|
||||
|
||||
|
||||
[logging]
|
||||
level=info
|
||||
# uncomment for logging to file
|
||||
#type=file
|
||||
#file=/path/to/logfile
|
||||
# uncomment for syslog logging
|
||||
#type=syslog
|
||||
|
||||
[metrics]
|
||||
json-metrics-path=/root/.lokinet/metrics.json
|
||||
|
||||
# admin api (disabled by default)
|
||||
[api]
|
||||
enabled=true
|
||||
#authkey=insertpubkey1here
|
||||
#authkey=insertpubkey2here
|
||||
#authkey=insertpubkey3here
|
||||
bind=127.0.0.1:1190
|
||||
|
||||
# system settings for privileges and such
|
||||
[system]
|
||||
user=lokinet
|
||||
group=lokinet
|
||||
pidfile=/root/.lokinet/lokinet.pid
|
||||
|
||||
# dns provider configuration section
|
||||
[dns]
|
||||
# resolver
|
||||
upstream=1.1.1.1
|
||||
bind=127.3.2.1:53
|
||||
|
||||
# network database settings block
|
||||
[netdb]
|
||||
# directory for network database skiplist storage
|
||||
dir=/netdb
|
||||
|
||||
# lokid settings (disabled by default)
|
||||
[lokid]
|
||||
enabled=false
|
||||
jsonrpc=127.0.0.1:22023
|
||||
#service-node-seed=/path/to/servicenode/seed
|
||||
|
||||
# network settings
|
||||
[network]
|
||||
profiles=/root/.lokinet/profiles.dat
|
||||
enabled=true
|
||||
exit=false
|
||||
#exit-blacklist=tcp:25
|
||||
#exit-whitelist=tcp:*
|
||||
#exit-whitelist=udp:*
|
||||
ifaddr=10.200.0.1/8
|
||||
ifname=loki-docker0
|
||||
|
||||
# ROUTERS ONLY: publish network interfaces for handling inbound traffic
|
||||
[bind]
|
||||
eth0=1090
|
16
docker/compose/compose-base.Dockerfile
Normal file
16
docker/compose/compose-base.Dockerfile
Normal file
|
@ -0,0 +1,16 @@
|
|||
ARG LOKINET_NETID=docker
|
||||
|
||||
FROM alpine:edge as builder
|
||||
|
||||
RUN apk update && \
|
||||
apk add build-base cmake git libcap-dev libcap-static libuv-dev libuv-static curl ninja bash binutils-gold
|
||||
|
||||
WORKDIR /src/
|
||||
COPY . /src/
|
||||
|
||||
RUN make NINJA=ninja STATIC_LINK=ON BUILD_TYPE=Release
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=builder /src/build/lokinet /
|
||||
COPY --from=builder /src/build/lokinet-rcutil /
|
61
docker/compose/docker-compose.yml
Normal file
61
docker/compose/docker-compose.yml
Normal file
|
@ -0,0 +1,61 @@
|
|||
version: '3.4'
|
||||
services:
|
||||
bootstrap-router:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/compose/bootstrap.Dockerfile
|
||||
image: bootstrap
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
devices:
|
||||
- "/dev/net/tun:/dev/net/tun"
|
||||
ports:
|
||||
- target: 1090
|
||||
protocol: udp
|
||||
mode: host
|
||||
- target: 1190
|
||||
protocol: tcp
|
||||
mode: host
|
||||
volumes:
|
||||
- bootstrap-dir:/root/.lokinet/
|
||||
environment:
|
||||
- LOKINET_NETID=docker
|
||||
networks:
|
||||
testing_net:
|
||||
|
||||
router:
|
||||
depends_on:
|
||||
- bootstrap-router
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/compose/router.Dockerfile
|
||||
image: router
|
||||
devices:
|
||||
- "/dev/net/tun:/dev/net/tun"
|
||||
ports:
|
||||
- target: 1090
|
||||
protocol: udp
|
||||
mode: host
|
||||
- target: 1190
|
||||
protocol: tcp
|
||||
mode: host
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
volumes:
|
||||
- bootstrap-dir:/bootstrap/
|
||||
environment:
|
||||
- LOKINET_NETID=docker
|
||||
networks:
|
||||
testing_net:
|
||||
|
||||
volumes:
|
||||
bootstrap-dir:
|
||||
|
||||
networks:
|
||||
testing_net:
|
||||
driver: bridge
|
||||
internal: true
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: 172.28.0.0/16
|
6
docker/compose/router.Dockerfile
Normal file
6
docker/compose/router.Dockerfile
Normal file
|
@ -0,0 +1,6 @@
|
|||
FROM compose-base:latest
|
||||
|
||||
COPY ./docker/compose/router.ini /root/.lokinet/lokinet.ini
|
||||
|
||||
CMD ["/lokinet"]
|
||||
EXPOSE 1090/udp 1190/tcp
|
82
docker/compose/router.ini
Normal file
82
docker/compose/router.ini
Normal file
|
@ -0,0 +1,82 @@
|
|||
# this configuration was auto generated with 'sane' defaults
|
||||
# change these values as desired
|
||||
|
||||
|
||||
[router]
|
||||
# number of crypto worker threads
|
||||
threads=4
|
||||
# path to store signed RC
|
||||
contact-file=/root/.lokinet/self.signed
|
||||
# path to store transport private key
|
||||
transport-privkey=/root/.lokinet/transport.private
|
||||
# path to store identity signing key
|
||||
ident-privkey=/root/.lokinet/identity.private
|
||||
# encryption key for onion routing
|
||||
encryption-privkey=/root/.lokinet/encryption.private
|
||||
|
||||
# uncomment following line to set router nickname to 'lokinet'
|
||||
#nickname=lokinet
|
||||
|
||||
|
||||
[logging]
|
||||
level=info
|
||||
# uncomment for logging to file
|
||||
#type=file
|
||||
#file=/path/to/logfile
|
||||
# uncomment for syslog logging
|
||||
#type=syslog
|
||||
|
||||
[metrics]
|
||||
json-metrics-path=/root/.lokinet/metrics.json
|
||||
|
||||
# admin api (disabled by default)
|
||||
[api]
|
||||
enabled=true
|
||||
#authkey=insertpubkey1here
|
||||
#authkey=insertpubkey2here
|
||||
#authkey=insertpubkey3here
|
||||
bind=127.0.0.1:1190
|
||||
|
||||
# system settings for privileges and such
|
||||
[system]
|
||||
user=lokinet
|
||||
group=lokinet
|
||||
pidfile=/root/.lokinet/lokinet.pid
|
||||
|
||||
# dns provider configuration section
|
||||
[dns]
|
||||
# resolver
|
||||
upstream=1.1.1.1
|
||||
bind=127.3.2.1:53
|
||||
|
||||
# network database settings block
|
||||
[netdb]
|
||||
# directory for network database skiplist storage
|
||||
dir=/netdb
|
||||
|
||||
# bootstrap settings
|
||||
[bootstrap]
|
||||
# add a bootstrap node's signed identity to the list of nodes we want to bootstrap from
|
||||
# if we don't have any peers we connect to this router
|
||||
add-node=/bootstrap/self.signed
|
||||
|
||||
# lokid settings (disabled by default)
|
||||
[lokid]
|
||||
enabled=false
|
||||
jsonrpc=127.0.0.1:22023
|
||||
#service-node-seed=/path/to/servicenode/seed
|
||||
|
||||
# network settings
|
||||
[network]
|
||||
profiles=/root/.lokinet/profiles.dat
|
||||
enabled=true
|
||||
exit=false
|
||||
#exit-blacklist=tcp:25
|
||||
#exit-whitelist=tcp:*
|
||||
#exit-whitelist=udp:*
|
||||
ifaddr=10.200.0.1/8
|
||||
ifname=loki-docker0
|
||||
|
||||
# ROUTERS ONLY: publish network interfaces for handling inbound traffic
|
||||
[bind]
|
||||
eth0=1090
|
|
@ -1,3 +1,4 @@
|
|||
ARG bootstrap="https://i2p.rocks/i2procks.signed"
|
||||
FROM alpine:edge as builder
|
||||
|
||||
RUN apk update && \
|
||||
|
@ -7,7 +8,7 @@ WORKDIR /src/
|
|||
COPY . /src/
|
||||
|
||||
RUN make NINJA=ninja STATIC_LINK=ON BUILD_TYPE=Release
|
||||
RUN ./lokinet-bootstrap
|
||||
RUN ./lokinet-bootstrap ${bootstrap}
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ set(LIB_UTIL_SRC
|
|||
config/config.cpp
|
||||
config/ini.cpp
|
||||
constants/defaults.cpp
|
||||
constants/limits.cpp
|
||||
constants/link_layer.cpp
|
||||
constants/path.cpp
|
||||
constants/proto.cpp
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <config/ini.hpp>
|
||||
#include <constants/defaults.hpp>
|
||||
#include <constants/limits.hpp>
|
||||
#include <net/net.hpp>
|
||||
#include <util/fs.hpp>
|
||||
#include <util/logger.hpp>
|
||||
|
@ -510,7 +511,7 @@ llarp_ensure_config(const char *fname, const char *basedir, bool overwrite,
|
|||
return false;
|
||||
}
|
||||
auto &f = optional_f.value();
|
||||
llarp_generic_ensure_config(f, basepath);
|
||||
llarp_generic_ensure_config(f, basepath, asRouter);
|
||||
if(asRouter)
|
||||
{
|
||||
llarp_ensure_router_config(f, basepath);
|
||||
|
@ -524,63 +525,70 @@ llarp_ensure_config(const char *fname, const char *basedir, bool overwrite,
|
|||
}
|
||||
|
||||
void
|
||||
llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
|
||||
llarp_generic_ensure_config(std::ofstream &f, std::string basepath,
|
||||
bool isRouter)
|
||||
{
|
||||
f << "# this configuration was auto generated with 'sane' defaults"
|
||||
<< std::endl;
|
||||
f << "# change these values as desired" << std::endl;
|
||||
f << std::endl << std::endl;
|
||||
f << "[router]" << std::endl;
|
||||
f << "# number of crypto worker threads " << std::endl;
|
||||
f << "threads=4" << std::endl;
|
||||
f << "# path to store signed RC" << std::endl;
|
||||
f << "contact-file=" << basepath << "self.signed" << std::endl;
|
||||
f << "# path to store transport private key" << std::endl;
|
||||
f << "transport-privkey=" << basepath << "transport.private" << std::endl;
|
||||
f << "# path to store identity signing key" << std::endl;
|
||||
f << "ident-privkey=" << basepath << "identity.private" << std::endl;
|
||||
f << "# encryption key for onion routing" << std::endl;
|
||||
f << "encryption-privkey=" << basepath << "encryption.private" << std::endl;
|
||||
f << "# this configuration was auto generated with 'sane' defaults\n";
|
||||
f << "# change these values as desired\n";
|
||||
f << "\n\n";
|
||||
f << "[router]\n";
|
||||
f << "# number of crypto worker threads \n";
|
||||
f << "threads=4\n";
|
||||
f << "# path to store signed RC\n";
|
||||
f << "contact-file=" << basepath << "self.signed\n";
|
||||
f << "# path to store transport private key\n";
|
||||
f << "transport-privkey=" << basepath << "transport.private\n";
|
||||
f << "# path to store identity signing key\n";
|
||||
f << "ident-privkey=" << basepath << "identity.private\n";
|
||||
f << "# encryption key for onion routing\n";
|
||||
f << "encryption-privkey=" << basepath << "encryption.private\n";
|
||||
f << std::endl;
|
||||
f << "# uncomment following line to set router nickname to 'lokinet'"
|
||||
<< std::endl;
|
||||
f << "#nickname=lokinet" << std::endl;
|
||||
f << std::endl << std::endl;
|
||||
f << "#nickname=lokinet\n";
|
||||
const auto limits = isRouter ? llarp::limits::snode : llarp::limits::client;
|
||||
|
||||
f << "# maintain min connections to other routers\n";
|
||||
f << "min-routers=" << std::to_string(limits.DefaultMinRouters) << std::endl;
|
||||
f << "# hard limit of routers globally we are connected to at any given "
|
||||
"time\n";
|
||||
f << "max-routers=" << std::to_string(limits.DefaultMaxRouters) << std::endl;
|
||||
f << "\n\n";
|
||||
|
||||
// logging
|
||||
f << "[logging]" << std::endl;
|
||||
f << "level=info" << std::endl;
|
||||
f << "# uncomment for logging to file" << std::endl;
|
||||
f << "#type=file" << std::endl;
|
||||
f << "#file=/path/to/logfile" << std::endl;
|
||||
f << "# uncomment for syslog logging" << std::endl;
|
||||
f << "#type=syslog" << std::endl;
|
||||
f << "[logging]\n";
|
||||
f << "level=info\n";
|
||||
f << "# uncomment for logging to file\n";
|
||||
f << "#type=file\n";
|
||||
f << "#file=/path/to/logfile\n";
|
||||
f << "# uncomment for syslog logging\n";
|
||||
f << "#type=syslog\n";
|
||||
|
||||
// metrics
|
||||
f << "[metrics]" << std::endl;
|
||||
f << "json-metrics-path=" << basepath << "metrics.json" << std::endl;
|
||||
f << "[metrics]\n";
|
||||
f << "json-metrics-path=" << basepath << "metrics.json\n";
|
||||
|
||||
f << std::endl << std::endl;
|
||||
f << "\n\n";
|
||||
|
||||
f << "# admin api (disabled by default)" << std::endl;
|
||||
f << "[api]" << std::endl;
|
||||
f << "enabled=false" << std::endl;
|
||||
f << "#authkey=insertpubkey1here" << std::endl;
|
||||
f << "#authkey=insertpubkey2here" << std::endl;
|
||||
f << "#authkey=insertpubkey3here" << std::endl;
|
||||
f << "bind=127.0.0.1:1190" << std::endl;
|
||||
f << std::endl << std::endl;
|
||||
f << "# admin api (disabled by default)\n";
|
||||
f << "[api]\n";
|
||||
f << "enabled=false\n";
|
||||
f << "#authkey=insertpubkey1here\n";
|
||||
f << "#authkey=insertpubkey2here\n";
|
||||
f << "#authkey=insertpubkey3here\n";
|
||||
f << "bind=127.0.0.1:1190\n";
|
||||
f << "\n\n";
|
||||
|
||||
f << "# system settings for privileges and such" << std::endl;
|
||||
f << "[system]" << std::endl;
|
||||
f << "# system settings for privileges and such\n";
|
||||
f << "[system]\n";
|
||||
f << "user=" << DEFAULT_LOKINET_USER << std::endl;
|
||||
f << "group=" << DEFAULT_LOKINET_GROUP << std::endl;
|
||||
f << "pidfile=" << basepath << "lokinet.pid" << std::endl;
|
||||
f << std::endl << std::endl;
|
||||
f << "pidfile=" << basepath << "lokinet.pid\n";
|
||||
f << "\n\n";
|
||||
|
||||
f << "# dns provider configuration section" << std::endl;
|
||||
f << "[dns]" << std::endl;
|
||||
f << "# resolver" << std::endl;
|
||||
f << "# dns provider configuration section\n";
|
||||
f << "[dns]\n";
|
||||
f << "# resolver\n";
|
||||
f << "upstream=" << DEFAULT_RESOLVER_US << std::endl;
|
||||
|
||||
// Make auto-config smarter
|
||||
|
@ -588,65 +596,64 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
|
|||
// (probably)
|
||||
#ifdef __linux__
|
||||
#ifdef ANDROID
|
||||
f << "bind=127.0.0.1:1153" << std::endl;
|
||||
f << "bind=127.0.0.1:1153\n";
|
||||
#else
|
||||
f << "bind=127.3.2.1:53" << std::endl;
|
||||
f << "bind=127.3.2.1:53\n";
|
||||
#endif
|
||||
#else
|
||||
f << "bind=127.0.0.1:53" << std::endl;
|
||||
f << "bind=127.0.0.1:53\n";
|
||||
#endif
|
||||
f << std::endl << std::endl;
|
||||
f << "\n\n";
|
||||
|
||||
f << "# network database settings block " << std::endl;
|
||||
f << "[netdb]" << std::endl;
|
||||
f << "# directory for network database skiplist storage" << std::endl;
|
||||
f << "dir=" << basepath << "netdb" << std::endl;
|
||||
f << std::endl << std::endl;
|
||||
f << "# network database settings block \n";
|
||||
f << "[netdb]\n";
|
||||
f << "# directory for network database skiplist storage\n";
|
||||
f << "dir=" << basepath << "netdb\n";
|
||||
f << "\n\n";
|
||||
|
||||
f << "# bootstrap settings" << std::endl;
|
||||
f << "[bootstrap]" << std::endl;
|
||||
f << "# bootstrap settings\n";
|
||||
f << "[bootstrap]\n";
|
||||
f << "# add a bootstrap node's signed identity to the list of nodes we want "
|
||||
"to bootstrap from"
|
||||
<< std::endl;
|
||||
f << "# if we don't have any peers we connect to this router" << std::endl;
|
||||
f << "add-node=" << basepath << "bootstrap.signed" << std::endl;
|
||||
"to bootstrap from\n";
|
||||
f << "# if we don't have any peers we connect to this router\n";
|
||||
f << "add-node=" << basepath << "bootstrap.signed\n";
|
||||
// we only process one of these...
|
||||
// f << "# add another bootstrap node" << std::endl;
|
||||
// f << "#add-node=/path/to/alternative/self.signed" << std::endl;
|
||||
f << std::endl << std::endl;
|
||||
// f << "# add another bootstrap node\n";
|
||||
// f << "#add-node=/path/to/alternative/self.signed\n";
|
||||
f << "\n\n";
|
||||
}
|
||||
|
||||
void
|
||||
llarp_ensure_router_config(std::ofstream &f, std::string basepath)
|
||||
{
|
||||
f << "# lokid settings (disabled by default)" << std::endl;
|
||||
f << "[lokid]" << std::endl;
|
||||
f << "enabled=false" << std::endl;
|
||||
f << "jsonrpc=127.0.0.1:22023" << std::endl;
|
||||
f << "#service-node-seed=/path/to/servicenode/seed" << std::endl;
|
||||
f << "# lokid settings (disabled by default)\n";
|
||||
f << "[lokid]\n";
|
||||
f << "enabled=false\n";
|
||||
f << "jsonrpc=127.0.0.1:22023\n";
|
||||
f << "#service-node-seed=/path/to/servicenode/seed\n";
|
||||
f << std::endl;
|
||||
f << "# network settings " << std::endl;
|
||||
f << "[network]" << std::endl;
|
||||
f << "profiles=" << basepath << "profiles.dat" << std::endl;
|
||||
f << "# network settings \n";
|
||||
f << "[network]\n";
|
||||
f << "profiles=" << basepath << "profiles.dat\n";
|
||||
// better to let the routers auto-configure
|
||||
// f << "ifaddr=auto" << std::endl;
|
||||
// f << "ifname=auto" << std::endl;
|
||||
f << "enabled=true" << std::endl;
|
||||
f << "exit=false" << std::endl;
|
||||
f << "#exit-blacklist=tcp:25" << std::endl;
|
||||
f << "#exit-whitelist=tcp:*" << std::endl;
|
||||
f << "#exit-whitelist=udp:*" << std::endl;
|
||||
// f << "ifaddr=auto\n";
|
||||
// f << "ifname=auto\n";
|
||||
f << "enabled=true\n";
|
||||
f << "exit=false\n";
|
||||
f << "#exit-blacklist=tcp:25\n";
|
||||
f << "#exit-whitelist=tcp:*\n";
|
||||
f << "#exit-whitelist=udp:*\n";
|
||||
f << std::endl;
|
||||
f << "# ROUTERS ONLY: publish network interfaces for handling inbound traffic"
|
||||
<< std::endl;
|
||||
f << "[bind]" << std::endl;
|
||||
f << "# ROUTERS ONLY: publish network interfaces for handling inbound "
|
||||
"traffic\n";
|
||||
f << "[bind]\n";
|
||||
// get ifname
|
||||
std::string ifname;
|
||||
if(llarp::GetBestNetIF(ifname, AF_INET))
|
||||
f << ifname << "=1090" << std::endl;
|
||||
f << ifname << "=1090\n";
|
||||
else
|
||||
f << "# could not autodetect network interface" << std::endl
|
||||
<< "#eth0=1090" << std::endl;
|
||||
f << "# could not autodetect network interface\n"
|
||||
<< "#eth0=1090\n";
|
||||
|
||||
f << std::endl;
|
||||
}
|
||||
|
@ -676,23 +683,18 @@ llarp_ensure_client_config(std::ofstream &f, std::string basepath)
|
|||
return false;
|
||||
}
|
||||
*/
|
||||
example_f << "# this is an example configuration for a snapp"
|
||||
<< std::endl;
|
||||
example_f << "[example-snapp]" << std::endl;
|
||||
example_f << "# this is an example configuration for a snapp\n";
|
||||
example_f << "[example-snapp]\n";
|
||||
example_f << "# keyfile is the path to the private key of the snapp, "
|
||||
"your .loki is tied to this key, DON'T LOSE IT"
|
||||
<< std::endl;
|
||||
example_f << "keyfile=" << basepath << "example-snap-keyfile.private"
|
||||
<< std::endl;
|
||||
example_f << "# ifaddr is the ip range to allocate to this snapp"
|
||||
<< std::endl;
|
||||
"your .loki is tied to this key, DON'T LOSE IT\n";
|
||||
example_f << "keyfile=" << basepath << "example-snap-keyfile.private\n";
|
||||
example_f << "# ifaddr is the ip range to allocate to this snapp\n";
|
||||
example_f << "ifaddr=" << ip << std::endl;
|
||||
// probably fine to leave this (and not-auto-detect it) I'm not worried
|
||||
// about any collisions
|
||||
example_f << "# ifname is the name to try and give to the network "
|
||||
"interface this snap owns"
|
||||
<< std::endl;
|
||||
example_f << "ifname=snapp-tun0" << std::endl;
|
||||
"interface this snap owns\n";
|
||||
example_f << "ifname=snapp-tun0\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -700,31 +702,29 @@ llarp_ensure_client_config(std::ofstream &f, std::string basepath)
|
|||
}
|
||||
}
|
||||
// now do up fname
|
||||
f << std::endl << std::endl;
|
||||
f << "# snapps configuration section" << std::endl;
|
||||
f << "[services]";
|
||||
f << "# uncomment next line to enable a snapp" << std::endl;
|
||||
f << "\n\n";
|
||||
f << "# snapps configuration section\n";
|
||||
f << "[services]\n";
|
||||
f << "# uncomment next line to enable a snapp\n";
|
||||
f << "#example-snapp=" << snappExample_fpath << std::endl;
|
||||
f << std::endl << std::endl;
|
||||
f << "\n\n";
|
||||
|
||||
f << "# network settings " << std::endl;
|
||||
f << "[network]" << std::endl;
|
||||
f << "profiles=" << basepath << "profiles.dat" << std::endl;
|
||||
f << "# network settings \n";
|
||||
f << "[network]\n";
|
||||
f << "profiles=" << basepath << "profiles.dat\n";
|
||||
f << "# uncomment next line to add router with pubkey to list of routers we "
|
||||
"connect directly to"
|
||||
<< std::endl;
|
||||
f << "#strict-connect=pubkey" << std::endl;
|
||||
f << "# uncomment next line to use router with pubkey as an exit node"
|
||||
<< std::endl;
|
||||
f << "#exit-node=pubkey" << std::endl;
|
||||
"connect directly to\n";
|
||||
f << "#strict-connect=pubkey\n";
|
||||
f << "# uncomment next line to use router with pubkey as an exit node\n";
|
||||
f << "#exit-node=pubkey\n";
|
||||
|
||||
// better to set them to auto then to hard code them now
|
||||
// operating environment may change over time and this will help adapt
|
||||
// f << "ifname=auto" << std::endl;
|
||||
// f << "ifaddr=auto" << std::endl;
|
||||
// f << "ifname=auto\n";
|
||||
// f << "ifaddr=auto\n";
|
||||
|
||||
// should this also be auto? or not declared?
|
||||
// probably auto in case they want to set up a hidden service
|
||||
f << "enabled=true" << std::endl;
|
||||
f << "enabled=true\n";
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,8 @@ namespace llarp
|
|||
{
|
||||
return ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -43,10 +41,8 @@ namespace llarp
|
|||
{
|
||||
return std::atoi(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -59,10 +55,8 @@ namespace llarp
|
|||
{
|
||||
return std::atoi(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -75,10 +69,8 @@ namespace llarp
|
|||
{
|
||||
return std::atoll(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -92,10 +84,8 @@ namespace llarp
|
|||
{
|
||||
return IsTrueValue(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
class RouterConfig
|
||||
|
@ -105,7 +95,7 @@ namespace llarp
|
|||
size_t m_minConnectedRouters = 2;
|
||||
|
||||
/// hard upperbound limit on the number of router to router connections
|
||||
size_t m_maxConnectedRouters = 2000;
|
||||
size_t m_maxConnectedRouters = 5;
|
||||
|
||||
std::string m_netId;
|
||||
std::string m_nickname;
|
||||
|
@ -335,7 +325,8 @@ namespace llarp
|
|||
} // namespace llarp
|
||||
|
||||
void
|
||||
llarp_generic_ensure_config(std::ofstream& f, std::string basepath);
|
||||
llarp_generic_ensure_config(std::ofstream& f, std::string basepath,
|
||||
bool isRouter);
|
||||
|
||||
void
|
||||
llarp_ensure_router_config(std::ofstream& f, std::string basepath);
|
||||
|
|
13
llarp/constants/limits.cpp
Normal file
13
llarp/constants/limits.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <constants/limits.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace limits
|
||||
{
|
||||
/// snode limit parameters
|
||||
const LimitParameters snode = {6, 60};
|
||||
|
||||
/// client limit parameters
|
||||
const LimitParameters client = {4, 6};
|
||||
} // namespace limits
|
||||
} // namespace llarp
|
26
llarp/constants/limits.hpp
Normal file
26
llarp/constants/limits.hpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef LLARP_CONSTANTS_LIMITS_HPP
|
||||
#define LLARP_CONSTANTS_LIMITS_HPP
|
||||
#include <cstddef>
|
||||
namespace llarp
|
||||
{
|
||||
namespace limits
|
||||
{
|
||||
/// Limits are a struct that contains all hard and soft limit
|
||||
/// parameters for a given mode of operation
|
||||
struct LimitParameters
|
||||
{
|
||||
/// minimum routers needed to run
|
||||
std::size_t DefaultMinRouters;
|
||||
/// hard limit on router sessions (by pubkey)
|
||||
std::size_t DefaultMaxRouters;
|
||||
};
|
||||
|
||||
/// snode limit parameters
|
||||
const extern LimitParameters snode;
|
||||
|
||||
/// client limit parameters
|
||||
const extern LimitParameters client;
|
||||
} // namespace limits
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
|
@ -2,7 +2,7 @@
|
|||
#define LLARP_LINK_LAYER_HPP
|
||||
#include <util/types.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
constexpr size_t MAX_LINK_MSG_SIZE = 8192;
|
||||
constexpr llarp_time_t DefaultLinkSessionLifetime = 60 * 1000;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <cxxopts.hpp>
|
||||
#include <signal.h>
|
||||
#include <csignal>
|
||||
|
||||
#if(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__)
|
||||
#include <pthread_np.h>
|
||||
|
@ -27,9 +27,7 @@
|
|||
|
||||
namespace llarp
|
||||
{
|
||||
Context::Context()
|
||||
{
|
||||
}
|
||||
Context::Context() = default;
|
||||
|
||||
Context::~Context()
|
||||
{
|
||||
|
@ -421,8 +419,8 @@ extern "C"
|
|||
{
|
||||
cSetLogLevel(eLogDebug);
|
||||
}
|
||||
llarp_main *m = new llarp_main;
|
||||
m->ctx = std::make_unique< llarp::Context >();
|
||||
auto *m = new llarp_main;
|
||||
m->ctx = std::make_unique< llarp::Context >();
|
||||
if(!m->ctx->LoadConfig(fname))
|
||||
{
|
||||
m->ctx->Close();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef LLARP_CRYPTO_CONSTANTS_HPP
|
||||
#define LLARP_CRYPTO_CONSTANTS_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
#include <libntrup/ntru.h>
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
#include <absl/base/optimization.h>
|
||||
#include <functional>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* crypto.hpp
|
||||
|
@ -89,9 +89,7 @@ namespace llarp
|
|||
pqe_encrypt(PQCipherBlock &, SharedSecret &, const PQPubKey &) = 0;
|
||||
};
|
||||
|
||||
inline Crypto::~Crypto()
|
||||
{
|
||||
}
|
||||
inline Crypto::~Crypto() = default;
|
||||
|
||||
/// return random 64bit unsigned interger
|
||||
uint64_t
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <sodium/crypto_stream_xchacha20.h>
|
||||
#include <util/mem.hpp>
|
||||
|
||||
#include <assert.h>
|
||||
#include <cassert>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
|
|
@ -11,9 +11,7 @@ namespace llarp
|
|||
{
|
||||
CryptoLibSodium();
|
||||
|
||||
~CryptoLibSodium()
|
||||
{
|
||||
}
|
||||
~CryptoLibSodium() override = default;
|
||||
|
||||
/// xchacha symmetric cipher
|
||||
bool
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
~NoOpCrypto() = default;
|
||||
~NoOpCrypto() override = default;
|
||||
|
||||
bool
|
||||
xchacha20(const llarp_buffer_t &, const SharedSecret &,
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <crypto/encrypted.hpp>
|
||||
#include <crypto/types.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
#include <utility>
|
||||
#include <util/mem.h>
|
||||
#include <util/threadpool.h>
|
||||
|
||||
|
@ -60,8 +61,7 @@ namespace llarp
|
|||
static void
|
||||
Decrypt(void* user)
|
||||
{
|
||||
AsyncFrameDecrypter< User >* ctx =
|
||||
static_cast< AsyncFrameDecrypter< User >* >(user);
|
||||
auto* ctx = static_cast< AsyncFrameDecrypter< User >* >(user);
|
||||
|
||||
if(ctx->target.DecryptInPlace(ctx->seckey))
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
AsyncFrameDecrypter(const SecretKey& secretkey, DecryptHandler h)
|
||||
: result(h), seckey(secretkey)
|
||||
: result(std::move(h)), seckey(secretkey)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ namespace llarp
|
|||
using BucketStorage_t = std::map< Key_t, Val_t, XorMetric >;
|
||||
using Random_t = std::function< uint64_t() >;
|
||||
|
||||
Bucket(const Key_t& us, Random_t r) : nodes(XorMetric(us)), random(r)
|
||||
Bucket(const Key_t& us, Random_t r)
|
||||
: nodes(XorMetric(us)), random(std::move(r))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -29,7 +30,7 @@ namespace llarp
|
|||
util::StatusObject obj{};
|
||||
for(const auto& item : nodes)
|
||||
{
|
||||
obj.Put(item.first.ToHex(), item.second.ExtractStatus());
|
||||
obj[item.first.ToString()] = item.second.ExtractStatus();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
|
|
@ -26,17 +26,13 @@ namespace llarp
|
|||
{
|
||||
namespace dht
|
||||
{
|
||||
AbstractContext::~AbstractContext()
|
||||
{
|
||||
}
|
||||
AbstractContext::~AbstractContext() = default;
|
||||
|
||||
struct Context final : public AbstractContext
|
||||
{
|
||||
Context();
|
||||
|
||||
~Context()
|
||||
{
|
||||
}
|
||||
~Context() override = default;
|
||||
|
||||
util::StatusObject
|
||||
ExtractStatus() const override;
|
||||
|
@ -167,7 +163,7 @@ namespace llarp
|
|||
void
|
||||
Explore(size_t N = 3);
|
||||
|
||||
llarp::AbstractRouter* router;
|
||||
llarp::AbstractRouter* router{nullptr};
|
||||
// for router contacts
|
||||
std::unique_ptr< Bucket< RCNode > > _nodes;
|
||||
|
||||
|
@ -180,7 +176,7 @@ namespace llarp
|
|||
return _services.get();
|
||||
}
|
||||
|
||||
bool allowTransit;
|
||||
bool allowTransit{false};
|
||||
|
||||
bool&
|
||||
AllowTransit() override
|
||||
|
@ -308,7 +304,7 @@ namespace llarp
|
|||
Key_t ourKey;
|
||||
};
|
||||
|
||||
Context::Context() : router(nullptr), allowTransit(false)
|
||||
Context::Context()
|
||||
{
|
||||
randombytes((byte_t*)&ids, sizeof(uint64_t));
|
||||
}
|
||||
|
@ -346,7 +342,7 @@ namespace llarp
|
|||
{
|
||||
if(left)
|
||||
return;
|
||||
Context* ctx = static_cast< Context* >(u);
|
||||
auto* ctx = static_cast< Context* >(u);
|
||||
const auto num =
|
||||
std::min(ctx->router->NumberOfConnectedRouters(), size_t(4));
|
||||
if(num)
|
||||
|
@ -361,7 +357,7 @@ namespace llarp
|
|||
{
|
||||
if(left)
|
||||
return;
|
||||
Context* ctx = static_cast< Context* >(u);
|
||||
auto* ctx = static_cast< Context* >(u);
|
||||
// clean up transactions
|
||||
ctx->CleanupTX();
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ llarp_dht_context_start(struct llarp_dht_context* ctx, const byte_t* key);
|
|||
// remove this? dns needs it atm
|
||||
struct llarp_router_lookup_job;
|
||||
|
||||
typedef void (*llarp_router_lookup_handler)(struct llarp_router_lookup_job*);
|
||||
using llarp_router_lookup_handler = void (*)(struct llarp_router_lookup_job*);
|
||||
|
||||
struct llarp_router_lookup_job
|
||||
{
|
||||
|
|
|
@ -37,6 +37,12 @@ namespace llarp
|
|||
return rid.ToString();
|
||||
}
|
||||
|
||||
std::string
|
||||
ToString() const
|
||||
{
|
||||
return SNode();
|
||||
}
|
||||
|
||||
Key_t
|
||||
operator^(const Key_t& other) const
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <dht/context.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <util/bencode.hpp>
|
||||
#include <dht/messages/findintro.hpp>
|
||||
#include <dht/messages/findrouter.hpp>
|
||||
|
@ -46,29 +47,29 @@ namespace llarp
|
|||
switch(*strbuf.base)
|
||||
{
|
||||
case 'F':
|
||||
msg.reset(new FindIntroMessage(From, relayed));
|
||||
msg = std::make_unique< FindIntroMessage >(From, relayed);
|
||||
break;
|
||||
case 'R':
|
||||
if(relayed)
|
||||
msg.reset(new RelayedFindRouterMessage(From));
|
||||
msg = std::make_unique< RelayedFindRouterMessage >(From);
|
||||
else
|
||||
msg.reset(new FindRouterMessage(From));
|
||||
msg = std::make_unique< FindRouterMessage >(From);
|
||||
break;
|
||||
case 'S':
|
||||
msg.reset(new GotRouterMessage(From, relayed));
|
||||
msg = std::make_unique< GotRouterMessage >(From, relayed);
|
||||
break;
|
||||
case 'I':
|
||||
msg.reset(new PublishIntroMessage());
|
||||
msg = std::make_unique< PublishIntroMessage >();
|
||||
break;
|
||||
case 'G':
|
||||
if(relayed)
|
||||
{
|
||||
msg.reset(new RelayedGotIntroMessage());
|
||||
msg = std::make_unique< RelayedGotIntroMessage >();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.reset(new GotIntroMessage(From));
|
||||
msg = std::make_unique< GotIntroMessage >(From);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -16,9 +16,7 @@ namespace llarp
|
|||
|
||||
struct IMessage
|
||||
{
|
||||
virtual ~IMessage()
|
||||
{
|
||||
}
|
||||
virtual ~IMessage() = default;
|
||||
|
||||
/// construct
|
||||
IMessage(const Key_t& from) : From(from)
|
||||
|
|
|
@ -7,9 +7,7 @@ namespace llarp
|
|||
{
|
||||
namespace dht
|
||||
{
|
||||
FindIntroMessage::~FindIntroMessage()
|
||||
{
|
||||
}
|
||||
FindIntroMessage::~FindIntroMessage() = default;
|
||||
|
||||
bool
|
||||
FindIntroMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val)
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace llarp
|
|||
R = 1;
|
||||
}
|
||||
|
||||
~FindIntroMessage();
|
||||
~FindIntroMessage() override;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const override;
|
||||
|
|
|
@ -57,9 +57,7 @@ namespace llarp
|
|||
return true;
|
||||
}
|
||||
|
||||
FindRouterMessage::~FindRouterMessage()
|
||||
{
|
||||
}
|
||||
FindRouterMessage::~FindRouterMessage() = default;
|
||||
|
||||
bool
|
||||
FindRouterMessage::BEncode(llarp_buffer_t *buf) const
|
||||
|
@ -183,8 +181,8 @@ namespace llarp
|
|||
replies.emplace_back(new GotRouterMessage(k, txid, {found}, false));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
dht.LookupRouterRelayed(From, txid, k, !iterative, replies);
|
||||
|
||||
dht.LookupRouterRelayed(From, txid, k, !iterative, replies);
|
||||
return true;
|
||||
}
|
||||
} // namespace dht
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace llarp
|
|||
K.Randomize();
|
||||
}
|
||||
|
||||
~FindRouterMessage();
|
||||
~FindRouterMessage() override;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const override;
|
||||
|
@ -33,7 +33,7 @@ namespace llarp
|
|||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
||||
|
||||
virtual bool
|
||||
bool
|
||||
HandleMessage(
|
||||
llarp_dht_context* ctx,
|
||||
std::vector< std::unique_ptr< IMessage > >& replies) const override;
|
||||
|
@ -55,7 +55,7 @@ namespace llarp
|
|||
/// handle a relayed FindRouterMessage, do a lookup on the dht and inform
|
||||
/// the path of the result
|
||||
/// TODO: smart path expiration logic needs to be implemented
|
||||
virtual bool
|
||||
bool
|
||||
HandleMessage(llarp_dht_context* ctx,
|
||||
std::vector< IMessage::Ptr_t >& replies) const override;
|
||||
};
|
||||
|
|
|
@ -1,29 +1,27 @@
|
|||
#include <dht/messages/gotintro.hpp>
|
||||
|
||||
#include <dht/context.hpp>
|
||||
#include <memory>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace dht
|
||||
{
|
||||
GotIntroMessage::GotIntroMessage(
|
||||
const std::vector< llarp::service::IntroSet > &results, uint64_t tx)
|
||||
: IMessage({}), I(results), T(tx)
|
||||
{
|
||||
}
|
||||
|
||||
GotIntroMessage::~GotIntroMessage()
|
||||
GotIntroMessage::GotIntroMessage(std::vector< service::IntroSet > results,
|
||||
uint64_t tx)
|
||||
: IMessage({}), I(std::move(results)), T(tx)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
GotIntroMessage::HandleMessage(
|
||||
llarp_dht_context *ctx,
|
||||
__attribute__((unused))
|
||||
std::vector< std::unique_ptr< IMessage > > &replies) const
|
||||
ABSL_ATTRIBUTE_UNUSED std::vector< std::unique_ptr< IMessage > >
|
||||
&replies) const
|
||||
{
|
||||
auto &dht = *ctx->impl;
|
||||
|
||||
|
@ -31,7 +29,7 @@ namespace llarp
|
|||
{
|
||||
if(!introset.Verify(dht.Now()))
|
||||
{
|
||||
llarp::LogWarn(
|
||||
LogWarn(
|
||||
"Invalid introset while handling direct GotIntro "
|
||||
"from ",
|
||||
From);
|
||||
|
@ -59,7 +57,7 @@ namespace llarp
|
|||
}
|
||||
return true;
|
||||
}
|
||||
llarp::LogError("no pending TX for GIM from ", From, " txid=", T);
|
||||
LogError("no pending TX for GIM from ", From, " txid=", T);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -77,7 +75,7 @@ namespace llarp
|
|||
auto copy = std::make_shared< const RelayedGotIntroMessage >(*this);
|
||||
return pathset->HandleGotIntroMessage(copy);
|
||||
}
|
||||
llarp::LogWarn("No path for got intro message pathid=", pathID);
|
||||
LogWarn("No path for got intro message pathid=", pathID);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -92,7 +90,7 @@ namespace llarp
|
|||
{
|
||||
if(K) // duplicate key?
|
||||
return false;
|
||||
K.reset(new dht::Key_t());
|
||||
K = std::make_unique< dht::Key_t >();
|
||||
return K->BDecode(buf);
|
||||
}
|
||||
bool read = false;
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace llarp
|
|||
struct GotIntroMessage : public IMessage
|
||||
{
|
||||
/// the found introsets
|
||||
std::vector< llarp::service::IntroSet > I;
|
||||
std::vector< service::IntroSet > I;
|
||||
/// txid
|
||||
uint64_t T = 0;
|
||||
/// the key of a router closer in keyspace if iterative lookup
|
||||
|
@ -41,10 +41,9 @@ namespace llarp
|
|||
}
|
||||
|
||||
/// for recursive reply
|
||||
GotIntroMessage(const std::vector< llarp::service::IntroSet >& results,
|
||||
uint64_t txid);
|
||||
GotIntroMessage(std::vector< service::IntroSet > results, uint64_t txid);
|
||||
|
||||
~GotIntroMessage();
|
||||
~GotIntroMessage() override = default;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const override;
|
||||
|
@ -52,7 +51,7 @@ namespace llarp
|
|||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
||||
|
||||
virtual bool
|
||||
bool
|
||||
HandleMessage(llarp_dht_context* ctx,
|
||||
std::vector< IMessage::Ptr_t >& replies) const override;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <dht/context.hpp>
|
||||
#include <dht/messages/gotrouter.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
|
||||
|
@ -8,9 +9,7 @@ namespace llarp
|
|||
{
|
||||
namespace dht
|
||||
{
|
||||
GotRouterMessage::~GotRouterMessage()
|
||||
{
|
||||
}
|
||||
GotRouterMessage::~GotRouterMessage() = default;
|
||||
|
||||
bool
|
||||
GotRouterMessage::BEncode(llarp_buffer_t *buf) const
|
||||
|
@ -56,7 +55,7 @@ namespace llarp
|
|||
{
|
||||
if(K) // duplicate key?
|
||||
return false;
|
||||
K.reset(new dht::Key_t());
|
||||
K = std::make_unique< dht::Key_t >();
|
||||
return K->BDecode(val);
|
||||
}
|
||||
if(key == "N")
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef LLARP_DHT_MESSAGES_GOT_ROUTER_HPP
|
||||
#define LLARP_DHT_MESSAGES_GOT_ROUTER_HPP
|
||||
|
||||
#include <dht/message.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <util/copy_or_nullptr.hpp>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -15,9 +18,8 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
GotRouterMessage(const Key_t& from, uint64_t id,
|
||||
const std::vector< RouterContact >& results,
|
||||
bool tunneled)
|
||||
: IMessage(from), R(results), txid(id), relayed(tunneled)
|
||||
std::vector< RouterContact > results, bool tunneled)
|
||||
: IMessage(from), R(std::move(results)), txid(id), relayed(tunneled)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -27,9 +29,9 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
GotRouterMessage(uint64_t id, const std::vector< RouterID >& near,
|
||||
GotRouterMessage(uint64_t id, std::vector< RouterID > _near,
|
||||
bool tunneled)
|
||||
: IMessage({}), N(near), txid(id), relayed(tunneled)
|
||||
: IMessage({}), N(std::move(_near)), txid(id), relayed(tunneled)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -44,7 +46,7 @@ namespace llarp
|
|||
version = other.version;
|
||||
}
|
||||
|
||||
~GotRouterMessage();
|
||||
~GotRouterMessage() override;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const override;
|
||||
|
@ -52,7 +54,7 @@ namespace llarp
|
|||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
||||
|
||||
virtual bool
|
||||
bool
|
||||
HandleMessage(
|
||||
llarp_dht_context* ctx,
|
||||
std::vector< std::unique_ptr< IMessage > >& replies) const override;
|
||||
|
|
|
@ -10,9 +10,7 @@ namespace llarp
|
|||
{
|
||||
namespace dht
|
||||
{
|
||||
PublishIntroMessage::~PublishIntroMessage()
|
||||
{
|
||||
}
|
||||
PublishIntroMessage::~PublishIntroMessage() = default;
|
||||
|
||||
bool
|
||||
PublishIntroMessage::DecodeKey(const llarp_buffer_t &key,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <dht/message.hpp>
|
||||
#include <service/intro_set.hpp>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace llarp
|
||||
|
@ -22,14 +23,14 @@ namespace llarp
|
|||
}
|
||||
|
||||
PublishIntroMessage(const llarp::service::IntroSet& i, uint64_t tx,
|
||||
uint64_t s, const std::vector< Key_t >& exclude = {})
|
||||
: IMessage({}), E(exclude), txID(tx)
|
||||
uint64_t s, std::vector< Key_t > exclude = {})
|
||||
: IMessage({}), E(std::move(exclude)), txID(tx)
|
||||
{
|
||||
I = i;
|
||||
S = s;
|
||||
}
|
||||
|
||||
~PublishIntroMessage();
|
||||
~PublishIntroMessage() override;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const override;
|
||||
|
@ -37,7 +38,7 @@ namespace llarp
|
|||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
||||
|
||||
virtual bool
|
||||
bool
|
||||
HandleMessage(
|
||||
llarp_dht_context* ctx,
|
||||
std::vector< std::unique_ptr< IMessage > >& replies) const override;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <dht/key.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <service/intro_set.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -47,7 +48,7 @@ namespace llarp
|
|||
ID.Zero();
|
||||
}
|
||||
|
||||
ISNode(const service::IntroSet& other) : introset(other)
|
||||
ISNode(service::IntroSet other) : introset(std::move(other))
|
||||
{
|
||||
introset.A.CalculateAddress(ID.as_array());
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <dht/context.hpp>
|
||||
#include <dht/messages/pubintro.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -10,11 +11,11 @@ namespace llarp
|
|||
PublishServiceJob::PublishServiceJob(const TXOwner &asker,
|
||||
const service::IntroSet &introset,
|
||||
AbstractContext *ctx, uint64_t s,
|
||||
const std::set< Key_t > &exclude)
|
||||
std::set< Key_t > exclude)
|
||||
: TX< service::Address, service::IntroSet >(asker, introset.A.Addr(),
|
||||
ctx)
|
||||
, S(s)
|
||||
, dontTell(exclude)
|
||||
, dontTell(std::move(exclude))
|
||||
, I(introset)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace llarp
|
|||
|
||||
PublishServiceJob(const TXOwner &asker, const service::IntroSet &introset,
|
||||
AbstractContext *ctx, uint64_t s,
|
||||
const std::set< Key_t > &exclude);
|
||||
std::set< Key_t > exclude);
|
||||
|
||||
bool
|
||||
Validate(const service::IntroSet &introset) const override;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <dht/context.hpp>
|
||||
#include <dht/messages/findrouter.hpp>
|
||||
#include <dht/messages/gotrouter.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -13,7 +14,7 @@ namespace llarp
|
|||
AbstractContext *ctx,
|
||||
RouterLookupHandler result)
|
||||
: TX< RouterID, RouterContact >(_whoasked, _target, ctx)
|
||||
, resultHandler(result)
|
||||
, resultHandler(std::move(result))
|
||||
|
||||
{
|
||||
peersAsked.insert(ctx->OurKey());
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace llarp
|
|||
void
|
||||
Start(const TXOwner &peer) override;
|
||||
|
||||
virtual void
|
||||
void
|
||||
SendReply() override;
|
||||
};
|
||||
} // namespace dht
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <dht/context.hpp>
|
||||
#include <dht/messages/findintro.hpp>
|
||||
#include <dht/messages/gotintro.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -13,7 +14,7 @@ namespace llarp
|
|||
AbstractContext *ctx, uint64_t r,
|
||||
service::IntroSetLookupHandler handler)
|
||||
: TX< service::Address, service::IntroSet >(asker, addr, ctx)
|
||||
, handleResult(handler)
|
||||
, handleResult(std::move(handler))
|
||||
, R(r)
|
||||
{
|
||||
peersAsked.insert(ctx->OurKey());
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace llarp
|
|||
void
|
||||
DoNextRequest(const Key_t &ask) override;
|
||||
|
||||
virtual void
|
||||
void
|
||||
SendReply() override;
|
||||
};
|
||||
} // namespace dht
|
||||
|
|
|
@ -29,9 +29,7 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
virtual ~TX()
|
||||
{
|
||||
}
|
||||
virtual ~TX() = default;
|
||||
|
||||
void
|
||||
OnFound(const Key_t& askedPeer, const V& value);
|
||||
|
@ -44,7 +42,7 @@ namespace llarp
|
|||
ExtractStatus() const
|
||||
{
|
||||
util::StatusObject obj{{"whoasked", whoasked.ExtractStatus()},
|
||||
{"target", target.ToHex()}};
|
||||
{"target", target.ToString()}};
|
||||
std::vector< util::StatusObject > foundObjs;
|
||||
std::transform(valuesFound.begin(), valuesFound.end(),
|
||||
std::back_inserter(foundObjs),
|
||||
|
@ -52,12 +50,12 @@ namespace llarp
|
|||
return item.ExtractStatus();
|
||||
});
|
||||
|
||||
obj.Put("found", foundObjs);
|
||||
obj["found"] = foundObjs;
|
||||
std::vector< std::string > asked;
|
||||
std::transform(
|
||||
peersAsked.begin(), peersAsked.end(), std::back_inserter(asked),
|
||||
[](const auto& item) -> std::string { return item.ToHex(); });
|
||||
obj.Put("asked", asked);
|
||||
[](const auto& item) -> std::string { return item.ToString(); });
|
||||
obj["asked"] = asked;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,22 +40,22 @@ namespace llarp
|
|||
{"owner", item.first.ExtractStatus()},
|
||||
{"tx", item.second->ExtractStatus()}};
|
||||
});
|
||||
obj.Put("tx", txObjs);
|
||||
obj["tx"] = txObjs;
|
||||
std::transform(
|
||||
timeouts.begin(), timeouts.end(), std::back_inserter(timeoutsObjs),
|
||||
[](const auto& item) -> util::StatusObject {
|
||||
return util::StatusObject{{"time", item.second},
|
||||
{"target", item.first.ToHex()}};
|
||||
{"target", item.first.ToString()}};
|
||||
});
|
||||
obj.Put("timeouts", timeoutsObjs);
|
||||
obj["timeouts"] = timeoutsObjs;
|
||||
std::transform(waiting.begin(), waiting.end(),
|
||||
std::back_inserter(waitingObjs),
|
||||
[](const auto& item) -> util::StatusObject {
|
||||
return util::StatusObject{
|
||||
{"target", item.first.ToHex()},
|
||||
{"target", item.first.ToString()},
|
||||
{"whoasked", item.second.ExtractStatus()}};
|
||||
});
|
||||
obj.Put("waiting", waitingObjs);
|
||||
obj["waiting"] = waitingObjs;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ getDNSstring(const char *const buffer, uint32_t *pos)
|
|||
}
|
||||
|
||||
void
|
||||
code_domain(char *&buffer, const std::string &domain) throw()
|
||||
code_domain(char *&buffer, const std::string &domain) noexcept
|
||||
{
|
||||
std::string::size_type start(0);
|
||||
std::string::size_type end; // indexes
|
||||
|
@ -124,7 +124,7 @@ code_domain(char *&buffer, const std::string &domain) throw()
|
|||
}
|
||||
|
||||
void
|
||||
vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) throw()
|
||||
vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) noexcept
|
||||
{
|
||||
std::string::size_type start(0);
|
||||
std::string::size_type end; // indexes
|
||||
|
@ -153,7 +153,7 @@ vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) throw()
|
|||
|
||||
// expects host order
|
||||
void
|
||||
vput16bits(std::vector< byte_t > &bytes, uint16_t value) throw()
|
||||
vput16bits(std::vector< byte_t > &bytes, uint16_t value) noexcept
|
||||
{
|
||||
char buf[2] = {0};
|
||||
char *write_buffer = buf;
|
||||
|
@ -164,7 +164,7 @@ vput16bits(std::vector< byte_t > &bytes, uint16_t value) throw()
|
|||
|
||||
// expects host order
|
||||
void
|
||||
vput32bits(std::vector< byte_t > &bytes, uint32_t value) throw()
|
||||
vput32bits(std::vector< byte_t > &bytes, uint32_t value) noexcept
|
||||
{
|
||||
char buf[4] = {0};
|
||||
char *write_buffer = buf;
|
||||
|
@ -178,7 +178,7 @@ vput32bits(std::vector< byte_t > &bytes, uint32_t value) throw()
|
|||
void
|
||||
dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record)
|
||||
{
|
||||
llarp::dns::type_1a *type1a = dynamic_cast< llarp::dns::type_1a * >(record);
|
||||
auto *type1a = dynamic_cast< llarp::dns::type_1a * >(record);
|
||||
if(type1a)
|
||||
{
|
||||
std::vector< byte_t > more_bytes = type1a->to_bytes();
|
||||
|
@ -186,8 +186,7 @@ dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record)
|
|||
bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end());
|
||||
}
|
||||
|
||||
llarp::dns::type_2ns *type2ns =
|
||||
dynamic_cast< llarp::dns::type_2ns * >(record);
|
||||
auto *type2ns = dynamic_cast< llarp::dns::type_2ns * >(record);
|
||||
if(type2ns)
|
||||
{
|
||||
std::vector< byte_t > more_bytes = type2ns->to_bytes();
|
||||
|
@ -195,8 +194,7 @@ dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record)
|
|||
bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end());
|
||||
}
|
||||
|
||||
llarp::dns::type_5cname *type5cname =
|
||||
dynamic_cast< llarp::dns::type_5cname * >(record);
|
||||
auto *type5cname = dynamic_cast< llarp::dns::type_5cname * >(record);
|
||||
if(type5cname)
|
||||
{
|
||||
std::vector< byte_t > more_bytes = type5cname->to_bytes();
|
||||
|
@ -204,24 +202,21 @@ dns_writeType(std::vector< byte_t > &bytes, llarp::dns::record *record)
|
|||
bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end());
|
||||
}
|
||||
|
||||
llarp::dns::type_12ptr *type12ptr =
|
||||
dynamic_cast< llarp::dns::type_12ptr * >(record);
|
||||
auto *type12ptr = dynamic_cast< llarp::dns::type_12ptr * >(record);
|
||||
if(type12ptr)
|
||||
{
|
||||
std::vector< byte_t > more_bytes = type12ptr->to_bytes();
|
||||
llarp::LogDebug("[12]Adding ", more_bytes.size());
|
||||
bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end());
|
||||
}
|
||||
llarp::dns::type_15mx *type15mx =
|
||||
dynamic_cast< llarp::dns::type_15mx * >(record);
|
||||
auto *type15mx = dynamic_cast< llarp::dns::type_15mx * >(record);
|
||||
if(type15mx)
|
||||
{
|
||||
std::vector< byte_t > more_bytes = type15mx->to_bytes();
|
||||
llarp::LogDebug("[15]Adding ", more_bytes.size());
|
||||
bytes.insert(bytes.end(), more_bytes.begin(), more_bytes.end());
|
||||
}
|
||||
llarp::dns::type_16txt *type16txt =
|
||||
dynamic_cast< llarp::dns::type_16txt * >(record);
|
||||
auto *type16txt = dynamic_cast< llarp::dns::type_16txt * >(record);
|
||||
if(type16txt)
|
||||
{
|
||||
std::vector< byte_t > more_bytes = type16txt->to_bytes();
|
||||
|
@ -292,7 +287,7 @@ packet2bytes(dns_packet &in)
|
|||
extern "C"
|
||||
{
|
||||
uint16_t
|
||||
get16bits(const char *&buffer) throw()
|
||||
get16bits(const char *&buffer) noexcept
|
||||
{
|
||||
uint16_t value = bufbe16toh(buffer);
|
||||
buffer += 2;
|
||||
|
@ -300,7 +295,7 @@ extern "C"
|
|||
}
|
||||
|
||||
uint32_t
|
||||
get32bits(const char *&buffer) throw()
|
||||
get32bits(const char *&buffer) noexcept
|
||||
{
|
||||
uint32_t value = bufbe32toh(buffer);
|
||||
buffer += 4;
|
||||
|
@ -350,7 +345,7 @@ extern "C"
|
|||
dns_msg_question *
|
||||
decode_question(const char *buffer, uint32_t *pos)
|
||||
{
|
||||
dns_msg_question *question = new dns_msg_question;
|
||||
auto *question = new dns_msg_question;
|
||||
|
||||
std::string m_qName = getDNSstring(buffer, pos);
|
||||
llarp::LogDebug("Got question name: ", m_qName);
|
||||
|
@ -369,7 +364,7 @@ extern "C"
|
|||
dns_msg_answer *
|
||||
decode_answer(const char *const buffer, uint32_t *pos)
|
||||
{
|
||||
dns_msg_answer *answer = new dns_msg_answer;
|
||||
auto *answer = new dns_msg_answer;
|
||||
/*
|
||||
llarp_buffer_t bob;
|
||||
bob.base = (unsigned char *)buffer;
|
||||
|
@ -589,14 +584,14 @@ extern "C"
|
|||
}
|
||||
|
||||
void
|
||||
put16bits(char *&buffer, uint16_t value) throw()
|
||||
put16bits(char *&buffer, uint16_t value) noexcept
|
||||
{
|
||||
htobe16buf(buffer, value);
|
||||
buffer += 2;
|
||||
}
|
||||
|
||||
void
|
||||
put32bits(char *&buffer, uint32_t value) throw()
|
||||
put32bits(char *&buffer, uint32_t value) noexcept
|
||||
{
|
||||
htobe32buf(buffer, value);
|
||||
buffer += 4;
|
||||
|
|
|
@ -14,7 +14,7 @@ extern "C"
|
|||
// fwd declr
|
||||
struct dnsc_answer_request;
|
||||
|
||||
typedef void (*dnsc_answer_hook_func)(dnsc_answer_request *request);
|
||||
using dnsc_answer_hook_func = void (*)(dnsc_answer_request *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -111,24 +111,24 @@ std::string
|
|||
getDNSstring(const char *const buffer, uint32_t *pos);
|
||||
|
||||
void
|
||||
code_domain(char *&buffer, const std::string &domain) throw();
|
||||
code_domain(char *&buffer, const std::string &domain) noexcept;
|
||||
|
||||
void
|
||||
vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) throw();
|
||||
vcode_domain(std::vector< byte_t > &bytes, const std::string &domain) noexcept;
|
||||
|
||||
void
|
||||
vput16bits(std::vector< byte_t > &bytes, uint16_t value) throw();
|
||||
vput16bits(std::vector< byte_t > &bytes, uint16_t value) noexcept;
|
||||
|
||||
void
|
||||
vput32bits(std::vector< byte_t > &bytes, uint32_t value) throw();
|
||||
vput32bits(std::vector< byte_t > &bytes, uint32_t value) noexcept;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
uint16_t
|
||||
get16bits(const char *&buffer) throw();
|
||||
get16bits(const char *&buffer) noexcept;
|
||||
|
||||
uint32_t
|
||||
get32bits(const char *&buffer) throw();
|
||||
get32bits(const char *&buffer) noexcept;
|
||||
|
||||
bool
|
||||
decode_hdr(llarp_buffer_t *buffer, dns_msg_header *hdr);
|
||||
|
@ -140,10 +140,10 @@ extern "C"
|
|||
decode_answer(const char *const buffer, uint32_t *pos);
|
||||
|
||||
void
|
||||
put16bits(char *&buffer, uint16_t value) throw();
|
||||
put16bits(char *&buffer, uint16_t value) noexcept;
|
||||
|
||||
void
|
||||
put32bits(char *&buffer, uint32_t value) throw();
|
||||
put32bits(char *&buffer, uint32_t value) noexcept;
|
||||
|
||||
void
|
||||
llarp_handle_dns_recvfrom(struct llarp_udp_io *udp,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef LLARP_DNS_DNS_HPP
|
||||
#define LLARP_DNS_DNS_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
|
|
@ -107,11 +107,11 @@ namespace llarp
|
|||
ip = net::IPPacket::ExpandV4(llarp::ipaddr_ipv4_bits(a, b, c, d));
|
||||
return true;
|
||||
}
|
||||
else if(numdots == 32 && isV6)
|
||||
if(numdots == 32 && isV6)
|
||||
{
|
||||
size_t idx = 0;
|
||||
uint8_t lo, hi;
|
||||
uint8_t* ptr = (uint8_t*)&ip.h;
|
||||
auto* ptr = (uint8_t*)&ip.h;
|
||||
while(idx < 16)
|
||||
{
|
||||
pos = sub.find('.');
|
||||
|
|
|
@ -5,9 +5,7 @@ namespace llarp
|
|||
{
|
||||
namespace dns
|
||||
{
|
||||
record::~record()
|
||||
{
|
||||
}
|
||||
record::~record() = default;
|
||||
|
||||
bool
|
||||
record::parse(std::vector< byte_t > bytes)
|
||||
|
|
|
@ -13,9 +13,7 @@ namespace llarp
|
|||
struct record
|
||||
{
|
||||
virtual ~record() = 0;
|
||||
record()
|
||||
{
|
||||
}
|
||||
record() = default;
|
||||
|
||||
virtual bool
|
||||
parse(std::vector< byte_t > bytes) = 0;
|
||||
|
@ -28,9 +26,7 @@ namespace llarp
|
|||
{
|
||||
huint32_t ipaddr;
|
||||
|
||||
virtual ~type_1a()
|
||||
{
|
||||
}
|
||||
~type_1a() override = default;
|
||||
type_1a();
|
||||
|
||||
bool
|
||||
|
@ -44,9 +40,7 @@ namespace llarp
|
|||
{
|
||||
std::string ns;
|
||||
|
||||
virtual ~type_2ns()
|
||||
{
|
||||
}
|
||||
~type_2ns() override = default;
|
||||
type_2ns();
|
||||
|
||||
bool
|
||||
|
@ -66,9 +60,7 @@ namespace llarp
|
|||
uint32_t expire;
|
||||
uint32_t minimum;
|
||||
|
||||
virtual ~type_6soa()
|
||||
{
|
||||
}
|
||||
~type_6soa() override = default;
|
||||
type_6soa();
|
||||
|
||||
bool
|
||||
|
@ -82,9 +74,7 @@ namespace llarp
|
|||
{
|
||||
std::string cname;
|
||||
|
||||
virtual ~type_5cname()
|
||||
{
|
||||
}
|
||||
~type_5cname() override = default;
|
||||
type_5cname();
|
||||
|
||||
bool
|
||||
|
@ -98,9 +88,7 @@ namespace llarp
|
|||
{
|
||||
std::string revname;
|
||||
|
||||
virtual ~type_12ptr()
|
||||
{
|
||||
}
|
||||
~type_12ptr() override = default;
|
||||
type_12ptr();
|
||||
|
||||
bool
|
||||
|
@ -115,9 +103,7 @@ namespace llarp
|
|||
std::string mx;
|
||||
uint16_t priority;
|
||||
|
||||
virtual ~type_15mx()
|
||||
{
|
||||
}
|
||||
~type_15mx() override = default;
|
||||
type_15mx();
|
||||
|
||||
bool
|
||||
|
@ -131,9 +117,7 @@ namespace llarp
|
|||
{
|
||||
std::string txt;
|
||||
|
||||
virtual ~type_16txt()
|
||||
{
|
||||
}
|
||||
~type_16txt() override = default;
|
||||
type_16txt();
|
||||
|
||||
bool
|
||||
|
|
|
@ -5,9 +5,7 @@ namespace llarp
|
|||
{
|
||||
namespace dns
|
||||
{
|
||||
Serialize::~Serialize()
|
||||
{
|
||||
}
|
||||
Serialize::~Serialize() = default;
|
||||
|
||||
bool
|
||||
EncodeRData(llarp_buffer_t* buf, const std::vector< byte_t >& v)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <crypto/crypto.hpp>
|
||||
#include <util/logic.hpp>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -11,10 +12,10 @@ namespace llarp
|
|||
Proxy::Proxy(llarp_ev_loop_ptr serverLoop, Logic_ptr serverLogic,
|
||||
llarp_ev_loop_ptr clientLoop, Logic_ptr clientLogic,
|
||||
IQueryHandler* h)
|
||||
: m_ServerLoop(serverLoop)
|
||||
, m_ClientLoop(clientLoop)
|
||||
, m_ServerLogic(serverLogic)
|
||||
, m_ClientLogic(clientLogic)
|
||||
: m_ServerLoop(std::move(serverLoop))
|
||||
, m_ClientLoop(std::move(clientLoop))
|
||||
, m_ServerLogic(std::move(serverLogic))
|
||||
, m_ClientLogic(std::move(clientLogic))
|
||||
, m_QueryHandler(h)
|
||||
{
|
||||
m_Client.user = this;
|
||||
|
|
|
@ -16,9 +16,7 @@ namespace llarp
|
|||
/// handler of dns query hooking
|
||||
struct IQueryHandler
|
||||
{
|
||||
virtual ~IQueryHandler()
|
||||
{
|
||||
}
|
||||
virtual ~IQueryHandler() = default;
|
||||
|
||||
/// return true if we should hook this message
|
||||
virtual bool
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
#include <unistd.h> /* close */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* exit */
|
||||
#include <string.h> /* memset */
|
||||
#include <cstdlib> /* exit */
|
||||
#include <cstring> /* memset */
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <algorithm> // for std::find_if
|
||||
#include <stdio.h> // sprintf
|
||||
#include <cstdio> // sprintf
|
||||
|
||||
dns_tracker dns_udp_tracker;
|
||||
|
||||
|
@ -36,8 +36,8 @@ struct dns_query
|
|||
struct dns_query *
|
||||
build_dns_packet(char *url, uint16_t id, uint16_t reqType)
|
||||
{
|
||||
dns_query *dnsQuery = new dns_query;
|
||||
dnsQuery->length = 12;
|
||||
auto *dnsQuery = new dns_query;
|
||||
dnsQuery->length = 12;
|
||||
// ID
|
||||
// buffer[0] = (value & 0xFF00) >> 8;
|
||||
// buffer[1] = value & 0xFF;
|
||||
|
@ -505,7 +505,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
|
|||
}
|
||||
else if(answer->type == 15)
|
||||
{
|
||||
llarp::dns::type_15mx *record =
|
||||
auto *record =
|
||||
dynamic_cast< llarp::dns::type_15mx * >(answer->record.get());
|
||||
llarp::LogDebug("Resolving MX ", record->mx, "@", record->priority);
|
||||
request->found = true;
|
||||
|
@ -639,7 +639,7 @@ raw_resolve_host(struct dnsc_context *const dnsc, const char *url,
|
|||
llarp::LogInfo("response header says it belongs to id #", hdr.id);
|
||||
|
||||
// if we sent this out, then there's an id
|
||||
struct dns_tracker *tracker = (struct dns_tracker *)dnsc->tracker;
|
||||
auto *tracker = (struct dns_tracker *)dnsc->tracker;
|
||||
struct dnsc_answer_request *request = tracker->client_request[hdr.id].get();
|
||||
|
||||
if(request)
|
||||
|
@ -675,7 +675,7 @@ llarp_handle_dnsc_recvfrom(struct llarp_udp_io *const udp,
|
|||
llarp::LogDebug("Header got client responses for id: ", hdr.id);
|
||||
|
||||
// if we sent this out, then there's an id
|
||||
struct dns_tracker *tracker = (struct dns_tracker *)udp->user;
|
||||
auto *tracker = (struct dns_tracker *)udp->user;
|
||||
struct dnsc_answer_request *request = tracker->client_request[hdr.id].get();
|
||||
|
||||
// sometimes we'll get double responses
|
||||
|
@ -766,8 +766,8 @@ llarp_resolve_host(struct dnsc_context *const dnsc, const char *url,
|
|||
void
|
||||
llarp_host_resolved(dnsc_answer_request *const request)
|
||||
{
|
||||
dns_tracker *tracker = (dns_tracker *)request->context->tracker;
|
||||
auto val = std::find_if(
|
||||
auto *tracker = (dns_tracker *)request->context->tracker;
|
||||
auto val = std::find_if(
|
||||
tracker->client_request.begin(), tracker->client_request.end(),
|
||||
[request](
|
||||
std::pair< const uint32_t, std::unique_ptr< dnsc_answer_request > >
|
||||
|
|
|
@ -26,7 +26,7 @@ build_dns_packet(char *url, uint16_t id, uint16_t reqType);
|
|||
/// hook function to handle an dns client request
|
||||
// should we pass by llarp::Addr
|
||||
// not as long as we're supporting raw
|
||||
typedef void (*dnsc_answer_hook_func)(dnsc_answer_request *request);
|
||||
using dnsc_answer_hook_func = void (*)(dnsc_answer_request *);
|
||||
|
||||
/// struct for dns client requests
|
||||
struct dnsc_answer_request
|
||||
|
|
|
@ -27,7 +27,7 @@ ssize_t
|
|||
llarp_sendto_dns_hook_func(void *sock, const struct sockaddr *from,
|
||||
ManagedBuffer buf)
|
||||
{
|
||||
struct llarp_udp_io *udp = (struct llarp_udp_io *)sock;
|
||||
auto *udp = (struct llarp_udp_io *)sock;
|
||||
if(!udp)
|
||||
{
|
||||
llarp::LogWarn("couldnt cast to udp");
|
||||
|
@ -333,8 +333,7 @@ writesend_dnss_txtresponse(std::string txt, const struct sockaddr *from,
|
|||
void
|
||||
handle_dnsc_result(dnsc_answer_request *client_request)
|
||||
{
|
||||
dnsd_question_request *server_request =
|
||||
(dnsd_question_request *)client_request->user;
|
||||
auto *server_request = (dnsd_question_request *)client_request->user;
|
||||
if(!server_request)
|
||||
{
|
||||
llarp::LogError("Couldn't map client requser user to a server request");
|
||||
|
@ -522,7 +521,7 @@ llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp,
|
|||
return;
|
||||
}
|
||||
// create new request
|
||||
dnsd_question_request *llarp_dns_request = new dnsd_question_request;
|
||||
auto *llarp_dns_request = new dnsd_question_request;
|
||||
llarp_dns_request->context = dns_udp_tracker.dnsd; // set context
|
||||
llarp_dns_request->from =
|
||||
new sockaddr(*saddr); // make a copy of the sockaddr
|
||||
|
@ -543,7 +542,7 @@ raw_handle_recvfrom(int *sockfd, const struct sockaddr *saddr,
|
|||
llarp::LogError("No tracker set in dnsd context");
|
||||
return;
|
||||
}
|
||||
dnsd_question_request *llarp_dns_request = new dnsd_question_request;
|
||||
auto *llarp_dns_request = new dnsd_question_request;
|
||||
llarp_dns_request->context = dns_udp_tracker.dnsd; // set context
|
||||
llarp_dns_request->from =
|
||||
new sockaddr(*saddr); // make a copy of the sockaddr
|
||||
|
|
|
@ -23,9 +23,9 @@ typedef SSIZE_T ssize_t;
|
|||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#if !defined(WIN32)
|
||||
#include <uv.h>
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <deque>
|
||||
#include <list>
|
||||
#include <future>
|
||||
#include <utility>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <win32/win32_up.h>
|
||||
|
@ -305,7 +306,7 @@ namespace llarp
|
|||
struct GetNow
|
||||
{
|
||||
llarp_ev_loop_ptr loop;
|
||||
GetNow(llarp_ev_loop_ptr l) : loop(l)
|
||||
GetNow(llarp_ev_loop_ptr l) : loop(std::move(l))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -319,7 +320,7 @@ namespace llarp
|
|||
struct PutTime
|
||||
{
|
||||
llarp_ev_loop_ptr loop;
|
||||
PutTime(llarp_ev_loop_ptr l) : loop(l)
|
||||
PutTime(llarp_ev_loop_ptr l) : loop(std::move(l))
|
||||
{
|
||||
}
|
||||
void
|
||||
|
@ -570,9 +571,7 @@ namespace llarp
|
|||
tcp.close = &DoClose;
|
||||
}
|
||||
|
||||
virtual ~tcp_conn()
|
||||
{
|
||||
}
|
||||
~tcp_conn() override = default;
|
||||
|
||||
/// start connecting
|
||||
void
|
||||
|
@ -631,10 +630,10 @@ namespace llarp
|
|||
errno = 0;
|
||||
}
|
||||
|
||||
virtual ssize_t
|
||||
ssize_t
|
||||
do_write(void* buf, size_t sz) override;
|
||||
|
||||
virtual int
|
||||
int
|
||||
read(byte_t* buf, size_t sz) override;
|
||||
|
||||
bool
|
||||
|
@ -652,7 +651,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
tick()
|
||||
tick() override
|
||||
{
|
||||
if(tcp->tick)
|
||||
tcp->tick(tcp);
|
||||
|
@ -660,8 +659,8 @@ namespace llarp
|
|||
}
|
||||
|
||||
/// actually does accept() :^)
|
||||
virtual int
|
||||
read(byte_t*, size_t);
|
||||
int
|
||||
read(byte_t*, size_t) override;
|
||||
};
|
||||
|
||||
} // namespace llarp
|
||||
|
@ -784,9 +783,7 @@ struct llarp_ev_loop
|
|||
return conn && add_ev(conn, true);
|
||||
}
|
||||
|
||||
virtual ~llarp_ev_loop()
|
||||
{
|
||||
}
|
||||
virtual ~llarp_ev_loop() = default;
|
||||
|
||||
std::list< std::unique_ptr< llarp::ev_io > > handlers;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <ev/ev_libuv.hpp>
|
||||
#include <net/net_addr.hpp>
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace libuv
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ namespace libuv
|
|||
static void
|
||||
OnOutboundConnect(uv_connect_t* c, int status)
|
||||
{
|
||||
conn_glue* self = static_cast< conn_glue* >(c->data);
|
||||
auto* self = static_cast< conn_glue* >(c->data);
|
||||
self->HandleConnectResult(status);
|
||||
c->data = nullptr;
|
||||
}
|
||||
|
@ -181,9 +181,9 @@ namespace libuv
|
|||
{
|
||||
m_WriteQueue.emplace_back(sz);
|
||||
std::copy_n(data, sz, m_WriteQueue.back().begin());
|
||||
auto buf = uv_buf_init(m_WriteQueue.back().data(), sz);
|
||||
uv_write_t* req = new uv_write_t();
|
||||
req->data = this;
|
||||
auto buf = uv_buf_init(m_WriteQueue.back().data(), sz);
|
||||
auto* req = new uv_write_t();
|
||||
req->data = this;
|
||||
return uv_write(req, Stream(), &buf, 1, &OnWritten) == 0 ? sz : 0;
|
||||
}
|
||||
|
||||
|
@ -196,10 +196,10 @@ namespace libuv
|
|||
static void
|
||||
FullClose(uv_handle_t* h)
|
||||
{
|
||||
conn_glue* self = static_cast< conn_glue* >(h->data);
|
||||
h->data = nullptr;
|
||||
auto* self = static_cast< conn_glue* >(h->data);
|
||||
h->data = nullptr;
|
||||
delete self;
|
||||
llarp::LogInfo("deleted");
|
||||
llarp::LogDebug("deleted");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -217,7 +217,7 @@ namespace libuv
|
|||
m_Conn.closed(&m_Conn);
|
||||
}
|
||||
m_Conn.impl = nullptr;
|
||||
llarp::LogInfo("closed");
|
||||
llarp::LogDebug("closed");
|
||||
uv_close((uv_handle_t*)&m_Ticker, &FullClose);
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ namespace libuv
|
|||
OnShutdown(uv_shutdown_t* shut, int code)
|
||||
{
|
||||
llarp::LogDebug("shut down ", code);
|
||||
conn_glue* self = static_cast< conn_glue* >(shut->data);
|
||||
auto* self = static_cast< conn_glue* >(shut->data);
|
||||
uv_close((uv_handle_t*)&self->m_Handle, &OnClosed);
|
||||
delete shut;
|
||||
}
|
||||
|
@ -236,8 +236,8 @@ namespace libuv
|
|||
llarp::LogDebug("close tcp connection");
|
||||
uv_check_stop(&m_Ticker);
|
||||
uv_read_stop(Stream());
|
||||
uv_shutdown_t* shut = new uv_shutdown_t();
|
||||
shut->data = this;
|
||||
auto* shut = new uv_shutdown_t();
|
||||
shut->data = this;
|
||||
uv_shutdown(shut, Stream(), &OnShutdown);
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ namespace libuv
|
|||
{
|
||||
if(m_Accept && m_Accept->accepted)
|
||||
{
|
||||
conn_glue* child = new conn_glue(this);
|
||||
auto* child = new conn_glue(this);
|
||||
llarp::LogDebug("accepted new connection");
|
||||
child->m_Conn.impl = child;
|
||||
child->m_Conn.loop = m_Accept->loop;
|
||||
|
@ -375,7 +375,7 @@ namespace libuv
|
|||
static int
|
||||
SendTo(llarp_udp_io* udp, const sockaddr* to, const byte_t* ptr, size_t sz)
|
||||
{
|
||||
udp_glue* self = static_cast< udp_glue* >(udp->impl);
|
||||
auto* self = static_cast< udp_glue* >(udp->impl);
|
||||
if(self == nullptr)
|
||||
return -1;
|
||||
uv_buf_t buf = uv_buf_init((char*)ptr, sz);
|
||||
|
@ -410,7 +410,7 @@ namespace libuv
|
|||
static void
|
||||
OnClosed(uv_handle_t* h)
|
||||
{
|
||||
udp_glue* glue = static_cast< udp_glue* >(h->data);
|
||||
auto* glue = static_cast< udp_glue* >(h->data);
|
||||
if(glue)
|
||||
{
|
||||
h->data = nullptr;
|
||||
|
@ -443,7 +443,7 @@ namespace libuv
|
|||
readpkt = false;
|
||||
}
|
||||
|
||||
~tun_glue()
|
||||
~tun_glue() override
|
||||
{
|
||||
tuntap_destroy(m_Device);
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ namespace libuv
|
|||
static void
|
||||
OnClosed(uv_handle_t* h)
|
||||
{
|
||||
tun_glue* self = static_cast< tun_glue* >(h->data);
|
||||
auto* self = static_cast< tun_glue* >(h->data);
|
||||
if(self)
|
||||
{
|
||||
self->m_Tun->impl = nullptr;
|
||||
|
@ -597,8 +597,8 @@ namespace libuv
|
|||
bool
|
||||
Loop::tcp_connect(llarp_tcp_connecter* tcp, const sockaddr* addr)
|
||||
{
|
||||
conn_glue* impl = new conn_glue(m_Impl.get(), tcp, addr);
|
||||
tcp->impl = impl;
|
||||
auto* impl = new conn_glue(m_Impl.get(), tcp, addr);
|
||||
tcp->impl = impl;
|
||||
if(impl->ConnectAsync())
|
||||
return true;
|
||||
delete impl;
|
||||
|
@ -656,8 +656,8 @@ namespace libuv
|
|||
bool
|
||||
Loop::udp_listen(llarp_udp_io* udp, const sockaddr* src)
|
||||
{
|
||||
udp_glue* impl = new udp_glue(m_Impl.get(), udp, src);
|
||||
udp->impl = impl;
|
||||
auto* impl = new udp_glue(m_Impl.get(), udp, src);
|
||||
udp->impl = impl;
|
||||
if(impl->Bind())
|
||||
{
|
||||
return true;
|
||||
|
@ -671,7 +671,7 @@ namespace libuv
|
|||
{
|
||||
if(udp == nullptr)
|
||||
return false;
|
||||
udp_glue* glue = static_cast< udp_glue* >(udp->impl);
|
||||
auto* glue = static_cast< udp_glue* >(udp->impl);
|
||||
if(glue == nullptr)
|
||||
return false;
|
||||
glue->Close();
|
||||
|
@ -681,8 +681,8 @@ namespace libuv
|
|||
bool
|
||||
Loop::tun_listen(llarp_tun_io* tun)
|
||||
{
|
||||
tun_glue* glue = new tun_glue(tun);
|
||||
tun->impl = glue;
|
||||
auto* glue = new tun_glue(tun);
|
||||
tun->impl = glue;
|
||||
if(glue->Init(m_Impl.get()))
|
||||
{
|
||||
return true;
|
||||
|
@ -694,8 +694,8 @@ namespace libuv
|
|||
bool
|
||||
Loop::tcp_listen(llarp_tcp_acceptor* tcp, const sockaddr* addr)
|
||||
{
|
||||
conn_glue* glue = new conn_glue(m_Impl.get(), tcp, addr);
|
||||
tcp->impl = glue;
|
||||
auto* glue = new conn_glue(m_Impl.get(), tcp, addr);
|
||||
tcp->impl = glue;
|
||||
if(glue->Server())
|
||||
return true;
|
||||
tcp->impl = nullptr;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <ev/pipe.hpp>
|
||||
#include <utility>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
|
@ -6,7 +7,7 @@
|
|||
#include <fcntl.h>
|
||||
|
||||
llarp_ev_pkt_pipe::llarp_ev_pkt_pipe(llarp_ev_loop_ptr loop)
|
||||
: llarp::ev_io(-1, new LosslessWriteQueue_t()), m_Loop(loop)
|
||||
: llarp::ev_io(-1, new LosslessWriteQueue_t()), m_Loop(std::move(loop))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ struct llarp_ev_pkt_pipe : public llarp::ev_io
|
|||
ssize_t
|
||||
do_write(void* buf, size_t sz) override;
|
||||
|
||||
virtual bool
|
||||
bool
|
||||
tick() override;
|
||||
|
||||
int
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <exit/context.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -7,9 +8,7 @@ namespace llarp
|
|||
Context::Context(AbstractRouter* r) : m_Router(r)
|
||||
{
|
||||
}
|
||||
Context::~Context()
|
||||
{
|
||||
}
|
||||
Context::~Context() = default;
|
||||
|
||||
void
|
||||
Context::Tick(llarp_time_t now)
|
||||
|
@ -53,7 +52,7 @@ namespace llarp
|
|||
auto itr = m_Exits.begin();
|
||||
while(itr != m_Exits.end())
|
||||
{
|
||||
obj.Put(itr->first, itr->second->ExtractStatus());
|
||||
obj[itr->first] = itr->second->ExtractStatus();
|
||||
++itr;
|
||||
}
|
||||
return obj;
|
||||
|
@ -112,7 +111,7 @@ namespace llarp
|
|||
}
|
||||
std::unique_ptr< handlers::ExitEndpoint > endpoint;
|
||||
// make new endpoint
|
||||
endpoint.reset(new handlers::ExitEndpoint(name, m_Router));
|
||||
endpoint = std::make_unique< handlers::ExitEndpoint >(name, m_Router);
|
||||
// configure
|
||||
{
|
||||
auto itr = conf.begin();
|
||||
|
|
|
@ -14,20 +14,18 @@ namespace llarp
|
|||
struct ObtainExitMessage final : public IMessage
|
||||
{
|
||||
std::vector< llarp::exit::Policy > B;
|
||||
uint64_t E;
|
||||
uint64_t E{0};
|
||||
llarp::PubKey I;
|
||||
uint64_t T;
|
||||
uint64_t T{0};
|
||||
std::vector< llarp::exit::Policy > W;
|
||||
llarp_time_t X;
|
||||
llarp_time_t X{0};
|
||||
llarp::Signature Z;
|
||||
|
||||
ObtainExitMessage() : IMessage(), E(0), T(0), X(0)
|
||||
ObtainExitMessage() : IMessage()
|
||||
{
|
||||
}
|
||||
|
||||
~ObtainExitMessage()
|
||||
{
|
||||
}
|
||||
~ObtainExitMessage() override = default;
|
||||
|
||||
void
|
||||
Clear() override
|
||||
|
@ -132,7 +130,7 @@ namespace llarp
|
|||
Nonce_t Y;
|
||||
llarp::Signature Z;
|
||||
|
||||
~UpdateExitVerifyMessage() = default;
|
||||
~UpdateExitVerifyMessage() override = default;
|
||||
|
||||
void
|
||||
Clear() override
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <path/path.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <util/memfn.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -17,7 +18,7 @@ namespace llarp
|
|||
AbstractRouter* r, size_t numpaths, size_t hoplen, bool bundleRC)
|
||||
: llarp::path::Builder(r, numpaths, hoplen)
|
||||
, m_ExitRouter(routerId)
|
||||
, m_WritePacket(writepkt)
|
||||
, m_WritePacket(std::move(writepkt))
|
||||
, m_Counter(0)
|
||||
, m_LastUse(0)
|
||||
, m_BundleRC(bundleRC)
|
||||
|
@ -25,9 +26,7 @@ namespace llarp
|
|||
CryptoManager::instance()->identity_keygen(m_ExitIdentity);
|
||||
}
|
||||
|
||||
BaseSession::~BaseSession()
|
||||
{
|
||||
}
|
||||
BaseSession::~BaseSession() = default;
|
||||
|
||||
void
|
||||
BaseSession::HandlePathDied(path::Path_ptr p)
|
||||
|
@ -38,10 +37,10 @@ namespace llarp
|
|||
util::StatusObject
|
||||
BaseSession::ExtractStatus() const
|
||||
{
|
||||
auto obj = path::Builder::ExtractStatus();
|
||||
obj.Put("lastExitUse", m_LastUse);
|
||||
auto pub = m_ExitIdentity.toPublic();
|
||||
obj.Put("exitIdentity", pub.ToString());
|
||||
auto obj = path::Builder::ExtractStatus();
|
||||
obj["lastExitUse"] = m_LastUse;
|
||||
auto pub = m_ExitIdentity.toPublic();
|
||||
obj["exitIdentity"] = pub.ToString();
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace llarp
|
|||
AbstractRouter* r, size_t numpaths, size_t hoplen,
|
||||
bool bundleRC);
|
||||
|
||||
virtual ~BaseSession();
|
||||
~BaseSession() override;
|
||||
|
||||
std::shared_ptr< path::PathSet >
|
||||
GetSelf() override
|
||||
|
@ -51,7 +51,7 @@ namespace llarp
|
|||
return m_BundleRC;
|
||||
}
|
||||
|
||||
virtual void
|
||||
void
|
||||
ResetInternalState() override;
|
||||
|
||||
bool UrgentBuild(llarp_time_t) const override;
|
||||
|
@ -175,13 +175,13 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
~ExitSession() = default;
|
||||
~ExitSession() override = default;
|
||||
|
||||
std::string
|
||||
Name() const override;
|
||||
|
||||
protected:
|
||||
virtual void
|
||||
void
|
||||
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const override
|
||||
{
|
||||
// TODO: set expiration time
|
||||
|
@ -197,7 +197,7 @@ namespace llarp
|
|||
AbstractRouter* r, size_t numpaths, size_t hoplen,
|
||||
bool useRouterSNodeKey, bool bundleRC);
|
||||
|
||||
~SNodeSession() = default;
|
||||
~SNodeSession() override = default;
|
||||
|
||||
std::string
|
||||
Name() const override;
|
||||
|
|
|
@ -29,7 +29,8 @@ namespace llarp
|
|||
, m_Resolver(std::make_shared< dns::Proxy >(
|
||||
r->netloop(), r->logic(), r->netloop(), r->logic(), this))
|
||||
, m_Name(name)
|
||||
, m_Tun{{0}, 0, {0}, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
, m_Tun{{0}, 0, {0}, nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr}
|
||||
, m_LocalResolverAddr("127.0.0.1", 53)
|
||||
, m_InetToNetwork(name + "_exit_rx", r->netloop(), r->netloop())
|
||||
|
||||
|
@ -40,9 +41,7 @@ namespace llarp
|
|||
m_ShouldInitTun = true;
|
||||
}
|
||||
|
||||
ExitEndpoint::~ExitEndpoint()
|
||||
{
|
||||
}
|
||||
ExitEndpoint::~ExitEndpoint() = default;
|
||||
|
||||
util::StatusObject
|
||||
ExitEndpoint::ExtractStatus() const
|
||||
|
@ -52,9 +51,9 @@ namespace llarp
|
|||
util::StatusObject exitsObj{};
|
||||
for(const auto &item : m_ActiveExits)
|
||||
{
|
||||
exitsObj.Put(item.first.ToHex(), item.second->ExtractStatus());
|
||||
exitsObj[item.first.ToString()] = item.second->ExtractStatus();
|
||||
}
|
||||
obj.Put("exits", exitsObj);
|
||||
obj["exits"] = exitsObj;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace llarp
|
|||
struct ExitEndpoint : public dns::IQueryHandler
|
||||
{
|
||||
ExitEndpoint(const std::string& name, AbstractRouter* r);
|
||||
~ExitEndpoint();
|
||||
~ExitEndpoint() override;
|
||||
|
||||
void
|
||||
Tick(llarp_time_t now);
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace llarp
|
|||
static void
|
||||
tunifTick(llarp_tun_io *tun)
|
||||
{
|
||||
TunEndpoint *self = static_cast< TunEndpoint * >(tun->user);
|
||||
auto *self = static_cast< TunEndpoint * >(tun->user);
|
||||
self->Flush();
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,14 @@ namespace llarp
|
|||
util::StatusObject
|
||||
TunEndpoint::ExtractStatus() const
|
||||
{
|
||||
auto obj = service::Endpoint::ExtractStatus();
|
||||
obj.Put("ifaddr", m_OurRange.ToString());
|
||||
auto obj = service::Endpoint::ExtractStatus();
|
||||
obj["ifaddr"] = m_OurRange.ToString();
|
||||
|
||||
std::vector< std::string > resolvers;
|
||||
for(const auto &addr : m_UpstreamResolvers)
|
||||
resolvers.emplace_back(addr.ToString());
|
||||
obj.Put("ustreamResolvers", resolvers);
|
||||
obj.Put("localResolver", m_LocalResolverAddr.ToString());
|
||||
obj["ustreamResolvers"] = resolvers;
|
||||
obj["localResolver"] = m_LocalResolverAddr.ToString();
|
||||
util::StatusObject ips{};
|
||||
for(const auto &item : m_IPActivity)
|
||||
{
|
||||
|
@ -84,14 +84,14 @@ namespace llarp
|
|||
remoteStr = RouterID(addr.as_array()).ToString();
|
||||
else
|
||||
remoteStr = service::Address(addr.as_array()).ToString();
|
||||
ipObj.Put("remote", remoteStr);
|
||||
ipObj["remote"] = remoteStr;
|
||||
std::string ipaddr = item.first.ToString();
|
||||
ips.Put(ipaddr.c_str(), ipObj);
|
||||
ips[ipaddr] = ipObj;
|
||||
}
|
||||
obj.Put("addrs", ips);
|
||||
obj.Put("ourIP", m_OurIP.ToString());
|
||||
obj.Put("nextIP", m_NextIP.ToString());
|
||||
obj.Put("maxIP", m_MaxIP.ToString());
|
||||
obj["addrs"] = ips;
|
||||
obj["ourIP"] = m_OurIP.ToString();
|
||||
obj["nextIP"] = m_NextIP.ToString();
|
||||
obj["maxIP"] = m_MaxIP.ToString();
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -412,7 +412,7 @@ namespace llarp
|
|||
}
|
||||
else
|
||||
{
|
||||
dns::Message *replyMsg = new dns::Message(std::move(msg));
|
||||
auto *replyMsg = new dns::Message(std::move(msg));
|
||||
using service::Address;
|
||||
using service::OutboundContext;
|
||||
return EnsurePathToService(
|
||||
|
@ -432,7 +432,7 @@ namespace llarp
|
|||
}
|
||||
else
|
||||
{
|
||||
dns::Message *replyMsg = new dns::Message(std::move(msg));
|
||||
auto *replyMsg = new dns::Message(std::move(msg));
|
||||
EnsurePathToSNode(addr.as_array(),
|
||||
[=](const RouterID &, exit::BaseSession_ptr s) {
|
||||
SendDNSReply(addr, s, replyMsg, reply, true,
|
||||
|
@ -577,7 +577,7 @@ namespace llarp
|
|||
return false;
|
||||
}
|
||||
|
||||
struct addrinfo hint, *res = NULL;
|
||||
struct addrinfo hint, *res = nullptr;
|
||||
int ret;
|
||||
|
||||
memset(&hint, 0, sizeof hint);
|
||||
|
@ -585,7 +585,7 @@ namespace llarp
|
|||
hint.ai_family = PF_UNSPEC;
|
||||
hint.ai_flags = AI_NUMERICHOST;
|
||||
|
||||
ret = getaddrinfo(tunif.ifaddr, NULL, &hint, &res);
|
||||
ret = getaddrinfo(tunif.ifaddr, nullptr, &hint, &res);
|
||||
if(ret)
|
||||
{
|
||||
llarp::LogError(Name(),
|
||||
|
@ -909,7 +909,7 @@ namespace llarp
|
|||
TunEndpoint::tunifBeforeWrite(llarp_tun_io *tun)
|
||||
{
|
||||
// called in the isolated network thread
|
||||
TunEndpoint *self = static_cast< TunEndpoint * >(tun->user);
|
||||
auto *self = static_cast< TunEndpoint * >(tun->user);
|
||||
// flush user to network
|
||||
self->FlushSend();
|
||||
// flush exit traffic queues if it's there
|
||||
|
@ -928,15 +928,13 @@ namespace llarp
|
|||
TunEndpoint::tunifRecvPkt(llarp_tun_io *tun, const llarp_buffer_t &b)
|
||||
{
|
||||
// called for every packet read from user in isolated network thread
|
||||
TunEndpoint *self = static_cast< TunEndpoint * >(tun->user);
|
||||
auto *self = static_cast< TunEndpoint * >(tun->user);
|
||||
const ManagedBuffer buf(b);
|
||||
self->m_UserToNetworkPktQueue.EmplaceIf(
|
||||
[&buf](net::IPPacket &pkt) -> bool { return pkt.Load(buf); });
|
||||
}
|
||||
|
||||
TunEndpoint::~TunEndpoint()
|
||||
{
|
||||
}
|
||||
TunEndpoint::~TunEndpoint() = default;
|
||||
|
||||
} // namespace handlers
|
||||
} // namespace llarp
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace llarp
|
|||
{
|
||||
TunEndpoint(const std::string& nickname, AbstractRouter* r,
|
||||
llarp::service::Context* parent);
|
||||
~TunEndpoint();
|
||||
~TunEndpoint() override;
|
||||
|
||||
path::PathSet_ptr
|
||||
GetSelf() override
|
||||
|
@ -29,10 +29,10 @@ namespace llarp
|
|||
return shared_from_this();
|
||||
}
|
||||
|
||||
virtual bool
|
||||
bool
|
||||
SetOption(const std::string& k, const std::string& v) override;
|
||||
|
||||
virtual void
|
||||
void
|
||||
Tick(llarp_time_t now) override;
|
||||
|
||||
util::StatusObject
|
||||
|
@ -165,7 +165,7 @@ namespace llarp
|
|||
void
|
||||
Flush();
|
||||
|
||||
virtual void
|
||||
void
|
||||
ResetInternalState() override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -26,9 +26,7 @@ namespace llarp
|
|||
|
||||
using Backend_ptr = std::shared_ptr< IBackend >;
|
||||
|
||||
inline IBackend::~IBackend()
|
||||
{
|
||||
}
|
||||
inline IBackend::~IBackend() = default;
|
||||
} // namespace hooks
|
||||
} // namespace llarp
|
||||
|
||||
|
|
|
@ -13,9 +13,7 @@ namespace llarp
|
|||
m_FlowCookie.Randomize();
|
||||
}
|
||||
|
||||
LinkLayer::~LinkLayer()
|
||||
{
|
||||
}
|
||||
LinkLayer::~LinkLayer() = default;
|
||||
|
||||
void
|
||||
LinkLayer::Pump()
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace llarp
|
|||
SessionRenegotiateHandler reneg, SignBufferFunc sign,
|
||||
TimeoutHandler timeout, SessionClosedHandler closed);
|
||||
|
||||
~LinkLayer();
|
||||
~LinkLayer() override;
|
||||
|
||||
bool
|
||||
Start(std::shared_ptr< Logic > l) override;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <iwp/outermessage.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -15,9 +16,7 @@ namespace llarp
|
|||
Clear();
|
||||
}
|
||||
|
||||
OuterMessage::~OuterMessage()
|
||||
{
|
||||
}
|
||||
OuterMessage::~OuterMessage() = default;
|
||||
|
||||
void
|
||||
OuterMessage::Clear()
|
||||
|
@ -131,7 +130,7 @@ namespace llarp
|
|||
return false;
|
||||
if(buf->size_left() == Zsig.size() + 32)
|
||||
{
|
||||
A.reset(new AlignedBuffer< 32 >());
|
||||
A = std::make_unique< AlignedBuffer< 32 > >();
|
||||
if(!buf->read_into(A->begin(), A->end()))
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,6 @@ namespace llarp
|
|||
struct IOutboundSessionMaker;
|
||||
struct RouterID;
|
||||
|
||||
namespace util
|
||||
{
|
||||
struct StatusObject;
|
||||
} // namespace util
|
||||
|
||||
struct ILinkManager
|
||||
{
|
||||
virtual ~ILinkManager() = default;
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace llarp
|
|||
struct LinkManager final : public ILinkManager
|
||||
{
|
||||
public:
|
||||
~LinkManager() = default;
|
||||
~LinkManager() override = default;
|
||||
|
||||
LinkLayer_ptr
|
||||
GetCompatibleLink(const RouterContact &rc) const override;
|
||||
|
@ -71,7 +71,7 @@ namespace llarp
|
|||
void
|
||||
CheckPersistingSessions(llarp_time_t now) override;
|
||||
|
||||
virtual util::StatusObject
|
||||
util::StatusObject
|
||||
ExtractStatus() const override;
|
||||
|
||||
void
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <util/fs.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -12,20 +13,18 @@ namespace llarp
|
|||
SessionEstablishedHandler establishedSession,
|
||||
SessionRenegotiateHandler reneg,
|
||||
TimeoutHandler timeout, SessionClosedHandler closed)
|
||||
: HandleMessage(handler)
|
||||
, HandleTimeout(timeout)
|
||||
, Sign(signbuf)
|
||||
, GetOurRC(getrc)
|
||||
, SessionEstablished(establishedSession)
|
||||
, SessionClosed(closed)
|
||||
, SessionRenegotiate(reneg)
|
||||
: HandleMessage(std::move(handler))
|
||||
, HandleTimeout(std::move(timeout))
|
||||
, Sign(std::move(signbuf))
|
||||
, GetOurRC(std::move(getrc))
|
||||
, SessionEstablished(std::move(establishedSession))
|
||||
, SessionClosed(std::move(closed))
|
||||
, SessionRenegotiate(std::move(reneg))
|
||||
, m_RouterEncSecret(routerEncSecret)
|
||||
{
|
||||
}
|
||||
|
||||
ILinkLayer::~ILinkLayer()
|
||||
{
|
||||
}
|
||||
ILinkLayer::~ILinkLayer() = default;
|
||||
|
||||
bool
|
||||
ILinkLayer::HasSessionTo(const RouterID& id)
|
||||
|
|
|
@ -16,9 +16,7 @@ namespace llarp
|
|||
|
||||
struct ILinkSession
|
||||
{
|
||||
virtual ~ILinkSession()
|
||||
{
|
||||
}
|
||||
virtual ~ILinkSession() = default;
|
||||
|
||||
/// delivery status of a message
|
||||
enum class DeliveryStatus
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace llarp
|
|||
{
|
||||
struct DHTImmediateMessage final : public ILinkMessage
|
||||
{
|
||||
DHTImmediateMessage() = default;
|
||||
~DHTImmediateMessage() = default;
|
||||
DHTImmediateMessage() = default;
|
||||
~DHTImmediateMessage() override = default;
|
||||
|
||||
std::vector< std::unique_ptr< dht::IMessage > > msgs;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace llarp
|
|||
{
|
||||
return bencode_read_integer(buf, &P);
|
||||
}
|
||||
else if(key == "r")
|
||||
if(key == "r")
|
||||
{
|
||||
if(rc.BDecode(buf))
|
||||
return true;
|
||||
|
@ -39,7 +39,7 @@ namespace llarp
|
|||
llarp::DumpBuffer(*buf);
|
||||
return false;
|
||||
}
|
||||
else if(key == "v")
|
||||
if(key == "v")
|
||||
{
|
||||
if(!bencode_read_integer(buf, &version))
|
||||
return false;
|
||||
|
@ -52,15 +52,13 @@ namespace llarp
|
|||
llarp::LogDebug("LIM version ", version);
|
||||
return true;
|
||||
}
|
||||
else if(key == "z")
|
||||
if(key == "z")
|
||||
{
|
||||
return Z.BDecode(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
llarp::LogWarn("invalid LIM key: ", *key.cur);
|
||||
return false;
|
||||
}
|
||||
|
||||
llarp::LogWarn("invalid LIM key: ", *key.cur);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -37,9 +37,7 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
LinkMessageParser::~LinkMessageParser()
|
||||
{
|
||||
}
|
||||
LinkMessageParser::~LinkMessageParser() = default;
|
||||
|
||||
bool
|
||||
LinkMessageParser::operator()(llarp_buffer_t* buffer, llarp_buffer_t* key)
|
||||
|
|
|
@ -171,9 +171,9 @@ namespace llarp
|
|||
|
||||
struct LRCMFrameDecrypt
|
||||
{
|
||||
typedef llarp::path::PathContext Context;
|
||||
typedef llarp::path::TransitHop Hop;
|
||||
typedef AsyncFrameDecrypter< LRCMFrameDecrypt > Decrypter;
|
||||
using Context = llarp::path::PathContext;
|
||||
using Hop = llarp::path::TransitHop;
|
||||
using Decrypter = AsyncFrameDecrypter< LRCMFrameDecrypt >;
|
||||
using Decrypter_ptr = std::unique_ptr< Decrypter >;
|
||||
Decrypter_ptr decrypter;
|
||||
std::array< EncryptedFrame, 8 > frames;
|
||||
|
@ -193,9 +193,7 @@ namespace llarp
|
|||
hop->info.downstream = commit->session->GetPubKey();
|
||||
}
|
||||
|
||||
~LRCMFrameDecrypt()
|
||||
{
|
||||
}
|
||||
~LRCMFrameDecrypt() = default;
|
||||
|
||||
static void
|
||||
OnForwardLRCMResult(AbstractRouter* router, const PathID_t pathid,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -49,14 +50,14 @@ namespace llarp
|
|||
{
|
||||
std::array< EncryptedFrame, 8 > frames;
|
||||
|
||||
LR_CommitMessage(const std::array< EncryptedFrame, 8 > &_frames)
|
||||
: ILinkMessage(), frames(_frames)
|
||||
LR_CommitMessage(std::array< EncryptedFrame, 8 > _frames)
|
||||
: ILinkMessage(), frames(std::move(_frames))
|
||||
{
|
||||
}
|
||||
|
||||
LR_CommitMessage() = default;
|
||||
|
||||
~LR_CommitMessage() = default;
|
||||
~LR_CommitMessage() override = default;
|
||||
|
||||
void
|
||||
Clear() override;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <util/memfn.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -25,10 +26,12 @@ namespace llarp
|
|||
HopHandler_ptr path;
|
||||
AbstractRouter* router;
|
||||
|
||||
LRSM_AsyncHandler(const std::array< EncryptedFrame, 8 >& _frames,
|
||||
uint64_t _status, HopHandler_ptr _path,
|
||||
AbstractRouter* _router)
|
||||
: frames(_frames), status(_status), path(_path), router(_router)
|
||||
LRSM_AsyncHandler(std::array< EncryptedFrame, 8 > _frames, uint64_t _status,
|
||||
HopHandler_ptr _path, AbstractRouter* _router)
|
||||
: frames(std::move(_frames))
|
||||
, status(_status)
|
||||
, path(std::move(_path))
|
||||
, router(_router)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -57,7 +60,7 @@ namespace llarp
|
|||
{
|
||||
return BEncodeReadArray(frames, buf);
|
||||
}
|
||||
else if(key == "p")
|
||||
if(key == "p")
|
||||
{
|
||||
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
|
||||
{
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue