mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:09:52 +02:00
Merge pull request #2676 from birarda/authentication
re-instate DS connect behavior
This commit is contained in:
commit
8257e25969
8 changed files with 44 additions and 54 deletions
|
@ -66,18 +66,6 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
|
|
||||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||||
|
|
||||||
#if defined(IP_DONTFRAG) || defined(IP_MTU_DISCOVER)
|
|
||||||
qDebug() << "Making required DTLS changes to NodeList DTLS socket.";
|
|
||||||
|
|
||||||
int socketHandle = LimitedNodeList::getInstance()->getDTLSSocket().socketDescriptor();
|
|
||||||
#if defined(IP_DONTFRAG)
|
|
||||||
int optValue = 1;yea
|
|
||||||
setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, (const void*) optValue, sizeof(optValue));
|
|
||||||
#elif defined(IP_MTU_DISCOVER)
|
|
||||||
int optValue = 1;
|
|
||||||
setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, (const void*) optValue, sizeof(optValue));
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
// connect our socket to read datagrams received on the DTLS socket
|
// connect our socket to read datagrams received on the DTLS socket
|
||||||
connect(&nodeList->getDTLSSocket(), &QUdpSocket::readyRead, this, &DomainServer::readAvailableDTLSDatagrams);
|
connect(&nodeList->getDTLSSocket(), &QUdpSocket::readyRead, this, &DomainServer::readAvailableDTLSDatagrams);
|
||||||
}
|
}
|
||||||
|
@ -311,8 +299,7 @@ const NodeSet STATICALLY_ASSIGNED_NODES = NodeSet() << NodeType::AudioMixer
|
||||||
<< NodeType::MetavoxelServer;
|
<< NodeType::MetavoxelServer;
|
||||||
|
|
||||||
|
|
||||||
void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr,
|
void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr) {
|
||||||
const QJsonObject& authJsonObject) {
|
|
||||||
|
|
||||||
NodeType_t nodeType;
|
NodeType_t nodeType;
|
||||||
HifiSockAddr publicSockAddr, localSockAddr;
|
HifiSockAddr publicSockAddr, localSockAddr;
|
||||||
|
@ -336,7 +323,8 @@ void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packe
|
||||||
// create a new session UUID for this node
|
// create a new session UUID for this node
|
||||||
QUuid nodeUUID = QUuid::createUuid();
|
QUuid nodeUUID = QUuid::createUuid();
|
||||||
|
|
||||||
SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType, publicSockAddr, localSockAddr);
|
SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType,
|
||||||
|
publicSockAddr, localSockAddr);
|
||||||
|
|
||||||
// when the newNode is created the linked data is also created
|
// when the newNode is created the linked data is also created
|
||||||
// if this was a static assignment set the UUID, set the sendingSockAddr
|
// if this was a static assignment set the UUID, set the sendingSockAddr
|
||||||
|
@ -345,12 +333,6 @@ void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packe
|
||||||
nodeData->setStaticAssignmentUUID(assignmentUUID);
|
nodeData->setStaticAssignmentUUID(assignmentUUID);
|
||||||
nodeData->setSendingSockAddr(senderSockAddr);
|
nodeData->setSendingSockAddr(senderSockAddr);
|
||||||
|
|
||||||
if (!authJsonObject.isEmpty()) {
|
|
||||||
// pull the connection secret from the authJsonObject and set it as the connection secret for this node
|
|
||||||
QUuid connectionSecret(authJsonObject["data"].toObject()["connection_secret"].toString());
|
|
||||||
newNode->setConnectionSecret(connectionSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reply back to the user with a PacketTypeDomainList
|
// reply back to the user with a PacketTypeDomainList
|
||||||
sendDomainListToNode(newNode, senderSockAddr, nodeInterestListFromPacket(packet, numPreInterestBytes));
|
sendDomainListToNode(newNode, senderSockAddr, nodeInterestListFromPacket(packet, numPreInterestBytes));
|
||||||
}
|
}
|
||||||
|
@ -361,18 +343,6 @@ int DomainServer::parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr&
|
||||||
QDataStream packetStream(packet);
|
QDataStream packetStream(packet);
|
||||||
packetStream.skipRawData(numBytesForPacketHeader(packet));
|
packetStream.skipRawData(numBytesForPacketHeader(packet));
|
||||||
|
|
||||||
if (packetTypeForPacket(packet) == PacketTypeDomainConnectRequest) {
|
|
||||||
// we need to skip a quint8 that indicates if there is a registration token
|
|
||||||
// and potentially the registration token itself
|
|
||||||
quint8 hasRegistrationToken;
|
|
||||||
packetStream >> hasRegistrationToken;
|
|
||||||
|
|
||||||
if (hasRegistrationToken) {
|
|
||||||
QByteArray registrationToken;
|
|
||||||
packetStream >> registrationToken;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
packetStream >> nodeType;
|
packetStream >> nodeType;
|
||||||
packetStream >> publicSockAddr >> localSockAddr;
|
packetStream >> publicSockAddr >> localSockAddr;
|
||||||
|
|
||||||
|
@ -648,7 +618,11 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS
|
||||||
if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
|
if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
|
||||||
PacketType requestType = packetTypeForPacket(receivedPacket);
|
PacketType requestType = packetTypeForPacket(receivedPacket);
|
||||||
|
|
||||||
if (requestType == PacketTypeDomainListRequest) {
|
if (requestType == PacketTypeDomainConnectRequest) {
|
||||||
|
// add this node to our NodeList
|
||||||
|
// and send back session UUID right away
|
||||||
|
addNodeToNodeListAndConfirmConnection(receivedPacket, senderSockAddr);
|
||||||
|
} else if (requestType == PacketTypeDomainListRequest) {
|
||||||
QUuid nodeUUID = uuidFromPacketHeader(receivedPacket);
|
QUuid nodeUUID = uuidFromPacketHeader(receivedPacket);
|
||||||
|
|
||||||
if (!nodeUUID.isNull() && nodeList->nodeWithUUID(nodeUUID)) {
|
if (!nodeUUID.isNull() && nodeList->nodeWithUUID(nodeUUID)) {
|
||||||
|
@ -665,12 +639,7 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS
|
||||||
checkInNode->setLastHeardMicrostamp(timeNow);
|
checkInNode->setLastHeardMicrostamp(timeNow);
|
||||||
|
|
||||||
sendDomainListToNode(checkInNode, senderSockAddr, nodeInterestListFromPacket(receivedPacket, numNodeInfoBytes));
|
sendDomainListToNode(checkInNode, senderSockAddr, nodeInterestListFromPacket(receivedPacket, numNodeInfoBytes));
|
||||||
} else {
|
|
||||||
// new node - add this node to our NodeList
|
|
||||||
// and send back session UUID right away
|
|
||||||
addNodeToNodeListAndConfirmConnection(receivedPacket, senderSockAddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (requestType == PacketTypeNodeJsonStats) {
|
} else if (requestType == PacketTypeNodeJsonStats) {
|
||||||
SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket);
|
SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket);
|
||||||
if (matchingNode) {
|
if (matchingNode) {
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include <Assignment.h>
|
#include <Assignment.h>
|
||||||
#include <HTTPManager.h>
|
#include <HTTPManager.h>
|
||||||
#include <NodeList.h>
|
#include <LimitedNodeList.h>
|
||||||
|
|
||||||
#include "DTLSServerSession.h"
|
#include "DTLSServerSession.h"
|
||||||
|
|
||||||
|
@ -57,8 +57,7 @@ private:
|
||||||
|
|
||||||
void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr);
|
void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr);
|
||||||
|
|
||||||
void addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr,
|
void addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr);
|
||||||
const QJsonObject& authJsonObject = QJsonObject());
|
|
||||||
int parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& publicSockAddr,
|
int parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& publicSockAddr,
|
||||||
HifiSockAddr& localSockAddr, const QByteArray& packet, const HifiSockAddr& senderSockAddr);
|
HifiSockAddr& localSockAddr, const QByteArray& packet, const HifiSockAddr& senderSockAddr);
|
||||||
NodeSet nodeInterestListFromPacket(const QByteArray& packet, int numPreceedingBytes);
|
NodeSet nodeInterestListFromPacket(const QByteArray& packet, int numPreceedingBytes);
|
||||||
|
|
|
@ -105,7 +105,21 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() {
|
||||||
_dtlsSocket = new QUdpSocket(this);
|
_dtlsSocket = new QUdpSocket(this);
|
||||||
|
|
||||||
_dtlsSocket->bind(QHostAddress::AnyIPv4, 0, QAbstractSocket::DontShareAddress);
|
_dtlsSocket->bind(QHostAddress::AnyIPv4, 0, QAbstractSocket::DontShareAddress);
|
||||||
qDebug() << "NodeList DTLS socket is listening on" << _dtlsSocket->localPort();
|
|
||||||
|
#if defined(IP_DONTFRAG) || defined(IP_MTU_DISCOVER)
|
||||||
|
qDebug() << "Making required DTLS changes to LimitedNodeList DTLS socket.";
|
||||||
|
|
||||||
|
int socketHandle = _dtlsSocket->socketDescriptor();
|
||||||
|
#if defined(IP_DONTFRAG)
|
||||||
|
int optValue = 1;
|
||||||
|
setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, reinterpret_cast<const void*>(&optValue), sizeof(optValue));
|
||||||
|
#elif defined(IP_MTU_DISCOVER)
|
||||||
|
int optValue = 1;
|
||||||
|
setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, reinterpret_cast<const void*>(&optValue), sizeof(optValue));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
qDebug() << "LimitedNodeList DTLS socket is listening on" << _dtlsSocket->localPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *_dtlsSocket;
|
return *_dtlsSocket;
|
||||||
|
@ -331,7 +345,7 @@ void LimitedNodeList::processKillNode(const QByteArray& dataByteArray) {
|
||||||
killNodeWithUUID(nodeUUID);
|
killNodeWithUUID(nodeUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, char nodeType,
|
SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
|
||||||
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) {
|
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) {
|
||||||
_nodeHashMutex.lock();
|
_nodeHashMutex.lock();
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
SharedNodePointer nodeWithUUID(const QUuid& nodeUUID, bool blockingLock = true);
|
SharedNodePointer nodeWithUUID(const QUuid& nodeUUID, bool blockingLock = true);
|
||||||
SharedNodePointer sendingNodeForPacket(const QByteArray& packet);
|
SharedNodePointer sendingNodeForPacket(const QByteArray& packet);
|
||||||
|
|
||||||
SharedNodePointer addOrUpdateNode(const QUuid& uuid, char nodeType,
|
SharedNodePointer addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
|
||||||
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
||||||
SharedNodePointer updateSocketsForNode(const QUuid& uuid,
|
SharedNodePointer updateSocketsForNode(const QUuid& uuid,
|
||||||
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
||||||
|
|
|
@ -42,7 +42,7 @@ const QString& NodeType::getNodeTypeName(NodeType_t nodeType) {
|
||||||
return matchedTypeName != TypeNameHash.end() ? matchedTypeName.value() : UNKNOWN_NodeType_t_NAME;
|
return matchedTypeName != TypeNameHash.end() ? matchedTypeName.value() : UNKNOWN_NodeType_t_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) :
|
Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) :
|
||||||
_type(type),
|
_type(type),
|
||||||
_uuid(uuid),
|
_uuid(uuid),
|
||||||
_wakeTimestamp(QDateTime::currentMSecsSinceEpoch()),
|
_wakeTimestamp(QDateTime::currentMSecsSinceEpoch()),
|
||||||
|
@ -58,6 +58,7 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const
|
||||||
_clockSkewUsec(0),
|
_clockSkewUsec(0),
|
||||||
_mutex()
|
_mutex()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::~Node() {
|
Node::~Node() {
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace NodeType {
|
||||||
class Node : public QObject {
|
class Node : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
||||||
~Node();
|
~Node();
|
||||||
|
|
||||||
bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; }
|
bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; }
|
||||||
|
|
|
@ -209,8 +209,10 @@ void NodeList::reset() {
|
||||||
// clear the domain connection information
|
// clear the domain connection information
|
||||||
_domainHandler.clearConnectionInfo();
|
_domainHandler.clearConnectionInfo();
|
||||||
|
|
||||||
// also disconnect from the DTLS socket readyRead() so it can handle handshaking
|
// if we setup the DTLS socket, also disconnect from the DTLS socket readyRead() so it can handle handshaking
|
||||||
disconnect(_dtlsSocket, 0, this, 0);
|
if (_dtlsSocket) {
|
||||||
|
disconnect(_dtlsSocket, 0, this, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd) {
|
void NodeList::addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd) {
|
||||||
|
@ -376,10 +378,14 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct the DS check in packet
|
PacketType domainPacketType = _sessionUUID.isNull()
|
||||||
QUuid packetUUID = (!_sessionUUID.isNull() ? _sessionUUID : _domainHandler.getAssignmentUUID());
|
? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest;
|
||||||
|
|
||||||
QByteArray domainServerPacket = byteArrayWithPopulatedHeader(PacketTypeDomainListRequest, packetUUID);
|
// construct the DS check in packet
|
||||||
|
QUuid packetUUID = (domainPacketType == PacketTypeDomainListRequest
|
||||||
|
? _sessionUUID : _domainHandler.getAssignmentUUID());
|
||||||
|
|
||||||
|
QByteArray domainServerPacket = byteArrayWithPopulatedHeader(domainPacketType, packetUUID);
|
||||||
QDataStream packetStream(&domainServerPacket, QIODevice::Append);
|
QDataStream packetStream(&domainServerPacket, QIODevice::Append);
|
||||||
|
|
||||||
// pack our data to send to the domain-server
|
// pack our data to send to the domain-server
|
||||||
|
|
|
@ -58,7 +58,7 @@ enum PacketType {
|
||||||
PacketTypeMetavoxelData,
|
PacketTypeMetavoxelData,
|
||||||
PacketTypeAvatarIdentity,
|
PacketTypeAvatarIdentity,
|
||||||
PacketTypeAvatarBillboard,
|
PacketTypeAvatarBillboard,
|
||||||
PacketTypeDomainConnectRequest, // reusable
|
PacketTypeDomainConnectRequest,
|
||||||
PacketTypeDomainServerRequireDTLS,
|
PacketTypeDomainServerRequireDTLS,
|
||||||
PacketTypeNodeJsonStats,
|
PacketTypeNodeJsonStats,
|
||||||
};
|
};
|
||||||
|
@ -66,7 +66,8 @@ enum PacketType {
|
||||||
typedef char PacketVersion;
|
typedef char PacketVersion;
|
||||||
|
|
||||||
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
|
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
|
||||||
<< PacketTypeDomainServerRequireDTLS << PacketTypeDomainList << PacketTypeDomainListRequest
|
<< PacketTypeDomainServerRequireDTLS << PacketTypeDomainConnectRequest
|
||||||
|
<< PacketTypeDomainList << PacketTypeDomainListRequest
|
||||||
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse
|
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse
|
||||||
<< PacketTypeNodeJsonStats;
|
<< PacketTypeNodeJsonStats;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue