diff --git a/.gitignore b/.gitignore index 2ecbab1ef..083a9fac6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ compile_commands.json /tests .DS_Store .idea - +.vs diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f4a5b99d..0bb79a0be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,7 +352,7 @@ if(NOT NO_TESTS) CXX_STANDARD 17) set_target_properties(datachannel-tests PROPERTIES OUTPUT_NAME tests) target_include_directories(datachannel-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) - target_link_libraries(datachannel-tests datachannel) + target_link_libraries(datachannel-tests datachannel-static) # Benchmark if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") diff --git a/deps/json b/deps/json index 973c52dd4..e220ab89e 160000 --- a/deps/json +++ b/deps/json @@ -1 +1 @@ -Subproject commit 973c52dd4a9e92ede5ca4afe8b3d01ef677dc57f +Subproject commit e220ab89e5119f12e5aa25b85f4f55123db5aeeb diff --git a/include/rtc/websocket.hpp b/include/rtc/websocket.hpp index 328bafd64..311f04324 100644 --- a/include/rtc/websocket.hpp +++ b/include/rtc/websocket.hpp @@ -51,6 +51,7 @@ class RTC_CPP_EXPORT WebSocket final : public Channel, struct Configuration { bool disableTlsVerification = false; // if true, don't verify the TLS certificate std::vector protocols; + std::vector headers; }; WebSocket(std::optional config = nullopt); diff --git a/scripts/build_linux.sh b/scripts/build_linux.sh new file mode 100755 index 000000000..32e78c048 --- /dev/null +++ b/scripts/build_linux.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +# in libdatachannel/scripts directory + +cd ../../libdatachannel +cmake -B ../libdatachannel_build_linux_debug_with_static_openssl -DUSE_GNUTLS=0 -DUSE_NICE=0 -DOPENSSL_USE_STATIC_LIBS=TRUE -DCMAKE_BUILD_TYPE=Debug +cd ../libdatachannel_build_linux_debug_with_static_openssl +make +./tests + +cd ../libdatachannel +cmake -B ../libdatachannel_build_linux_relsym_with_static_openssl -DUSE_GNUTLS=0 -DUSE_NICE=0 -DOPENSSL_USE_STATIC_LIBS=TRUE -DCMAKE_BUILD_TYPE=RelWithDebInfo +cd ../libdatachannel_build_linux_relsym_with_static_openssl/ +make +./tests + +cd ../libdatachannel/scripts + +# copy builds to qt-shared +#./copy_build_linux_to_qt-shared.sh diff --git a/scripts/build_linux_debug.sh b/scripts/build_linux_debug.sh new file mode 100755 index 000000000..dfc39f8f7 --- /dev/null +++ b/scripts/build_linux_debug.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e + +# in libdatachannel/scripts directory + +cd .. + +OPENSSL_ROOT_DIR=/home/paperspace/projects/PS_OPENSSL/release/linux111u18/ cmake -B ../libdatachannel_build_linux_debug_with_static_openssl -DUSE_GNUTLS=0 -DUSE_NICE=0 -DOPENSSL_USE_STATIC_LIBS=TRUE -DCMAKE_BUILD_TYPE=Debug + +cd ../libdatachannel_build_linux_debug_with_static_openssl +make + diff --git a/scripts/build_linux_release.sh b/scripts/build_linux_release.sh new file mode 100755 index 000000000..30e2e2e2e --- /dev/null +++ b/scripts/build_linux_release.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -e + + +cd libdatachannel + +OPENSSL_ROOT_DIR=/home/paperspace/projects/PS_OPENSSL/release/linux111u18/ cmake -B ../libdatachannel_build_linux_relsym_with_static_openssl -DUSE_GNUTLS=0 -DUSE_NICE=0 -DOPENSSL_USE_STATIC_LIBS=TRUE -DCMAKE_BUILD_TYPE=RelWithDebInfo + +cd ../libdatachannel_build_linux_relsym_with_static_openssl +make + diff --git a/scripts/build_mac.sh b/scripts/build_mac.sh new file mode 100755 index 000000000..47e7daaa1 --- /dev/null +++ b/scripts/build_mac.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -e + +# in libdatachannel/scripts directory + +cd ../../libdatachannel + +cmake -B ../libdatachannel_build_mac_debug_static_openssl_debug -DUSE_GNUTLS=0 -DUSE_NICE=0 -DOPENSSL_USE_STATIC_LIBS=TRUE -DOPENSSL_ROOT_DIR=~/github/PS_OPENSSL/debug/mac111 -DCMAKE_BUILD_TYPE=Debug + +cd ../libdatachannel_build_mac_debug_static_openssl_debug + +make +./tests + +cd ../libdatachannel/scripts + +cd ../../libdatachannel + +cmake -B ../libdatachannel_build_mac_static_openssl -DUSE_GNUTLS=0 -DUSE_NICE=0 -DOPENSSL_USE_STATIC_LIBS=TRUE -DOPENSSL_ROOT_DIR=~/github/PS_OPENSSL/release/mac111 -DCMAKE_BUILD_TYPE=RelWithDebInfo + +cd ../libdatachannel_build_mac_static_openssl/ +make +./tests + +cd ../libdatachannel/scripts + +# copy build to qt-shared +#./copy_build_mac_to_qt-shared.sh diff --git a/scripts/build_mac_universal.sh b/scripts/build_mac_universal.sh new file mode 100644 index 000000000..85857a7b8 --- /dev/null +++ b/scripts/build_mac_universal.sh @@ -0,0 +1,6 @@ +set -euxo pipefail + +cmake -B build -DCMAKE_INSTALL_PREFIX=./release -DUSE_GNUTLS=0 -DUSE_NICE=0 -DOPENSSL_USE_STATIC_LIBS=TRUE -DOPENSSL_ROOT_DIR=~/code/ps_openssl/release/v3.0.10/mac-universal-static -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWARNINGS_AS_ERRORS=OFF -Dsctp_werror=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" +cmake --build build --parallel +./build/tests +cmake --install build diff --git a/scripts/build_mac_xcode.sh b/scripts/build_mac_xcode.sh new file mode 100755 index 000000000..dec0136fc --- /dev/null +++ b/scripts/build_mac_xcode.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -e + +# in libdatachannel/scripts directory + +cd ../../libdatachannel + +cmake -B ../libdatachannel_build_mac_xcode_static_openssl -DUSE_GNUTLS=0 -DUSE_NICE=0 -G Xcode -DOPENSSL_USE_STATIC_LIBS=TRUE -DOPENSSL_ROOT_DIR=~/github/PS_OPENSSL/release/mac111 + +cd ../libdatachannel_build_mac_xcode_static_openssl + +# requires xcode 11.7 + +xcodebuild -scheme ALL_BUILD -configuration Debug +./Debug/tests + +xcodebuild -scheme ALL_BUILD -configuration RelWithDebInfo +./RelWithDebInfo/tests + +cd ../libdatachannel/scripts + +# copy build to qt-shared +#./copy_build_mac_xcode_to_qt-shared.sh diff --git a/scripts/build_win.bat b/scripts/build_win.bat new file mode 100644 index 000000000..1daa53792 --- /dev/null +++ b/scripts/build_win.bat @@ -0,0 +1,44 @@ +rem run from libdatachannel scripts dir + +rem NOTE: REQUIRES OPENSSL 1.1.1i debug and release builds and install locations + +set SAVED_PATH=%PATH% +set SAVED_OPENSSL_ROOT_DIR=%OPENSSL_ROOT_DIR% + +rem build debug with openssl static debug + +pushd ..\..\libdatachannel + +set OPENSSL_ROOT_DIR=C:\openssl +set PATH=C:\openssl\bin;%SAVED_PATH% + +rem checks: +rem dir C:\openssl\openssl_1.1.1i-debug\lib\libssl_static.lib +rem dir C:\openssl\openssl_1.1.1i-debug\lib\libcrypto_static.lib + +cmake -B ..\libdatachannel_build_debug_static_openssl_debug -G "NMake Makefiles" -D OPENSSL_USE_STATIC_LIBS=TRUE -D CMAKE_BUILD_TYPE=Debug -D CMAKE_SHARED_LINKER_FLAGS="crypt32.lib" +pushd ..\libdatachannel_build_debug_static_openssl_debug +nmake +tests + +rem build relsym with openssl static + +popd + +set OPENSSL_ROOT_DIR=C:\openssl +set PATH=C:\openssl\bin;%SAVED_PATH% + +rem checks: +rem dir C:\Program^ Files\OpenSSL\lib\libssl_static.lib +rem dir C:\Program^ Files\OpenSSL\lib\libcrypto_static.lib + +cmake -B ..\libdatachannel_build_relsym_static_openssl -G "NMake Makefiles" -D OPENSSL_USE_STATIC_LIBS=TRUE -D CMAKE_BUILD_TYPE=RelWithDebInfo -D CMAKE_SHARED_LINKER_FLAGS="crypt32.lib" +pushd ..\libdatachannel_build_relsym_static_openssl +nmake +tests + +set PATH=%SAVED_PATH% +set OPENSSL_ROOT_DIR=%SAVED_OPENSSL_ROOT_DIR% + +popd +popd diff --git a/scripts/copy_build_linux_to_qt-shared.sh b/scripts/copy_build_linux_to_qt-shared.sh new file mode 100755 index 000000000..314618aaf --- /dev/null +++ b/scripts/copy_build_linux_to_qt-shared.sh @@ -0,0 +1,10 @@ +#/usr/bin/env bash +PS_QT="${PS_QT:-/mnt/c/ps}" +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/release +cp ../../libdatachannel_build_linux_relsym_with_static_openssl/libdatachannel.so.0.11.4 ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/release/ +rm -f ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/release/libdatachannel.so +ln -rs ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/release/libdatachannel.so.0.11.4 ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/release/libdatachannel.so +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/debug +cp ../../libdatachannel_build_linux_debug_with_static_openssl/libdatachannel.so.0.11.4 ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/debug/ +rm -f ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/debug/libdatachannel.so +ln -rs ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/debug/libdatachannel.so.0.11.4 ${PS_QT}/qt-shared/libs/libdatachannel/build/linux/debug/libdatachannel.so diff --git a/scripts/copy_build_mac_to_qt-shared.sh b/scripts/copy_build_mac_to_qt-shared.sh new file mode 100755 index 000000000..65b6b9b28 --- /dev/null +++ b/scripts/copy_build_mac_to_qt-shared.sh @@ -0,0 +1,14 @@ +#/usr/bin/env bash +set -e + +PS_QT="$(cd ${PS_QT:-$(pwd)/../../PS_QTNativeApp}; pwd)" + +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release +rm -f ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release/*.dylib +cp -a ../../libdatachannel_build_mac_static_openssl/*.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release/ +install_name_tool -id @rpath/libdatachannel.0.11.4.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release/libdatachannel.0.11.4.dylib + +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug +rm -f ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug/*.dylib +cp -a ../../libdatachannel_build_mac_debug_static_openssl_debug/*.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug/ +install_name_tool -id @rpath/libdatachannel.0.11.4.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug/libdatachannel.0.11.4.dylib diff --git a/scripts/copy_build_mac_to_qtdatachan.sh b/scripts/copy_build_mac_to_qtdatachan.sh new file mode 100755 index 000000000..6902b865b --- /dev/null +++ b/scripts/copy_build_mac_to_qtdatachan.sh @@ -0,0 +1,14 @@ +#/usr/bin/env bash +set -e + +PS_QT="$(cd ${PS_QT:-$(pwd)/../../qtdatachan}; pwd)" + +mkdir -p ${PS_QT}/libdatachannel/build/mac/release +rm -f ${PS_QT}/libdatachannel/build/mac/release/*.dylib +cp -a ../../libdatachannel_build_mac_static_openssl/*.dylib ${PS_QT}/libdatachannel/build/mac/release/ +install_name_tool -id @rpath/libdatachannel.0.11.4.dylib ${PS_QT}/libdatachannel/build/mac/release/libdatachannel.0.11.4.dylib + +mkdir -p ${PS_QT}/libdatachannel/build/mac/debug +rm -f ${PS_QT}/libdatachannel/build/mac/debug/*.dylib +cp -a ../../libdatachannel_build_mac_debug_static_openssl_debug/*.dylib ${PS_QT}/libdatachannel/build/mac/debug/ +install_name_tool -id @rpath/libdatachannel.0.11.4.dylib ${PS_QT}/libdatachannel/build/mac/debug/libdatachannel.0.11.4.dylib diff --git a/scripts/copy_build_mac_xcode_to_qt-shared.sh b/scripts/copy_build_mac_xcode_to_qt-shared.sh new file mode 100755 index 000000000..9ad20128f --- /dev/null +++ b/scripts/copy_build_mac_xcode_to_qt-shared.sh @@ -0,0 +1,14 @@ +#/usr/bin/env bash +set -e + +PS_QT="$(cd ${PS_QT:-$(pwd)/../../PS_QTNativeApp}; pwd)" + +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release_xcode +rm -f ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release_xcode/*.dylib +cp -a ../../libdatachannel_build_mac_xcode_static_openssl/RelWithDebInfo/*.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release_xcode/ +install_name_tool -id @rpath/libdatachannel.0.11.4.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/release_xcode/libdatachannel.0.11.4.dylib + +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug_xcode +rm -f ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug_xcode/*.dylib +cp -a ../../libdatachannel_build_mac_xcode_static_openssl/Debug/*.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug_xcode/ +install_name_tool -id @rpath/libdatachannel.0.11.4.dylib ${PS_QT}/qt-shared/libs/libdatachannel/build/mac/debug_xcode/libdatachannel.0.11.4.dylib diff --git a/scripts/copy_build_win_to_qt-shared.bat b/scripts/copy_build_win_to_qt-shared.bat new file mode 100644 index 000000000..8025824f3 --- /dev/null +++ b/scripts/copy_build_win_to_qt-shared.bat @@ -0,0 +1,13 @@ +rem run from scripts dir +if "%PS_QT%"=="" set PS_QT=C:\ps +xcopy /s /y ..\include %PS_QT%\qt-shared\libs\libdatachannel\include\ +xcopy /s /y ..\deps\json\single_include %PS_QT%\qt-shared\libs\libdatachannel\deps\json\single_include\ +xcopy /s /y ..\deps\plog\include %PS_QT%\qt-shared\libs\libdatachannel\deps\plog\include\ + +xcopy /y ..\..\libdatachannel_build_debug_static_openssl_debug\datachannel.dll %PS_QT%\qt-shared\libs\libdatachannel\build\win\debug\ +xcopy /y ..\..\libdatachannel_build_debug_static_openssl_debug\datachannel.lib %PS_QT%\qt-shared\libs\libdatachannel\build\win\debug\ +xcopy /y ..\..\libdatachannel_build_debug_static_openssl_debug\datachannel.pdb %PS_QT%\qt-shared\libs\libdatachannel\build\win\debug\ + +xcopy /y ..\..\libdatachannel_build_relsym_static_openssl\datachannel.dll %PS_QT%\qt-shared\libs\libdatachannel\build\win\release\ +xcopy /y ..\..\libdatachannel_build_relsym_static_openssl\datachannel.lib %PS_QT%\qt-shared\libs\libdatachannel\build\win\release\ +xcopy /y ..\..\libdatachannel_build_relsym_static_openssl\datachannel.pdb %PS_QT%\qt-shared\libs\libdatachannel\build\win\release\ diff --git a/scripts/copy_includes_to_qt-shared.sh b/scripts/copy_includes_to_qt-shared.sh new file mode 100755 index 000000000..61b7ca765 --- /dev/null +++ b/scripts/copy_includes_to_qt-shared.sh @@ -0,0 +1,15 @@ +#/usr/bin/env bash +set -e + +PS_QT="$(cd ${PS_QT:-$(pwd)/../../PS_QTNativeApp}; pwd)" + +rm -rf ${PS_QT}/qt-shared/libs/libdatachannel/include +rm -rf ${PS_QT}/qt-shared/libs/libdatachannel/deps + +cp -R ../../libdatachannel/include ${PS_QT}/qt-shared/libs/libdatachannel/. + +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/deps/json +cp -R ../../libdatachannel/deps/json/single_include ${PS_QT}/qt-shared/libs/libdatachannel/deps/json/. + +mkdir -p ${PS_QT}/qt-shared/libs/libdatachannel/deps/plog +cp -R ../../libdatachannel/deps/plog/include ${PS_QT}/qt-shared/libs/libdatachannel/deps/plog/. diff --git a/scripts/copy_includes_to_qtdatachan.sh b/scripts/copy_includes_to_qtdatachan.sh new file mode 100755 index 000000000..6a4490e02 --- /dev/null +++ b/scripts/copy_includes_to_qtdatachan.sh @@ -0,0 +1,15 @@ +#/usr/bin/env bash +set -e + +PS_QT="$(cd ${PS_QT:-$(pwd)/../../qtdatachan}; pwd)" + +rm -rf ${PS_QT}/libdatachannel/include +rm -rf ${PS_QT}/libdatachannel/deps + +cp -R ../../libdatachannel/include ${PS_QT}/libdatachannel/. + +mkdir -p ${PS_QT}/libdatachannel/deps/json +cp -R ../../libdatachannel/deps/json/single_include ${PS_QT}/libdatachannel/deps/json/. + +mkdir -p ${PS_QT}/libdatachannel/deps/plog +cp -R ../../libdatachannel/deps/plog/include ${PS_QT}/libdatachannel/deps/plog/. diff --git a/src/dtlstransport.cpp b/src/dtlstransport.cpp index d11322f35..a5fe69468 100644 --- a/src/dtlstransport.cpp +++ b/src/dtlstransport.cpp @@ -313,6 +313,46 @@ void DtlsTransport::Cleanup() { // Nothing to do } +#define FIRSTLINE "# SSL key logfile generated by libdatachannel\n" +#define FIRSTLINE_LEN (sizeof(FIRSTLINE) - 1) + +static int keylog_file_fd = -1; + +static void init_keylog_file(void) { + if (keylog_file_fd >= 0) + return; + + const char *filename = getenv("SSLKEYLOGFILE"); + if (filename) { +#ifdef _WIN32 + keylog_file_fd = _open(filename, O_WRONLY | O_APPEND | O_CREAT, 0644); + if (keylog_file_fd >= 0 && _lseek(keylog_file_fd, 0, SEEK_END) == 0) { + /* file is opened successfully and there is no data (pos == 0) */ + _write(keylog_file_fd, FIRSTLINE, FIRSTLINE_LEN); + } +#else + keylog_file_fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0644); + if (keylog_file_fd >= 0 && lseek(keylog_file_fd, 0, SEEK_END) == 0) { + /* file is opened successfully and there is no data (pos == 0) */ + write(keylog_file_fd, FIRSTLINE, FIRSTLINE_LEN); + } +#endif + } +} + +void keylog_callback(const SSL *, const char *line) { + init_keylog_file(); + if (keylog_file_fd >= 0) { +#ifdef _WIN32 + _write(keylog_file_fd, line, static_cast(strlen(line))); + _write(keylog_file_fd, "\n", 1); +#else + write(keylog_file_fd, line, static_cast(strlen(line))); + write(keylog_file_fd, "\n", 1); +#endif + } +} + DtlsTransport::DtlsTransport(shared_ptr lower, shared_ptr certificate, verifier_callback verifierCallback, state_callback stateChangeCallback) : Transport(lower, std::move(stateChangeCallback)), mCertificate(certificate), @@ -325,6 +365,7 @@ DtlsTransport::DtlsTransport(shared_ptr lower, shared_ptr #include -#if __clang__ && defined(__APPLE__) -namespace { -template -inline std::shared_ptr reinterpret_pointer_cast(std::shared_ptr const &ptr) noexcept { - return std::shared_ptr(ptr, reinterpret_cast(ptr.get())); -} -} // namespace -#else using std::reinterpret_pointer_cast; -#endif static rtc::LogCounter COUNTER_MEDIA_TRUNCATED(plog::warning, "Number of RTP packets truncated over past second"); diff --git a/src/threadpool.cpp b/src/threadpool.cpp index 42f3693c0..a3fc70670 100644 --- a/src/threadpool.cpp +++ b/src/threadpool.cpp @@ -33,7 +33,7 @@ ThreadPool &ThreadPool::Instance() { return *instance; } -ThreadPool::ThreadPool() { std::atexit(joinThreadPoolInstance); } +ThreadPool::ThreadPool() { /*std::atexit(joinThreadPoolInstance);*/ } ThreadPool::~ThreadPool() {} diff --git a/src/tlstransport.cpp b/src/tlstransport.cpp index 246c3f169..f26dea267 100644 --- a/src/tlstransport.cpp +++ b/src/tlstransport.cpp @@ -258,6 +258,8 @@ void TlsTransport::Cleanup() { // Nothing to do } +void keylog_callback(const SSL *, const char *line); + TlsTransport::TlsTransport(shared_ptr lower, string host, state_callback callback) : Transport(lower, std::move(callback)), mHost(std::move(host)) { @@ -267,6 +269,7 @@ TlsTransport::TlsTransport(shared_ptr lower, string host, state_ca if (!(mCtx = SSL_CTX_new(SSLv23_method()))) // version-flexible throw std::runtime_error("Failed to create SSL context"); + SSL_CTX_set_keylog_callback(mCtx, keylog_callback); openssl::check(SSL_CTX_set_cipher_list(mCtx, "ALL:!LOW:!EXP:!RC4:!MD5:@STRENGTH"), "Failed to set SSL priorities"); diff --git a/src/websocket.cpp b/src/websocket.cpp index 454a2b9c7..8a8c89755 100644 --- a/src/websocket.cpp +++ b/src/websocket.cpp @@ -296,6 +296,7 @@ shared_ptr WebSocket::initWsTransport() { wsConfig.host = mHost; wsConfig.path = mPath; wsConfig.protocols = mConfig.protocols; + wsConfig.headers = mConfig.headers; auto transport = std::make_shared( lower, wsConfig, weak_bind(&WebSocket::incoming, this, _1), diff --git a/src/wstransport.cpp b/src/wstransport.cpp index 527dee994..263a3a16f 100644 --- a/src/wstransport.cpp +++ b/src/wstransport.cpp @@ -165,9 +165,9 @@ bool WsTransport::sendHttpRequest() { auto k = reinterpret_cast(key.data()); std::generate(k, k + key.size(), [&]() { return uint8_t(generator()); }); - string appendHeader = ""; + string appendHeaders = ""; if (mConfig.protocols.size() > 0) { - appendHeader += + appendHeaders += "Sec-WebSocket-Protocol: " + std::accumulate(mConfig.protocols.begin(), mConfig.protocols.end(), string(), [](const string &a, const string &b) -> string { @@ -175,6 +175,14 @@ bool WsTransport::sendHttpRequest() { }) + "\r\n"; } + if (mConfig.headers.size() > 0) { + appendHeaders += + std::accumulate(mConfig.headers.begin(), mConfig.headers.end(), string(), + [](const string &a, const string &b) -> string { + return a + (a.length() > 0 ? "\r\n" : "") + b; + }) + + "\r\n"; + } const string request = "GET " + mConfig.path + " HTTP/1.1\r\n" @@ -185,7 +193,7 @@ bool WsTransport::sendHttpRequest() { "Upgrade: websocket\r\n" "Sec-WebSocket-Version: 13\r\n" "Sec-WebSocket-Key: " + - to_base64(key) + "\r\n" + std::move(appendHeader) + "\r\n"; + to_base64(key) + "\r\n" + std::move(appendHeaders) + "\r\n"; auto data = reinterpret_cast(request.data()); auto size = request.size(); diff --git a/src/wstransport.hpp b/src/wstransport.hpp index 0f80dee52..b9ac944b4 100644 --- a/src/wstransport.hpp +++ b/src/wstransport.hpp @@ -35,6 +35,7 @@ class WsTransport : public Transport { string host; string path = "/"; std::vector protocols; + std::vector headers; }; WsTransport(std::shared_ptr lower, Configuration config, diff --git a/test/main.cpp b/test/main.cpp index 1a619b52b..a078537b2 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -52,6 +52,8 @@ int main(int argc, char **argv) { return -1; } this_thread::sleep_for(1s); + // open relay turn server is unreliable + /* try { cout << endl << "*** Running WebRTC TURN connectivity test..." << endl; test_turn_connectivity(); @@ -61,6 +63,7 @@ int main(int argc, char **argv) { return -1; } this_thread::sleep_for(1s); + */ try { cout << endl << "*** Running WebRTC C API connectivity test..." << endl; test_capi_connectivity();