mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2a7ebce8f4
13 changed files with 337 additions and 246 deletions
127
CMakeLists.txt
127
CMakeLists.txt
|
@ -22,17 +22,32 @@ option(WITH_COVERAGE "generate coverage data")
|
|||
option(WARNINGS_AS_ERRORS "treat all warnings as errors. turn off for development, on for release" OFF)
|
||||
|
||||
include(cmake/target_link_libraries_system.cmake)
|
||||
include(cmake/add_import_library.cmake)
|
||||
include(cmake/add_log_tag.cmake)
|
||||
|
||||
# Basic definitions
|
||||
get_filename_component(CORE_INCLUDE include ABSOLUTE)
|
||||
get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/${ABYSS}/include" ABSOLUTE)
|
||||
set(LIB lokinet)
|
||||
set(SHARED_LIB ${LIB}-shared)
|
||||
set(STATIC_LIB ${LIB}-static)
|
||||
set(CRYPTOGRAPHY_LIB ${LIB}-cryptography)
|
||||
set(UTIL_LIB ${LIB}-util)
|
||||
set(PLATFORM_LIB ${LIB}-platform)
|
||||
set(ANDROID_LIB ${LIB}android)
|
||||
set(ABYSS libabyss)
|
||||
set(ABYSS_LIB abyss)
|
||||
set(ABYSS_EXE ${ABYSS_LIB}-main)
|
||||
get_filename_component(TT_ROOT "vendor/libtuntap-master" ABSOLUTE)
|
||||
add_definitions(-D${CMAKE_SYSTEM_NAME})
|
||||
|
||||
get_filename_component(CORE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include" ABSOLUTE)
|
||||
get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" ABSOLUTE)
|
||||
|
||||
find_program(CCACHE_PROGRAM ccache)
|
||||
if(CCACHE_PROGRAM)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
|
||||
endif()
|
||||
|
||||
if (MSVC_VERSION)
|
||||
if(MSVC_VERSION)
|
||||
enable_language(ASM_MASM)
|
||||
list(APPEND CMAKE_ASM_MASM_SOURCE_FILE_EXTENSIONS s)
|
||||
add_definitions(/D_WIN32_WINNT=0x0600 /DNOMINMAX /DSODIUM_STATIC)
|
||||
|
@ -44,8 +59,6 @@ include(cmake/solaris.cmake)
|
|||
|
||||
if(WIN32)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
ENABLE_LANGUAGE(RC)
|
||||
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lshlwapi")
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
endif(WIN32)
|
||||
|
@ -57,19 +70,13 @@ if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW)
|
|||
message( FATAL_ERROR "shadow-framework is Linux only" )
|
||||
endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW)
|
||||
|
||||
if (WIN32 AND NOT STATIC_LINK_RUNTIME)
|
||||
if(NOT MSVC)
|
||||
message("must ship compiler runtime libraries with this build: libwinpthread-1.dll, libgcc_s_dw2-1.dll, and libstdc++-6.dll")
|
||||
message("for release builds, turn on STATIC_LINK_RUNTIME in cmake options")
|
||||
endif()
|
||||
endif(WIN32 AND NOT STATIC_LINK_RUNTIME)
|
||||
|
||||
set(ABSEIL_DIR vendor/abseil-cpp)
|
||||
add_subdirectory(${ABSEIL_DIR})
|
||||
include_directories(SYSTEM ${ABSEIL_DIR})
|
||||
add_subdirectory(vendor/cxxopts)
|
||||
add_subdirectory(vendor/nlohmann)
|
||||
include_directories(SYSTEM vendor/cxxopts/include)
|
||||
|
||||
# still need the headers unconditionally
|
||||
set(ABSEIL_DIR vendor/abseil-cpp)
|
||||
if (NOT WIN32)
|
||||
add_compile_options(-fPIC)
|
||||
endif(NOT WIN32)
|
||||
|
@ -94,31 +101,9 @@ include(cmake/coverage.cmake)
|
|||
|
||||
# these vars are set by the cmake toolchain spec
|
||||
if (WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE)
|
||||
# dynamic linking does this all the time
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
option(NO_LIBGCC "use libunwind+compiler-rt instead, must already be installed in mingw-w64 sysroot" OFF)
|
||||
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}")
|
||||
endif(NO_LIBGCC)
|
||||
else()
|
||||
# found it. this is GNU only
|
||||
add_compile_options(-Wno-cast-function-type)
|
||||
endif()
|
||||
include(cmake/cross_compile.cmake)
|
||||
endif(WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE)
|
||||
|
||||
if(WIN32 AND NOT MSVC_VERSION)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-bad-function-cast>)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-cast-function-type>)
|
||||
# unlike unix where you get a *single* compiler ID string in .comment
|
||||
# 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)
|
||||
set(FS_LIB stdc++fs)
|
||||
endif()
|
||||
|
||||
if(DEBIAN)
|
||||
add_definitions(-DDEBIAN)
|
||||
elseif(NOT ANDROID AND NOT NON_PC_TARGET)
|
||||
|
@ -185,11 +170,6 @@ if(SHADOW)
|
|||
include(cmake/shadow.cmake)
|
||||
endif(SHADOW)
|
||||
|
||||
# if(CMAKE_BUILD_TYPE MATCHES Release AND CMAKE_CXX_COMPILER_ID MATCHES "Clang|GCC")
|
||||
# set(OPTIMIZE_FLAGS -UNDEBUG)
|
||||
# endif()
|
||||
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
|
||||
set(OPTIMIZE_FLAGS "")
|
||||
add_definitions(-DLOKINET_DEBUG=1)
|
||||
|
@ -212,13 +192,6 @@ if(NOT GIT_VERSION)
|
|||
add_definitions("-DGIT_REV=\"${GIT_VERSION}\"")
|
||||
endif(NOT GIT_VERSION)
|
||||
|
||||
if(RELEASE_MOTTO)
|
||||
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
|
||||
if(WIN32)
|
||||
add_definitions(-DRELEASE_MOTTO=${RELEASE_MOTTO})
|
||||
endif(WIN32)
|
||||
endif(RELEASE_MOTTO)
|
||||
|
||||
set(EXE lokinet)
|
||||
set(EXE_SRC daemon/main.cpp)
|
||||
|
||||
|
@ -242,35 +215,13 @@ if(ANDROID)
|
|||
set(ANDROID_PLATFORM_SRC android/ifaddrs.c)
|
||||
endif(ANDROID)
|
||||
|
||||
set(LIB lokinet)
|
||||
set(SHARED_LIB ${LIB}-shared)
|
||||
set(STATIC_LIB ${LIB}-static)
|
||||
set(CRYPTOGRAPHY_LIB ${LIB}-cryptography)
|
||||
set(UTIL_LIB ${LIB}-util)
|
||||
set(PLATFORM_LIB ${LIB}-platform)
|
||||
set(ANDROID_LIB ${LIB}android)
|
||||
set(ABYSS libabyss)
|
||||
set(ABYSS_LIB abyss)
|
||||
set(ABYSS_EXE ${ABYSS_LIB}-main)
|
||||
get_filename_component(TT_ROOT "vendor/libtuntap-master" ABSOLUTE)
|
||||
add_definitions(-D${CMAKE_SYSTEM_NAME})
|
||||
|
||||
function(add_import_library libname)
|
||||
add_library(libname SHARED IMPORTED)
|
||||
if(NOT TARGET libname)
|
||||
message(FATAL "unable to find library ${libname}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(UNIX)
|
||||
include(cmake/unix.cmake)
|
||||
elseif(WIN32)
|
||||
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 -D_WIN32_WINNT=0x0500)
|
||||
include(cmake/win32.cmake)
|
||||
else()
|
||||
message(FATAL_ERROR "What operating system _are_ you building on/for?")
|
||||
endif(UNIX)
|
||||
endif()
|
||||
|
||||
set(LIBTUNTAP_SRC_BASE
|
||||
${TT_ROOT}/tuntap.cpp
|
||||
|
@ -281,34 +232,16 @@ if(UNIX)
|
|||
set(LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c ${LIBTUNTAP_SRC_BASE})
|
||||
else()
|
||||
set(LIBTUNTAP_SRC ${LIBTUNTAP_SRC_BASE})
|
||||
endif(UNIX)
|
||||
endif()
|
||||
|
||||
if(NOT WIN32)
|
||||
add_subdirectory(vendor)
|
||||
endif(NOT WIN32)
|
||||
|
||||
function(add_log_tag target)
|
||||
get_target_property(TARGET_SRCS ${target} SOURCES)
|
||||
foreach(F ${TARGET_SRCS})
|
||||
set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\")
|
||||
endforeach(F)
|
||||
endfunction()
|
||||
|
||||
set(ABYSS_SRC
|
||||
${ABYSS}/src/md5.cpp
|
||||
${ABYSS}/src/http.cpp
|
||||
${ABYSS}/src/client.cpp
|
||||
${ABYSS}/src/server.cpp)
|
||||
add_library(${ABYSS_LIB} STATIC ${ABYSS_SRC})
|
||||
|
||||
add_subdirectory(${ABSEIL_DIR})
|
||||
include_directories(SYSTEM ${ABSEIL_DIR})
|
||||
endif()
|
||||
|
||||
add_subdirectory(crypto)
|
||||
add_subdirectory(libutp)
|
||||
add_subdirectory(llarp)
|
||||
|
||||
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
|
||||
add_subdirectory(libabyss)
|
||||
|
||||
if (NOT WIN32)
|
||||
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp)
|
||||
|
@ -331,12 +264,6 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
|||
add_log_tag(${ABYSS_EXE})
|
||||
add_log_tag(${ABYSS_LIB})
|
||||
|
||||
if (WIN32)
|
||||
set(EXE_LIBS ${STATIC_LIB} ws2_32 iphlpapi)
|
||||
else()
|
||||
set(EXE_LIBS ${STATIC_LIB} cppbackport libutp)
|
||||
endif(WIN32)
|
||||
|
||||
|
||||
if(SHADOW)
|
||||
set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB})
|
||||
|
|
6
cmake/add_import_library.cmake
Normal file
6
cmake/add_import_library.cmake
Normal file
|
@ -0,0 +1,6 @@
|
|||
function(add_import_library libname)
|
||||
add_library(libname SHARED IMPORTED)
|
||||
if(NOT TARGET libname)
|
||||
message(FATAL "unable to find library ${libname}")
|
||||
endif()
|
||||
endfunction()
|
6
cmake/add_log_tag.cmake
Normal file
6
cmake/add_log_tag.cmake
Normal file
|
@ -0,0 +1,6 @@
|
|||
function(add_log_tag target)
|
||||
get_target_property(TARGET_SRCS ${target} SOURCES)
|
||||
foreach(F ${TARGET_SRCS})
|
||||
set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\")
|
||||
endforeach(F)
|
||||
endfunction()
|
13
cmake/cross_compile.cmake
Normal file
13
cmake/cross_compile.cmake
Normal file
|
@ -0,0 +1,13 @@
|
|||
# dynamic linking does this all the time
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
option(NO_LIBGCC "use libunwind+compiler-rt instead, must already be installed in mingw-w64 sysroot" OFF)
|
||||
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}")
|
||||
endif(NO_LIBGCC)
|
||||
else()
|
||||
# found it. this is GNU only
|
||||
add_compile_options(-Wno-cast-function-type)
|
||||
endif()
|
|
@ -1,10 +1,11 @@
|
|||
add_definitions(-DUNIX)
|
||||
add_definitions(-DPOSIX)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_epoll.cpp" ABSOLUTE)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
||||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_epoll.cpp" ABSOLUTE)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
|
@ -28,3 +29,9 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
|
|||
else()
|
||||
message(FATAL_ERROR "Your operating system is not supported yet")
|
||||
endif()
|
||||
|
||||
set(EXE_LIBS ${STATIC_LIB} cppbackport libutp)
|
||||
|
||||
if(RELEASE_MOTTO)
|
||||
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
|
||||
endif()
|
||||
|
|
27
cmake/win32.cmake
Normal file
27
cmake/win32.cmake
Normal file
|
@ -0,0 +1,27 @@
|
|||
enable_language(RC)
|
||||
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lshlwapi")
|
||||
|
||||
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 -D_WIN32_WINNT=0x0500)
|
||||
set(EXE_LIBS ${STATIC_LIB} ws2_32 iphlpapi)
|
||||
|
||||
if(RELEASE_MOTTO)
|
||||
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
|
||||
add_definitions(-DRELEASE_MOTTO=${RELEASE_MOTTO})
|
||||
endif()
|
||||
|
||||
if (NOT STATIC_LINK_RUNTIME AND NOT MSVC)
|
||||
message("must ship compiler runtime libraries with this build: libwinpthread-1.dll, libgcc_s_dw2-1.dll, and libstdc++-6.dll")
|
||||
message("for release builds, turn on STATIC_LINK_RUNTIME in cmake options")
|
||||
endif()
|
||||
|
||||
if(NOT MSVC_VERSION)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-bad-function-cast>)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-cast-function-type>)
|
||||
# unlike unix where you get a *single* compiler ID string in .comment
|
||||
# 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)
|
||||
set(FS_LIB stdc++fs)
|
||||
endif()
|
|
@ -1,15 +1,7 @@
|
|||
add_library(${ABYSS_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/src/md5.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/http.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/client.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp")
|
||||
|
||||
set(ABYSS src)
|
||||
|
||||
set(ABYSS_LIB abyss)
|
||||
|
||||
include_directories(include)
|
||||
|
||||
set(ABYSS_SRC
|
||||
${ABYSS}/md5.cpp
|
||||
${ABYSS}/http.cpp
|
||||
${ABYSS}/client.cpp
|
||||
${ABYSS}/server.cpp
|
||||
${ABYSS}/json.cpp)
|
||||
|
||||
add_library(${ABYSS_LIB} ${ABYSS_SRC})
|
||||
target_include_directories(${ABYSS_LIB} PUBLIC include)
|
||||
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
|
||||
|
|
|
@ -216,6 +216,7 @@ set(LIB_SRC
|
|||
service/async_key_exchange.cpp
|
||||
service/config.cpp
|
||||
service/context.cpp
|
||||
service/endpoint_util.cpp
|
||||
service/endpoint.cpp
|
||||
service/handler.cpp
|
||||
service/hidden_service_address_lookup.cpp
|
||||
|
|
|
@ -217,6 +217,7 @@ namespace llarp
|
|||
// we are not allowed to forward it ... now what?
|
||||
llarp::LogError("path to ", self->hop->info.upstream,
|
||||
"not allowed, dropping build request on the floor");
|
||||
self->hop = nullptr;
|
||||
return;
|
||||
}
|
||||
// persist sessions to upstream and downstream routers until the commit
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <nodedb.hpp>
|
||||
#include <profiling.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <service/endpoint_util.hpp>
|
||||
#include <service/hidden_service_address_lookup.hpp>
|
||||
#include <service/outbound_context.hpp>
|
||||
#include <service/protocol.hpp>
|
||||
|
@ -242,54 +243,11 @@ namespace llarp
|
|||
}
|
||||
|
||||
// expire snode sessions
|
||||
{
|
||||
auto itr = m_SNodeSessions.begin();
|
||||
while(itr != m_SNodeSessions.end())
|
||||
{
|
||||
itr->second->Tick(now);
|
||||
if(itr->second->ShouldRemove())
|
||||
{
|
||||
itr = m_SNodeSessions.erase(itr);
|
||||
continue;
|
||||
}
|
||||
// expunge next tick
|
||||
if(itr->second->IsExpired(now))
|
||||
itr->second->Stop();
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
EndpointUtil::ExpireSNodeSessions(now, m_SNodeSessions);
|
||||
// expire pending tx
|
||||
{
|
||||
auto itr = m_PendingLookups.begin();
|
||||
while(itr != m_PendingLookups.end())
|
||||
{
|
||||
if(itr->second->IsTimedOut(now))
|
||||
{
|
||||
std::unique_ptr< IServiceLookup > lookup = std::move(itr->second);
|
||||
|
||||
LogInfo(lookup->name, " timed out txid=", lookup->txid);
|
||||
lookup->HandleResponse({});
|
||||
itr = m_PendingLookups.erase(itr);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
EndpointUtil::ExpirePendingTx(now, m_PendingLookups);
|
||||
// expire pending router lookups
|
||||
{
|
||||
auto itr = m_PendingRouters.begin();
|
||||
while(itr != m_PendingRouters.end())
|
||||
{
|
||||
if(itr->second.IsExpired(now))
|
||||
{
|
||||
LogInfo("lookup for ", itr->first, " timed out");
|
||||
itr = m_PendingRouters.erase(itr);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
EndpointUtil::ExpirePendingRouterLookups(now, m_PendingRouters);
|
||||
|
||||
// prefetch addrs
|
||||
for(const auto& addr : m_PrefetchAddrs)
|
||||
|
@ -298,8 +256,8 @@ namespace llarp
|
|||
{
|
||||
if(!EnsurePathToService(
|
||||
addr,
|
||||
[](__attribute__((unused)) Address addr,
|
||||
__attribute__((unused)) OutboundContext* ctx) {},
|
||||
[](ABSL_ATTRIBUTE_UNUSED Address addr,
|
||||
ABSL_ATTRIBUTE_UNUSED OutboundContext* ctx) {},
|
||||
10000))
|
||||
{
|
||||
LogWarn("failed to ensure path to ", addr);
|
||||
|
@ -349,61 +307,20 @@ namespace llarp
|
|||
#endif
|
||||
|
||||
// deregister dead sessions
|
||||
{
|
||||
auto itr = m_DeadSessions.begin();
|
||||
while(itr != m_DeadSessions.end())
|
||||
{
|
||||
itr->second->Tick(now);
|
||||
if(itr->second->IsDone(now))
|
||||
itr = m_DeadSessions.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
EndpointUtil::DeregisterDeadSessions(now, m_DeadSessions);
|
||||
// tick remote sessions
|
||||
{
|
||||
auto itr = m_RemoteSessions.begin();
|
||||
while(itr != m_RemoteSessions.end())
|
||||
{
|
||||
if(itr->second->Pump(now))
|
||||
{
|
||||
itr->second->Stop();
|
||||
m_DeadSessions.emplace(itr->first, std::move(itr->second));
|
||||
itr = m_RemoteSessions.erase(itr);
|
||||
}
|
||||
else
|
||||
{
|
||||
itr->second->Tick(now);
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
EndpointUtil::TickRemoteSessions(now, m_RemoteSessions, m_DeadSessions);
|
||||
// expire convotags
|
||||
{
|
||||
auto itr = m_Sessions.begin();
|
||||
while(itr != m_Sessions.end())
|
||||
{
|
||||
if(itr->second.IsExpired(now))
|
||||
itr = m_Sessions.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
EndpointUtil::ExpireConvoSessions(now, m_Sessions);
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::Stop()
|
||||
{
|
||||
// stop remote sessions
|
||||
for(auto& item : m_RemoteSessions)
|
||||
{
|
||||
item.second->Stop();
|
||||
}
|
||||
EndpointUtil::StopRemoteSessions(m_RemoteSessions);
|
||||
// stop snode sessions
|
||||
for(auto& item : m_SNodeSessions)
|
||||
{
|
||||
item.second->Stop();
|
||||
}
|
||||
EndpointUtil::StopSnodeSessions(m_SNodeSessions);
|
||||
if(m_OnDown)
|
||||
m_OnDown->NotifyAsync(NotifyParams());
|
||||
return path::Builder::Stop();
|
||||
|
@ -427,15 +344,7 @@ namespace llarp
|
|||
bool
|
||||
Endpoint::HasPathToService(const Address& addr) const
|
||||
{
|
||||
auto range = m_RemoteSessions.equal_range(addr);
|
||||
Sessions::const_iterator itr = range.first;
|
||||
while(itr != range.second)
|
||||
{
|
||||
if(itr->second->ReadyToSend())
|
||||
return true;
|
||||
++itr;
|
||||
}
|
||||
return false;
|
||||
return EndpointUtil::HasPathToService(addr, m_RemoteSessions);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1016,8 +925,7 @@ namespace llarp
|
|||
|
||||
bool
|
||||
Endpoint::EnsurePathToService(const Address& remote, PathEnsureHook hook,
|
||||
__attribute__((unused))
|
||||
llarp_time_t timeoutMS,
|
||||
ABSL_ATTRIBUTE_UNUSED llarp_time_t timeoutMS,
|
||||
bool randomPath)
|
||||
{
|
||||
path::Path_ptr path = nullptr;
|
||||
|
|
|
@ -353,6 +353,8 @@ namespace llarp
|
|||
hooks::Backend_ptr m_OnReady;
|
||||
|
||||
private:
|
||||
friend struct EndpointUtil;
|
||||
|
||||
AbstractRouter* m_Router;
|
||||
llarp_threadpool* m_IsolatedWorker = nullptr;
|
||||
Logic* m_IsolatedLogic = nullptr;
|
||||
|
@ -413,8 +415,9 @@ namespace llarp
|
|||
}
|
||||
};
|
||||
|
||||
std::unordered_map< RouterID, RouterLookupJob, RouterID::Hash >
|
||||
m_PendingRouters;
|
||||
using PendingRouters =
|
||||
std::unordered_map< RouterID, RouterLookupJob, RouterID::Hash >;
|
||||
PendingRouters m_PendingRouters;
|
||||
|
||||
uint64_t m_CurrentPublishTX = 0;
|
||||
llarp_time_t m_LastPublish = 0;
|
||||
|
@ -423,8 +426,10 @@ namespace llarp
|
|||
/// our introset
|
||||
service::IntroSet m_IntroSet;
|
||||
/// pending remote service lookups by id
|
||||
std::unordered_map< uint64_t, std::unique_ptr< service::IServiceLookup > >
|
||||
m_PendingLookups;
|
||||
using PendingLookups =
|
||||
std::unordered_map< uint64_t,
|
||||
std::unique_ptr< service::IServiceLookup > >;
|
||||
PendingLookups m_PendingLookups;
|
||||
/// prefetch remote address list
|
||||
std::set< Address > m_PrefetchAddrs;
|
||||
/// hidden service tag
|
||||
|
@ -435,10 +440,9 @@ namespace llarp
|
|||
std::list< std::function< bool(void) > > m_OnInit;
|
||||
|
||||
/// conversations
|
||||
using ConvoMap_t =
|
||||
std::unordered_map< ConvoTag, Session, ConvoTag::Hash >;
|
||||
using ConvoMap = std::unordered_map< ConvoTag, Session, ConvoTag::Hash >;
|
||||
|
||||
ConvoMap_t m_Sessions;
|
||||
ConvoMap m_Sessions;
|
||||
|
||||
std::unordered_map< Tag, CachedTagResult, Tag::Hash > m_PrefetchedTags;
|
||||
};
|
||||
|
|
153
llarp/service/endpoint_util.cpp
Normal file
153
llarp/service/endpoint_util.cpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
#include <service/endpoint_util.hpp>
|
||||
|
||||
#include <service/outbound_context.hpp>
|
||||
#include <util/logger.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
void
|
||||
EndpointUtil::ExpireSNodeSessions(llarp_time_t now,
|
||||
Endpoint::SNodeSessions& sessions)
|
||||
{
|
||||
auto itr = sessions.begin();
|
||||
while(itr != sessions.end())
|
||||
{
|
||||
if(itr->second->ShouldRemove() && itr->second->IsStopped())
|
||||
{
|
||||
itr = sessions.erase(itr);
|
||||
continue;
|
||||
}
|
||||
// expunge next tick
|
||||
if(itr->second->IsExpired(now))
|
||||
{
|
||||
itr->second->Stop();
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EndpointUtil::ExpirePendingTx(llarp_time_t now,
|
||||
Endpoint::PendingLookups& lookups)
|
||||
{
|
||||
for(auto itr = lookups.begin(); itr != lookups.end();)
|
||||
{
|
||||
if(!itr->second->IsTimedOut(now))
|
||||
{
|
||||
++itr;
|
||||
continue;
|
||||
}
|
||||
std::unique_ptr< IServiceLookup > lookup = std::move(itr->second);
|
||||
|
||||
LogInfo(lookup->name, " timed out txid=", lookup->txid);
|
||||
lookup->HandleResponse({});
|
||||
itr = lookups.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EndpointUtil::ExpirePendingRouterLookups(llarp_time_t now,
|
||||
Endpoint::PendingRouters& routers)
|
||||
{
|
||||
for(auto itr = routers.begin(); itr != routers.end();)
|
||||
{
|
||||
if(!itr->second.IsExpired(now))
|
||||
{
|
||||
++itr;
|
||||
continue;
|
||||
}
|
||||
LogInfo("lookup for ", itr->first, " timed out");
|
||||
itr = routers.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EndpointUtil::DeregisterDeadSessions(llarp_time_t now,
|
||||
Endpoint::Sessions& sessions)
|
||||
{
|
||||
auto itr = sessions.begin();
|
||||
while(itr != sessions.end())
|
||||
{
|
||||
if(itr->second->IsDone(now))
|
||||
{
|
||||
itr = sessions.erase(itr);
|
||||
}
|
||||
else
|
||||
{
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EndpointUtil::TickRemoteSessions(llarp_time_t now,
|
||||
Endpoint::Sessions& remoteSessions,
|
||||
Endpoint::Sessions& deadSessions)
|
||||
{
|
||||
auto itr = remoteSessions.begin();
|
||||
while(itr != remoteSessions.end())
|
||||
{
|
||||
if(itr->second->Tick(now))
|
||||
{
|
||||
itr->second->Stop();
|
||||
deadSessions.emplace(std::move(*itr));
|
||||
itr = remoteSessions.erase(itr);
|
||||
}
|
||||
else
|
||||
{
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EndpointUtil::ExpireConvoSessions(llarp_time_t now,
|
||||
Endpoint::ConvoMap& sessions)
|
||||
{
|
||||
auto itr = sessions.begin();
|
||||
while(itr != sessions.end())
|
||||
{
|
||||
if(itr->second.IsExpired(now))
|
||||
itr = sessions.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EndpointUtil::StopRemoteSessions(Endpoint::Sessions& remoteSessions)
|
||||
{
|
||||
for(auto& item : remoteSessions)
|
||||
{
|
||||
item.second->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EndpointUtil::StopSnodeSessions(Endpoint::SNodeSessions& sessions)
|
||||
{
|
||||
for(auto& item : sessions)
|
||||
{
|
||||
item.second->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
EndpointUtil::HasPathToService(const Address& addr,
|
||||
const Endpoint::Sessions& remoteSessions)
|
||||
{
|
||||
auto range = remoteSessions.equal_range(addr);
|
||||
auto itr = range.first;
|
||||
while(itr != range.second)
|
||||
{
|
||||
if(itr->second->ReadyToSend())
|
||||
return true;
|
||||
++itr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace service
|
||||
} // namespace llarp
|
46
llarp/service/endpoint_util.hpp
Normal file
46
llarp/service/endpoint_util.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef LLARP_SERVICE_ENDPOINT_UTIL_HPP
|
||||
#define LLARP_SERVICE_ENDPOINT_UTIL_HPP
|
||||
|
||||
#include <service/endpoint.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
struct EndpointUtil
|
||||
{
|
||||
static void
|
||||
ExpireSNodeSessions(llarp_time_t now, Endpoint::SNodeSessions& sessions);
|
||||
|
||||
static void
|
||||
ExpirePendingTx(llarp_time_t now, Endpoint::PendingLookups& lookups);
|
||||
|
||||
static void
|
||||
ExpirePendingRouterLookups(llarp_time_t now,
|
||||
Endpoint::PendingRouters& routers);
|
||||
|
||||
static void
|
||||
DeregisterDeadSessions(llarp_time_t now, Endpoint::Sessions& sessions);
|
||||
|
||||
static void
|
||||
TickRemoteSessions(llarp_time_t now, Endpoint::Sessions& remoteSessions,
|
||||
Endpoint::Sessions& deadSessions);
|
||||
|
||||
static void
|
||||
ExpireConvoSessions(llarp_time_t now, Endpoint::ConvoMap& sessions);
|
||||
|
||||
static void
|
||||
StopRemoteSessions(Endpoint::Sessions& remoteSessions);
|
||||
|
||||
static void
|
||||
StopSnodeSessions(Endpoint::SNodeSessions& sessions);
|
||||
|
||||
static bool
|
||||
HasPathToService(const Address& addr,
|
||||
const Endpoint::Sessions& remoteSessions);
|
||||
};
|
||||
} // namespace service
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue