working to integrate serverless domains into history, etc

This commit is contained in:
Seth Alves 2018-02-16 12:58:50 -08:00
parent b5fe5a0c23
commit b2a4181bc0
7 changed files with 62 additions and 54 deletions

View file

@ -2951,14 +2951,12 @@ void Application::setServersEnabled(bool serversEnabled) {
qDebug() << "QQQQ serversEnabled =" << serversEnabled; qDebug() << "QQQQ serversEnabled =" << serversEnabled;
if (_serversEnabled != serversEnabled) { if (_serversEnabled != serversEnabled) {
_serversEnabled = serversEnabled; _serversEnabled = serversEnabled;
// auto nodeList = DependencyManager::get<NodeList>();
auto nodeList = DependencyManager::get<NodeList>(); // nodeList->getDomainHandler().setAPIRefreshTimerEnabled(serversEnabled);
nodeList->getDomainHandler().setAPIRefreshTimerEnabled(serversEnabled); // if (!_serversEnabled) {
// nodeList->reset();
if (!_serversEnabled) { // clearDomainOctreeDetails();
nodeList->reset(); // }
clearDomainOctreeDetails();
}
} }
} }
@ -2969,8 +2967,8 @@ bool Application::visitServerlessDomain(const QString& urlString) {
} }
void Application::loadServerlessDomain(QUrl domainURL) { void Application::loadServerlessDomain(QUrl domainURL) {
resettingDomain(); // resettingDomain();
domainChanged(""); // domainChanged("");
importJSONFromURL(domainURL.toString()); importJSONFromURL(domainURL.toString());
} }

View file

