History

add downstream server settings handling to ThreadedAssignment

Stephen Birarda committed 9 years ago

Commit 4539d611 parent 9fa97d66 files · +54 −6Browse files

Showing the changes to libraries/networking/src/ThreadedAssignment.cpp (1 of 6 files). Show all

Unified · Split

libraries/networking/src/ThreadedAssignment.cpp+35−0
@@ -10,6 +10,7 @@ · 9 unmodified lines
10//10//
11 11
12#include <QtCore/QCoreApplication>12#include <QtCore/QCoreApplication>
13#include <QtCore/QJsonArray>
13#include <QtCore/QJsonObject>14#include <QtCore/QJsonObject>
14#include <QtCore/QThread>15#include <QtCore/QThread>
15#include <QtCore/QTimer>16#include <QtCore/QTimer>
@@ -132,3 +133,37 @@ void ThreadedAssignment::domainSettingsRequestFailed() { · 116 unmodified lines
132 qCDebug(networking) << "Failed to retreive settings object from domain-server. Bailing on assignment.";133 qCDebug(networking) << "Failed to retreive settings object from domain-server. Bailing on assignment.";
133 setFinished(true);134 setFinished(true);
134}135}
136
137void ThreadedAssignment::parseDownstreamServers(const QJsonObject& settingsObject, NodeType_t nodeType) {
138 static const QString REPLICATION_GROUP_KEY = "replication";
139 static const QString DOWNSTREAM_SERVERS_SETTING_KEY = "downstream_servers";
140 if (settingsObject.contains(REPLICATION_GROUP_KEY)) {
141 const QJsonObject replicationObject = settingsObject[REPLICATION_GROUP_KEY].toObject();
142
143 const QJsonArray downstreamServers = replicationObject[DOWNSTREAM_SERVERS_SETTING_KEY].toArray();
144
145 auto nodeList = DependencyManager::get<NodeList>();
146
147 foreach(const QJsonValue& downstreamServerValue, downstreamServers) {
148 const QJsonArray downstreamServer = downstreamServerValue.toArray();
149
150 // make sure we have the number of values we need
151 if (downstreamServer.size() >= 3) {
152 // make sure this is a downstream server that matches our type
153 if (downstreamServer[2].toString() == NodeType::getNodeTypeName(nodeType)) {
154 // read the address and port and construct a HifiSockAddr from them
155 HifiSockAddr downstreamServerAddr {
156 downstreamServer[0].toString(),
157 static_cast<quint16>(downstreamServer[1].toInt())
158 };
159
160 // manually add the downstream node to our node list
161 nodeList->addOrUpdateNode(QUuid::createUuid(), NodeType::downstreamType(nodeType),
162 downstreamServerAddr, downstreamServerAddr);
163
164 }
165 }
166
167 }
168 }
169}