Browse Source

Merge pull request #125 from paullouisageneau/change-juice-flag

Replace USE_JUICE flag with USE_NICE
Paul-Louis Ageneau 5 years ago
parent
commit
fdbc038d51

+ 2 - 2
.github/workflows/build-gnutls.yml

@@ -16,7 +16,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=1
+      run: cmake -B build -DUSE_GNUTLS=1
     - name: make
       run: (cd build; make -j2)
     - name: test
@@ -30,7 +30,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=1
+      run: cmake -B build -DUSE_GNUTLS=1
     - name: make
       run: (cd build; make -j2)
     - name: test

+ 1 - 1
.github/workflows/build-nice.yml

@@ -16,7 +16,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_JUICE=0 -DUSE_GNUTLS=1
+      run: cmake -B build -DUSE_GNUTLS=1 -DUSE_NICE=1
     - name: make
       run: (cd build; make -j2)
     - name: test

+ 3 - 3
.github/workflows/build-openssl.yml

@@ -16,7 +16,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=0
+      run: cmake -B build -DUSE_GNUTLS=0
     - name: make
       run: (cd build; make -j2)
     - name: test
@@ -30,7 +30,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=0
+      run: cmake -B build -DUSE_GNUTLS=0
       env:
         OPENSSL_ROOT_DIR: /usr/local/opt/openssl
         OPENSSL_LIBRARIES: /usr/local/opt/openssl/lib
@@ -48,7 +48,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -G "NMake Makefiles" -DUSE_JUICE=1 -DUSE_GNUTLS=0
+      run: cmake -B build -G "NMake Makefiles" -DUSE_GNUTLS=0
     - name: nmake
       run: |
         cd build

+ 17 - 10
CMakeLists.txt

@@ -4,12 +4,19 @@ project(libdatachannel
 	VERSION 0.6.6
 	LANGUAGES CXX)
 
+# Options
 option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
-option(USE_JUICE "Use libjuice instead of libnice" OFF)
+option(USE_NICE "Use libnice instead of libjuice" OFF)
 option(USE_SRTP "Enable SRTP for media support" OFF)
 option(NO_WEBSOCKET "Disable WebSocket support" OFF)
 option(NO_EXAMPLES "Disable examples" OFF)
 
+if(USE_NICE)
+	option(USE_JUICE "Use libjuice" OFF)
+else()
+	option(USE_JUICE "Use libjuice" ON)
+endif()
+
 if(USE_GNUTLS)
 	option(USE_NETTLE "Use Nettle instead of OpenSSL in libjuice" ON)
 else()
@@ -185,18 +192,18 @@ else()
 	target_link_libraries(datachannel-static PRIVATE OpenSSL::SSL)
 endif()
 
-if (USE_JUICE)
-	add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
-	target_compile_definitions(datachannel PRIVATE USE_JUICE=1)
-	target_compile_definitions(datachannel-static PRIVATE USE_JUICE=1)
-	target_link_libraries(datachannel PRIVATE LibJuice::LibJuiceStatic)
-	target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuiceStatic)
-else()
+if (USE_NICE OR NOT USE_JUICE)
 	find_package(LibNice REQUIRED)
-	target_compile_definitions(datachannel PRIVATE USE_JUICE=0)
-	target_compile_definitions(datachannel-static PRIVATE USE_JUICE=0)
+	target_compile_definitions(datachannel PRIVATE USE_NICE=1)
+	target_compile_definitions(datachannel-static PRIVATE USE_NICE=1)
 	target_link_libraries(datachannel PRIVATE LibNice::LibNice)
 	target_link_libraries(datachannel-static PRIVATE LibNice::LibNice)
+else()
+	add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
+	target_compile_definitions(datachannel PRIVATE USE_NICE=0)
+	target_compile_definitions(datachannel-static PRIVATE USE_NICE=0)
+	target_link_libraries(datachannel PRIVATE LibJuice::LibJuiceStatic)
+	target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuiceStatic)
 endif()
 
 add_library(LibDataChannel::LibDataChannel ALIAS datachannel)

