mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 15:59:49 +02:00
Declare metadata descriptors
This commit is contained in:
parent
5c293646b9
commit
55e5c1f6e0
3 changed files with 93 additions and 19 deletions
|
@ -15,29 +15,77 @@
|
||||||
|
|
||||||
#include "DomainServerNodeData.h"
|
#include "DomainServerNodeData.h"
|
||||||
|
|
||||||
const QString DomainMetadata::USERS_KEY = "users";
|
const QString DomainMetadata::USERS = "users";
|
||||||
const QString DomainMetadata::USERS_NUM_KEY = "num_users";
|
const QString DomainMetadata::USERS_NUM_TOTAL = "num_users";
|
||||||
const QString DomainMetadata::USERS_HOSTNAMES_KEY = "users_hostnames";
|
const QString DomainMetadata::USERS_NUM_ANON = "num_anon_users";
|
||||||
|
const QString DomainMetadata::USERS_HOSTNAMES = "user_hostnames";
|
||||||
|
// users metadata will appear as (JSON):
|
||||||
|
// { "num_users": Number,
|
||||||
|
// "num_anon_users": Number,
|
||||||
|
// "user_hostnames": { <HOSTNAME>: Number }
|
||||||
|
// }
|
||||||
|
|
||||||
DomainMetadata::DomainMetadata() :
|
const QString DomainMetadata::DESCRIPTORS = "descriptors";
|
||||||
_metadata{{ USERS_KEY, {} }} {
|
const QString DomainMetadata::DESCRIPTORS_DESCRIPTION = "description";
|
||||||
|
const QString DomainMetadata::DESCRIPTORS_CAPACITY = "capacity"; // parsed from security
|
||||||
|
const QString DomainMetadata::DESCRIPTORS_RESTRICTION = "restriction"; // parsed from ACL
|
||||||
|
const QString DomainMetadata::DESCRIPTORS_MATURITY = "maturity";
|
||||||
|
const QString DomainMetadata::DESCRIPTORS_HOSTS = "hosts";
|
||||||
|
const QString DomainMetadata::DESCRIPTORS_TAGS = "tags";
|
||||||
|
// descriptors metadata will appear as (JSON):
|
||||||
|
// { "capacity": Number,
|
||||||
|
// TODO: "hours": String, // UTF-8 representation of the week, split into 15" segments
|
||||||
|
// "restriction": String, // enum of either OPEN, RESTRICTED_HIFI, RESTRICTED_ACL
|
||||||
|
// "maturity": String, // enum corresponding to ESRB ratings
|
||||||
|
// "hosts": [ String ], // capped list of usernames
|
||||||
|
// "description": String, // capped description
|
||||||
|
// TODO: "img": {
|
||||||
|
// "src": String,
|
||||||
|
// "type": String,
|
||||||
|
// "size": Number,
|
||||||
|
// "updated_at": Number,
|
||||||
|
// },
|
||||||
|
// "tags": [ String ], // capped list of tags
|
||||||
|
// }
|
||||||
|
|
||||||
|
// metadata will appear as (JSON):
|
||||||
|
// { users: <USERS>, descriptors: <DESCRIPTORS> }
|
||||||
|
//
|
||||||
|
// it is meant to be sent to and consumed by an external API
|
||||||
|
|
||||||
|
DomainMetadata::DomainMetadata() {
|
||||||
|
_metadata[USERS] = {};
|
||||||
|
_metadata[DESCRIPTORS] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void DomainMetadata::setDescriptors(QVariantMap& settings) {
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
QVariantMap descriptors;
|
||||||
|
|
||||||
|
#if DEV_BUILD || PR_BUILD
|
||||||
|
qDebug() << "Regenerated domain metadata - descriptors:" << descriptors;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainMetadata::usersChanged() {
|
void DomainMetadata::usersChanged() {
|
||||||
static const QString DEFAULT_HOSTNAME = "*";
|
static const QString DEFAULT_HOSTNAME = "*";
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
int numConnectedUnassigned = 0;
|
int numConnected = 0;
|
||||||
|
int numConnectedAnonymously = 0;
|
||||||
QVariantMap userHostnames;
|
QVariantMap userHostnames;
|
||||||
|
|
||||||
// figure out the breakdown of currently connected interface clients
|
// figure out the breakdown of currently connected interface clients
|
||||||
nodeList->eachNode([&numConnectedUnassigned, &userHostnames](const SharedNodePointer& node) {
|
nodeList->eachNode([&numConnected, &numConnectedAnonymously, &userHostnames](const SharedNodePointer& node) {
|
||||||
auto linkedData = node->getLinkedData();
|
auto linkedData = node->getLinkedData();
|
||||||
if (linkedData) {
|
if (linkedData) {
|
||||||
auto nodeData = static_cast<DomainServerNodeData*>(linkedData);
|
auto nodeData = static_cast<DomainServerNodeData*>(linkedData);
|
||||||
|
|
||||||
if (!nodeData->wasAssigned()) {
|
if (!nodeData->wasAssigned()) {
|
||||||
++numConnectedUnassigned;
|
++numConnected;
|
||||||
|
|
||||||
|
// TODO: numConnectedAnonymously
|
||||||
|
|
||||||
// increment the count for this hostname (or the default if we don't have one)
|
// increment the count for this hostname (or the default if we don't have one)
|
||||||
auto placeName = nodeData->getPlaceName();
|
auto placeName = nodeData->getPlaceName();
|
||||||
|
@ -47,10 +95,13 @@ void DomainMetadata::usersChanged() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QVariantMap users = {{ USERS_NUM_KEY, numConnectedUnassigned }, { USERS_HOSTNAMES_KEY, userHostnames }};
|
QVariantMap users = {
|
||||||
_metadata[USERS_KEY] = users;
|
{ USERS_NUM_TOTAL, numConnected },
|
||||||
|
{ USERS_NUM_ANON, numConnectedAnonymously },
|
||||||
|
{ USERS_HOSTNAMES, userHostnames }};
|
||||||
|
_metadata[USERS] = users;
|
||||||
|
|
||||||
#if DEV_BUILD
|
#if DEV_BUILD || PR_BUILD
|
||||||
qDebug() << "Regenerated domain metadata - users:" << users;
|
qDebug() << "Regenerated domain metadata - users:" << users;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,36 @@
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
class DomainMetadata {
|
class DomainMetadata : public QObject {
|
||||||
static const QString USERS_KEY;
|
Q_OBJECT
|
||||||
static const QString USERS_NUM_KEY;
|
|
||||||
static const QString USERS_HOSTNAMES_KEY;
|
static const QString USERS;
|
||||||
|
static const QString USERS_NUM_TOTAL;
|
||||||
|
static const QString USERS_NUM_ANON;
|
||||||
|
static const QString USERS_HOSTNAMES;
|
||||||
|
|
||||||
|
static const QString DESCRIPTORS;
|
||||||
|
static const QString DESCRIPTORS_DESCRIPTION;
|
||||||
|
static const QString DESCRIPTORS_CAPACITY;
|
||||||
|
static const QString DESCRIPTORS_HOURS;
|
||||||
|
static const QString DESCRIPTORS_RESTRICTION;
|
||||||
|
static const QString DESCRIPTORS_MATURITY;
|
||||||
|
static const QString DESCRIPTORS_HOSTS;
|
||||||
|
static const QString DESCRIPTORS_TAGS;
|
||||||
|
static const QString DESCRIPTORS_IMG;
|
||||||
|
static const QString DESCRIPTORS_IMG_SRC;
|
||||||
|
static const QString DESCRIPTORS_IMG_TYPE;
|
||||||
|
static const QString DESCRIPTORS_IMG_SIZE;
|
||||||
|
static const QString DESCRIPTORS_IMG_UPDATED_AT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DomainMetadata();
|
DomainMetadata();
|
||||||
|
|
||||||
QJsonObject get() { return QJsonObject::fromVariantMap(_metadata); }
|
QJsonObject get() { return QJsonObject::fromVariantMap(_metadata); }
|
||||||
QJsonObject getUsers() { return QJsonObject::fromVariantMap(_metadata[USERS_KEY].toMap()); }
|
QJsonObject getUsers() { return QJsonObject::fromVariantMap(_metadata[USERS].toMap()); }
|
||||||
|
QJsonObject getDescriptors() { return QJsonObject::fromVariantMap(_metadata[DESCRIPTORS].toMap()); }
|
||||||
|
|
||||||
|
void setDescriptors(QVariantMap& settings);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void usersChanged();
|
void usersChanged();
|
||||||
|
|
|
@ -94,13 +94,13 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
qRegisterMetaType<DomainServerWebSessionData>("DomainServerWebSessionData");
|
qRegisterMetaType<DomainServerWebSessionData>("DomainServerWebSessionData");
|
||||||
qRegisterMetaTypeStreamOperators<DomainServerWebSessionData>("DomainServerWebSessionData");
|
qRegisterMetaTypeStreamOperators<DomainServerWebSessionData>("DomainServerWebSessionData");
|
||||||
|
|
||||||
// make sure we hear about newly connected nodes from our gatekeeper
|
|
||||||
connect(&_gatekeeper, &DomainGatekeeper::connectedNode, this, &DomainServer::handleConnectedNode);
|
|
||||||
|
|
||||||
// update the metadata when a user (dis)connects
|
// update the metadata when a user (dis)connects
|
||||||
connect(this, &DomainServer::userConnected, &_metadata, &DomainMetadata::usersChanged);
|
connect(this, &DomainServer::userConnected, &_metadata, &DomainMetadata::usersChanged);
|
||||||
connect(this, &DomainServer::userDisconnected, &_metadata, &DomainMetadata::usersChanged);
|
connect(this, &DomainServer::userDisconnected, &_metadata, &DomainMetadata::usersChanged);
|
||||||
|
|
||||||
|
// make sure we hear about newly connected nodes from our gatekeeper
|
||||||
|
connect(&_gatekeeper, &DomainGatekeeper::connectedNode, this, &DomainServer::handleConnectedNode);
|
||||||
|
|
||||||
if (optionallyReadX509KeyAndCertificate() && optionallySetupOAuth()) {
|
if (optionallyReadX509KeyAndCertificate() && optionallySetupOAuth()) {
|
||||||
// we either read a certificate and private key or were not passed one
|
// we either read a certificate and private key or were not passed one
|
||||||
// and completed login or did not need to
|
// and completed login or did not need to
|
||||||
|
@ -116,6 +116,9 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
|
|
||||||
optionallyGetTemporaryName(args);
|
optionallyGetTemporaryName(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the metadata with current descriptors
|
||||||
|
_metadata.setDescriptors(_settingsManager.getSettingsMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
DomainServer::~DomainServer() {
|
DomainServer::~DomainServer() {
|
||||||
|
|
Loading…
Reference in a new issue