From 5203113b416070f308759d6627f4a6107b9fb130 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 3 Oct 2014 17:01:33 -0700 Subject: [PATCH] separate ICE ID and domain ID for reconnections to moved domains --- interface/src/Application.cpp | 6 +++--- libraries/networking/src/DomainHandler.cpp | 12 +++++++++--- libraries/networking/src/DomainHandler.h | 3 +++ libraries/networking/src/NodeList.cpp | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d41b50a232..0551886abb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3462,9 +3462,9 @@ void Application::updateWindowTitle(){ void Application::updateLocationInServer() { AccountManager& accountManager = AccountManager::getInstance(); - const QUuid& domainUUID = NodeList::getInstance()->getDomainHandler().getUUID(); + DomainHandler& domainHandler = NodeList::getInstance()->getDomainHandler(); - if (accountManager.isLoggedIn() && !domainUUID.isNull()) { + if (accountManager.isLoggedIn() && domainHandler.isConnected() && !domainHandler.getUUID().isNull()) { // construct a QJsonObject given the user's current address information QJsonObject rootObject; @@ -3478,7 +3478,7 @@ void Application::updateLocationInServer() { const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; locationObject.insert(PATH_KEY_IN_LOCATION, pathString); - locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, domainUUID.toString()); + locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, domainHandler.getUUID().toString()); rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index fecbd1457f..5714e6923d 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -25,6 +25,7 @@ DomainHandler::DomainHandler(QObject* parent) : _uuid(), _sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)), _assignmentUUID(), + _iceDomainID(), _iceClientID(), _iceServerSockAddr(), _icePeer(), @@ -39,9 +40,13 @@ DomainHandler::DomainHandler(QObject* parent) : void DomainHandler::clearConnectionInfo() { _uuid = QUuid(); - _iceServerSockAddr = HifiSockAddr(); _icePeer = NetworkPeer(); + if (requiresICE()) { + // if we connected to this domain with ICE, re-set the socket so we reconnect through the ice-server + _sockAddr.setAddress(QHostAddress::Null); + } + _isConnected = false; emit disconnectedFromDomain(); @@ -65,6 +70,7 @@ void DomainHandler::softReset() { void DomainHandler::hardReset() { softReset(); + _iceDomainID = QUuid(); _hostname = QString(); _sockAddr.setAddress(QHostAddress::Null); } @@ -136,7 +142,7 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, // re-set the domain info to connect to new domain hardReset(); - setUUID(id); + _iceDomainID = id; _iceServerSockAddr = HifiSockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT); // refresh our ICE client UUID to something new @@ -265,7 +271,7 @@ void DomainHandler::processICEResponsePacket(const QByteArray& icePacket) { NetworkPeer packetPeer; iceResponseStream >> packetPeer; - if (packetPeer.getUUID() != _uuid) { + if (packetPeer.getUUID() != _iceDomainID) { qDebug() << "Received a network peer with ID that does not match current domain. Will not attempt connection."; } else { qDebug() << "Received network peer object for domain -" << packetPeer; diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index e9d7fb1725..86c6e6bc57 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -55,6 +55,8 @@ public: const QUuid& getAssignmentUUID() const { return _assignmentUUID; } void setAssignmentUUID(const QUuid& assignmentUUID) { _assignmentUUID = assignmentUUID; } + const QUuid& getICEDomainID() const { return _iceDomainID; } + const QUuid& getICEClientID() const { return _iceClientID; } bool requiresICE() const { return !_iceServerSockAddr.isNull(); } @@ -97,6 +99,7 @@ private: QString _hostname; HifiSockAddr _sockAddr; QUuid _assignmentUUID; + QUuid _iceDomainID; QUuid _iceClientID; HifiSockAddr _iceServerSockAddr; NetworkPeer _icePeer; diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 50539e1196..905fc06eeb 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -342,10 +342,10 @@ void NodeList::handleICEConnectionToDomainServer() { LimitedNodeList::sendHeartbeatToIceServer(_domainHandler.getICEServerSockAddr(), _domainHandler.getICEClientID(), - _domainHandler.getUUID()); + _domainHandler.getICEDomainID()); } else { qDebug() << "Sending ping packets to establish connectivity with domain-server with ID" - << uuidStringWithoutCurlyBraces(_domainHandler.getUUID()); + << uuidStringWithoutCurlyBraces(_domainHandler.getICEDomainID()); // send the ping packet to the local and public sockets for this nodfe QByteArray localPingPacket = constructPingPacket(PingType::Local, false, _domainHandler.getICEClientID());