mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 12:33:37 +02:00
more tweaks to domain check-ins to prepare for auth
This commit is contained in:
parent
37f1f7ba4f
commit
4c135dd3a7
4 changed files with 46 additions and 16 deletions
libraries/shared/src
|
@ -9,7 +9,10 @@
|
|||
#include "DomainInfo.h"
|
||||
|
||||
DomainInfo::DomainInfo() :
|
||||
_sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT))
|
||||
_sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
|
||||
_requiresAuthentication(false),
|
||||
_connectionSecret(),
|
||||
_registrationToken()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -52,9 +55,7 @@ void DomainInfo::completedHostnameLookup(const QHostInfo& hostInfo) {
|
|||
qDebug("DS at %s is at %s", _hostname.toLocal8Bit().constData(),
|
||||
_sockAddr.getAddress().toString().toLocal8Bit().constData());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// if we got here then we failed to lookup the address
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define __hifi__DomainInfo__
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QUuid>
|
||||
#include <QtNetwork/QHostInfo>
|
||||
|
||||
#include "HifiSockAddr.h"
|
||||
|
@ -32,6 +33,15 @@ public:
|
|||
void setSockAddr(const HifiSockAddr& sockAddr) { _sockAddr = sockAddr; }
|
||||
|
||||
unsigned short getPort() const { return _sockAddr.getPort(); }
|
||||
|
||||
bool requiresAuthentication() const { return _requiresAuthentication; }
|
||||
void setRequiresAuthentication(bool requiresAuthentication) { _requiresAuthentication = requiresAuthentication; }
|
||||
|
||||
const QUuid& getConnectionSecret() const { return _connectionSecret; }
|
||||
void setConnectionSecret(const QUuid& connectionSecret) { _connectionSecret = connectionSecret; }
|
||||
|
||||
const QString& getRegistrationToken() const { return _registrationToken; }
|
||||
void setRegistrationToken(const QString& registrationToken);
|
||||
private slots:
|
||||
void completedHostnameLookup(const QHostInfo& hostInfo);
|
||||
signals:
|
||||
|
@ -39,6 +49,9 @@ signals:
|
|||
private:
|
||||
QString _hostname;
|
||||
HifiSockAddr _sockAddr;
|
||||
bool _requiresAuthentication;
|
||||
QUuid _connectionSecret;
|
||||
QString _registrationToken;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__DomainInfo__) */
|
||||
|
|
|
@ -113,6 +113,17 @@ bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
|
|||
return false;
|
||||
}
|
||||
|
||||
qint64 NodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr,
|
||||
const QUuid& connectionSecret) {
|
||||
QByteArray datagramCopy = datagram;
|
||||
|
||||
// setup the MD5 hash for source verification in the header
|
||||
replaceHashInPacketGivenConnectionUUID(datagramCopy, connectionSecret);
|
||||
|
||||
return _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr.getAddress(), destinationSockAddr.getPort());
|
||||
|
||||
}
|
||||
|
||||
qint64 NodeList::writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode,
|
||||
const HifiSockAddr& overridenSockAddr) {
|
||||
if (destinationNode) {
|
||||
|
@ -128,11 +139,7 @@ qint64 NodeList::writeDatagram(const QByteArray& datagram, const SharedNodePoint
|
|||
}
|
||||
}
|
||||
|
||||
QByteArray datagramCopy = datagram;
|
||||
// setup the MD5 hash for source verification in the header
|
||||
replaceHashInPacketGivenConnectionUUID(datagramCopy, destinationNode->getConnectionSecret());
|
||||
|
||||
return _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr->getAddress(), destinationSockAddr->getPort());
|
||||
writeDatagram(datagram, *destinationSockAddr, destinationNode->getConnectionSecret());
|
||||
}
|
||||
|
||||
// didn't have a destinationNode to send to, return 0
|
||||
|
@ -460,13 +467,19 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
// we don't know our public socket and we need to send it to the domain server
|
||||
// send a STUN request to figure it out
|
||||
sendSTUNRequest();
|
||||
} else if (!_domainInfo.getIP().isNull()) {
|
||||
// construct the DS check in packet if we can
|
||||
|
||||
// check in packet has header, optional UUID, node type, port, IP, node types of interest, null termination
|
||||
QByteArray domainServerPacket = byteArrayWithPopluatedHeader(PacketTypeDomainListRequest);
|
||||
} else if (!_domainInfo.getIP().isNull()
|
||||
&& (!_domainInfo.requiresAuthentication()
|
||||
|| !_sessionUUID.isNull()
|
||||
|| !_domainInfo.getRegistrationToken().isEmpty()) ) {
|
||||
// construct the DS check in packet
|
||||
|
||||
PacketType domainPacketType = _domainInfo.getRegistrationToken().isEmpty()
|
||||
? PacketTypeDomainListRequest
|
||||
: PacketTypeDomainConnectRequest;
|
||||
|
||||
QByteArray domainServerPacket = byteArrayWithPopluatedHeader(domainPacketType);
|
||||
QDataStream packetStream(&domainServerPacket, QIODevice::Append);
|
||||
|
||||
|
||||
// pack our data to send to the domain-server
|
||||
packetStream << _ownerType << _publicSockAddr
|
||||
<< HifiSockAddr(QHostAddress(getHostOrderLocalAddress()), _nodeSocket.localPort())
|
||||
|
@ -477,7 +490,7 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
packetStream << nodeTypeOfInterest;
|
||||
}
|
||||
|
||||
_nodeSocket.writeDatagram(domainServerPacket, _domainInfo.getIP(), _domainInfo.getPort());
|
||||
writeDatagram(domainServerPacket, _domainInfo.getSockAddr(), _domainInfo.getConnectionSecret());
|
||||
const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5;
|
||||
static unsigned int numDomainCheckins = 0;
|
||||
|
||||
|
|
|
@ -139,6 +139,9 @@ private:
|
|||
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||
void sendSTUNRequest();
|
||||
void processSTUNResponse(const QByteArray& packet);
|
||||
|
||||
qint64 NodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr,
|
||||
const QUuid& connectionSecret);
|
||||
|
||||
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
|
||||
|
||||
|
|
Loading…
Reference in a new issue