Skip to content

Commit

Permalink
Merge pull request #1089 from paullouisageneau/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
paullouisageneau authored Jan 9, 2024
2 parents b5518ff + 5515f71 commit b159383
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
7 changes: 3 additions & 4 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ $ git submodule update --init --recursive --depth 1

The CMake library targets `libdatachannel` and `libdatachannel-static` respectively correspond to the shared and static libraries. The default target will build tests and examples.

The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice.
Options `USE_GNUTLS` and `USE_MBEDTLS` allow to switch the cryptographic backend to GnuTLS and Mbed TLS respectively, otherwise OpenSSL is selected by default. The option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice as system library.

The option `PREFER_SYSTEM_LIB` allow to link against the system library rather than building all the submodule.
Options `USE_SYSTEM_SRTP`, `USE_SYSTEM_JUICE`, `USE_SYSTEM_USRSCTP`, `USE_SYSTEM_PLOG` and `USE_SYSTEM_JSON` allow to do the same but per submodule, for libsrtp, libjuice, libusrsctp, Plog and Nlohmann JSON respectively.
The option `PREFER_SYSTEM_LIB` allows to link against the system library rather than building all the submodule. Options `USE_SYSTEM_SRTP`, `USE_SYSTEM_JUICE`, `USE_SYSTEM_USRSCTP`, `USE_SYSTEM_PLOG` and `USE_SYSTEM_JSON` allow to do the same but per submodule, for libsrtp, libjuice, libusrsctp, Plog and Nlohmann JSON respectively.

If you only need Data Channels, the option `NO_MEDIA` allows to make the library lighter by removing media support. Similarly, `NO_WEBSOCKET` removes WebSocket support.

Expand Down Expand Up @@ -78,7 +77,7 @@ $ nmake

## Build directly with Make (Linux only)

The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice.
Options `USE_GNUTLS` and `USE_MBEDTLS` allow to switch the cryptographic backend to GnuTLS and Mbed TLS respectively, otherwise OpenSSL is selected by default. The option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice as system library.

If you only need Data Channels, the option `NO_MEDIA` removes media support. Similarly, `NO_WEBSOCKET` removes WebSocket support.

Expand Down
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, M
include(GNUInstallDirs)

# Options
option(USE_MBEDTLS "Use Mbed TLS instead of OpenSSL" OFF)
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
option(USE_MBEDTLS "Use Mbed TLS instead of OpenSSL" OFF)
option(USE_NICE "Use libnice instead of libjuice" OFF)
option(PREFER_SYSTEM_LIB "Prefer system libraries over deps folder" OFF)
option(USE_SYSTEM_SRTP "Use system libSRTP" ${PREFER_SYSTEM_LIB})
Expand All @@ -24,11 +24,10 @@ option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
option(CAPI_STDCALL "Set calling convention of C API callbacks stdcall" OFF)
option(SCTP_DEBUG "Enable SCTP debugging output to verbose log" OFF)

if (USE_MBEDTLS AND USE_GNUTLS)
message(FATAL_ERROR "Both USE_MBEDTLS and USE_GNUTLS can not be enabled at the same time")
if (USE_GNUTLS AND USE_MBEDTLS)
message(FATAL_ERROR "Both USE_MBEDTLS and USE_GNUTLS cannot be enabled at the same time")
endif()


if(USE_GNUTLS)
option(USE_NETTLE "Use Nettle in libjuice" ON)
else()
Expand Down Expand Up @@ -355,9 +354,8 @@ if (USE_GNUTLS)
endif()
elseif(USE_MBEDTLS)
find_package(MbedTLS 3 REQUIRED)

target_compile_definitions(datachannel PRIVATE USE_MBEDTLS)
target_compile_definitions(datachannel-static PRIVATE USE_MBEDTLS)
target_compile_definitions(datachannel PRIVATE USE_MBEDTLS=1)
target_compile_definitions(datachannel-static PRIVATE USE_MBEDTLS=1)
target_link_libraries(datachannel PRIVATE MbedTLS::MbedTLS)
target_link_libraries(datachannel-static PRIVATE MbedTLS::MbedTLS)
else()
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ INCLUDES=-Isrc -Iinclude/rtc -Iinclude -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/us
LDLIBS=

