diff --git a/Jamfile b/Jamfile index ffae408..5e1a90f 100644 --- a/Jamfile +++ b/Jamfile @@ -3,6 +3,12 @@ import feature : feature ; project libdatachannel ; path-constant CWD : . ; +feature gnutls : off on : composite propagated ; +feature.compose off + : USE_GNUTLS=0 ; +feature.compose on + : USE_GNUTLS=1 ; + lib libdatachannel : # sources [ glob ./src/*.cpp ] @@ -12,9 +18,15 @@ lib libdatachannel USE_JUICE=1 RTC_ENABLE_MEDIA=0 RTC_ENABLE_WEBSOCKET=0 + msvc:WIN32_LEAN_AND_MEAN + msvc:NOMINMAX + msvc:_CRT_SECURE_NO_WARNINGS + msvc:_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING /libdatachannel//usrsctp /libdatachannel//juice /libdatachannel//plog + off:ssl + off:crypto : # default build static : # usage requirements @@ -22,15 +34,8 @@ lib libdatachannel /libdatachannel//plog gcc:"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable" clang:"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable" - msvc:"/DWIN32_LEAN_AND_MEAN /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING" ; -feature gnutls : off on : composite propagated ; -feature.compose off - : USE_GNUTLS=0 ; -feature.compose on - : USE_GNUTLS=1 ; - alias plog : # no sources : # no build requirements @@ -85,7 +90,7 @@ actions make_libusrsctp } actions make_libusrsctp_msvc { - (cd $(CWD)/deps/usrsctp && cmake -B build -G "NMake Makefiles" && cd build && nmake usrsctplib-static) + (cd $(CWD)/deps/usrsctp && cmake -B build -G "Visual Studio 16 2019" && cd build && msbuild usrsctplib.sln) cp $(CWD)/deps/usrsctp/build/usrsctplib/libusrsctp.lib $(<) } @@ -121,7 +126,86 @@ rule make_libjuice_msvc ( targets * : sources * : properties * ) } actions make_libjuice_msvc { - (cd $(CWD)/deps/libjuice && cmake -B build -G "NMake Makefiles" $(CMAKEOPTS) && cd build && nmake juice-static) + (cd $(CWD)/deps/libjuice && cmake -B build -G "Visual Studio 16 2019" $(CMAKEOPTS) && cd build && msbuild libjuice.sln) cp $(CWD)/deps/libjuice/build/libjuice-static.lib $(<) } +# the search path to pick up the openssl libraries from. This is the +# property of those libraries +rule openssl-lib-path ( properties * ) +{ + local OPENSSL_LIB = [ feature.get-values : $(properties) ] ; + + if darwin in $(properties) && $(OPENSSL_LIB) = "" + { + # on macOS, default to pick up openssl from the homebrew installation + # brew install openssl + OPENSSL_LIB = /usr/local/opt/openssl/lib ; + } + else if windows in $(properties) && $(OPENSSL_LIB) = "" + { + # on windows, assume openssl is installed to c:\OpenSSL-Win32 + if 64 in $(properties) + { OPENSSL_LIB = c:\\OpenSSL-Win64\\lib ; } + else + { OPENSSL_LIB = c:\\OpenSSL-Win32\\lib ; } + } + + local result ; + result += $(OPENSSL_LIB) ; + return $(result) ; +} + +# the include path to pick up openssl headers from. This is the +# usage-requirement for the openssl-related libraries +rule openssl-include-path ( properties * ) +{ + local OPENSSL_INCLUDE = [ feature.get-values : $(properties) ] ; + + if darwin in $(properties) && $(OPENSSL_INCLUDE) = "" + { + # on macOS, default to pick up openssl from the homebrew installation + # brew install openssl + OPENSSL_INCLUDE = /usr/local/opt/openssl/include ; + } + else if windows in $(properties) && $(OPENSSL_INCLUDE) = "" + { + # on windows, assume openssl is installed to c:\OpenSSL-Win32 + if 64 in $(properties) + { OPENSSL_INCLUDE = c:\\OpenSSL-Win64\\include ; } + else + { OPENSSL_INCLUDE = c:\\OpenSSL-Win32\\include ; } + } + + local result ; + result += $(OPENSSL_INCLUDE) ; + return $(result) ; +} + +# libraries for openssl on windows +lib advapi32 : : advapi32 ; +lib user32 : : user32 ; +lib shell32 : : shell32 ; +lib gdi32 : : gdi32 ; +lib bcrypt : : bcrypt ; +lib z : : shared z ; +alias ssl-deps : advapi32 user32 shell32 gdi32 ; + +# pre OpenSSL 1.1 windows +lib crypto : ssl-deps : windows pre1.1 libeay32 + @openssl-lib-path : : @openssl-include-path ; +lib ssl : ssl-deps : windows pre1.1 ssleay32 + crypto @openssl-lib-path : : @openssl-include-path ; + +# OpenSSL 1.1+ windows +lib crypto : ssl-deps : msvc 1.1 libcrypto + @openssl-lib-path : : @openssl-include-path ; +lib ssl : ssl-deps : msvc 1.1 libssl crypto + @openssl-lib-path : : @openssl-include-path ; + +# generic OpenSSL +lib crypto : : crypto z @openssl-lib-path : : + @openssl-include-path ; +lib ssl : : ssl crypto @openssl-lib-path : : + @openssl-include-path ; + diff --git a/src/dtlstransport.cpp b/src/dtlstransport.cpp index 0436094..22fcee8 100644 --- a/src/dtlstransport.cpp +++ b/src/dtlstransport.cpp @@ -428,7 +428,7 @@ void DtlsTransport::runRecvLoop() { if (state() == State::Connecting) { // Continue the handshake - int ret = SSL_do_handshake(mSsl); + ret = SSL_do_handshake(mSsl); if (!openssl::check(mSsl, ret, "Handshake failed")) break; @@ -442,7 +442,7 @@ void DtlsTransport::runRecvLoop() { postHandshake(); } } else { - int ret = SSL_read(mSsl, buffer, bufferSize); + ret = SSL_read(mSsl, buffer, bufferSize); if (!openssl::check(mSsl, ret)) break; @@ -455,7 +455,7 @@ void DtlsTransport::runRecvLoop() { std::optional duration; if (state() == State::Connecting) { // Warning: This function breaks the usual return value convention - int ret = DTLSv1_handle_timeout(mSsl); + ret = DTLSv1_handle_timeout(mSsl); if (ret < 0) { throw std::runtime_error("Handshake timeout"); // write BIO can't fail } else if (ret > 0) { diff --git a/src/peerconnection.cpp b/src/peerconnection.cpp index 58d4188..03b32ee 100644 --- a/src/peerconnection.cpp +++ b/src/peerconnection.cpp @@ -483,7 +483,7 @@ void PeerConnection::forwardMessage(message_ptr message) { return; } - auto channel = findDataChannel(message->stream); + auto channel = findDataChannel(uint16_t(message->stream)); auto iceTransport = std::atomic_load(&mIceTransport); auto sctpTransport = std::atomic_load(&mSctpTransport); @@ -658,7 +658,8 @@ void PeerConnection::resetCallbacks() { mGatheringStateChangeCallback = nullptr; } -bool PeerConnection::getSelectedCandidatePair(CandidateInfo *local, CandidateInfo *remote) { +bool PeerConnection::getSelectedCandidatePair([[maybe_unused]] CandidateInfo *local, + [[maybe_unused]] CandidateInfo *remote) { #if USE_JUICE PLOG_WARNING << "getSelectedCandidatePair() is not implemented for libjuice"; return false; diff --git a/src/sctptransport.cpp b/src/sctptransport.cpp index bfe5ced..e6e92b4 100644 --- a/src/sctptransport.cpp +++ b/src/sctptransport.cpp @@ -448,8 +448,8 @@ bool SctpTransport::safeFlush() { } } -int SctpTransport::handleRecv(struct socket *sock, union sctp_sockstore addr, const byte *data, - size_t len, struct sctp_rcvinfo info, int flags) { +int SctpTransport::handleRecv(struct socket * /*sock*/, union sctp_sockstore /*addr*/, + const byte *data, size_t len, struct sctp_rcvinfo info, int flags) { try { PLOG_VERBOSE << "Handle recv, len=" << len; if (!len) @@ -500,7 +500,7 @@ int SctpTransport::handleSend(size_t free) { return safeFlush() ? 0 : -1; } -int SctpTransport::handleWrite(byte *data, size_t len, uint8_t tos, uint8_t set_df) { +int SctpTransport::handleWrite(byte *data, size_t len, uint8_t /*tos*/, uint8_t /*set_df*/) { try { PLOG_VERBOSE << "Handle write, len=" << len; diff --git a/src/tls.hpp b/src/tls.hpp index ec0bbb0..c7639b9 100644 --- a/src/tls.hpp +++ b/src/tls.hpp @@ -48,6 +48,11 @@ gnutls_datum_t make_datum(char *data, size_t size); #else // USE_GNUTLS==0 +#ifdef _WIN32 +// Include winsock2.h header first since OpenSSL may include winsock.h +#include +#endif + #include #include