@ -137,7 +137,7 @@ void WindowScriptingInterface::promptAsync(const QString& message, const QString
} }
void WindowScriptingInterface::disconnectedFromDomain() { void WindowScriptingInterface::disconnectedFromDomain() {
emit domainChanged(""); emit domainChanged("", QUrl());
} }
CustomPromptResult WindowScriptingInterface::customPrompt(const QVariant& config) { CustomPromptResult WindowScriptingInterface::customPrompt(const QVariant& config) {

View file

@ -547,7 +547,7 @@ signals:
* *
* Window.domainChanged.connect(onDomainChanged); * Window.domainChanged.connect(onDomainChanged);
*/ */
void domainChanged(const QString& domain); void domainChanged(const QString& domain, const QUrl& serverlessDomainURL);
/**jsdoc /**jsdoc
* Triggered when you try to navigate to a *.json, *.svo, or *.svo.json URL in a Web browser within Interface. * Triggered when you try to navigate to a *.json, *.svo, or *.svo.json URL in a Web browser within Interface.

View file

@ -293,9 +293,9 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) {
return true; return true;
} else if (lookupUrl.scheme() == "http" || lookupUrl.scheme() == "https" || lookupUrl.scheme() == "file") { } else if (lookupUrl.scheme() == "http" || lookupUrl.scheme() == "https" || lookupUrl.scheme() == "file") {
qDebug() << "QQQQ file or http before serverless domain" << lookupUrl.toString();
qDebug() << "QQQQ do http before serverless domain" << lookupUrl.toString();
emit setServersEnabled(false); emit setServersEnabled(false);
setDomainInfo(lookupUrl, QString(), 0, trigger);
emit loadServerlessDomain(lookupUrl); emit loadServerlessDomain(lookupUrl);
emit lookupResultsFinished(); emit lookupResultsFinished();
return true; return true;
@ -387,6 +387,7 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const
QVariantMap domainObject = rootMap[LOCATION_API_DOMAIN_KEY].toMap(); QVariantMap domainObject = rootMap[LOCATION_API_DOMAIN_KEY].toMap();
if (!domainObject.isEmpty()) { if (!domainObject.isEmpty()) {
// XXX serverless domain URL ?
const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address"; const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
const QString DOMAIN_NETWORK_PORT_KEY = "network_port"; const QString DOMAIN_NETWORK_PORT_KEY = "network_port";
const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address"; const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address";
@ -406,7 +407,7 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const
qCDebug(networking) << "Possible domain change required to connect to" << domainHostname qCDebug(networking) << "Possible domain change required to connect to" << domainHostname
<< "on" << domainPort; << "on" << domainPort;
emit possibleDomainChangeRequired(domainHostname, domainPort, domainID); emit possibleDomainChangeRequired(QUrl(), domainHostname, domainPort, domainID);
} else { } else {
QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString(); QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString();
@ -578,7 +579,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString, LookupTri
} }
emit lookupResultsFinished(); emit lookupResultsFinished();
hostChanged = setDomainInfo(domainIPString, domainPort, trigger); hostChanged = setDomainInfo(QUrl(), domainIPString, domainPort, trigger);
return true; return true;
} }
@ -595,7 +596,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString, LookupTri
} }
emit lookupResultsFinished(); emit lookupResultsFinished();
hostChanged = setDomainInfo(domainHostname, domainPort, trigger); hostChanged = setDomainInfo(QUrl(), domainHostname, domainPort, trigger);
return true; return true;
} }
@ -739,7 +740,8 @@ bool AddressManager::setHost(const QString& host, LookupTrigger trigger, quint16
return false; return false;
} }
bool AddressManager::setDomainInfo(const QString& hostname, quint16 port, LookupTrigger trigger) { bool AddressManager::setDomainInfo(const QUrl& serverlessDomainURL,
const QString& hostname, quint16 port, LookupTrigger trigger) {
bool hostChanged = setHost(hostname, trigger, port); bool hostChanged = setHost(hostname, trigger, port);
// clear any current place information // clear any current place information
@ -750,7 +752,7 @@ bool AddressManager::setDomainInfo(const QString& hostname, quint16 port, Lookup
DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress); DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress);
emit possibleDomainChangeRequired(hostname, port, QUuid()); emit possibleDomainChangeRequired(serverlessDomainURL, hostname, port, QUuid());
return hostChanged; return hostChanged;
} }

View file

@ -311,13 +311,15 @@ signals:
/**jsdoc /**jsdoc
* Triggered when a request is made to go to an IP address. * Triggered when a request is made to go to an IP address.
* @function location.possibleDomainChangeRequired * @function location.possibleDomainChangeRequired
* @param {string} serverlessDomainURL - URL for a file-based domain
* @param {string} hostName - The name of the domain to go do. * @param {string} hostName - The name of the domain to go do.
* @param {number} port - The integer number of the network port to connect to. * @param {number} port - The integer number of the network port to connect to.
* @param {Uuid} domainID - The UUID of the domain to go to. * @param {Uuid} domainID - The UUID of the domain to go to.
* @returns {Signal} * @returns {Signal}
*/ */
// No example because this function isn't typically used in scripts. // No example because this function isn't typically used in scripts.
void possibleDomainChangeRequired(const QString& newHostname, quint16 newPort, const QUuid& domainID); void possibleDomainChangeRequired(const QUrl& serverlessDomainURL,
const QString& newHostname, quint16 newPort, const QUuid& domainID);
/**jsdoc /**jsdoc
* Triggered when a request is made to go to a named domain or user. * Triggered when a request is made to go to a named domain or user.
@ -432,7 +434,7 @@ private:
// Set host and port, and return `true` if it was changed. // Set host and port, and return `true` if it was changed.
bool setHost(const QString& host, LookupTrigger trigger, quint16 port = 0); bool setHost(const QString& host, LookupTrigger trigger, quint16 port = 0);
bool setDomainInfo(const QString& hostname, quint16 port, LookupTrigger trigger); bool setDomainInfo(const QUrl& serverlessDomainURL, const QString& hostname, quint16 port, LookupTrigger trigger);
const JSONCallbackParameters& apiCallbackParameters(); const JSONCallbackParameters& apiCallbackParameters();
@ -453,6 +455,7 @@ private:
QString _host; QString _host;
quint16 _port; quint16 _port;
QString _placeName; QString _placeName;
QUrl _filebasedDomainURL; // for serverless domains
QUuid _rootPlaceID; QUuid _rootPlaceID;
PositionGetter _positionGetter; PositionGetter _positionGetter;
OrientationGetter _orientationGetter; OrientationGetter _orientationGetter;
@ -464,7 +467,7 @@ private:
quint64 _lastBackPush = 0; quint64 _lastBackPush = 0;
QString _newHostLookupPath; QString _newHostLookupPath;
QUrl _previousLookup; QUrl _previousLookup;
}; };

View file

@ -48,33 +48,23 @@ DomainHandler::DomainHandler(QObject* parent) :
const int API_REFRESH_TIMEOUT_MSEC = 2500; const int API_REFRESH_TIMEOUT_MSEC = 2500;
_apiRefreshTimer.setInterval(API_REFRESH_TIMEOUT_MSEC); // 2.5s, Qt::CoarseTimer acceptable _apiRefreshTimer.setInterval(API_REFRESH_TIMEOUT_MSEC); // 2.5s, Qt::CoarseTimer acceptable
connect(&_apiRefreshTimer, &QTimer::timeout, [this] { auto addressManager = DependencyManager::get<AddressManager>();
if (_apiRefreshTimerEnabled) { connect(&_apiRefreshTimer, &QTimer::timeout, addressManager.data(), &AddressManager::refreshPreviousLookup);
auto addressManager = DependencyManager::get<AddressManager>();
if (addressManager) {
addressManager->refreshPreviousLookup();
}
}
});
// stop the refresh timer if we connect to a domain // stop the refresh timer if we connect to a domain
connect(this, &DomainHandler::connectedToDomain, &_apiRefreshTimer, &QTimer::stop); connect(this, &DomainHandler::connectedToDomain, &_apiRefreshTimer, &QTimer::stop);
} }
void DomainHandler::setAPIRefreshTimerEnabled(bool enabled) {
_apiRefreshTimerEnabled = enabled;
}
void DomainHandler::disconnect() { void DomainHandler::disconnect() {
// if we're currently connected to a domain, send a disconnect packet on our way out // if we're currently connected to a domain, send a disconnect packet on our way out
if (_isConnected) { if (_isConnected) {
sendDisconnectPacket(); sendDisconnectPacket();
} }
// clear member variables that hold the connection state to a domain // clear member variables that hold the connection state to a domain
_uuid = QUuid(); _uuid = QUuid();
_connectionToken = QUuid(); _connectionToken = QUuid();
_icePeer.reset(); _icePeer.reset();
if (requiresICE()) { if (requiresICE()) {
@ -88,10 +78,10 @@ void DomainHandler::disconnect() {
void DomainHandler::sendDisconnectPacket() { void DomainHandler::sendDisconnectPacket() {
// The DomainDisconnect packet is not verified - we're relying on the eventual addition of DTLS to the // The DomainDisconnect packet is not verified - we're relying on the eventual addition of DTLS to the
// domain-server connection to stop greifing here // domain-server connection to stop greifing here
// construct the disconnect packet once (an empty packet but sourced with our current session UUID) // construct the disconnect packet once (an empty packet but sourced with our current session UUID)
static auto disconnectPacket = NLPacket::create(PacketType::DomainDisconnectRequest, 0); static auto disconnectPacket = NLPacket::create(PacketType::DomainDisconnectRequest, 0);
// send the disconnect packet to the current domain server // send the disconnect packet to the current domain server
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
nodeList->sendUnreliablePacket(*disconnectPacket, _sockAddr); nodeList->sendUnreliablePacket(*disconnectPacket, _sockAddr);
@ -104,7 +94,7 @@ void DomainHandler::clearSettings() {
void DomainHandler::softReset() { void DomainHandler::softReset() {
qCDebug(networking) << "Resetting current domain connection information."; qCDebug(networking) << "Resetting current domain connection information.";
disconnect(); disconnect();
clearSettings(); clearSettings();
_connectionDenialsSinceKeypairRegen = 0; _connectionDenialsSinceKeypairRegen = 0;
@ -127,6 +117,7 @@ void DomainHandler::hardReset() {
_iceServerSockAddr = HifiSockAddr(); _iceServerSockAddr = HifiSockAddr();
_hostname = QString(); _hostname = QString();
_sockAddr.clear(); _sockAddr.clear();
_serverlessDomainURL = QUrl();
_domainConnectionRefusals.clear(); _domainConnectionRefusals.clear();
@ -150,6 +141,7 @@ void DomainHandler::setSockAddr(const HifiSockAddr& sockAddr, const QString& hos
// some callers may pass a hostname, this is not to be used for lookup but for DTLS certificate verification // some callers may pass a hostname, this is not to be used for lookup but for DTLS certificate verification
_hostname = hostname; _hostname = hostname;
_serverlessDomainURL = QUrl();
} }
void DomainHandler::setUUID(const QUuid& uuid) { void DomainHandler::setUUID(const QUuid& uuid) {
@ -159,27 +151,35 @@ void DomainHandler::setUUID(const QUuid& uuid) {
} }
} }
void DomainHandler::setSocketAndID(const QString& hostname, quint16 port, const QUuid& domainID) { void DomainHandler::setSocketAndID(const QUrl& serverlessDomainURL,
const QString& hostname, quint16 port, const QUuid& domainID) {
_pendingDomainID = domainID; _pendingDomainID = domainID;
if (hostname != _hostname || _sockAddr.getPort() != port) { if (serverlessDomainURL != _serverlessDomainURL || hostname != _hostname || _sockAddr.getPort() != port) {
// re-set the domain info so that auth information is reloaded // re-set the domain info so that auth information is reloaded
hardReset(); hardReset();
if (serverlessDomainURL != _serverlessDomainURL) {
_serverlessDomainURL = serverlessDomainURL;
}
if (hostname != _hostname) { if (hostname != _hostname) {
// set the new hostname // set the new hostname
_hostname = hostname; _hostname = hostname;
qCDebug(networking) << "Updated domain hostname to" << _hostname; qCDebug(networking) << "Updated domain hostname to" << _hostname;
// re-set the sock addr to null and fire off a lookup of the IP address for this domain-server's hostname if (!_hostname.isEmpty()) {
qCDebug(networking, "Looking up DS hostname %s.", _hostname.toLocal8Bit().constData()); // re-set the sock addr to null and fire off a lookup of the IP address for this domain-server's hostname
QHostInfo::lookupHost(_hostname, this, SLOT(completedHostnameLookup(const QHostInfo&))); qCDebug(networking, "Looking up DS hostname %s.", _hostname.toLocal8Bit().constData());
QHostInfo::lookupHost(_hostname, this, SLOT(completedHostnameLookup(const QHostInfo&)));
DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SetDomainHostname); DependencyManager::get<NodeList>()->flagTimeForConnectionStep(
LimitedNodeList::ConnectionStep::SetDomainHostname);
UserActivityLogger::getInstance().changedDomain(_hostname); UserActivityLogger::getInstance().changedDomain(_hostname);
}
emit hostnameChanged(_hostname); emit hostnameChanged(_hostname);
} }
@ -197,10 +197,10 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,
if (_iceServerSockAddr.getAddress().toString() != iceServerHostname || id != _pendingDomainID) { if (_iceServerSockAddr.getAddress().toString() != iceServerHostname || id != _pendingDomainID) {
// re-set the domain info to connect to new domain // re-set the domain info to connect to new domain
hardReset(); hardReset();
// refresh our ICE client UUID to something new // refresh our ICE client UUID to something new
_iceClientID = QUuid::createUuid(); _iceClientID = QUuid::createUuid();
_pendingDomainID = id; _pendingDomainID = id;
HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr; HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr;
@ -227,6 +227,7 @@ void DomainHandler::activateICELocalSocket() {
DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SetDomainSocket); DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SetDomainSocket);
_sockAddr = _icePeer.getLocalSocket(); _sockAddr = _icePeer.getLocalSocket();
_hostname = _sockAddr.getAddress().toString(); _hostname = _sockAddr.getAddress().toString();
_serverlessDomainURL = QUrl();
emit completedSocketDiscovery(); emit completedSocketDiscovery();
} }
@ -234,6 +235,7 @@ void DomainHandler::activateICEPublicSocket() {
DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SetDomainSocket); DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SetDomainSocket);
_sockAddr = _icePeer.getPublicSocket(); _sockAddr = _icePeer.getPublicSocket();
_hostname = _sockAddr.getAddress().toString(); _hostname = _sockAddr.getAddress().toString();
_serverlessDomainURL = QUrl();
emit completedSocketDiscovery(); emit completedSocketDiscovery();
} }
@ -271,10 +273,12 @@ void DomainHandler::setIsConnected(bool isConnected) {
_isConnected = isConnected; _isConnected = isConnected;
if (_isConnected) { if (_isConnected) {
emit connectedToDomain(_hostname); emit connectedToDomain(_hostname, _serverlessDomainURL);
// we've connected to new domain - time to ask it for global settings if (!_hostname.isEmpty()) {
requestDomainSettings(); // we've connected to new domain - time to ask it for global settings
requestDomainSettings();
}
} else { } else {
emit disconnectedFromDomain(); emit disconnectedFromDomain();

View file

@ -141,7 +141,8 @@ public:
void setAPIRefreshTimerEnabled(bool enabled); void setAPIRefreshTimerEnabled(bool enabled);
public slots: public slots:
void setSocketAndID(const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT, const QUuid& id = QUuid()); void setSocketAndID(const QUrl& serverlessDomainURL,
const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT, const QUuid& id = QUuid());
void setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id); void setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id);
void processSettingsPacketList(QSharedPointer<ReceivedMessage> packetList); void processSettingsPacketList(QSharedPointer<ReceivedMessage> packetList);
@ -162,7 +163,7 @@ signals:
void completedSocketDiscovery(); void completedSocketDiscovery();
void resetting(); void resetting();
void connectedToDomain(const QString& hostname); void connectedToDomain(const QString& hostname, const QUrl& serverlessDomainURL);
void disconnectedFromDomain(); void disconnectedFromDomain();
void iceSocketAndIDReceived(); void iceSocketAndIDReceived();
@ -181,6 +182,7 @@ private:
void hardReset(); void hardReset();
QUuid _uuid; QUuid _uuid;
QUrl _serverlessDomainURL;
QString _hostname; QString _hostname;
HifiSockAddr _sockAddr; HifiSockAddr _sockAddr;
QUuid _assignmentUUID; QUuid _assignmentUUID;
@ -200,7 +202,6 @@ private:
int _checkInPacketsSinceLastReply { 0 }; int _checkInPacketsSinceLastReply { 0 };
QTimer _apiRefreshTimer; QTimer _apiRefreshTimer;
bool _apiRefreshTimerEnabled { true };
}; };
#endif // hifi_DomainHandler_h #endif // hifi_DomainHandler_h