USE_GNUTLS ?= 0
USE_MBEDTLS ?= 0
ifneq ($(USE_GNUTLS), 0)
CPPFLAGS+=-DUSE_GNUTLS=1
ifneq ($(USE_MBEDTLS), 0)
$(error Both USE_MBEDTLS and USE_GNUTLS cannot be enabled at the same time)
endif
CPPFLAGS+=-DUSE_GNUTLS=1
LIBS+=gnutls
else ifneq ($(USE_MBEDTLS), 0)
CPPFLAGS+=-DUSE_MBEDTLS=1
LIBS+=mbedtls
else
CPPFLAGS+=-DUSE_GNUTLS=0
LIBS+=openssl
SRTP_CONFIGURE_FLAGS+=--enable-openssl
endif
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ libdatachannel is available on [AUR](https://aur.archlinux.org/packages/libdatac

- [GnuTLS](https://www.gnutls.org/), [Mbed TLS](https://www.trustedfirmware.org/projects/mbed-tls/), or [OpenSSL](https://www.openssl.org/)
- [usrsctp](https://github.com/sctplab/usrsctp) (as submodule by default)
- [Plog](https://github.com/SergiusTheBest/plog) (as submodule by default)
- [plog](https://github.com/SergiusTheBest/plog) (as submodule by default)
- [libjuice](https://github.com/paullouisageneau/libjuice) (as submodule by default) or [libnice](https://nice.freedesktop.org/) as an ICE backend.
- [libsrtp](https://github.com/cisco/libsrtp) (as submodule by default) required if compiled with media support.
- [nlohmann JSON](https://github.com/nlohmann/json) (as submodule by default) required to build examples.
Expand Down
2 changes: 1 addition & 1 deletion examples/streamer/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) {
x.LowPart = filetime.dwLowDateTime;
x.HighPart = filetime.dwHighDateTime;
usec = x.QuadPart / 10 - epoch_offset_us;
tv->tv_sec = time_t(usec / 1000000ULL);
tv->tv_sec = long(usec / 1000000ULL);
tv->tv_usec = long(usec % 1000000ULL);
}
if (tz) {
Expand Down
14 changes: 7 additions & 7 deletions include/rtc/nalunit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,29 @@ struct RTC_CPP_EXPORT NalUnitFragmentHeader {

#pragma pack(pop)

typedef enum {
enum NalUnitStartSequenceMatch {
NUSM_noMatch,
NUSM_firstZero,
NUSM_secondZero,
NUSM_thirdZero,
NUSM_shortMatch,
NUSM_longMatch
} NalUnitStartSequenceMatch;
};

static const size_t H264_NAL_HEADER_SIZE = 1;
static const size_t H265_NAL_HEADER_SIZE = 2;
/// Nal unit
struct RTC_CPP_EXPORT NalUnit : binary {
typedef enum { H264, H265 } Type;
enum class Type { H264, H265 };

NalUnit(const NalUnit &unit) = default;
NalUnit(size_t size, bool includingHeader = true, Type type = H264)
NalUnit(size_t size, bool includingHeader = true, Type type = Type::H264)
: binary(size + (includingHeader
? 0
: (type == H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE))) {}
: (type == Type::H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE))) {}
NalUnit(binary &&data) : binary(std::move(data)) {}
NalUnit(Type type = H264)
: binary(type == H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE) {}
NalUnit(Type type = Type::H264)
: binary(type == Type::H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE) {}
template <typename Iterator> NalUnit(Iterator begin_, Iterator end_) : binary(begin_, end_) {}

bool forbiddenBit() const { return header()->forbiddenBit(); }
Expand Down
2 changes: 1 addition & 1 deletion pages/content/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ save_as: index.html
<h3>Portable</h3>
<ul>
<li>Support for POSIX platforms (including GNU/Linux, Android, FreeBSD, Apple macOS and iOS) and Microsoft Windows</li>
<li>Support for both <a href="https://www.openssl.org/">OpenSSL</a> and <a href="https://www.gnutls.org/">GnuTLS</a> as TLS backend
<li>Support for <a href="https://www.gnutls.org/">GnuTLS</a>, <a href="https://www.trustedfirmware.org/projects/mbed-tls/">Mbed TLS</a>, or <a href="https://www.openssl.org/">OpenSSL</a> as TLS backend
<li>Code using Data Channels and WebSockets may be compiled as-is to WebAssembly for browsers with <a href="https://github.com/paullouisageneau/datachannel-wasm">datachannel-wasm</a></li>
</ul>
</section>
Expand Down
1 change: 0 additions & 1 deletion src/impl/dtlstransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ DtlsTransport::DtlsTransport(shared_ptr<IceTransport> lower, certificate_ptr cer
auto ecdh = unique_ptr<EC_KEY, decltype(&EC_KEY_free)>(
EC_KEY_new_by_curve_name(NID_X9_62_prime256v1), EC_KEY_free);
SSL_CTX_set_tmp_ecdh(mCtx, ecdh.get());
SSL_CTX_set_options(mCtx, SSL_OP_SINGLE_ECDH_USE);
#endif

auto [x509, pkey] = mCertificate->credentials();
Expand Down
1 change: 0 additions & 1 deletion src/impl/tlstransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ TlsTransport::TlsTransport(variant<shared_ptr<TcpTransport>, shared_ptr<HttpProx
auto ecdh = unique_ptr<EC_KEY, decltype(&EC_KEY_free)>(
EC_KEY_new_by_curve_name(NID_X9_62_prime256v1), EC_KEY_free);
SSL_CTX_set_tmp_ecdh(mCtx, ecdh.get());
SSL_CTX_set_options(mCtx, SSL_OP_SINGLE_ECDH_USE);
#endif

if(mIsClient) {
Expand Down

0 comments on commit b159383

Please sign in to comment.