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()) { 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); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 98494aa00a..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); } @@ -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; diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 265b28f126..974cef2997 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); } @@ -336,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; @@ -486,7 +495,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 +567,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;