From 071a779930321b853fbdbe5b40395a0435530925 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Tue, 11 Jun 2019 14:38:39 -0700 Subject: [PATCH] convert enum reason for disconnect to boolean --- libraries/networking/src/LimitedNodeList.h | 7 +------ libraries/networking/src/NodeList.cpp | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 42fb5311b1..4df6df621f 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -337,12 +337,6 @@ public: NodeType::EntityScriptServer }; - enum DomainConnectReason : quint32 { - START = 0, - RECONNECT - }; - Q_ENUM(DomainConnectReason); - public slots: void reset(); void eraseAllNodes(); @@ -469,6 +463,7 @@ protected: std::unordered_map _connectionIDs; quint64 _nodeConnectTimestamp { 0 }; quint64 _nodeDisconnectTimestamp { 0 }; + bool _wasSilentDomainDisconnect { false }; private slots: void flagTimeForConnectionStep(ConnectionStep connectionStep, quint64 timestamp); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index c352b9f5ea..fa3c40b138 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -113,6 +113,9 @@ NodeList::NodeList(char newOwnerType, int socketListenPort, int dtlsListenPort) connect(&_domainHandler, SIGNAL(connectedToDomain(QUrl)), &_keepAlivePingTimer, SLOT(start())); connect(&_domainHandler, &DomainHandler::disconnectedFromDomain, &_keepAlivePingTimer, &QTimer::stop); + connect(&_domainHandler, &DomainHandler::limitOfSilentDomainCheckInsReached, + this, [this]() {_wasSilentDomainDisconnect = true; }); + // set our sockAddrBelongsToDomainOrNode method as the connection creation filter for the udt::Socket using std::placeholders::_1; _nodeSocket.setConnectionCreationFilterOperator(std::bind(&NodeList::sockAddrBelongsToDomainOrNode, this, _1)); @@ -296,8 +299,6 @@ void NodeList::addSetOfNodeTypesToNodeInterestSet(const NodeSet& setOfNodeTypes) void NodeList::sendDomainServerCheckIn() { - int outstandingCheckins = _domainHandler.getCheckInPacketsSinceLastReply(); - // On ThreadedAssignments (assignment clients), this function // is called by the server check-in timer thread // not the NodeList thread. Calling it on the NodeList thread @@ -417,7 +418,7 @@ void NodeList::sendDomainServerCheckIn() { auto accountManager = DependencyManager::get(); packetStream << FingerprintUtils::getMachineFingerprint(); - packetStream << ((outstandingCheckins >= MAX_SILENT_DOMAIN_SERVER_CHECK_INS) ? RECONNECT : START); + packetStream << quint32(_wasSilentDomainDisconnect ? 1 : 0); if (_nodeDisconnectTimestamp < _nodeConnectTimestamp) { _nodeDisconnectTimestamp = usecTimestampNow(); @@ -451,7 +452,7 @@ void NodeList::sendDomainServerCheckIn() { // Send duplicate check-ins in the exponentially increasing sequence 1, 1, 2, 4, ... static const int MAX_CHECKINS_TOGETHER = 20; static const int REBIND_CHECKIN_COUNT = 2; - + int outstandingCheckins = _domainHandler.getCheckInPacketsSinceLastReply(); if (outstandingCheckins > REBIND_CHECKIN_COUNT) { _nodeSocket.rebind(); } @@ -637,7 +638,6 @@ void NodeList::processDomainServerConnectionTokenPacket(QSharedPointerreadWithoutCopy(NUM_BYTES_RFC4122_UUID))); _domainHandler.clearPendingCheckins(); - _nodeConnectTimestamp = usecTimestampNow(); sendDomainServerCheckIn(); } @@ -678,6 +678,14 @@ void NodeList::processDomainServerList(QSharedPointer message) quint64 domainServerCheckinProcessingTime; packetStream >> domainServerCheckinProcessingTime; + bool newConnection; + packetStream >> newConnection; + + if (newConnection) { + _nodeConnectTimestamp = usecTimestampNow(); + _wasSilentDomainDisconnect = false; + } + qint64 pingLagTime = (now - qint64(connectRequestTimestamp)) / qint64(USECS_PER_MSEC); qint64 domainServerRequestLag = (qint64(domainServerPingSendTime - domainServerCheckinProcessingTime) - qint64(connectRequestTimestamp)) / qint64(USECS_PER_MSEC);;