Skip to content

Commit

Permalink
[+] fix mpquic dead loop, support windows and optimize cmake env (#383)
Browse files Browse the repository at this point in the history
[+] restruct CMakeLists.txt;
[+] support windows compile;
[~] move reinjected pkts from tmp_buf to path-level buffer;
[!] fix dead loop triggered by dropping packets belonging to a reset stream;
[!] set default sched_params for clients;
  • Loading branch information
Kulsk authored Dec 11, 2023
1 parent b9d272f commit 599e614
Show file tree
Hide file tree
Showing 55 changed files with 1,802 additions and 928 deletions.
243 changes: 79 additions & 164 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,122 @@ project (xquic)

set (xquic_VERSION_MAJOR 0)
set (xquic_VERSION_MINOR 1)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option (XQC_ENABLE_BBR2 "enable bbr2" OFF)
option (XQC_ENABLE_COPA "enable copa" OFF)
option (XQC_ENABLE_RENO "enable reno" OFF)
option (XQC_ENABLE_UNLIMITED "enable unlimited cc" OFF)
option (XQC_ENABLE_MP_INTEROP "enable MPQUIC interop" OFF)
option (XQC_NO_PID_PACKET_PROCESS "do not expose path_id in xqc_engine_packet_process" OFF)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()


# SSL lib type, xquic support babassl and boringssl interfaces
if(NOT SSL_TYPE)
set(SSL_TYPE "babassl")
message(NOTICE "-- SSL_TYPE not set, use default babassl")
endif()

if(${SSL_TYPE} MATCHES "babassl")
# PATH of ssl
# PATH of ssl, by default XQUIC will use babassl installed in
# /usr/local/babassl if SSL_PATH is not set
if(NOT SSL_PATH)
set(SSL_PATH "/usr/local/babassl")
message(NOTICE "-- SSL_PATH not set, use default ${SSL_PATH}")
endif()

# ssl lib denpendency
if(NOT SSL_LIB_PATH)
set(SSL_LIB_PATH
${SSL_PATH}/lib/libssl.a
${SSL_PATH}/lib/libcrypto.a
)
endif()
elseif(${SSL_TYPE} MATCHES "boringssl")
# PATH of ssl
add_definitions(-DNOCRYPT=1)
# PATH of ssl, by default XQUIC will use boringssl in third_party
if(NOT SSL_PATH)
set(SSL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party/boringssl)
message(NOTICE "-- SSL_PATH not set, use default ${SSL_PATH}")
endif()
endif()

# ssl lib denpendency
if(NOT SSL_LIB_PATH)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions(-DNOCRYPT=1)
set(SSL_LIB_PATH
${SSL_PATH}/build/ssl/${CMAKE_BUILD_TYPE}/ssl.lib
${SSL_PATH}/build/crypto/${CMAKE_BUILD_TYPE}/crypto.lib
)
else()
set(SSL_LIB_PATH
${SSL_PATH}/build/ssl/libssl.a
${SSL_PATH}/build/crypto/libcrypto.a
)
endif()
# Users can use both SSL_DIR or SSL_PATH to specify the ssl path to find the ssl
# module, if both are defined, SSL_DIR will be used.
if(NOT SSL_DIR)
if(NOT SSL_PATH)
# at least SSL_DIR or SSL_PATH shall be set
message(FATAL_ERROR "SSL_PATH not set")
else()
set(SSL_DIR ${SSL_PATH})
endif()
endif()

# ssl include path
if(NOT SSL_INC_PATH)
set(SSL_INC_PATH
${SSL_PATH}/include
)
endif()

# find ssl module from SSL_DIR.
find_package(SSL)

if(NOT SSL_FOUND)
message(FATAL_ERROR "ssl moudle not found")
endif(NOT SSL_FOUND)

if(NOT SSL_LIBRARIES_STATIC)
message(FATAL_ERROR "ssl/crypto static library not found")
endif(NOT SSL_LIBRARIES_STATIC)

# compat with elder macros
set(SSL_LIB_PATH ${SSL_LIBRARIES_STATIC})
set(SSL_INC_PATH ${SSL_INCLUDE_DIR})

MESSAGE("-- SSL_TYPE: ${SSL_TYPE}")
MESSAGE("-- SSL_PATH: ${SSL_PATH}")
MESSAGE("-- SSL_LIB_PATH: ${SSL_LIB_PATH}")
MESSAGE("-- SSL_INC_PATH: ${SSL_INC_PATH}")


# C_FLAGS
if(ANDROID_ABI OR PLATFORM MATCHES "mac")
if(PLATFORM STREQUAL "mac32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
endif()
endif()

if(NOT (CMAKE_C_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
set(CMAKE_C_FLAGS_OPTION "-Werror -Wno-unused -Wno-pointer-sign -Wno-format-security ")
endif()

# C_FLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -std=gnu11 -Wall ${CMAKE_C_FLAGS_OPTION} -DNDEBUG_PRINT -DNPRINT_MALLOC ")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -std=gnu11 -Wall ${CMAKE_C_FLAGS_OPTION} -DNDEBUG_PRINT -DNPRINT_MALLOC -DXQC_DEBUG ")


if(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions(-DXQC_SYS_WINDOWS=1)
endif()


# configure file
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/xqc_configure.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/include/xquic/xqc_configure.h"
)

include_directories(include
${CMAKE_CURRENT_SOURCE_DIR}
${SSL_INC_PATH}
${CMAKE_SOURCE_DIR}
)



# print tls traffic secret in keylog
if(XQC_PRINT_SECRET)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXQC_PRINT_SECRET")
endif()

# compat with the duplicate instruction of HTTP/3 module before version v1.1.0
if(XQC_COMPAT_DUPLICATE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXQC_COMPAT_DUPLICATE")
endif()

# compat with the stateless reset before version v1.6.0
if(XQC_COMPAT_GENERATE_SR_PKT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXQC_COMPAT_GENERATE_SR_PKT")
endif()
Expand All @@ -98,41 +140,19 @@ if(XQC_SUPPORT_SENDMMSG_BUILD)
add_definitions(-DXQC_SUPPORT_SENDMMSG)
endif()

#coverity
# coverity
if(GCOV STREQUAL "on")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif()



# C_FLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -std=gnu11 -Wall -DNDEBUG_PRINT -DNPRINT_MALLOC ")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -std=gnu11 -Wall -DNDEBUG_PRINT -DNPRINT_MALLOC -DXQC_DEBUG ")

if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-unused -Wno-pointer-sign -Wno-format-security ")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror -Wno-unused -Wno-pointer-sign -Wno-format-security ")
else()
add_definitions(-DXQC_SYS_WINDOWS=1)
endif()

# additional C_FLAGS on mac
if(PLATFORM STREQUAL "mac32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
endif()


# configure file
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/xqc_configure.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/include/xquic/xqc_configure.h"
)
# testing
if(XQC_ENABLE_TESTING)
add_subdirectory(tests)
add_subdirectory(demo)
endif(XQC_ENABLE_TESTING)

include_directories(
include
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)

# http3/qpack source
set(
Expand Down Expand Up @@ -292,6 +312,7 @@ endif()
# xquic source
set (
XQC_SOURCE
${XQC_SOURCE}
${HTTP3_SOURCES}
${TRANSPORT_SOURCES}
${TLS_SOURCE}
Expand Down Expand Up @@ -339,109 +360,3 @@ if(CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
COMMAND ${CMAKE_STRIP} libxquic.so)
endif()


include_directories(${SSL_INC_PATH})
include_directories(${CMAKE_SOURCE_DIR}/)


##### build unittest, test client/server, demo client/server #####
if (XQC_ENABLE_TESTING)

# CUnit TODO: fix test unit on windows
find_package(CUnit 2.1)
enable_testing()
set(HAVE_CUNIT ${CUNIT_FOUND})
if(HAVE_CUNIT)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
endif()

# find LibEvent include and library path
find_package(LibEvent 2.0.21)
if(NOT LIBEVENT_FOUND)
message(FATAL_ERROR "libevent with required version not found")
endif()
include_directories(${LIBEVENT_INCLUDE_DIR})

# add tests
add_subdirectory(tests)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/test)

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
# used wingetopt on windows
if(NOT GETOPT_INC_PATH)
set(GETOPT_INC_PATH
${CMAKE_SOURCE_DIR}/third_party/wingetopt
)
endif()
MESSAGE("GETOPT_INC_PATH= ${GETOPT_INC_PATH}")

include_directories(${GETOPT_INC_PATH}/src)
set(GETOPT_SOURCES "${GETOPT_INC_PATH}/src/getopt.c")
endif()

### test client/server ###
add_executable(test_server tests/test_server.c ${GETOPT_SOURCES})
add_executable(test_client tests/test_client.c ${GETOPT_SOURCES})

### hq demo client/server ###
set(
HQ_SOURCES
"demo/xqc_hq_ctx.c"
"demo/xqc_hq_conn.c"
"demo/xqc_hq_request.c"
)

set(
DEMO_CLIENT_SOURCES
${HQ_SOURCES}
"demo/demo_client.c"
)

set(
DEMO_SERVER_SOURCES
${HQ_SOURCES}
"demo/demo_server.c"
)

add_executable(demo_server ${DEMO_SERVER_SOURCES} ${GETOPT_SOURCES})
add_executable(demo_client ${DEMO_CLIENT_SOURCES} ${GETOPT_SOURCES})

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
if (NOT EVENT_LIB_DIR)
message("YOU NEED SET -DEVENT_LIB_DIR=your_event_path, eg:-DEVENT_LIB_DIR=D:/project/vcpkg/packages/libevent_x64-windows-static")
endif()

include_directories( ${EVENT_LIB_DIR}/include )
link_directories( ${EVENT_LIB_DIR}/lib )

SET(EVENT_LIB_PATH
${EVENT_LIB_DIR}/lib/event.lib
${EVENT_LIB_DIR}/lib/event_core.lib
${EVENT_LIB_DIR}/lib/event_extra.lib
)
endif()

if(PLATFORM STREQUAL "mac32")
target_link_libraries(test_server xquic-static ${SSL_LIB_PATH} -ldl -lpthread -lm ${LIBEVENT_LIBRARY})
target_link_libraries(test_client xquic-static ${SSL_LIB_PATH} -ldl -lpthread -lm ${LIBEVENT_LIBRARY})
target_link_libraries(demo_server xquic -lm ${LIBEVENT_LIBRARY})
target_link_libraries(demo_client xquic -lm ${LIBEVENT_LIBRARY})
elseif(PLATFORM STREQUAL "mac")
target_link_libraries(test_server xquic-static ${SSL_LIB_PATH} -ldl -lpthread -lm ${LIBEVENT_LIBRARY})
target_link_libraries(test_client xquic-static ${SSL_LIB_PATH} -ldl -lpthread -lm ${LIBEVENT_LIBRARY})
target_link_libraries(demo_server xquic -lm ${LIBEVENT_LIBRARY})
target_link_libraries(demo_client xquic -lm ${LIBEVENT_LIBRARY})
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
target_link_libraries(test_server xquic ${EVENT_LIB_PATH} -lm)
target_link_libraries(test_client xquic ${EVENT_LIB_PATH} -lm)
target_link_libraries(demo_server xquic ${EVENT_LIB_PATH} -lm)
target_link_libraries(demo_client xquic ${EVENT_LIB_PATH} -lm)
else()
target_link_libraries(test_server xquic-static ${SSL_LIB_PATH} -ldl -lpthread -lm ${LIBEVENT_LIBRARY})
target_link_libraries(test_client xquic-static ${SSL_LIB_PATH} -ldl -lpthread -lm ${LIBEVENT_LIBRARY})
target_link_libraries(demo_server xquic ${LIBEVENT_LIBRARY} -lm)
target_link_libraries(demo_client xquic ${LIBEVENT_LIBRARY} -lm)
endif()

endif()

2 changes: 1 addition & 1 deletion CMakeOptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

option(ENABLE_DEBUG "Turn on debug output" ON)
option(XQC_BUILD_OPENSSL "Turn on OpenSSL" ON)
option(XQC_OPENSSL_IS_BORINGSSL "Using BoringSSL" ON)
option(SSL_TYPE "Using BoringSSL" boringssl)
option(XQC_ENABLE_TESTING "Enable Testing" OFF)
option(XQC_BUILD_SAMPLE "Build Sample" OFF)
option(GCOV "Test Coverage" OFF)
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,6 @@ In no particular order, thanks to these excellent individuals who contributed co
* @ruanshanshan
* @alagoutte
* @MPK1
* @tang-mouren

This list will be continuously updated. Contributions are welcome!
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,42 @@ make ssl crypto
cd ..
SSL_TYPE_STR="boringssl"
SSL_PATH_STR="${PWD}"
SSL_INC_PATH_STR="${PWD}/include"
SSL_LIB_PATH_STR="${PWD}/build/ssl/libssl.a;${PWD}/build/crypto/libcrypto.a"
cd ../..
## Note: if you don’t have golang in your environment, please install [golang](https://go.dev/doc/install) first.

# build XQUIC with BoringSSL
# When build XQUIC with boringssl, /usr/local/babassl directory will be searched
# as default. if boringssl is deployed in other directories, SSL_PATH could be
# used to specify the search path of boringssl
git submodule update --init --recursive
mkdir -p build; cd build
cmake -DGCOV=on -DCMAKE_BUILD_TYPE=Debug -DXQC_ENABLE_TESTING=1 -DXQC_SUPPORT_SENDMMSG_BUILD=1 -DXQC_ENABLE_EVENT_LOG=1 -DXQC_ENABLE_BBR2=1 -DXQC_ENABLE_RENO=1 -DSSL_TYPE=${SSL_TYPE_STR} -DSSL_PATH=${SSL_PATH_STR} -DSSL_INC_PATH=${SSL_INC_PATH_STR} -DSSL_LIB_PATH=${SSL_LIB_PATH_STR} ..
cmake -DGCOV=on -DCMAKE_BUILD_TYPE=Debug -DXQC_ENABLE_TESTING=1 -DXQC_SUPPORT_SENDMMSG_BUILD=1 -DXQC_ENABLE_EVENT_LOG=1 -DXQC_ENABLE_BBR2=1 -DXQC_ENABLE_RENO=1 -DSSL_TYPE=${SSL_TYPE_STR} -DSSL_PATH=${SSL_PATH_STR} ..
make -j
```

### Build with BabaSSL
### Build with BabaSSL(Tongsuo)

```bash
# get XQUIC source code
git clone https://github.com/alibaba/xquic.git
cd xquic

# get and build BabaSSL
# get and build BabaSSL(Tongsuo)
git clone -b 8.3-stable https://github.com/Tongsuo-Project/Tongsuo.git ./third_party/babassl
cd ./third_party/babassl/
./config --prefix=/usr/local/babassl
make -j
SSL_TYPE_STR="babassl"
SSL_PATH_STR="${PWD}"
SSL_INC_PATH_STR="${PWD}/include"
SSL_LIB_PATH_STR="${PWD}/libssl.a;${PWD}/libcrypto.a"
cd -

# build XQUIC with BabaSSL
# When build XQUIC with boringssl, /usr/local/babassl directory will be searched
# as default. if boringssl is deployed in other directories, SSL_PATH could be
# used to specify the search path of boringssl
git submodule update --init --recursive
mkdir -p build; cd build
cmake -DGCOV=on -DCMAKE_BUILD_TYPE=Debug -DXQC_ENABLE_TESTING=1 -DXQC_SUPPORT_SENDMMSG_BUILD=1 -DXQC_ENABLE_EVENT_LOG=1 -DXQC_ENABLE_BBR2=1 -DXQC_ENABLE_RENO=1 -DSSL_TYPE=${SSL_TYPE_STR} -DSSL_PATH=${SSL_PATH_STR} -DSSL_INC_PATH=${SSL_INC_PATH_STR} -DSSL_LIB_PATH=${SSL_LIB_PATH_STR} ..
cmake -DGCOV=on -DCMAKE_BUILD_TYPE=Debug -DXQC_ENABLE_TESTING=1 -DXQC_SUPPORT_SENDMMSG_BUILD=1 -DXQC_ENABLE_EVENT_LOG=1 -DXQC_ENABLE_BBR2=1 -DXQC_ENABLE_RENO=1 -DSSL_TYPE=${SSL_TYPE_STR} -DSSL_PATH=${SSL_PATH_STR} ..
make -j
```

Expand Down
4 changes: 2 additions & 2 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ if (XQC_BUILD_OPENSSL)
endif()

else()
#set(EXTRA_CONFIGURE_OPENSSL_PARAMS "${EXTRA_CONFIGURE_OPENSSL_PARAMS} ${DYNAMIC_COMPILE_FLAGS} ")
#add_subdirectory(external/openssl-cmake)
set(EXTRA_CONFIGURE_OPENSSL_PARAMS "${EXTRA_CONFIGURE_OPENSSL_PARAMS} ${DYNAMIC_COMPILE_FLAGS} ")
add_subdirectory(external/openssl-cmake)
endif()

set(DYMAMIC_LINK_OPTION
Expand Down
Loading

0 comments on commit 599e614

Please sign in to comment.