From ed36321e25d8f6892d36c366b49cec31dd1e0536 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 30 Jul 2021 14:12:38 +1200 Subject: [PATCH 1/6] Fill in connected client's ports with WebRTC data channel IDs --- domain-server/src/NodeConnectionData.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/domain-server/src/NodeConnectionData.cpp b/domain-server/src/NodeConnectionData.cpp index 1ef8ebf6a9..60a8d6878c 100644 --- a/domain-server/src/NodeConnectionData.cpp +++ b/domain-server/src/NodeConnectionData.cpp @@ -55,6 +55,21 @@ NodeConnectionData NodeConnectionData::fromDataStream(QDataStream& dataStream, c >> newHeader.publicSockAddr >> newHeader.localSockAddr >> newHeader.interestList >> newHeader.placeName; + // A WebRTC web client doesn't necessarily know it's public Internet or local network addresses, and for WebRTC they aren't + // needed: for WebRTC, the data channel ID is the important thing. The client's public Internet IP address still needs to + // be known for domain access permissions, though, and this can be obtained from the WebSocket signaling connection. + if (senderSockAddr.getSocketType() == SocketType::WebRTC) { + // WEBRTC TODO: Rather than setting the SocketType here, serialize and deserialize the SocketType in the leading byte of + // the 5 bytes used to encode the IP address. + newHeader.publicSockAddr.setSocketType(SocketType::WebRTC); + newHeader.localSockAddr.setSocketType(SocketType::WebRTC); + + // WEBRTC TODO: Set the public Internet address obtained from the WebSocket used in WebRTC signaling. + + newHeader.publicSockAddr.setPort(senderSockAddr.getPort()); // We don't know whether it's a public or local connection + newHeader.localSockAddr.setPort(senderSockAddr.getPort()); // so set both ports. + } + newHeader.senderSockAddr = senderSockAddr; if (newHeader.publicSockAddr.getAddress().isNull()) { From fa01ead130e47d0adde292fed7d524fe9a068eb8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 30 Jul 2021 14:13:15 +1200 Subject: [PATCH 2/6] Add extra WebRTC debug --- 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 265b28f126..1fd9ae42e5 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -291,6 +291,9 @@ void WDCConnection::onDataChannelOpened(rtc::scoped_refptr _dataChannelID = _parent->getNewDataChannelID(); // Not dataChannel->id() because it's only unique per peer connection. _dataChannel->RegisterObserver(_dataChannelObserver.get()); +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "WDCConnection::onDataChannelOpened() : channel ID:" << _dataChannelID; +#endif _parent->onDataChannelOpened(this, _dataChannelID); } @@ -486,7 +489,8 @@ void WebRTCDataChannels::sendSignalingMessage(const QJsonObject& message) { void WebRTCDataChannels::emitDataMessage(int dataChannelID, const QByteArray& byteArray) { #ifdef WEBRTC_DEBUG - qCDebug(networking_webrtc) << "WebRTCDataChannels::emitDataMessage() :" << dataChannelID << byteArray; + qCDebug(networking_webrtc) << "WebRTCDataChannels::emitDataMessage() :" << dataChannelID << byteArray.toHex() + << byteArray.length(); #endif emit dataMessage(dataChannelID, byteArray); } @@ -557,6 +561,9 @@ void WebRTCDataChannels::closePeerConnectionNow(WDCConnection* connection) { connection->closePeerConnection(); // Delete the WDCConnection. +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "Dispose of connection for channel ID:" << connection->getDataChannelID(); +#endif _connectionsByWebSocket.remove(connection->getWebSocketID()); _connectionsByDataChannel.remove(connection->getDataChannelID()); delete connection; From 3603520c946a5165878079d6eb60a57766cf2527 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 30 Jul 2021 14:13:44 +1200 Subject: [PATCH 3/6] fillPacketHeader() can be private --- libraries/networking/src/LimitedNodeList.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 98494aa00a..86c9d90a3b 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -420,7 +420,6 @@ protected: qint64 sendPacket(std::unique_ptr packet, const Node& destinationNode, const SockAddr& overridenSockAddr); - void fillPacketHeader(const NLPacket& packet, HMACAuth* hmacAuth = nullptr); void setLocalSocket(const SockAddr& sockAddr); @@ -487,6 +486,8 @@ private slots: void addSTUNHandlerToUnfiltered(); // called once STUN socket known private: + void fillPacketHeader(const NLPacket& packet, HMACAuth* hmacAuth = nullptr); + mutable QReadWriteLock _sessionUUIDLock; QUuid _sessionUUID; using LocalIDMapping = tbb::concurrent_unordered_map; From 0ea6d88bf5982525c7aacff2093dd12cb621e68c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 30 Jul 2021 14:14:36 +1200 Subject: [PATCH 4/6] Fix function parameter ID --- libraries/networking/src/LimitedNodeList.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 86c9d90a3b..9e6458225f 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -121,7 +121,7 @@ public: QUuid getSessionUUID() const; void setSessionUUID(const QUuid& sessionUUID); Node::LocalID getSessionLocalID() const; - void setSessionLocalID(Node::LocalID localID); + void setSessionLocalID(Node::LocalID sessionLocalID); void setPermissions(const NodePermissions& newPermissions); bool isAllowedEditor() const { return _permissions.can(NodePermissions::Permission::canAdjustLocks); } From 9be1c08c8cd714e3e3fc523bb3e60bd07ca9de09 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 31 Jul 2021 23:03:48 +1200 Subject: [PATCH 5/6] Fix domain server crash --- libraries/networking/src/webrtc/WebRTCDataChannels.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 1fd9ae42e5..974cef2997 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -339,14 +339,20 @@ qint64 WDCConnection::getBufferedAmount() const { #ifdef WEBRTC_DEBUG qCDebug(networking_webrtc) << "WDCConnection::getBufferedAmount()"; #endif - return _dataChannel->buffered_amount(); + return _dataChannel ? _dataChannel->buffered_amount() : 0; } bool WDCConnection::sendDataMessage(const DataBuffer& buffer) { #ifdef WEBRTC_DEBUG qCDebug(networking_webrtc) << "WDCConnection::sendDataMessage()"; + if (!_dataChannel) { + qCDebug(networking_webrtc) << "No data channel to send on"; + } #endif - if (_dataChannel->buffered_amount() + buffer.size() > MAX_WEBRTC_BUFFER_SIZE) { + if (!_dataChannel) { + // Data channel may have been closed while message to send was being prepared. + return false; + } else if (_dataChannel->buffered_amount() + buffer.size() > MAX_WEBRTC_BUFFER_SIZE) { // Don't send, otherwise the data channel will be closed. qCDebug(networking_webrtc) << "WebRTC send buffer overflow"; return false; From 500da963ade0c62bed25c52ab85d73f6ef51110c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 4 Aug 2021 16:11:04 +1200 Subject: [PATCH 6/6] Make parameter names consistent across usages --- libraries/networking/src/DomainHandler.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index 954fd35a67..c76cadeb3e 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -242,7 +242,7 @@ public: }; public slots: - void setURLAndID(QUrl domainURL, QUuid id); + void setURLAndID(QUrl domainURL, QUuid domainID); void setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id); void processSettingsPacketList(QSharedPointer packetList); @@ -252,7 +252,7 @@ public slots: void processDomainServerConnectionDeniedPacket(QSharedPointer message); // sets domain handler in error state. - void setRedirectErrorState(QUrl errorUrl, QString reasonMessage = "", int reason = -1, const QString& extraInfo = ""); + void setRedirectErrorState(QUrl errorUrl, QString reasonMessage = "", int reasonCode = -1, const QString& extraInfo = ""); bool isInErrorState() { return _isInErrorState; } @@ -278,7 +278,7 @@ signals: void settingsReceived(const QJsonObject& domainSettingsObject); void settingsReceiveFail(); - void domainConnectionRefused(QString reasonMessage, int reason, const QString& extraInfo); + void domainConnectionRefused(QString reasonMessage, int reasonCode, const QString& extraInfo); void redirectToErrorDomainURL(QUrl errorDomainURL); void redirectErrorStateChanged(bool isInErrorState);