+ 1 - 1
Jamfile

@@ -15,7 +15,7 @@ lib libdatachannel
 	: # requirements
 	<cxxstd>17
 	<include>./include/rtc
-	<define>USE_JUICE=1
+	<define>USE_NICE=0
 	<define>RTC_ENABLE_MEDIA=0
 	<define>RTC_ENABLE_WEBSOCKET=0
 	<toolset>msvc:<define>WIN32_LEAN_AND_MEAN

+ 6 - 6
Makefile

@@ -25,17 +25,17 @@ else
         LIBS+=openssl
 endif
 
-USE_JUICE ?= 0
-ifneq ($(USE_JUICE), 0)
-        CPPFLAGS+=-DUSE_JUICE=1
+USE_NICE ?= 0
+ifneq ($(USE_NICE), 0)
+        CPPFLAGS+=-DUSE_NICE=1
+        LIBS+=glib-2.0 gobject-2.0 nice
+else
+        CPPFLAGS+=-DUSE_NICE=0
         INCLUDES+=-I$(JUICE_DIR)/include
         LOCALLIBS+=libjuice.a
 ifneq ($(USE_GNUTLS), 0)
         LIBS+=nettle
 endif
-else
-        CPPFLAGS+=-DUSE_JUICE=0
-        LIBS+=glib-2.0 gobject-2.0 nice
 endif
 
 USE_SRTP ?= 0

+ 14 - 10
README.md

@@ -2,7 +2,7 @@
 
 libdatachannel is a standalone implementation of WebRTC Data Channels and WebSockets in C++17 with C bindings for POSIX platforms (including Linux and Apple macOS) and Microsoft Windows. It enables direct connectivity between native applications and web browsers without the pain of importing the entire WebRTC stack. The interface consists of simplified versions of the JavaScript WebRTC and WebSocket APIs present in browsers, in order to ease the design of cross-environment applications.
 It can be compiled with multiple backends:
