split port and hostname for cleaner domain changes

This commit is contained in:
Stephen Birarda 2014-12-18 16:17:03 -08:00
parent 087ac1db90
commit 1ab66c2bfe
7 changed files with 40 additions and 63 deletions

View file

@ -309,13 +309,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
// use our MyAvatar position and quat for address manager path
addressManager.setPositionGetter(getPositionForPath);
addressManager.setOrientationGetter(getOrientationForPath);
// handle domain change signals from AddressManager
connect(&addressManager, &AddressManager::possibleDomainChangeRequiredToHostname,
this, &Application::changeDomainHostname);
connect(&addressManager, &AddressManager::possibleDomainChangeRequiredViaICEForID,
&domainHandler, &DomainHandler::setIceServerHostnameAndID);
_settings = new QSettings(this);
_numChangedSettings = 0;
@ -1435,7 +1428,7 @@ void Application::dropEvent(QDropEvent *event) {
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
if (snapshotData) {
if (!snapshotData->getDomain().isEmpty()) {
changeDomainHostname(snapshotData->getDomain());
NodeList::getInstance()->getDomainHandler().setHostnameAndPort(snapshotData->getDomain());
}
_myAvatar->setPosition(snapshotData->getLocation());
@ -3700,19 +3693,6 @@ void Application::updateLocationInServer() {
}
}
void Application::changeDomainHostname(const QString &newDomainHostname) {
NodeList* nodeList = NodeList::getInstance();
if (!nodeList->getDomainHandler().isCurrentHostname(newDomainHostname)) {
// tell the MyAvatar object to send a kill packet so that it dissapears from its old avatar mixer immediately
_myAvatar->sendKillAvatar();
// call the domain hostname change as a queued connection on the nodelist
QMetaObject::invokeMethod(&NodeList::getInstance()->getDomainHandler(), "setHostname",
Q_ARG(const QString&, newDomainHostname));
}
}
void Application::clearDomainOctreeDetails() {
qDebug() << "Clearing domain octree details...";
// reset the environment so that we don't erroneously end up with multiple

View file

@ -335,7 +335,6 @@ signals:
void importDone();
public slots:
void changeDomainHostname(const QString& newDomainHostname);
void domainChanged(const QString& domainHostname);
void updateWindowTitle();
void updateLocationInServer();

View file

@ -173,7 +173,7 @@ void AddressManager::goToAddressFromObject(const QVariantMap& addressMap) {
if (domainObject.contains(DOMAIN_NETWORK_ADDRESS_KEY)) {
QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString();
emit possibleDomainChangeRequiredToHostname(domainHostname);
emit possibleDomainChangeRequired(domainHostname, DEFAULT_DOMAIN_SERVER_PORT);
} else {
QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString();
@ -250,10 +250,15 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
QRegExp ipAddressRegex(IP_ADDRESS_REGEX_STRING);
if (ipAddressRegex.indexIn(lookupString) != -1) {
QString domainIPString = ipAddressRegex.cap(0);
QString domainIPString = ipAddressRegex.cap(1);
qint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT;
if (ipAddressRegex.captureCount() > 1) {
domainPort = (qint16) ipAddressRegex.cap(2).toInt();
}
emit lookupResultsFinished();
setDomainHostnameAndName(domainIPString);
setDomainInfo(domainIPString, domainPort);
return true;
}
@ -261,10 +266,15 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
QRegExp hostnameRegex(HOSTNAME_REGEX_STRING, Qt::CaseInsensitive);
if (hostnameRegex.indexIn(lookupString) != -1) {
QString domainHostname = hostnameRegex.cap(0);
QString domainHostname = hostnameRegex.cap(1);
qint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT;
if (ipAddressRegex.captureCount() > 1) {
domainPort = (qint16) ipAddressRegex.cap(2).toInt();
}
emit lookupResultsFinished();
setDomainHostnameAndName(domainHostname);
setDomainInfo(domainHostname, domainPort);
return true;
}
@ -340,9 +350,9 @@ bool AddressManager::handleUsername(const QString& lookupString) {
}
void AddressManager::setDomainHostnameAndName(const QString& hostname, const QString& domainName) {
void AddressManager::setDomainInfo(const QString &hostname, quint16 port, const QString& domainName) {
_currentDomain = domainName.isEmpty() ? hostname : domainName;
emit possibleDomainChangeRequiredToHostname(hostname);
emit possibleDomainChangeRequired(hostname, port);
}
void AddressManager::goToUser(const QString& username) {

View file

@ -59,7 +59,7 @@ signals:
void lookupResultsFinished();
void lookupResultIsOffline();
void lookupResultIsNotFound();
void possibleDomainChangeRequiredToHostname(const QString& newHostname);
void possibleDomainChangeRequired(const QString& newHostname, quint16 newPort);
void possibleDomainChangeRequiredViaICEForID(const QString& iceServerHostname, const QUuid& domainID);
void locationChangeRequired(const glm::vec3& newPosition,
bool hasOrientationChange, const glm::quat& newOrientation,
@ -70,7 +70,7 @@ private slots:
private:
AddressManager();
void setDomainHostnameAndName(const QString& hostname, const QString& domainName = QString());
void setDomainInfo(const QString& hostname, quint16 port, const QString& domainName = QString());
const JSONCallbackParameters& apiCallbackParameters();

View file

@ -97,39 +97,19 @@ void DomainHandler::setUUID(const QUuid& uuid) {
}
}
QString DomainHandler::hostnameWithoutPort(const QString& hostname) {
int colonIndex = hostname.indexOf(':');
return colonIndex > 0 ? hostname.left(colonIndex) : hostname;
}
bool DomainHandler::isCurrentHostname(const QString& hostname) {
return hostnameWithoutPort(hostname) == _hostname;
}
void DomainHandler::setHostname(const QString& hostname) {
void DomainHandler::setHostnameAndPort(const QString& hostname, quint16 port) {
if (hostname != _hostname) {
if (hostname != _hostname || _sockAddr.getPort() != port) {
// re-set the domain info so that auth information is reloaded
hardReset();
int colonIndex = hostname.indexOf(':');
// the new hostname is everything up to the colon
_hostname = hostname;
if (colonIndex > 0) {
// the user has included a custom DS port with the hostname
// the new hostname is everything up to the colon
_hostname = hostname.left(colonIndex);
// grab the port by reading the string after the colon
_sockAddr.setPort(atoi(hostname.mid(colonIndex + 1, hostname.size()).toLocal8Bit().constData()));
qDebug() << "Updated hostname to" << _hostname << "and port to" << _sockAddr.getPort();
} else {
// no port included with the hostname, simply set the member variable and reset the domain server port to default
_hostname = hostname;
_sockAddr.setPort(DEFAULT_DOMAIN_SERVER_PORT);
}
// grab the port by reading the string after the colon
_sockAddr.setPort(port);
qDebug() << "Updated hostname to" << _hostname << "and port to" << _sockAddr.getPort();
// re-set the sock addr to null and fire off a lookup of the IP address for this domain-server's hostname
qDebug("Looking up DS hostname %s.", _hostname.toLocal8Bit().constData());

View file

@ -37,9 +37,7 @@ public:
const QUuid& getUUID() const { return _uuid; }
void setUUID(const QUuid& uuid);
static QString hostnameWithoutPort(const QString& hostname);
bool isCurrentHostname(const QString& hostname);
const QString& getHostname() const { return _hostname; }
const QHostAddress& getIP() const { return _sockAddr.getAddress(); }
@ -75,7 +73,7 @@ public:
void softReset();
public slots:
void setHostname(const QString& hostname);
void setHostnameAndPort(const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT);
void setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id);
private slots:

View file

@ -18,6 +18,7 @@
#include <LogHandler.h>
#include "AccountManager.h"
#include "AddressManager.h"
#include "Assignment.h"
#include "HifiSockAddr.h"
#include "NodeList.h"
@ -62,6 +63,15 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned
_hasCompletedInitialSTUNFailure(false),
_stunRequestsSinceSuccess(0)
{
AddressManager& addressManager = AddressManager::getInstance();
// handle domain change signals from AddressManager
connect(&addressManager, &AddressManager::possibleDomainChangeRequired,
&_domainHandler, &DomainHandler::setHostnameAndPort);
connect(&addressManager, &AddressManager::possibleDomainChangeRequiredViaICEForID,
&_domainHandler, &DomainHandler::setIceServerHostnameAndID);
// clear our NodeList when the domain changes
connect(&_domainHandler, &DomainHandler::disconnectedFromDomain, this, &NodeList::reset);