Merge pull request #10671 from huffman/feat/replicate-usernamed

Add support for replicating by username
This commit is contained in:
Stephen Birarda 2017-06-13 17:19:42 -07:00 committed by GitHub
commit dadbf445a1
5 changed files with 52 additions and 8 deletions

View file

@ -117,6 +117,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
// if permissions are updated, relay the changes to the Node datastructures
connect(&_settingsManager, &DomainServerSettingsManager::updateNodePermissions,
&_gatekeeper, &DomainGatekeeper::updateNodePermissions);
connect(&_settingsManager, &DomainServerSettingsManager::settingsUpdated,
this, &DomainServer::updateReplicatedNodes);
setupGroupCacheRefresh();
@ -129,6 +131,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
setupNodeListAndAssignments();
updateReplicatedNodes();
if (_type != NonMetaverse) {
// if we have a metaverse domain, we'll use an access token for API calls
resetAccountManagerAccessToken();
@ -958,6 +962,11 @@ void DomainServer::handleConnectedNode(SharedNodePointer newNode) {
emit userConnected();
}
if (shouldReplicateNode(*newNode)) {
qDebug() << "Setting node to replicated: " << newNode->getUUID();
newNode->setIsReplicated(true);
}
// send out this node to our other connected nodes
broadcastNewNode(newNode);
}
@ -2210,12 +2219,37 @@ void DomainServer::refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer&
_unfulfilledAssignments.enqueue(assignment);
}
void DomainServer::nodeAdded(SharedNodePointer node) {
// TODO Check to see if node is in list of replicated nodes
if (node->getType() == NodeType::Agent) {
node->setIsReplicated(true);
void DomainServer::updateReplicatedNodes() {
static const QString REPLICATION_SETTINGS_KEY = "replication";
_replicatedUsernames.clear();
auto settings = _settingsManager.getSettingsMap();
if (settings.contains(REPLICATION_SETTINGS_KEY)) {
auto replicationSettings = settings.value(REPLICATION_SETTINGS_KEY).toMap();
if (replicationSettings.contains("users")) {
auto usersSettings = replicationSettings.value("users").toList();
for (auto& username : usersSettings) {
_replicatedUsernames.push_back(username.toString());
}
}
}
auto nodeList = DependencyManager::get<LimitedNodeList>();
nodeList->eachNode([&](const SharedNodePointer& otherNode) {
if (shouldReplicateNode(*otherNode)) {
qDebug() << "Setting node to replicated: " << otherNode->getUUID();
otherNode->setIsReplicated(true);
}
});
}
bool DomainServer::shouldReplicateNode(const Node& node) {
QString verifiedUsername = node.getPermissions().getVerifiedUserName();
qDebug() << "Verified username: " << verifiedUsername;
auto it = find(_replicatedUsernames.cbegin(), _replicatedUsernames.cend(), verifiedUsername);
return it != _replicatedUsernames.end() && node.getType() == NodeType::Agent;
};
void DomainServer::nodeAdded(SharedNodePointer node) {
// we don't use updateNodeWithData, so add the DomainServerNodeData to the node here
node->setLinkedData(std::unique_ptr<DomainServerNodeData> { new DomainServerNodeData() });
}

View file

@ -102,6 +102,8 @@ private slots:
void handleOctreeFileReplacement(QByteArray octreeFile);
void updateReplicatedNodes();
signals:
void iceServerChanged();
void userConnected();
@ -161,12 +163,16 @@ private:
QJsonObject jsonForSocket(const HifiSockAddr& socket);
QJsonObject jsonObjectForNode(const SharedNodePointer& node);
bool shouldReplicateNode(const Node& node);
void setupGroupCacheRefresh();
QString pathForRedirect(QString path = QString()) const;
SubnetList _acSubnetWhitelist;
std::vector<QString> _replicatedUsernames;
DomainGatekeeper _gatekeeper;
HTTPManager _httpManager;

View file

@ -991,6 +991,7 @@ bool DomainServerSettingsManager::handleAuthenticatedHTTPRequest(HTTPConnection
unpackPermissions();
apiRefreshGroupInformation();
emit updateNodePermissions();
emit settingsUpdated();
}
return true;
@ -1196,13 +1197,14 @@ QJsonObject DomainServerSettingsManager::settingDescriptionFromGroup(const QJson
bool DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject) {
static const QString SECURITY_ROOT_KEY = "security";
static const QString AC_SUBNET_WHITELIST_KEY = "ac_subnet_whitelist";
static const QString REPLICATION_KEY = "replication";
auto& settingsVariant = _configMap.getConfig();
bool needRestart = false;
// Iterate on the setting groups
foreach(const QString& rootKey, postedObject.keys()) {
QJsonValue rootValue = postedObject[rootKey];
const QJsonValue& rootValue = postedObject[rootKey];
if (!settingsVariant.contains(rootKey)) {
// we don't have a map below this key yet, so set it up now
@ -1247,7 +1249,7 @@ bool DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
if (!matchingDescriptionObject.isEmpty()) {
updateSetting(rootKey, rootValue, *thisMap, matchingDescriptionObject);
if (rootKey != SECURITY_ROOT_KEY) {
if (rootKey != SECURITY_ROOT_KEY && rootKey != REPLICATION_KEY) {
needRestart = true;
}
} else {
@ -1261,9 +1263,9 @@ bool DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
// if we matched the setting then update the value
if (!matchingDescriptionObject.isEmpty()) {
QJsonValue settingValue = rootValue.toObject()[settingKey];
const QJsonValue& settingValue = rootValue.toObject()[settingKey];
updateSetting(settingKey, settingValue, *thisMap, matchingDescriptionObject);
if (rootKey != SECURITY_ROOT_KEY || settingKey == AC_SUBNET_WHITELIST_KEY) {
if ((rootKey != SECURITY_ROOT_KEY && rootKey != REPLICATION_KEY) || settingKey == AC_SUBNET_WHITELIST_KEY) {
needRestart = true;
}
} else {

View file

@ -108,6 +108,7 @@ public:
signals:
void updateNodePermissions();
void settingsUpdated();
public slots:
void apiGetGroupIDJSONCallback(QNetworkReply& requestReply);

View file

@ -105,6 +105,7 @@ private:
bool _isUpstream { false };
tbb::concurrent_unordered_set<QUuid, UUIDHasher> _ignoredNodeIDSet;
mutable QReadWriteLock _ignoredNodeIDSetLock;
std::vector<QString> _replicatedUsernames { };
std::atomic_bool _ignoreRadiusEnabled;
};