-- The security layer can be provided through [GnuTLS](https://www.gnutls.org/) or [OpenSSL](https://www.openssl.org/).
+- The security layer can be provided through [OpenSSL](https://www.openssl.org/) or [GnuTLS](https://www.gnutls.org/).
 - The connectivity for WebRTC can be provided through my ad-hoc ICE library [libjuice](https://github.com/paullouisageneau/libjuice) as submodule or through [libnice](https://github.com/libnice/libnice).
 
 This projet is originally inspired by [librtcdcpp](https://github.com/chadnickbok/librtcdcpp), however it is a complete rewrite from scratch, because the messy architecture of librtcdcpp made solving its implementation issues difficult.
@@ -47,14 +47,14 @@ Features:
 Dependencies:
 - GnuTLS: https://www.gnutls.org/ or OpenSSL: https://www.openssl.org/
 
-Optional dependencies:
-- libnice: https://nice.freedesktop.org/ (substituable with libjuice)
-- libSRTP: https://github.com/cisco/libsrtp (only necessary for media transport)
-
 Submodules:
 - libjuice: https://github.com/paullouisageneau/libjuice
 - usrsctp: https://github.com/sctplab/usrsctp
 
+Optional dependencies:
+- libnice: https://nice.freedesktop.org/ (only if selected as ICE backend instead of libjuice)
+- libSRTP: https://github.com/cisco/libsrtp (only necessary for supporting media transport)
+
 ## Building
 
 ### Clone repository and submodules
@@ -67,33 +67,37 @@ $ git submodule update --init --recursive
 
 ### Building with CMake
 
-The CMake library targets `libdatachannel` and `libdatachannel-static` respectively correspond to the shared and static libraries. On Windows, the DLL resulting from the shared library build only exposes the C API, use the static library for the C++ API. The default target will build tests and examples.
+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.
+
+On Windows, the DLL resulting from the shared library build only exposes the C API, use the static library for the C++ API.
 
 #### POSIX-compliant operating systems (including Linux and Apple macOS)
 ```bash
-$ cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=1
+$ cmake -B build -DUSE_GNUTLS=1 -DUSE_NICE=0
 $ cd build
 $ make -j2
 ```
 
 #### Microsoft Windows with MinGW cross-compilation
 ```bash
-$ cmake -B build -DUSE_JUICE=1 -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-x86_64-w64-mingw32.cmake # replace with your toolchain file
+$ cmake -B build -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-x86_64-w64-mingw32.cmake # replace with your toolchain file
 $ cd build
 $ make -j2
 ```
 
 #### Microsoft Windows with Microsoft Visual C++
 ```bash
-$ cmake -B build -G "NMake Makefiles" -DUSE_JUICE=1
+$ cmake -B build -G "NMake Makefiles"
 $ cd build
 $ nmake
 ```
 
 ### Building 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.
+
 ```bash
-$ make USE_JUICE=1 USE_GNUTLS=1
+$ make USE_GNUTLS=1 USE_NICE=0
 ```
 
 ## Examples

+ 2 - 2
src/icetransport.cpp

@@ -42,7 +42,7 @@ using std::shared_ptr;
 using std::weak_ptr;
 using std::chrono::system_clock;
 
-#if USE_JUICE
+#if !USE_NICE
 
 namespace rtc {
 
@@ -269,7 +269,7 @@ void IceTransport::LogCallback(juice_log_level_t level, const char *message) {
 
 } // namespace rtc
 
-#else // USE_JUICE == 0
+#else // USE_NICE == 1
 
 namespace rtc {
 

+ 3 - 3
src/icetransport.hpp

@@ -26,7 +26,7 @@
 #include "peerconnection.hpp"
 #include "transport.hpp"
 
-#if USE_JUICE
+#if !USE_NICE
 #include <juice/juice.h>
 #else
 #include <nice/agent.h>
@@ -63,7 +63,7 @@ public:
 	bool stop() override;
 	bool send(message_ptr message) override; // false if dropped
 
-#if !USE_JUICE
+#if USE_NICE
 	bool getSelectedCandidatePair(CandidateInfo *local, CandidateInfo *remote);
 #endif
 
@@ -85,7 +85,7 @@ private:
 	candidate_callback mCandidateCallback;
 	gathering_state_callback mGatheringStateChangeCallback;
 
-#if USE_JUICE
+#if !USE_NICE
 	std::unique_ptr<juice_agent_t, void (*)(juice_agent_t *)> mAgent;
 	string mStunHostname;
 	string mStunService;

+ 4 - 4
src/peerconnection.cpp

@@ -669,12 +669,12 @@ void PeerConnection::resetCallbacks() {
 
 bool PeerConnection::getSelectedCandidatePair([[maybe_unused]] CandidateInfo *local,
                                               [[maybe_unused]] CandidateInfo *remote) {
-#if USE_JUICE
-	PLOG_WARNING << "getSelectedCandidatePair() is not implemented for libjuice";
-	return false;
-#else
+#if USE_NICE
 	auto iceTransport = std::atomic_load(&mIceTransport);
 	return iceTransport->getSelectedCandidatePair(local, remote);
+#else
+	PLOG_WARNING << "getSelectedCandidatePair() is only implemented with libnice as ICE backend";
+	return false;
 #endif
 }
 

+ 2 - 2
src/sctptransport.cpp

@@ -24,7 +24,7 @@
 #include <thread>
 #include <vector>
 
-#ifdef USE_JUICE
+#if !USE_NICE
 #ifndef __APPLE__
 // libjuice enables Linux path MTU discovery or sets the DF flag
 #define USE_PMTUD 1
@@ -32,7 +32,7 @@
 // Setting the DF flag is not available on Mac OS
 #define USE_PMTUD 0
 #endif
-#else
+#else // USE_NICE == 1
 #ifdef __linux__
 // Linux UDP does path MTU discovery by default (setting DF and returning EMSGSIZE)
 // It should be safe to enable discovery for SCTP.