Browse Source

Update libzt to the latest version

pull/3872/head^2
staphen 4 years ago committed by Anders Jenbo
parent
commit
9b32c8d541
  1. 4
      .github/workflows/Android.yml
  2. 4
      .github/workflows/Linux_x86.yml
  3. 4
      .github/workflows/Linux_x86_64_SDL1.yml
  4. 4
      .github/workflows/MacOSX.yml
  5. 51
      3rdParty/libzt/CMakeLists.txt
  6. 16
      CMake/platforms/mingw/zt_defs.cmake
  7. 4
      CMake/platforms/windows.cmake
  8. 21
      Source/dvlnet/zerotier_native.cpp

4
.github/workflows/Android.yml

@ -35,8 +35,8 @@ jobs:
uses: actions/cache@v2
with:
path: android-project/app/.cxx
key: android-cmake-${{ github.sha }}
restore-keys: android-cmake-
key: android-cmake-v2-${{ github.sha }}
restore-keys: android-cmake-v2-
- name: Build
working-directory: ${{github.workspace}}

4
.github/workflows/Linux_x86.yml

@ -26,8 +26,8 @@ jobs:
uses: actions/cache@v2
with:
path: build
key: linux-x86-cmake-v2-${{ github.sha }}
restore-keys: linux-x86-cmake-v2-
key: linux-x86-cmake-v3-${{ github.sha }}
restore-keys: linux-x86-cmake-v3-
- name: Configure CMake
shell: bash

4
.github/workflows/Linux_x86_64_SDL1.yml

@ -25,8 +25,8 @@ jobs:
uses: actions/cache@v2
with:
path: build
key: linux-x86_64-sdl1-cmake-${{ github.sha }}
restore-keys: linux-x86_64-sdl1-cmake-
key: linux-x86_64-sdl1-cmake-v2-${{ github.sha }}
restore-keys: linux-x86_64-sdl1-cmake-v2-
- name: Configure CMake
shell: bash

4
.github/workflows/MacOSX.yml

@ -31,8 +31,8 @@ jobs:
uses: actions/cache@v2
with:
path: build
key: macos-cmake-${{ github.sha }}
restore-keys: macos-cmake-
key: macos-cmake-v2-${{ github.sha }}
restore-keys: macos-cmake-v2-
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable

51
3rdParty/libzt/CMakeLists.txt vendored

