mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 17:17:58 +02:00
attempt to complete handshake every 100ms instead of every 1s
This commit is contained in:
parent
62de84315e
commit
1c4d44ba4a
3 changed files with 51 additions and 19 deletions
|
@ -13,12 +13,14 @@
|
||||||
|
|
||||||
#include "DomainHandler.h"
|
#include "DomainHandler.h"
|
||||||
|
|
||||||
DomainHandler::DomainHandler() :
|
DomainHandler::DomainHandler(QObject* parent) :
|
||||||
|
QObject(parent),
|
||||||
_uuid(),
|
_uuid(),
|
||||||
_sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
|
_sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
|
||||||
_assignmentUUID(),
|
_assignmentUUID(),
|
||||||
_isConnected(false),
|
_isConnected(false),
|
||||||
_dtlsSession(NULL)
|
_dtlsSession(NULL),
|
||||||
|
_handshakeTimer(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +35,12 @@ void DomainHandler::clearConnectionInfo() {
|
||||||
|
|
||||||
delete _dtlsSession;
|
delete _dtlsSession;
|
||||||
_dtlsSession = NULL;
|
_dtlsSession = NULL;
|
||||||
|
|
||||||
|
if (_handshakeTimer) {
|
||||||
|
_handshakeTimer->stop();
|
||||||
|
delete _handshakeTimer;
|
||||||
|
_handshakeTimer = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainHandler::reset() {
|
void DomainHandler::reset() {
|
||||||
|
@ -44,9 +52,21 @@ void DomainHandler::reset() {
|
||||||
_dtlsSession = NULL;
|
_dtlsSession = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unsigned int DTLS_HANDSHAKE_INTERVAL_MSECS = 100;
|
||||||
|
|
||||||
void DomainHandler::initializeDTLSSession() {
|
void DomainHandler::initializeDTLSSession() {
|
||||||
if (!_dtlsSession) {
|
if (!_dtlsSession) {
|
||||||
_dtlsSession = new DTLSClientSession(NodeList::getInstance()->getDTLSSocket(), _sockAddr);
|
_dtlsSession = new DTLSClientSession(NodeList::getInstance()->getDTLSSocket(), _sockAddr);
|
||||||
|
|
||||||
|
// start a timer to complete the handshake process
|
||||||
|
_handshakeTimer = new QTimer(this);
|
||||||
|
connect(_handshakeTimer, &QTimer::timeout, this, &DomainHandler::completeDTLSHandshake);
|
||||||
|
|
||||||
|
// start the handshake right now
|
||||||
|
completeDTLSHandshake();
|
||||||
|
|
||||||
|
// start the timer to finish off the handshake
|
||||||
|
_handshakeTimer->start(DTLS_HANDSHAKE_INTERVAL_MSECS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +112,28 @@ void DomainHandler::setHostname(const QString& hostname) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomainHandler::completeDTLSHandshake() {
|
||||||
|
int handshakeReturn = gnutls_handshake(*_dtlsSession->getGnuTLSSession());
|
||||||
|
|
||||||
|
qDebug() << "handshake return is" << handshakeReturn;
|
||||||
|
|
||||||
|
if (handshakeReturn == 0) {
|
||||||
|
// we've shaken hands, so we're good to go now
|
||||||
|
_dtlsSession->setCompletedHandshake(true);
|
||||||
|
|
||||||
|
_handshakeTimer->stop();
|
||||||
|
delete _handshakeTimer;
|
||||||
|
_handshakeTimer = NULL;
|
||||||
|
|
||||||
|
} else if (gnutls_error_is_fatal(handshakeReturn)) {
|
||||||
|
// this was a fatal error handshaking, so remove this session
|
||||||
|
qDebug() << "Fatal error -" << gnutls_strerror(handshakeReturn)
|
||||||
|
<< "- during DTLS handshake with DS at" << getHostname();
|
||||||
|
|
||||||
|
clearConnectionInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DomainHandler::completedHostnameLookup(const QHostInfo& hostInfo) {
|
void DomainHandler::completedHostnameLookup(const QHostInfo& hostInfo) {
|
||||||
for (int i = 0; i < hostInfo.addresses().size(); i++) {
|
for (int i = 0; i < hostInfo.addresses().size(); i++) {
|
||||||
if (hostInfo.addresses()[i].protocol() == QAbstractSocket::IPv4Protocol) {
|
if (hostInfo.addresses()[i].protocol() == QAbstractSocket::IPv4Protocol) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define __hifi__DomainHandler__
|
#define __hifi__DomainHandler__
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtNetwork/QHostInfo>
|
#include <QtNetwork/QHostInfo>
|
||||||
|
@ -24,7 +25,7 @@ const unsigned short DEFAULT_DOMAIN_SERVER_DTLS_PORT = 40103;
|
||||||
class DomainHandler : public QObject {
|
class DomainHandler : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DomainHandler();
|
DomainHandler(QObject* parent = 0);
|
||||||
~DomainHandler();
|
~DomainHandler();
|
||||||
|
|
||||||
void clearConnectionInfo();
|
void clearConnectionInfo();
|
||||||
|
@ -54,6 +55,7 @@ public:
|
||||||
void parseDTLSRequirementPacket(const QByteArray& dtlsRequirementPacket);
|
void parseDTLSRequirementPacket(const QByteArray& dtlsRequirementPacket);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void completeDTLSHandshake();
|
||||||
void completedHostnameLookup(const QHostInfo& hostInfo);
|
void completedHostnameLookup(const QHostInfo& hostInfo);
|
||||||
signals:
|
signals:
|
||||||
void hostnameChanged(const QString& hostname);
|
void hostnameChanged(const QString& hostname);
|
||||||
|
@ -69,6 +71,7 @@ private:
|
||||||
QUuid _assignmentUUID;
|
QUuid _assignmentUUID;
|
||||||
bool _isConnected;
|
bool _isConnected;
|
||||||
DTLSClientSession* _dtlsSession;
|
DTLSClientSession* _dtlsSession;
|
||||||
|
QTimer* _handshakeTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__DomainHandler__) */
|
#endif /* defined(__hifi__DomainHandler__) */
|
||||||
|
|
|
@ -53,6 +53,7 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned
|
||||||
LimitedNodeList(socketListenPort, dtlsListenPort),
|
LimitedNodeList(socketListenPort, dtlsListenPort),
|
||||||
_ownerType(newOwnerType),
|
_ownerType(newOwnerType),
|
||||||
_nodeTypesOfInterest(),
|
_nodeTypesOfInterest(),
|
||||||
|
_domainHandler(this),
|
||||||
_numNoReplyDomainCheckIns(0),
|
_numNoReplyDomainCheckIns(0),
|
||||||
_assignmentServerSocket(),
|
_assignmentServerSocket(),
|
||||||
_publicSockAddr(),
|
_publicSockAddr(),
|
||||||
|
@ -323,22 +324,8 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
|
|
||||||
DTLSClientSession* dtlsSession = _domainHandler.getDTLSSession();
|
DTLSClientSession* dtlsSession = _domainHandler.getDTLSSession();
|
||||||
|
|
||||||
if (dtlsSession) {
|
if (dtlsSession && dtlsSession->completedHandshake()) {
|
||||||
if (dtlsSession->completedHandshake()) {
|
qDebug() << "we can send a DTLS check in!";
|
||||||
qDebug() << "we can send a DTLS check in!";
|
|
||||||
} else {
|
|
||||||
int handshakeReturn = gnutls_handshake(*dtlsSession->getGnuTLSSession());
|
|
||||||
if (handshakeReturn == 0) {
|
|
||||||
dtlsSession->setCompletedHandshake(true);
|
|
||||||
} else if (gnutls_error_is_fatal(handshakeReturn)) {
|
|
||||||
// this was a fatal error handshaking, so remove this session
|
|
||||||
qDebug() << "Fatal error -" << gnutls_strerror(handshakeReturn)
|
|
||||||
<< "- during DTLS handshake with DS at" << _domainHandler.getHostname();
|
|
||||||
|
|
||||||
_domainHandler.clearConnectionInfo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// construct the DS check in packet
|
// construct the DS check in packet
|
||||||
QUuid packetUUID = (!_sessionUUID.isNull() ? _sessionUUID : _domainHandler.getAssignmentUUID());
|
QUuid packetUUID = (!_sessionUUID.isNull() ? _sessionUUID : _domainHandler.getAssignmentUUID());
|
||||||
|
|
Loading…
Reference in a new issue