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
1010 //
1111
1212 #include <QtCore/QCoreApplication>
13+#include <QtCore/QJsonArray>
1314 #include <QtCore/QJsonObject>
1415 #include <QtCore/QThread>
1516 #include <QtCore/QTimer>
@@ -132,3 +133,37 @@ void ThreadedAssignment::domainSettingsRequestFailed() { · 116 unmodified lines
132133 qCDebug(networking) << "Failed to retreive settings object from domain-server. Bailing on assignment.";
133134 setFinished(true);
134135 }
136+
137+void 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+}