mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 03:13:09 +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
|
@ -9,7 +9,10 @@
|
||||||
#include "DomainInfo.h"
|
#include "DomainInfo.h"
|
||||||
|
|
||||||
DomainInfo::DomainInfo() :
|
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(),
|
qDebug("DS at %s is at %s", _hostname.toLocal8Bit().constData(),
|
||||||
_sockAddr.getAddress().toString().toLocal8Bit().constData());
|
_sockAddr.getAddress().toString().toLocal8Bit().constData());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we got here then we failed to lookup the address
|
// if we got here then we failed to lookup the address
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define __hifi__DomainInfo__
|
#define __hifi__DomainInfo__
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QUuid>
|
||||||
#include <QtNetwork/QHostInfo>
|
#include <QtNetwork/QHostInfo>
|
||||||
|
|
||||||
#include "HifiSockAddr.h"
|
#include "HifiSockAddr.h"
|
||||||
|
@ -32,6 +33,15 @@ public:
|
||||||
void setSockAddr(const HifiSockAddr& sockAddr) { _sockAddr = sockAddr; }
|
void setSockAddr(const HifiSockAddr& sockAddr) { _sockAddr = sockAddr; }
|
||||||
|
|
||||||
unsigned short getPort() const { return _sockAddr.getPort(); }
|
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:
|
private slots:
|
||||||
void completedHostnameLookup(const QHostInfo& hostInfo);
|
void completedHostnameLookup(const QHostInfo& hostInfo);
|
||||||
signals:
|
signals:
|
||||||
|
@ -39,6 +49,9 @@ signals:
|
||||||
private:
|
private:
|
||||||
QString _hostname;
|
QString _hostname;
|
||||||
HifiSockAddr _sockAddr;
|
HifiSockAddr _sockAddr;
|
||||||
|
bool _requiresAuthentication;
|
||||||
|
QUuid _connectionSecret;
|
||||||
|
QString _registrationToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__DomainInfo__) */
|
#endif /* defined(__hifi__DomainInfo__) */
|
||||||
|
|
|
@ -113,6 +113,17 @@ bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
|
||||||
return false;
|
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,
|
qint64 NodeList::writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode,
|
||||||
const HifiSockAddr& overridenSockAddr) {
|
const HifiSockAddr& overridenSockAddr) {
|
||||||
if (destinationNode) {
|
if (destinationNode) {
|
||||||
|
@ -128,11 +139,7 @@ qint64 NodeList::writeDatagram(const QByteArray& datagram, const SharedNodePoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray datagramCopy = datagram;
|
writeDatagram(datagram, *destinationSockAddr, destinationNode->getConnectionSecret());
|
||||||
// setup the MD5 hash for source verification in the header
|
|
||||||
replaceHashInPacketGivenConnectionUUID(datagramCopy, destinationNode->getConnectionSecret());
|
|
||||||
|
|
||||||
return _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr->getAddress(), destinationSockAddr->getPort());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// didn't have a destinationNode to send to, return 0
|
// 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
|
// 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
|
// send a STUN request to figure it out
|
||||||
sendSTUNRequest();
|
sendSTUNRequest();
|
||||||
} else if (!_domainInfo.getIP().isNull()) {
|
} else if (!_domainInfo.getIP().isNull()
|
||||||
// construct the DS check in packet if we can
|
&& (!_domainInfo.requiresAuthentication()
|
||||||
|
|| !_sessionUUID.isNull()
|
||||||
// check in packet has header, optional UUID, node type, port, IP, node types of interest, null termination
|
|| !_domainInfo.getRegistrationToken().isEmpty()) ) {
|
||||||
QByteArray domainServerPacket = byteArrayWithPopluatedHeader(PacketTypeDomainListRequest);
|
// construct the DS check in packet
|
||||||
|
|
||||||
|
PacketType domainPacketType = _domainInfo.getRegistrationToken().isEmpty()
|
||||||
|
? PacketTypeDomainListRequest
|
||||||
|
: PacketTypeDomainConnectRequest;
|
||||||
|
|
||||||
|
QByteArray domainServerPacket = byteArrayWithPopluatedHeader(domainPacketType);
|
||||||
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
|
||||||
packetStream << _ownerType << _publicSockAddr
|
packetStream << _ownerType << _publicSockAddr
|
||||||
<< HifiSockAddr(QHostAddress(getHostOrderLocalAddress()), _nodeSocket.localPort())
|
<< HifiSockAddr(QHostAddress(getHostOrderLocalAddress()), _nodeSocket.localPort())
|
||||||
|
@ -477,7 +490,7 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
packetStream << nodeTypeOfInterest;
|
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;
|
const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5;
|
||||||
static unsigned int numDomainCheckins = 0;
|
static unsigned int numDomainCheckins = 0;
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,9 @@ private:
|
||||||
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
void sendSTUNRequest();
|
void sendSTUNRequest();
|
||||||
void processSTUNResponse(const QByteArray& packet);
|
void processSTUNResponse(const QByteArray& packet);
|
||||||
|
|
||||||
|
qint64 NodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr,
|
||||||
|
const QUuid& connectionSecret);
|
||||||
|
|
||||||
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
|
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue