mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 10:47:53 +02:00
trigger domain API refresh from DomainHandler
This commit is contained in:
parent
e39c708bf6
commit
c5a4a72a84
4 changed files with 32 additions and 24 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <QtCore/QJsonDocument>
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
#include "AddressManager.h"
|
||||
#include "Assignment.h"
|
||||
#include "HifiSockAddr.h"
|
||||
#include "NodeList.h"
|
||||
|
@ -30,7 +31,8 @@ DomainHandler::DomainHandler(QObject* parent) :
|
|||
QObject(parent),
|
||||
_sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
|
||||
_icePeer(this),
|
||||
_settingsTimer(this)
|
||||
_settingsTimer(this),
|
||||
_apiRefreshTimer(this)
|
||||
{
|
||||
_sockAddr.setObjectName("DomainServer");
|
||||
|
||||
|
@ -41,6 +43,16 @@ DomainHandler::DomainHandler(QObject* parent) :
|
|||
static const int DOMAIN_SETTINGS_TIMEOUT_MS = 5000;
|
||||
_settingsTimer.setInterval(DOMAIN_SETTINGS_TIMEOUT_MS);
|
||||
connect(&_settingsTimer, &QTimer::timeout, this, &DomainHandler::settingsReceiveFail);
|
||||
|
||||
// setup the API refresh timer for auto connection information refresh from API when failing to connect
|
||||
const int API_REFRESH_TIMEOUT_MSEC = 2500;
|
||||
_apiRefreshTimer.setInterval(API_REFRESH_TIMEOUT_MSEC);
|
||||
|
||||
auto addressManager = DependencyManager::get<AddressManager>();
|
||||
connect(&_apiRefreshTimer, &QTimer::timeout, addressManager.data(), &AddressManager::refreshPreviousLookup);
|
||||
|
||||
// stop the refresh timer if we connect to a domain
|
||||
connect(this, &DomainHandler::connectedToDomain, &_apiRefreshTimer, &QTimer::stop);
|
||||
}
|
||||
|
||||
void DomainHandler::disconnect() {
|
||||
|
@ -90,6 +102,9 @@ void DomainHandler::softReset() {
|
|||
|
||||
// cancel the failure timeout for any pending requests for settings
|
||||
QMetaObject::invokeMethod(&_settingsTimer, "stop");
|
||||
|
||||
// restart the API refresh timer in case we fail to connect and need to refresh information
|
||||
QMetaObject::invokeMethod(&_apiRefreshTimer, "start");
|
||||
}
|
||||
|
||||
void DomainHandler::hardReset() {
|
||||
|
@ -134,6 +149,8 @@ void DomainHandler::setUUID(const QUuid& uuid) {
|
|||
|
||||
void DomainHandler::setSocketAndID(const QString& hostname, quint16 port, const QUuid& domainID) {
|
||||
|
||||
_pendingDomainID = domainID;
|
||||
|
||||
if (hostname != _hostname || _sockAddr.getPort() != port) {
|
||||
// re-set the domain info so that auth information is reloaded
|
||||
hardReset();
|
||||
|
@ -161,8 +178,6 @@ void DomainHandler::setSocketAndID(const QString& hostname, quint16 port, const
|
|||
// grab the port by reading the string after the colon
|
||||
_sockAddr.setPort(port);
|
||||
}
|
||||
|
||||
_pendingDomainID = domainID;
|
||||
}
|
||||
|
||||
void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id) {
|
||||
|
@ -248,6 +263,7 @@ void DomainHandler::setIsConnected(bool isConnected) {
|
|||
|
||||
// we've connected to new domain - time to ask it for global settings
|
||||
requestDomainSettings();
|
||||
|
||||
} else {
|
||||
emit disconnectedFromDomain();
|
||||
}
|
||||
|
@ -298,6 +314,9 @@ void DomainHandler::processICEPingReplyPacket(QSharedPointer<ReceivedMessage> me
|
|||
qCDebug(networking) << "Received reply from domain-server on" << senderSockAddr;
|
||||
|
||||
if (getIP().isNull()) {
|
||||
// we're hearing back from this domain-server, no need to refresh API information
|
||||
_apiRefreshTimer.stop();
|
||||
|
||||
// for now we're unsafely assuming this came back from the domain
|
||||
if (senderSockAddr == _icePeer.getLocalSocket()) {
|
||||
qCDebug(networking) << "Connecting to domain using local socket";
|
||||
|
@ -326,10 +345,13 @@ void DomainHandler::processDTLSRequirementPacket(QSharedPointer<ReceivedMessage>
|
|||
void DomainHandler::processICEResponsePacket(QSharedPointer<ReceivedMessage> message) {
|
||||
if (_icePeer.hasSockets()) {
|
||||
qDebug() << "Received an ICE peer packet for domain-server but we already have sockets. Not processing.";
|
||||
// bail on processing this packet if our ice peer doesn't have sockets
|
||||
// bail on processing this packet if our ice peer already has sockets
|
||||
return;
|
||||
}
|
||||
|
||||
// start or restart the API refresh timer now that we have new information
|
||||
_apiRefreshTimer.start();
|
||||
|
||||
QDataStream iceResponseStream(message->getMessage());
|
||||
|
||||
iceResponseStream >> _icePeer;
|
||||
|
@ -366,6 +388,9 @@ bool DomainHandler::reasonSuggestsLogin(ConnectionRefusedReason reasonCode) {
|
|||
}
|
||||
|
||||
void DomainHandler::processDomainServerConnectionDeniedPacket(QSharedPointer<ReceivedMessage> message) {
|
||||
// we're hearing from this domain-server, don't need to refresh API info
|
||||
_apiRefreshTimer.stop();
|
||||
|
||||
// Read deny reason from packet
|
||||
uint8_t reasonCodeWire;
|
||||
|
||||
|
|
|
@ -72,8 +72,6 @@ public:
|
|||
bool isConnected() const { return _isConnected; }
|
||||
void setIsConnected(bool isConnected);
|
||||
|
||||
bool wasConnectionRefused() const { return !_domainConnectionRefusals.isEmpty(); }
|
||||
|
||||
bool hasSettings() const { return !_settingsObject.isEmpty(); }
|
||||
void requestDomainSettings();
|
||||
const QJsonObject& getSettingsObject() const { return _settingsObject; }
|
||||
|
@ -149,6 +147,8 @@ private:
|
|||
QStringList _domainConnectionRefusals;
|
||||
bool _hasCheckedForAccessToken { false };
|
||||
int _connectionDenialsSinceKeypairRegen { 0 };
|
||||
|
||||
QTimer _apiRefreshTimer;
|
||||
};
|
||||
|
||||
#endif // hifi_DomainHandler_h
|
||||
|
|
|
@ -355,24 +355,6 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
// increment the count of un-replied check-ins
|
||||
_numNoReplyDomainCheckIns++;
|
||||
}
|
||||
|
||||
static int numTriggersSinceAPIRefresh = 0;
|
||||
|
||||
if (!_publicSockAddr.isNull()
|
||||
&& !_domainHandler.isConnected()
|
||||
&& !_domainHandler.getPendingDomainID().isNull()
|
||||
&& !_domainHandler.wasConnectionRefused()
|
||||
&& ++numTriggersSinceAPIRefresh > 1) {
|
||||
|
||||
// if we aren't connected to the domain-server, and we have an ID
|
||||
// (that we presume belongs to a domain in the HF Metaverse)
|
||||
// we re-request connection information from the AdressManager
|
||||
// every 2 failing check in attempts to make sure what we have is up to date
|
||||
|
||||
DependencyManager::get<AddressManager>()->refreshPreviousLookup();
|
||||
numTriggersSinceAPIRefresh = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void NodeList::handleDSPathQuery(const QString& newPath) {
|
||||
|
|
|
@ -105,6 +105,7 @@ private slots:
|
|||
void pingPunchForDomainServer();
|
||||
|
||||
void sendKeepAlivePings();
|
||||
|
||||
private:
|
||||
NodeList() : LimitedNodeList(0, 0) { assert(false); } // Not implemented, needed for DependencyManager templates compile
|
||||
NodeList(char ownerType, unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0);
|
||||
|
|
Loading…
Reference in a new issue