Skip to content

paperspace-changes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ compile_commands.json
/tests
.DS_Store
.idea

.vs
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion deps/json
1 change: 1 addition & 0 deletions include/rtc/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> protocols;
std::vector<string> headers;
};

WebSocket(std::optional<Configuration> config = nullopt);
Expand Down
21 changes: 21 additions & 0 deletions scripts/build_linux.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions scripts/build_linux_debug.sh
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions scripts/build_linux_release.sh
Original file line number Diff line number Diff line change
@@ -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

28 changes: 28 additions & 0 deletions scripts/build_mac.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions scripts/build_mac_universal.sh
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions scripts/build_mac_xcode.sh
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions scripts/build_win.bat
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions scripts/copy_build_linux_to_qt-shared.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions scripts/copy_build_mac_to_qt-shared.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions scripts/copy_build_mac_to_qtdatachan.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions scripts/copy_build_mac_xcode_to_qt-shared.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions scripts/copy_build_win_to_qt-shared.bat
Original file line number Diff line number Diff line change
@@ -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\
15 changes: 15 additions & 0 deletions scripts/copy_includes_to_qt-shared.sh
Original file line number Diff line number Diff line change
@@ -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/.
15 changes: 15 additions & 0 deletions scripts/copy_includes_to_qtdatachan.sh
Original file line number Diff line number Diff line change
@@ -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/.
41 changes: 41 additions & 0 deletions src/dtlstransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(strlen(line)));
_write(keylog_file_fd, "\n", 1);
#else
write(keylog_file_fd, line, static_cast<unsigned int>(strlen(line)));
write(keylog_file_fd, "\n", 1);
#endif
}
}

DtlsTransport::DtlsTransport(shared_ptr<IceTransport> lower, shared_ptr<Certificate> certificate,
verifier_callback verifierCallback, state_callback stateChangeCallback)
: Transport(lower, std::move(stateChangeCallback)), mCertificate(certificate),
Expand All @@ -325,6 +365,7 @@ DtlsTransport::DtlsTransport(shared_ptr<IceTransport> lower, shared_ptr<Certific
if (!mCtx)
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");

Expand Down
9 changes: 0 additions & 9 deletions src/peerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@
#include <set>
#include <thread>

#if __clang__ && defined(__APPLE__)
namespace {
template <typename To, typename From>
inline std::shared_ptr<To> reinterpret_pointer_cast(std::shared_ptr<From> const &ptr) noexcept {
return std::shared_ptr<To>(ptr, reinterpret_cast<To *>(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");
Expand Down
2 changes: 1 addition & 1 deletion src/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ThreadPool &ThreadPool::Instance() {
return *instance;
}

ThreadPool::ThreadPool() { std::atexit(joinThreadPoolInstance); }
ThreadPool::ThreadPool() { /*std::atexit(joinThreadPoolInstance);*/ }

ThreadPool::~ThreadPool() {}

Expand Down
3 changes: 3 additions & 0 deletions src/tlstransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ void TlsTransport::Cleanup() {
// Nothing to do
}

void keylog_callback(const SSL *, const char *line);

TlsTransport::TlsTransport(shared_ptr<TcpTransport> lower, string host, state_callback callback)
: Transport(lower, std::move(callback)), mHost(std::move(host)) {

Expand All @@ -267,6 +269,7 @@ TlsTransport::TlsTransport(shared_ptr<TcpTransport> 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");

Expand Down
1 change: 1 addition & 0 deletions src/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ shared_ptr<WsTransport> WebSocket::initWsTransport() {
wsConfig.host = mHost;
wsConfig.path = mPath;
wsConfig.protocols = mConfig.protocols;
wsConfig.headers = mConfig.headers;

auto transport = std::make_shared<WsTransport>(
lower, wsConfig, weak_bind(&WebSocket::incoming, this, _1),
Expand Down
Loading