@ -1,9 +1,11 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
set(BUILD_HOST_SELFTEST OFF)
include(FetchContent)
FetchContent_Declare(libzt
GIT_REPOSITORY https://github.com/diasurgical/libzt.git
GIT_TAG b2be9882771116fcfd4ad918f36de8587324d9e7)
GIT_TAG a9974991b031fd8f84c4bcfd93f129b3938ed8c8)
FetchContent_MakeAvailableExcludeFromAll(libzt)
if(NOT ANDROID)
@ -12,19 +14,25 @@ else()
set(libzt_LIB_NAME zt-shared)
endif()
# External library, ignore all warnings
target_compile_options(zto_obj PRIVATE -w)
target_compile_options(libnatpmp_obj PRIVATE -w)
target_compile_options(libzt_obj PRIVATE -w)
target_compile_options(lwip_obj PRIVATE -w)
target_compile_options(miniupnpc_obj PRIVATE -w)
target_compile_options(${libzt_LIB_NAME} PRIVATE -w)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(zto_obj PRIVATE -fpermissive)
target_compile_options(libzt_obj PRIVATE -fpermissive)
target_compile_options(${libzt_LIB_NAME} PRIVATE -fpermissive)
endif()
foreach(
lib_name
zto_obj
libnatpmp_obj
libzt_obj
lwip_obj
miniupnpc_obj
zto_pic
natpmp_pic
lwip_pic
miniupnpc_pic
ztcore
${libzt_LIB_NAME}
)
if(TARGET ${lib_name})
# External library, ignore all warnings
target_compile_options(${lib_name} PRIVATE -w)
endif()
endforeach(lib_name)
target_include_directories(${libzt_LIB_NAME} INTERFACE
"${libzt_SOURCE_DIR}/include"
@ -40,22 +48,9 @@ else()
endif()
if(MINGW_CROSS)
option(MINGW_STDTHREADS_GENERATE_STDHEADERS "" ON)
FetchContent_Declare(mingw-std-threads
GIT_REPOSITORY https://github.com/meganz/mingw-std-threads
GIT_TAG bee085c0a6cb32c59f0b55c7bba976fe6dcfca7f)
FetchContent_MakeAvailableExcludeFromAll(mingw-std-threads)
target_compile_definitions(libnatpmp_obj PRIVATE -D_WIN32_WINNT=0x601 -DSTATICLIB)
target_compile_definitions(zto_obj PRIVATE -D_WIN32_WINNT=0x601 -DZT_SALSA20_SSE=0)
target_compile_definitions(libzt_obj PRIVATE -D_WIN32_WINNT=0x601)
target_link_libraries(libzt_obj PRIVATE mingw_stdthreads)
target_link_libraries(${libzt_LIB_NAME} PUBLIC iphlpapi shlwapi wsock32 ws2_32 wininet mingw_stdthreads)
target_include_directories(${libzt_LIB_NAME} INTERFACE "${libzt_SOURCE_DIR}/include/mingw-fixes")
include(zt_defs REQUIRED)
endif()
if(MSVC)
target_compile_definitions(libnatpmp_obj PRIVATE -DSTATICLIB)
target_link_libraries(${libzt_LIB_NAME} PUBLIC iphlpapi shlwapi wsock32 ws2_32 wininet)
endif()

16
CMake/platforms/mingw/zt_defs.cmake

@ -0,0 +1,16 @@
option(MINGW_STDTHREADS_GENERATE_STDHEADERS "" ON)
FetchContent_Declare(mingw-std-threads
GIT_REPOSITORY https://github.com/meganz/mingw-std-threads
GIT_TAG bee085c0a6cb32c59f0b55c7bba976fe6dcfca7f)
FetchContent_MakeAvailableExcludeFromAll(mingw-std-threads)
target_compile_definitions(libnatpmp_obj PRIVATE -D_WIN32_WINNT=0x601 -DSTATICLIB)
target_compile_definitions(zto_obj PRIVATE -D_WIN32_WINNT=0x601)
target_compile_definitions(zto_pic PRIVATE -D_WIN32_WINNT=0x601)
target_compile_definitions(libzt_obj PRIVATE -D_WIN32_WINNT=0x601)
target_compile_definitions(zt_pic PRIVATE -D_WIN32_WINNT=0x601)
target_compile_definitions(${libzt_LIB_NAME} PRIVATE -D_WIN32_WINNT=0x601 -DADD_EXPORTS=1)
target_compile_definitions(${libzt_LIB_NAME} PUBLIC -DADD_EXPORTS=1)
target_link_libraries(libzt_obj PRIVATE mingw_stdthreads)
target_link_libraries(${libzt_LIB_NAME} mingw_stdthreads)

4
CMake/platforms/windows.cmake

@ -16,3 +16,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
else()
list(APPEND DEVILUTIONX_PLATFORM_COMPILE_OPTIONS $<$<CONFIG:Debug>:-gstabs>)
endif()
if(MINGW_CROSS)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/mingw")
endif()

21
Source/dvlnet/zerotier_native.cpp

@ -27,24 +27,25 @@ static std::atomic_bool zt_network_ready(false);
static std::atomic_bool zt_node_online(false);
static std::atomic_bool zt_joined(false);
static void Callback(struct zts_callback_msg *msg)
static void Callback(void *ptr)
{
zts_event_msg_t *msg = reinterpret_cast<zts_event_msg_t *>(ptr);
// printf("callback %i\n", msg->eventCode);
if (msg->eventCode == ZTS_EVENT_NODE_ONLINE) {
Log("ZeroTier: ZTS_EVENT_NODE_ONLINE, nodeId={:x}", (unsigned long long)msg->node->address);
if (msg->event_code == ZTS_EVENT_NODE_ONLINE) {
Log("ZeroTier: ZTS_EVENT_NODE_ONLINE, nodeId={:x}", (unsigned long long)msg->node->node_id);
zt_node_online = true;
if (!zt_joined) {
zts_join(ZtNetwork);
zts_net_join(ZtNetwork);
zt_joined = true;
}
} else if (msg->eventCode == ZTS_EVENT_NODE_OFFLINE) {
} else if (msg->event_code == ZTS_EVENT_NODE_OFFLINE) {
Log("ZeroTier: ZTS_EVENT_NODE_OFFLINE");
zt_node_online = false;
} else if (msg->eventCode == ZTS_EVENT_NETWORK_READY_IP6) {
Log("ZeroTier: ZTS_EVENT_NETWORK_READY_IP6, networkId={:x}", (unsigned long long)msg->network->nwid);
} else if (msg->event_code == ZTS_EVENT_NETWORK_READY_IP6) {
Log("ZeroTier: ZTS_EVENT_NETWORK_READY_IP6, networkId={:x}", (unsigned long long)msg->network->net_id);
zt_ip6setup();
zt_network_ready = true;
} else if (msg->eventCode == ZTS_EVENT_ADDR_ADDED_IP6) {
} else if (msg->event_code == ZTS_EVENT_ADDR_ADDED_IP6) {
print_ip6_addr(&(msg->addr->addr));
}
}
@ -57,7 +58,9 @@ bool zerotier_network_ready()
void zerotier_network_start()
{
std::string ztpath = paths::ConfigPath() + "zerotier";
zts_start(ztpath.c_str(), (void (*)(void *))Callback, 0);
zts_init_from_storage(ztpath.c_str());
zts_init_set_event_handler(&Callback);
zts_node_start();
}
} // namespace net

Loading…
Cancel
Save