mirror of https://github.com/oxen-io/lokinet
Merge remote-tracking branch 'origin/master'
commit
2a7ebce8f4
@ -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()
|
@ -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()
|
@ -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,30 +1,37 @@
|
||||
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)
|
||||
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(EV_SRC "llarp/ev/ev_epoll.cpp" 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)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c)
|
||||
if (SOLARIS_HAVE_EPOLL)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_epoll.cpp" ABSOLUTE)
|
||||
else()
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_sun.cpp" ABSOLUTE)
|
||||
endif()
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c)
|
||||
if (SOLARIS_HAVE_EPOLL)
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_epoll.cpp" ABSOLUTE)
|
||||
else()
|
||||
get_filename_component(EV_SRC "llarp/ev/ev_sun.cpp" ABSOLUTE)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Your operating system is not supported yet")
|
||||
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()
|
||||
|
@ -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})
|
||||
|
@ -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
|
@ -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 New Issue