Browse Source

Added ICE UDP multiplexing support

Paul-Louis Ageneau 3 years ago
parent
commit
a35d634b54

+ 1 - 1
deps/libjuice

@@ -1 +1 @@
-Subproject commit ab1d0d0cd8597b3f356f3f2e700b06289ebcacd5
+Subproject commit 6950fb1a50484b76571a4806d028b5e206baed20

+ 5 - 0
examples/client/main.cpp

@@ -72,6 +72,11 @@ int main(int argc, char **argv) try {
 		config.iceServers.emplace_back(stunServer);
 	}
 
+	if (params.udpMux()) {
+		cout << "ICE UDP mux enabled" << endl;
+		config.enableIceUdpMux = true;
+	}
+
 	localId = randomId(4);
 	cout << "The local ID is: " << localId << endl;
 

+ 7 - 1
examples/client/parse_cl.cpp

@@ -44,6 +44,7 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
   static struct option long_options[] =
   {
     {"noStun", no_argument, NULL, 'n'},
+    {"udpMux", no_argument, NULL, 'm'},
     {"stunServer", required_argument, NULL, 's'},
     {"stunPort", required_argument, NULL, 't'},
     {"webSocketServer", required_argument, NULL, 'w'},
@@ -56,6 +57,7 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
 
   /* default values */
   _n = false;
+  _m = false;
   _s = "stun.l.google.com";
   _t = 19302;
   _w = "localhost";
@@ -63,7 +65,7 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
   _h = false;
 
   optind = 0;
-  while ((c = getopt_long (argc, argv, "s:t:w:x:enhv", long_options, &optind)) != - 1)
+  while ((c = getopt_long (argc, argv, "s:t:w:x:enmhv", long_options, &optind)) != - 1)
     {
       switch (c)
         {
@@ -71,6 +73,10 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
           _n = true;
           break;
 
+		case 'm':
+		  _m = true;
+		  break;
+
         case 's':
           _s = optarg;
           break;

+ 2 - 0
examples/client/parse_cl.h

@@ -35,6 +35,7 @@ class Cmdline
 private:
   /* parameters */
   bool _n;
+  bool _m;
   std::string _s;
   int _t;
   std::string _w;
@@ -57,6 +58,7 @@ public:
   int next_param () { return _optind; }
 
   bool noStun () const { return _n; }
+  bool udpMux () const { return _m; }
   std::string stunServer () const { return _s; }
   int stunPort () const { return _t; }
   std::string webSocketServer () const { return _w; }

+ 2 - 1
include/rtc/configuration.hpp

@@ -80,7 +80,8 @@ struct RTC_CPP_EXPORT Configuration {
 	// Options
 	CertificateType certificateType = CertificateType::Default;
 	TransportPolicy iceTransportPolicy = TransportPolicy::All;
-	bool enableIceTcp = false;
+	bool enableIceTcp = false;    // libnice only
+	bool enableIceUdpMux = false; // libjuice only
 	bool disableAutoNegotiation = false;
 
 	// Port range

+ 2 - 1
include/rtc/rtc.h

@@ -155,7 +155,8 @@ typedef struct {
 	const char *bindAddress; // libjuice only, NULL means any
 	rtcCertificateType certificateType;
 	rtcTransportPolicy iceTransportPolicy;
-	bool enableIceTcp;
+	bool enableIceTcp;    // libnice only
+	bool enableIceUdpMux; // libjuice only
 	bool disableAutoNegotiation;
 	uint16_t portRangeBegin; // 0 means automatic
 	uint16_t portRangeEnd;   // 0 means automatic

+ 2 - 0
src/capi.cpp

@@ -365,6 +365,7 @@ int rtcCreatePeerConnection(const rtcConfiguration *config) {
 		c.certificateType = static_cast<CertificateType>(config->certificateType);
 		c.iceTransportPolicy = static_cast<TransportPolicy>(config->iceTransportPolicy);
 		c.enableIceTcp = config->enableIceTcp;
+		c.enableIceUdpMux = config->enableIceUdpMux;
 		c.disableAutoNegotiation = config->disableAutoNegotiation;
 
 		if (config->mtu > 0)
@@ -1431,3 +1432,4 @@ int rtcSetSctpSettings(const rtcSctpSettings *settings) {
 		return RTC_ERR_SUCCESS;
 	});
 }
+

+ 19 - 7
src/impl/icetransport.cpp

@@ -42,9 +42,9 @@ using std::chrono::system_clock;
 
 namespace rtc::impl {
 
-#if !USE_NICE
+#if !USE_NICE // libjuice
 
-#define MAX_TURN_SERVERS_COUNT 2
+const int MAX_TURN_SERVERS_COUNT = 2;
 
 IceTransport::IceTransport(const Configuration &config, candidate_callback candidateCallback,
                            state_callback stateChangeCallback,
@@ -56,9 +56,6 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
       mAgent(nullptr, nullptr) {
 
 	PLOG_DEBUG << "Initializing ICE transport (libjuice)";
-	if (config.enableIceTcp) {
-		PLOG_WARNING << "ICE-TCP is not supported with libjuice";
-	}
 
 	juice_log_level_t level;
 	auto logger = plog::get();
@@ -93,6 +90,17 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
 	jconfig.cb_recv = IceTransport::RecvCallback;
 	jconfig.user_ptr = this;
 
+	if (config.enableIceTcp) {
+		PLOG_WARNING << "ICE-TCP is not supported with libjuice";
+	}
+
+	if (config.enableIceUdpMux) {
+		PLOG_DEBUG << "Enabling ICE UDP mux";
+		jconfig.concurrency_mode = JUICE_CONCURRENCY_MODE_MUX;
+	} else {
+		jconfig.concurrency_mode = JUICE_CONCURRENCY_MODE_POLL;
+	}
+
 	// Randomize servers order
 	std::vector<IceServer> servers = config.iceServers;
 	auto seed = static_cast<unsigned int>(system_clock::now().time_since_epoch().count());
@@ -167,7 +175,7 @@ Description IceTransport::getLocalDescription(Description::Type type) const {
 	// setup:actpass.
 	// See https://tools.ietf.org/html/rfc5763#section-5
 	Description desc(string(sdp), type,
-	                   type == Description::Type::Offer ? Description::Role::ActPass : mRole);
+	                 type == Description::Type::Offer ? Description::Role::ActPass : mRole);
 	desc.addIceOption("trickle");
 	return desc;
 }
@@ -420,6 +428,10 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
 		             nullptr);
 	}
 
+	if (config.enableIceUdpMux) {
+		PLOG_WARNING << "ICE UDP mux is not available with libnice";
+	}
+
 	// Randomize order
 	std::vector<IceServer> servers = config.iceServers;
 	auto seed = static_cast<unsigned int>(system_clock::now().time_since_epoch().count());
@@ -576,7 +588,7 @@ Description IceTransport::getLocalDescription(Description::Type type) const {
 	// setup:actpass.
 	// See https://tools.ietf.org/html/rfc5763#section-5
 	Description desc(string(sdp.get()), type,
-	                   type == Description::Type::Offer ? Description::Role::ActPass : mRole);
+	                 type == Description::Type::Offer ? Description::Role::ActPass : mRole);
 	desc.addIceOption("trickle");
 	return desc;
 }

+ 1 - 0
src/impl/icetransport.hpp

@@ -23,6 +23,7 @@
 #include "common.hpp"
 #include "configuration.hpp"
 #include "description.hpp"
+#include "global.hpp"
 #include "peerconnection.hpp"
 #include "transport.hpp"
 

+ 1 - 0
src/impl/init.cpp

@@ -23,6 +23,7 @@
 #include "dtlstransport.hpp"
 #include "pollservice.hpp"
 #include "sctptransport.hpp"
+#include "icetransport.hpp"
 #include "threadpool.hpp"
 #include "tls.hpp"
 

+ 1 - 0
src/impl/sctptransport.hpp

@@ -21,6 +21,7 @@
 
 #include "common.hpp"
 #include "configuration.hpp"
+#include "global.hpp"
 #include "processor.hpp"
 #include "queue.hpp"
 #include "transport.hpp"