From b6991ed04506f34bcaf096a85d576ab01cdbfc99 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 20 Oct 2021 21:52:31 +1300 Subject: [PATCH 1/8] Add WebRTC encryption enabled environment variable switch --- .../networking/src/webrtc/WebRTCDataChannels.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index cbc5a8ff6e8..2f1a0819036 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -12,6 +12,7 @@ #include #include +#include #include "../NetworkLogging.h" @@ -402,7 +403,15 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : dependencies.worker_thread = _rtcWorkerThread.get(); dependencies.signaling_thread = _rtcSignalingThread.get(); _peerConnectionFactory = CreateModularPeerConnectionFactory(std::move(dependencies)); - if (!_peerConnectionFactory) { + if (_peerConnectionFactory) { + auto enableEncryption = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_CRYPTO", "1") == "1"; +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "Peer connection encryption enabled =" << enableEncryption; +#endif + PeerConnectionFactoryInterface::Options pc_options; + pc_options.disable_encryption = !enableEncryption; + _peerConnectionFactory->SetOptions(pc_options); + } else { qCWarning(networking_webrtc) << "Failed to create WebRTC peer connection factory"; } From c9ed8c1c4ed6eb5e78356e65818ecf2736e60543 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 20 Oct 2021 21:52:50 +1300 Subject: [PATCH 2/8] Enable WebRTC debugging --- libraries/networking/src/webrtc/WebRTCDataChannels.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 2f1a0819036..f3299c65e54 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -24,7 +24,7 @@ const std::string ICE_SERVER_URI = "stun://ice.vircadia.com:7337"; const int MAX_WEBRTC_BUFFER_SIZE = 16777216; // 16MB -// #define WEBRTC_DEBUG +#define WEBRTC_DEBUG using namespace webrtc; From 9cb2922aa233e157cb0fea019c42484c7040718a Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 21 Oct 2021 16:46:49 +1300 Subject: [PATCH 3/8] Fix STUN URI --- libraries/networking/src/webrtc/WebRTCDataChannels.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index f3299c65e54..543b2fc3915 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -21,7 +21,7 @@ // - https://webrtc.github.io/webrtc-org/native-code/native-apis/ // - https://webrtc.googlesource.com/src/+/master/api/peer_connection_interface.h -const std::string ICE_SERVER_URI = "stun://ice.vircadia.com:7337"; +const std::string ICE_SERVER_URI = "stun:ice.vircadia.com:7337"; const int MAX_WEBRTC_BUFFER_SIZE = 16777216; // 16MB #define WEBRTC_DEBUG From 47f9fde991f08d3ed9c3c0b95e893819e7a8e941 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 21 Oct 2021 16:52:25 +1300 Subject: [PATCH 4/8] Add WebRTC SCTP enabled environment variable switch --- libraries/networking/src/webrtc/WebRTCDataChannels.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 543b2fc3915..9c904435547 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -405,11 +405,15 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : _peerConnectionFactory = CreateModularPeerConnectionFactory(std::move(dependencies)); if (_peerConnectionFactory) { auto enableEncryption = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_CRYPTO", "1") == "1"; + auto enableSCTP = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_SCTP", "1") == "1"; #ifdef WEBRTC_DEBUG qCDebug(networking_webrtc) << "Peer connection encryption enabled =" << enableEncryption; #endif PeerConnectionFactoryInterface::Options pc_options; + pc_options.disable_encryption = !enableEncryption; + pc_options.disable_sctp_data_channels = !enableSCTP; + _peerConnectionFactory->SetOptions(pc_options); } else { qCWarning(networking_webrtc) << "Failed to create WebRTC peer connection factory"; From 78a92ae24fb8a5ebeb836e569aa1d0aae58d56d6 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 21 Oct 2021 16:54:52 +1300 Subject: [PATCH 5/8] Add WebRTC init SSL environment variable switch --- .../networking/src/webrtc/WebRTCDataChannels.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 9c904435547..6b24c1d9e02 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include "../NetworkLogging.h" @@ -402,10 +404,18 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : dependencies.network_thread = _rtcNetworkThread.get(); dependencies.worker_thread = _rtcWorkerThread.get(); dependencies.signaling_thread = _rtcSignalingThread.get(); + + auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "1") == "0"; + if (initializeSSL) { + rtc::InitializeSSL(); + } + _peerConnectionFactory = CreateModularPeerConnectionFactory(std::move(dependencies)); if (_peerConnectionFactory) { + auto enableEncryption = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_CRYPTO", "1") == "1"; auto enableSCTP = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_SCTP", "1") == "1"; + #ifdef WEBRTC_DEBUG qCDebug(networking_webrtc) << "Peer connection encryption enabled =" << enableEncryption; #endif @@ -428,6 +438,12 @@ WebRTCDataChannels::~WebRTCDataChannels() { qCDebug(networking_webrtc) << "WebRTCDataChannels::~WebRTCDataChannels()"; #endif reset(); + + auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "1") == "0"; + if (initializeSSL) { + rtc::CleanupSSL(); + } + _peerConnectionFactory = nullptr; _rtcSignalingThread->Stop(); _rtcSignalingThread = nullptr; From a7d5562f99c3f1c01958eb875e38d0a22b65e2ee Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 21 Oct 2021 16:56:25 +1300 Subject: [PATCH 6/8] Add alternative WebRTC STUN server environment variable switch --- libraries/networking/src/webrtc/WebRTCDataChannels.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 6b24c1d9e02..b9413e49ea9 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -575,7 +575,14 @@ rtc::scoped_refptr WebRTCDataChannels::createPeerConnec PeerConnectionInterface::RTCConfiguration configuration; PeerConnectionInterface::IceServer iceServer; - iceServer.uri = ICE_SERVER_URI; + + auto stunURI = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_STUN", ""); + if (!stunURI.isEmpty()) { + iceServer.uri = stunURI; + } else { + iceServer.uri = ICE_SERVER_URI; + } + configuration.servers.push_back(iceServer); #ifdef WEBRTC_DEBUG From 1a46d64aba1289cfd6f943d6b190b9e826de83c3 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 21 Oct 2021 17:00:56 +1300 Subject: [PATCH 7/8] Typo --- libraries/networking/src/webrtc/WebRTCDataChannels.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index b9413e49ea9..4ba9ed1ba40 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -578,7 +578,7 @@ rtc::scoped_refptr WebRTCDataChannels::createPeerConnec auto stunURI = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_STUN", ""); if (!stunURI.isEmpty()) { - iceServer.uri = stunURI; + iceServer.uri = stunURI.toStdString(); } else { iceServer.uri = ICE_SERVER_URI; } From 93ab6c9b9904386961168fde61aa38cfc06aeafc Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 22 Oct 2021 22:19:02 +1300 Subject: [PATCH 8/8] Clarify settings used --- .../src/webrtc/WebRTCDataChannels.cpp | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 4ba9ed1ba40..a0d5958e705 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -23,7 +23,8 @@ // - https://webrtc.github.io/webrtc-org/native-code/native-apis/ // - https://webrtc.googlesource.com/src/+/master/api/peer_connection_interface.h -const std::string ICE_SERVER_URI = "stun:ice.vircadia.com:7337"; +//const std::string ICE_SERVER_URI = "stun:ice.vircadia.com:7337"; +const std::string ICE_SERVER_URI = "stun1.l.google.com:19302"; const int MAX_WEBRTC_BUFFER_SIZE = 16777216; // 16MB #define WEBRTC_DEBUG @@ -391,6 +392,16 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : // Create a peer connection factory. #ifdef WEBRTC_DEBUG + // Report environment variable values. + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_STUN:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_STUN"); + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_INITSSL:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL"); + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_CRYPTO:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_CRYPTO"); + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_SCTP:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_SCTP"); + // Numbers are per WebRTC's peer_connection_interface.h. qCDebug(networking_webrtc) << "1. Create a new PeerConnectionFactoryInterface"; #endif @@ -405,8 +416,11 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : dependencies.worker_thread = _rtcWorkerThread.get(); dependencies.signaling_thread = _rtcSignalingThread.get(); - auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "1") == "0"; + auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "0") == "1"; if (initializeSSL) { +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "InitializeSSL()"; +#endif rtc::InitializeSSL(); } @@ -415,12 +429,11 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : auto enableEncryption = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_CRYPTO", "1") == "1"; auto enableSCTP = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_SCTP", "1") == "1"; - #ifdef WEBRTC_DEBUG qCDebug(networking_webrtc) << "Peer connection encryption enabled =" << enableEncryption; + qCDebug(networking_webrtc) << "SCTP enabled =" << enableSCTP; #endif PeerConnectionFactoryInterface::Options pc_options; - pc_options.disable_encryption = !enableEncryption; pc_options.disable_sctp_data_channels = !enableSCTP; @@ -439,8 +452,11 @@ WebRTCDataChannels::~WebRTCDataChannels() { #endif reset(); - auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "1") == "0"; + auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "1") == "1"; if (initializeSSL) { +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "CleanupSSL()"; +#endif rtc::CleanupSSL(); } @@ -582,6 +598,9 @@ rtc::scoped_refptr WebRTCDataChannels::createPeerConnec } else { iceServer.uri = ICE_SERVER_URI; } +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "Using ICE server:" << QString::fromStdString(iceServer.uri); +#endif configuration.servers.push_back(iceServer);