Merge pull request #1300 from ctrlaltdavid/dev/webrtc-domain-server

Anonymous Web SDK connection to domain server
This commit is contained in:
Kalila 2021-08-15 23:51:36 -04:00 committed by GitHub
commit 4c0bda8bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 8 deletions

View file

@ -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()) {

View file

@ -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<ReceivedMessage> packetList);
@ -252,7 +252,7 @@ public slots:
void processDomainServerConnectionDeniedPacket(QSharedPointer<ReceivedMessage> 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);

View file

@ -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<NLPacket> 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<Node::LocalID, SharedNodePointer>;

View file

@ -291,6 +291,9 @@ void WDCConnection::onDataChannelOpened(rtc::scoped_refptr<DataChannelInterface>
_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;